xiongchao 3 years ago
parent
commit
f3ff8e2d6a

+ 0 - 1
platform-common/pom.xml

@@ -25,7 +25,6 @@
             <artifactId>hutool-all</artifactId>
             <version>${hutool.version}</version>
         </dependency>
-
         <dependency>
             <groupId>org.springframework.security</groupId>
             <artifactId>spring-security-crypto</artifactId>

+ 30 - 0
platform-common/src/main/java/com/platform/common/util/ImageZipUtils.java

@@ -0,0 +1,30 @@
+package com.platform.common.util;
+
+import cn.hutool.core.net.URLEncoder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.charset.Charset;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+/**
+ * @Description 图片压缩工具类
+ * @Author chenyuehu
+ * @Date 2020/2/19
+ * @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
+ */
+public class ImageZipUtils {
+    private static final Logger log = LoggerFactory.getLogger(ImageZipUtils.class);
+
+    private static final int BUFFER_SIZE = 2 * 1024;
+
+
+}

+ 18 - 1
platform-rest/src/main/java/com/platform/rest/controller/mobile/IgnoreController.java

@@ -31,6 +31,7 @@ import com.platform.service.sb.SbInfoService;
 import com.platform.service.upms.SysFileService;
 import lombok.AllArgsConstructor;
 import lombok.SneakyThrows;
+import net.coobird.thumbnailator.Thumbnails;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -40,8 +41,10 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
@@ -204,7 +207,21 @@ public class IgnoreController {
             fileVO.setUrl(path + fileFullName);
             fileVO.setFileFormat(fileType);
             try {
-                FileUtils.uploadFile(file.getBytes(), filePath, fileFullName);
+                if (fileVO.getFileFormat().contains("png") || fileVO.getFileFormat().contains("JPEG")
+                        || fileVO.getFileFormat().contains("jpg") || fileVO.getFileFormat().contains("jpeg")
+                        || fileVO.getFileFormat().contains("PNG") || fileVO.getFileFormat().contains("JPG")) {
+                    File targetFile = new File(filePath);
+                    if (!targetFile.exists()) {
+                        targetFile.mkdirs();
+                    }
+                    FileOutputStream out = new FileOutputStream(filePath + fileFullName);
+                    Thumbnails.of(file.getInputStream()).scale(1).outputQuality(0.2)
+                            .outputFormat(fileFullName.substring(endIndex + 1)).toOutputStream(out);
+                    out.flush();
+                    out.close();
+                } else {
+                    FileUtils.uploadFile(file.getBytes(), filePath, fileFullName);
+                }
             } catch (Exception e) {
                 throw new Exception("上传文件失败:" + e.getMessage());
             }

+ 19 - 1
platform-rest/src/main/java/com/platform/rest/controller/upms/SysFileController.java

@@ -22,7 +22,10 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.File;
+import java.io.FileOutputStream;
 import java.util.Date;
+import net.coobird.thumbnailator.Thumbnails;
 
 /**
  * @Description 文件管理 控制器
@@ -153,8 +156,23 @@ public class SysFileController {
             String filePath = UPLOAD_ROOT_FOLDER + path;
             fileVO.setUrl(path + fileFullName);
             fileVO.setFileFormat(fileType);
+
             try {
-                FileUtils.uploadFile(file.getBytes(), filePath, fileFullName);
+                if (fileVO.getFileFormat().contains("png") || fileVO.getFileFormat().contains("JPEG")
+                        || fileVO.getFileFormat().contains("jpg") || fileVO.getFileFormat().contains("jpeg")
+                        || fileVO.getFileFormat().contains("PNG") || fileVO.getFileFormat().contains("JPG")) {
+                    File targetFile = new File(filePath);
+                    if (!targetFile.exists()) {
+                        targetFile.mkdirs();
+                    }
+                    FileOutputStream out = new FileOutputStream(filePath + fileFullName);
+                    Thumbnails.of(file.getInputStream()).scale(1).outputQuality(0.2)
+                            .outputFormat(fileFullName.substring(endIndex + 1)).toOutputStream(out);
+                    out.flush();
+                    out.close();
+                } else {
+                    FileUtils.uploadFile(file.getBytes(), filePath, fileFullName);
+                }
             } catch (Exception e) {
                 throw new Exception("上传文件失败:" + e.getMessage());
             }

+ 8 - 0
pom.xml

@@ -36,6 +36,14 @@
     </properties>
 
     <dependencies>
+
+        <!-- 图片缩略图 -->
+        <dependency>
+            <groupId>net.coobird</groupId>
+            <artifactId>thumbnailator</artifactId>
+            <version>0.4.8</version>
+        </dependency>
+
         <!--Lombok-->
         <dependency>
             <groupId>org.projectlombok</groupId>