From 5f0cf49f76141e55cb8b2a5e570806e97167dfed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A3=E5=9C=A3=E5=8D=8E?= <752718920@qq.com> Date: Mon, 24 Jul 2023 23:28:31 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=95=86=E5=93=81=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E7=9A=84=E7=BC=A9=E7=95=A5=E5=9B=BE=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../erp/controller/DepotItemController.java | 9 ++++ .../erp/controller/MaterialController.java | 9 ++++ .../datasource/entities/MaterialVo4Unit.java | 10 ++++ .../erp/service/material/MaterialService.java | 7 +++ .../systemConfig/SystemConfigService.java | 47 +++++++++++++++---- 5 files changed, 74 insertions(+), 8 deletions(-) diff --git a/jshERP-boot/src/main/java/com/jsh/erp/controller/DepotItemController.java b/jshERP-boot/src/main/java/com/jsh/erp/controller/DepotItemController.java index f6087720..50b3931f 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/controller/DepotItemController.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/controller/DepotItemController.java @@ -23,6 +23,7 @@ import jxl.Sheet; import jxl.Workbook; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -70,6 +71,9 @@ public class DepotItemController { @Resource private SystemConfigService systemConfigService; + @Value(value="${file.uploadType}") + private Long fileUploadType; + /** * 根据仓库和商品查询单据列表 * @param mId @@ -255,6 +259,11 @@ public class DepotItemController { item.put("weight", allWeight); item.put("remark", diEx.getRemark()); item.put("imgName", diEx.getImgName()); + if(fileUploadType == 2) { + item.put("imgType", "small"); + } else { + item.put("imgType", ""); + } item.put("linkId", diEx.getLinkId()); item.put("depotId", diEx.getDepotId() == null ? "" : diEx.getDepotId()); item.put("depotName", diEx.getDepotId() == null ? "" : diEx.getDepotName()); diff --git a/jshERP-boot/src/main/java/com/jsh/erp/controller/MaterialController.java b/jshERP-boot/src/main/java/com/jsh/erp/controller/MaterialController.java index 61bcf36a..4dfbd624 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/controller/MaterialController.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/controller/MaterialController.java @@ -16,6 +16,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -51,6 +52,9 @@ public class MaterialController { @Resource private DepotService depotService; + @Value(value="${file.uploadType}") + private Long fileUploadType; + /** * 检查商品是否存在 * @param id @@ -263,6 +267,11 @@ public class MaterialController { item.put("stock", stock); item.put("expand", materialService.getMaterialOtherByParam(mpArr, material)); item.put("imgName", material.getImgName()); + if(fileUploadType == 2) { + item.put("imgType", "small"); + } else { + item.put("imgType", ""); + } dataArray.add(item); } } diff --git a/jshERP-boot/src/main/java/com/jsh/erp/datasource/entities/MaterialVo4Unit.java b/jshERP-boot/src/main/java/com/jsh/erp/datasource/entities/MaterialVo4Unit.java index 0a26b368..f79ae494 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/datasource/entities/MaterialVo4Unit.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/datasource/entities/MaterialVo4Unit.java @@ -47,6 +47,8 @@ public class MaterialVo4Unit extends Material{ */ private String bigUnitStock; + private String imgType; + public String getUnitName() { return unitName; } @@ -206,4 +208,12 @@ public class MaterialVo4Unit extends Material{ public void setBigUnitStock(String bigUnitStock) { this.bigUnitStock = bigUnitStock; } + + public String getImgType() { + return imgType; + } + + public void setImgType(String imgType) { + this.imgType = imgType; + } } \ No newline at end of file diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java index c5a77c7a..fb363560 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java @@ -24,6 +24,7 @@ import jxl.Sheet; import jxl.Workbook; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.context.request.RequestContextHolder; @@ -76,6 +77,9 @@ public class MaterialService { @Resource private MaterialExtendService materialExtendService; + @Value(value="${file.uploadType}") + private Long fileUploadType; + public Material getMaterial(long id)throws Exception { Material result=null; try{ @@ -131,6 +135,9 @@ public class MaterialService { if (null != list && list.size()>0) { Map currentStockMap = getCurrentStockMapByMaterialList(list); for (MaterialVo4Unit m : list) { + if(fileUploadType == 2) { + m.setImgType("small"); + } m.setMaterialOther(getMaterialOtherByParam(mpArr, m)); m.setStock(currentStockMap.get(m.getId())!=null? currentStockMap.get(m.getId()): BigDecimal.ZERO); m.setBigUnitStock(getBigUnitStock(m.getStock(), m.getUnitId())); diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/systemConfig/SystemConfigService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/systemConfig/SystemConfigService.java index f748d3d9..6cb5decf 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/systemConfig/SystemConfigService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/systemConfig/SystemConfigService.java @@ -32,13 +32,13 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.imageio.ImageIO; +import javax.imageio.stream.ImageOutputStream; import javax.servlet.http.HttpServletRequest; import java.awt.*; import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; import java.util.Date; import java.util.List; @@ -174,7 +174,7 @@ public class SystemConfigService { * @param name 自定义文件名 * @return */ - public String uploadLocal(MultipartFile mf, String bizPath, String name, HttpServletRequest request) { + public String uploadLocal(MultipartFile mf, String bizPath, String name, HttpServletRequest request) throws Exception { try { if(StringUtil.isEmpty(bizPath)){ bizPath = ""; @@ -202,6 +202,17 @@ public class SystemConfigService { String savePath = file.getPath() + File.separator + fileName; File savefile = new File(savePath); FileCopyUtils.copy(mf.getBytes(), savefile); + // 保存缩略图 + // String fileUrl = getFileUrlLocal(bizPath + File.separator + fileName); + // InputStream imgInputStream = new BufferedInputStream(new FileInputStream(fileUrl)); + // BufferedImage smallImage = getImageMini(imgInputStream, 80); + // int index = fileName.lastIndexOf("."); + // String ext = fileName.substring(index + 1); + // String smallUrl = filePath + "-small" + File.separator + bizPath + File.separator + fileName; + // FileUtils.createFile(smallUrl); + // File saveSmallFile = new File(smallUrl); + // ImageIO.write(smallImage, ext, saveSmallFile); + // 返回路径 String dbpath = null; if(StringUtil.isNotEmpty(bizPath)){ dbpath = bizPath + File.separator + fileName; @@ -251,6 +262,7 @@ public class SystemConfigService { } String filePathStr = StringUtil.isNotEmpty(filePath)? filePath.substring(1):""; String objectName = filePathStr + "/" + bizPath + "/" + fileName; + String smallObjectName = filePathStr + "-small/" + bizPath + "/" + fileName; // 如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。 byte [] byteArr = mf.getBytes(); @@ -258,11 +270,30 @@ public class SystemConfigService { OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); try { + // 保存原文件 InputStream inputStream = new ByteArrayInputStream(byteArr); - // 创建PutObjectRequest对象。 PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, inputStream); - // 创建PutObject请求。 - PutObjectResult result = ossClient.putObject(putObjectRequest); + ossClient.putObject(putObjectRequest); + // 如果是图片-保存缩略图 + int index = fileName.lastIndexOf("."); + String ext = fileName.substring(index + 1); + if(ext.contains("gif") || ext.contains("jpg") || ext.contains("jpeg") || ext.contains("png") + || ext.contains("GIF") || ext.contains("JPG") || ext.contains("JPEG") || ext.contains("PNG")) { + String fileUrl = getFileUrlAliOss(bizPath + "/" + fileName); + URL url = new URL(fileUrl); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + conn.setConnectTimeout(5 * 1000); + InputStream imgInputStream = conn.getInputStream();// 通过输入流获取图片数据 + BufferedImage smallImage = getImageMini(imgInputStream, 80); + ByteArrayOutputStream bs = new ByteArrayOutputStream(); + ImageOutputStream imOut = ImageIO.createImageOutputStream(bs); + ImageIO.write(smallImage, ext, imOut); + InputStream isImg = new ByteArrayInputStream(bs.toByteArray()); + PutObjectRequest putSmallObjectRequest = new PutObjectRequest(bucketName, smallObjectName, isImg); + ossClient.putObject(putSmallObjectRequest); + } + // 返回路径 return bizPath + "/" + fileName; } catch (OSSException oe) { logger.error("Caught an OSSException, which means your request made it to OSS, "