From c531eac7903eaf92d343f086a391fb412cf368a6 Mon Sep 17 00:00:00 2001
From: jinlin <jinlin>
Date: 星期四, 14 三月 2024 16:08:28 +0800
Subject: [PATCH] 修改
---
modules/mainPart/src/main/java/com/zt/life/modules/sysPictureBase/controller/SysPictureBaseController.java | 130 +++++++++++++++++++++++++++++++++----------
1 files changed, 99 insertions(+), 31 deletions(-)
diff --git a/modules/mainPart/src/main/java/com/zt/life/modules/sysPictureBase/controller/SysPictureBaseController.java b/modules/mainPart/src/main/java/com/zt/life/modules/sysPictureBase/controller/SysPictureBaseController.java
index 36701f5..ab33e0a 100644
--- a/modules/mainPart/src/main/java/com/zt/life/modules/sysPictureBase/controller/SysPictureBaseController.java
+++ b/modules/mainPart/src/main/java/com/zt/life/modules/sysPictureBase/controller/SysPictureBaseController.java
@@ -1,6 +1,7 @@
package com.zt.life.modules.sysPictureBase.controller;
+import com.spire.xls.Workbook;
import com.zt.common.annotation.LogOperation;
import com.zt.common.constant.Constant;
import com.zt.common.annotation.QueryParam;
@@ -16,13 +17,27 @@
import com.zt.life.modules.sysPictureBase.service.SysPictureBaseService;
import com.zt.life.sys.dto.OssDto;
import com.zt.life.sys.service.SysOssConfigService;
+import com.zt.modules.oss.enums.CloudChannel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;
+
+import javax.imageio.ImageIO;
+import javax.servlet.http.HttpServletResponse;
+import java.awt.image.BufferedImage;
+import java.io.*;
+import java.util.List;
/**
@@ -32,7 +47,7 @@
* @since 1.0.0 2024-02-27
*/
@RestController
-@RequestMapping("/sysPictureBase/SysPictureBase/")
+@RequestMapping("/sysPictureBase/")
@Api(tags = "sys_picture_base")
public class SysPictureBaseController {
@Autowired
@@ -40,56 +55,109 @@
@Autowired
private SysOssConfigService sysOssConfigService;
+ @Value("${zt.oss.local-path}")
+ private String localPath;
@GetMapping("page")
@ApiOperation("鍒嗛〉")
@ApiImplicitParams({
- @ApiImplicitParam(name = Constant.Q.PAGE, value = Constant.QV.PAGE, required = true, dataType = Constant.QT.INT),
- @ApiImplicitParam(name = Constant.Q.LIMIT, value = Constant.QV.LIMIT, required = true, dataType = Constant.QT.INT),
@ApiImplicitParam(name = Constant.Q.ORDER_FIELD, value = Constant.QV.ORDER_FIELD, dataType = Constant.QT.STRING),
@ApiImplicitParam(name = Constant.Q.ORDER, value = Constant.QV.ORDER, dataType = Constant.QT.STRING),
- @ApiImplicitParam(name = "contentType", value = "妫�绱㈠叧閿瓧", dataType = Constant.QT.STRING, format = "CONTENT_TYPE^LK"), @ApiImplicitParam(name = "systemMark", value = "绯荤粺鏍囪瘑", dataType = Constant.QT.STRING, format = "SYSTEM_MARK^LK")})
- public PageResult<SysPictureBase> page(@ApiIgnore @QueryParam QueryFilter queryFilter) {
+ @ApiImplicitParam(name = "productType", value = "妫�绱㈠叧閿瓧", dataType = Constant.QT.STRING, format = "CONTENT_TYPE^LK"), @ApiImplicitParam(name = "systemMark", value = "绯荤粺鏍囪瘑", dataType = Constant.QT.STRING, format = "SYSTEM_MARK^LK")})
+ public Result<List<SysPictureBase>> page(@ApiIgnore @QueryParam QueryFilter queryFilter) {
- return PageResult.ok(sysPictureBaseService.page(queryFilter));
+ return Result.ok(sysPictureBaseService.page(queryFilter));
}
@GetMapping("{id}")
@ApiOperation("淇℃伅")
public Result<SysPictureBase> get(@PathVariable("id") Long id) {
SysPictureBase data = sysPictureBaseService.get(id);
- if (id != null) {
- OssDto ossDto = sysOssConfigService.getOssByBusiType(id, "sys_picture");
- if (ossDto != null) {
- data.setFiles(ossDto);
- }
- }
return Result.ok(data);
}
- @PostMapping
- @ApiOperation("鏂板")
- @LogOperation("鏂板")
- public Result insert(@RequestBody SysPictureBase sysPictureBase) {
- //鏁堥獙鏁版嵁
- ValidatorUtils.validateEntity(sysPictureBase, AddGroup.class, DefaultGroup.class);
- Integer no = sysPictureBaseService.getNo();
- sysPictureBase.setSortNo(no + 1);
- sysPictureBaseService.insert(sysPictureBase);
- sysOssConfigService.updateOss(sysPictureBase.getId(), sysPictureBase.getFiles());// 淇濆瓨闄勪欢
+ @PostMapping("save")
+ @ApiOperation("淇濆瓨")
+ @LogOperation("淇濆瓨")
+ public Result save(@RequestBody MultipartFile file, Long id, Integer isDefault,
+ String name, String contentType, Integer productType, String remark) {
+ SysPictureBase sysPictureBase;
+ if (id != 0) {
+ sysPictureBase = sysPictureBaseService.get(id);
+ sysPictureBase.setIsDefault(isDefault);
+ sysPictureBase.setName(name);
+ sysPictureBase.setContentType(contentType);
+ sysPictureBase.setProductType(productType);
+ sysPictureBase.setRemark(remark);
+ sysPictureBaseService.update(sysPictureBase);
+ } else {
+ sysPictureBase = new SysPictureBase();
+ sysPictureBase.setIsDefault(isDefault);
+ sysPictureBase.setName(name);
+ sysPictureBase.setContentType(contentType);
+ sysPictureBase.setProductType(productType);
+ sysPictureBase.setRemark(remark);
+ sysPictureBaseService.insert(sysPictureBase);
+ }
+ if (sysPictureBase.getIsDefault()==1){
+ sysPictureBaseService.updateByDefault(sysPictureBase.getId(),sysPictureBase.getProductType());
+ sysPictureBaseService.updateProdeuctImg(sysPictureBase.getId(),sysPictureBase.getProductType());
+ }
+ if (file != null) {
+ BufferedImage bufferedImage = null;
+ try {
+ String fileName = file.getOriginalFilename();
+ String[] arr = fileName.split("\\.");
+ String suffixName = arr[arr.length - 1].toLowerCase();
+
+ bufferedImage = ImageIO.read(file.getInputStream());
+ // 瀹藉害
+ int width = bufferedImage.getWidth();
+ sysPictureBase.setWidth(width);
+ // 楂樺害
+ int height = bufferedImage.getHeight();
+ sysPictureBase.setHeight(height);
+ sysPictureBaseService.update(sysPictureBase);
+ String tempUploadDir = localPath + "/product_img/";
+ File dir = new File(tempUploadDir);
+ if (!dir.exists()) {
+ dir.mkdirs();
+ }
+ ImageIO.write(bufferedImage, suffixName, new File(tempUploadDir + sysPictureBase.getId().toString()));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
return Result.ok();
}
- @PutMapping
- @ApiOperation("淇敼")
- @LogOperation("淇敼")
- public Result update(@RequestBody SysPictureBase sysPictureBase) {
- //鏁堥獙鏁版嵁
- ValidatorUtils.validateEntity(sysPictureBase, UpdateGroup.class, DefaultGroup.class);
- sysPictureBaseService.update(sysPictureBase);
- sysOssConfigService.updateOss(sysPictureBase.getId(), sysPictureBase.getFiles());// 淇濆瓨闄勪欢
+ @RequestMapping("/getProductImg")
+ public void getProductImg(HttpServletResponse response, Long id) {
+ try {
+ String tempUploadDir = localPath + "/product_img/" + id;
+ File file = new File(tempUploadDir);
+ //璇诲彇鎸囧畾璺緞涓嬮潰鐨勬枃浠�
+ InputStream in = new FileInputStream(file);
- return Result.ok();
+ OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
+ //鍒涘缓瀛樻斁鏂囦欢鍐呭鐨勬暟缁�
+ byte[] buff = new byte[1024];
+ //鎵�璇诲彇鐨勫唴瀹逛娇鐢╪鏉ユ帴鏀�
+ int n;
+ //褰撴病鏈夎鍙栧畬鏃�,缁х画璇诲彇,寰幆
+ while ((n = in.read(buff)) != -1) {
+ //灏嗗瓧鑺傛暟缁勭殑鏁版嵁鍏ㄩ儴鍐欏叆鍒拌緭鍑烘祦涓�
+ outputStream.write(buff, 0, n);
+ }
+ //寮哄埗灏嗙紦瀛樺尯鐨勬暟鎹繘琛岃緭鍑�
+ outputStream.flush();
+ //鍏虫祦
+ outputStream.close();
+ in.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
@DeleteMapping
--
Gitblit v1.9.1