瀏覽代碼

图片矫正,附件排序

Administrator 8 月之前
父節點
當前提交
5a401847b5

+ 34 - 5
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java

@@ -83,6 +83,17 @@ public class CommonController {
     @PostMapping("/upload")
     public AjaxResult uploadFile(MultipartFile file) throws Exception {
         try {
+            String extension = FileUploadUtils.getExtension(file);
+            if("bmp".equals(extension) || "gif".equals(extension) || "jpg".equals(extension) || "jpeg".equals(extension) || "png".equals(extension)){
+                MultipartFile  multipartFile = ImageSizeUtil.compressImg(file);
+                //压缩图片
+                MultipartFile multipartFileCorrection = ImageSizeUtil.compressImg(multipartFile);
+                //矫正
+                file = FileUploadUtils.imageCorrection(multipartFileCorrection);
+                if (file == null){
+                    return AjaxResult.error("图片不合规");
+                }
+            }
             // 上传文件路径
             String filePath = RuoYiConfig.getUploadPath();
             // 上传并返回新文件名称
@@ -106,14 +117,21 @@ public class CommonController {
      * 按照项目编号创建文件夹通用上传请求(单个)
      */
     @PostMapping("/uploadNew")
-    public AjaxResult uploadNewFile(@RequestParam("file") MultipartFile multipartFile, @RequestParam("loanApplicationNumber") String loanApplicationNumber, @RequestParam("fileName") String originalFilename) throws Exception {
+    public AjaxResult uploadNewFile(@RequestParam("file") MultipartFile file, @RequestParam("loanApplicationNumber") String loanApplicationNumber, @RequestParam("fileName") String originalFilename) throws Exception {
         try {
-            //压缩图片
-            MultipartFile file = multipartFile;
-            String extension = FileUploadUtils.getExtension(multipartFile);
+            String extension = FileUploadUtils.getExtension(file);
             if("bmp".equals(extension) || "gif".equals(extension) || "jpg".equals(extension) || "jpeg".equals(extension) || "png".equals(extension)){
-                file = ImageSizeUtil.compressImg(multipartFile);
+                MultipartFile  multipartFile = ImageSizeUtil.compressImg(file);
+                //压缩图片
+                MultipartFile multipartFileCorrection = ImageSizeUtil.compressImg(multipartFile);
+                //矫正
+                 file = FileUploadUtils.imageCorrection(multipartFileCorrection);
+                if (file == null){
+                    return AjaxResult.error("图片不合规");
+                }
             }
+
+
             // 上传文件路径
             String filePath = RuoYiConfig.getUploadPath();
             if ("其他附件".equals(originalFilename)) {
@@ -143,6 +161,17 @@ public class CommonController {
     @PreAuthorize("@ss.hasPermi('common:upload:uploadNewOcr')")
     public AjaxResult uploadNewOcrFile(@RequestParam("file") MultipartFile file, @RequestParam("loanApplicationNumber") String loanApplicationNumber, @RequestParam("fileName") String originalFilename) throws Exception {
         try {
+            String extension = FileUploadUtils.getExtension(file);
+            if("bmp".equals(extension) || "gif".equals(extension) || "jpg".equals(extension) || "jpeg".equals(extension) || "png".equals(extension)){
+                MultipartFile  multipartFile = ImageSizeUtil.compressImg(file);
+                //压缩图片
+                MultipartFile multipartFileCorrection = ImageSizeUtil.compressImg(multipartFile);
+                //矫正
+                file = FileUploadUtils.imageCorrection(multipartFileCorrection);
+                if (file == null){
+                    return AjaxResult.error("图片不合规");
+                }
+            }
             // 上传文件路径
             String filePath = RuoYiConfig.getUploadPath();
             // 上传并返回新文件名称

+ 64 - 0
ruoyi-common/src/main/java/com/ruoyi/common/enums/FjType.java

@@ -0,0 +1,64 @@
+package com.ruoyi.common.enums;
+
+import org.omg.PortableInterceptor.INACTIVE;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 附件枚举
+ * @Author: tjf
+ * @Date: 2024/9/29 15:31
+ * @Describe:
+ */
+public enum FjType {
+    gdhyjy("gdhyjy",1),
+    rggzb("rggzb",2),
+    sdffpyn("sdffpyn",3),
+    frsfzrmx("frsfzrmx",4),
+    frsfzghm("frsfzghm",5),
+    frjhz("frjhz",6),
+    frhkbsy("frhkbsy",7),
+    frhkbbry("frhkbbry",8),
+    frhkbpoy("frhkbpoy",9),
+    sqqyzxbg("sqqyzxbg",10),
+    glqyzxbg("glqyzxbg",11),
+    qyfrzxbg("qyfrzxbg",12),
+    sjkgrzxbg("sjkgrzxbg",13),
+    nszm("nszm",14),
+    syndcwbb("syndcwbb",15),
+    dqcwbb("dqcwbb",16),
+    gxht("gxht",17),
+    jsyyhdzd("jsyyhdzd",18),
+    zyzhyhls("zyzhyhls",19),
+    jzdcbg("jzdcbg",20),
+    clhgb("clhgb",21),
+    psyjqpb("psyjqpb",22),
+    wtdbht("wtdbht",23);
+
+
+    private final String type;
+    private final Integer sort;
+
+    FjType(String type, Integer sort) {
+        this.type = type;
+        this.sort = sort;
+    }
+    public Integer getSort() {
+        return sort;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+
+    public static Integer getDriverType(String name) {
+        for (FjType type : FjType.values()) {
+            if (name.equals(type.getType())) {
+                return type.sort;
+            }
+        }
+        return 100;
+    }
+}

+ 1 - 1
ruoyi-common/src/main/java/com/ruoyi/common/utils/IdCardUtil.java

@@ -29,6 +29,7 @@ import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
 import com.ruoyi.common.core.domain.AjaxResult;
 import okhttp3.*;
+import org.apache.poi.util.IOUtils;
 
 import javax.crypto.Cipher;
 import javax.crypto.spec.SecretKeySpec;
@@ -1161,7 +1162,6 @@ public class IdCardUtil {
                 JSONArray wordsResult = jsonObject.getJSONArray("words_result");
                 Map<String, Object> bankMap = bankCj(wordsResult);
                 return bankMap;
-
             }
         } catch (IOException e) {
             e.printStackTrace();

+ 58 - 1
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java

@@ -2,9 +2,23 @@ package com.ruoyi.common.utils.file;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
+import java.net.URLEncoder;
 import java.nio.file.Paths;
 import java.util.*;
+
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
+import cn.hutool.json.JSONString;
+import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.beust.jcommander.internal.Maps;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.Base64Util;
+import com.ruoyi.common.utils.HttpUtils;
+import okhttp3.*;
 import org.apache.commons.io.FilenameUtils;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
@@ -13,6 +27,7 @@ import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory;
 import org.apache.pdfbox.pdmodel.graphics.image.LosslessFactory;
 import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
+import org.springframework.mock.web.MockMultipartFile;
 import org.springframework.web.multipart.MultipartFile;
 import com.ruoyi.common.config.RuoYiConfig;
 import com.ruoyi.common.constant.Constants;
@@ -22,6 +37,7 @@ import com.ruoyi.common.exception.file.InvalidExtensionException;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.uuid.Seq;
+
 import javax.imageio.ImageIO;
 
 /**
@@ -299,6 +315,7 @@ public class FileUploadUtils {
 
     /**
      * 合并图片生成PDF保存为文件
+     *
      * @return
      */
     public static AjaxResult createPdfFromImages(List<String> imagePaths, File outputFile) throws IOException {
@@ -308,7 +325,7 @@ public class FileUploadUtils {
             float quality = 0.5f;
             for (String imagePath : imagePaths) {
                 // Load image
-                PDImageXObject image = JPEGFactory.createFromImage(document, ImageIO.read(new File(imagePath)),quality);
+                PDImageXObject image = JPEGFactory.createFromImage(document, ImageIO.read(new File(imagePath)), quality);
 
                 // Calculate scaling factor to fit image within the page minus margins, maintaining aspect ratio
                 float imgWidth = image.getWidth();
@@ -344,4 +361,44 @@ public class FileUploadUtils {
         }
         return null;
     }
+
+    //图片矫正
+    static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();
+
+    public static MultipartFile imageCorrection(MultipartFile file) {
+        String name = file.getName();
+        String originalFilename = file.getOriginalFilename();
+        //文件后缀
+        String extension = getExtension(file);
+        String pre = "data:image/" + extension + ";base64,";
+        try {
+            String imgParam = pre + Base64Util.encode(file.getBytes());
+            String param = "{\"image\":\"" + imgParam + "\"}";
+            /**
+             ** headerMap是添加的请求头,
+             body是传入的参数,这里选择json,后端使用@RequestBody接收
+             */
+            String response = HttpRequest.post("http://69.172.93.148:5000/process")
+                    .header("Content-Type", "application/json")
+                    .header("x-api-key", "123456789")
+                    .body(param)
+                    .execute().body();
+
+            if (StringUtils.isNotBlank(response)) {
+                JSONObject jsonObject = JSONObject.parseObject(response);
+                String image = jsonObject.getString("image");
+                if (StringUtils.isNotBlank(image)){
+                    //有前缀
+                    byte[] decode = Base64.getDecoder().decode(image.split(",")[1]);
+                    // 内容类型
+                    String contentType = "image/" + extension;
+                    return new MockMultipartFile(name, originalFilename, contentType, decode);
+                }
+                return null;
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
 }

+ 19 - 9
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/LoanApplicationServiceImpl.java

@@ -10,6 +10,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.entity.SysRole;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.core.redis.RedisCache;
+import com.ruoyi.common.enums.FjType;
 import com.ruoyi.common.utils.*;
 import com.ruoyi.common.utils.jPush.JPushToolUtil;
 import com.ruoyi.common.utils.poi.ExcelFillUtils;
@@ -438,6 +439,7 @@ public class LoanApplicationServiceImpl implements ILoanApplicationService {
         int rows = loanApplicationMapper.updateLoanApplication(loanApplication);
         return rows > 0 ? AjaxResult.success() : AjaxResult.error();
     }
+
     /**
      * 修改贷款申请主新只新增实际放款金额(万元)实际放款时间
      */
@@ -1539,11 +1541,12 @@ public class LoanApplicationServiceImpl implements ILoanApplicationService {
 
         //反担保人附件
         List<GuaranteeInfoFj> guaranteeInfoFjs = guaranteeInfoFjMapper.selectGuaranteeInfoFjByLoanApplicationId(loanApplicationId);
-
+        Map<File, Integer> map = new HashMap<>();
         List<File> fileList = new ArrayList<>();
         if (loanApplicationFjList != null && loanApplicationFjList.size() > 0) {
             for (LoanApplicationFj loanApplicationFj : loanApplicationFjList) {
-                fileList.add(new File(loanApplicationFj.getUrl().replace("/profile/upload/", filePath)));
+                File file = new File(loanApplicationFj.getUrl().replace("/profile/upload/", filePath));
+                map.put(file, FjType.getDriverType(loanApplicationFj.getType()));
             }
         }
         String corporationFront = loanApplicationOld.getCorporationFront();
@@ -1552,18 +1555,25 @@ public class LoanApplicationServiceImpl implements ILoanApplicationService {
         String spouseBack = loanApplicationOld.getSpouseBack();
 
         if (StringUtils.isNotEmpty(corporationFront)) {
-            fileList.add(new File(corporationFront.replace("/profile/upload/", filePath)));
+            map.put(new File(corporationFront.replace("/profile/upload/", filePath)), FjType.getDriverType("frsfzrmx"));
         }
         if (StringUtils.isNotEmpty(corporationBack)) {
-            fileList.add(new File(corporationBack.replace("/profile/upload/", filePath)));
+            map.put(new File(corporationBack.replace("/profile/upload/", filePath)), FjType.getDriverType("frsfzghm"));
         }
         if (StringUtils.isNotEmpty(spouseFront)) {
-            fileList.add(new File(spouseFront.replace("/profile/upload/", filePath)));
+            map.put(new File(spouseFront.replace("/profile/upload/", filePath)), FjType.getDriverType("frsfzpormx"));
         }
         if (StringUtils.isNotEmpty(spouseBack)) {
-            fileList.add(new File(spouseBack.replace("/profile/upload/", filePath)));
+            map.put(new File(spouseBack.replace("/profile/upload/", filePath)), FjType.getDriverType("frsfzpoghm"));
         }
-
+        //进行排序
+        List<Map.Entry<File, Integer>> list = new ArrayList<>(map.entrySet());
+        // 根据 value 进行排序,这里使用了 lambda 表达式和比较器
+        list.sort(Collections.reverseOrder(Map.Entry.comparingByValue()));
+        for (Map.Entry<File, Integer> fileIntegerEntry : list) {
+            fileList.add(fileIntegerEntry.getKey());
+        }
+        //股东附件
         if (shareholderFjs != null && shareholderFjs.size() > 0) {
             for (ShareholderFj shareholderFj : shareholderFjs) {
                 fileList.add(new File(shareholderFj.getShareholderZxUrl().replace("/profile/upload/", filePath)));
@@ -1922,7 +1932,7 @@ public class LoanApplicationServiceImpl implements ILoanApplicationService {
                 loanApplicationFjTzs.setLoanApplicationId(loanApplication.getLoanApplicationId());
                 loanApplicationFjTzs.setType("jj");
                 List<LoanApplicationFj> loanApplicationFjs = loanApplicationFjMapper.selectLoanApplicationFjList(loanApplicationFjTzs);
-                if(loanApplicationFjs!=null && loanApplicationFjs.size()>0){
+                if (loanApplicationFjs != null && loanApplicationFjs.size() > 0) {
                     loanApplicationFjTzs = loanApplicationFjs.get(0);
                 }
 
@@ -1933,7 +1943,7 @@ public class LoanApplicationServiceImpl implements ILoanApplicationService {
                     chineseNum = userConference.getLineGuarantee();
                 }
                 params.put("chineseNum", chineseNum);
-                if(StringUtils.isNotEmpty(loanApplicationFjTzs.getUrl())){
+                if (StringUtils.isNotEmpty(loanApplicationFjTzs.getUrl())) {
                     // 上传文件路径
                     String filePath = RuoYiConfig.getUploadPath();
                     //服务器路径