liutao пре 7 месеци
родитељ
комит
37a2ea9c5d

+ 0 - 155
src/main/java/com/inkasso/factoring/file/controller/FileController.java

@@ -92,58 +92,6 @@ public class FileController {
         return ResponseData.success();
     }
 
-
-    /**
-     * 预览非图片的</br>
-     * 文档预览,不使用流直接输出到页面上,因为浏览器不支持这样的格式。通常word、excel都是用流下载的</br>
-     * 根据文件的类型,用不同的处理方式来预览文件
-     */
-    @RequestMapping("/fileStorage/preview")
-    public String previewTest(Long fileId, HttpServletResponse response, Model model) {
-        FileStorageDO fileStorage = fileService.getById(fileId);
-        if (null != fileStorage && StringUtil.isNotEmpty(fileStorage.getBusinessType())) {
-            String fileType = fileStorage.getBusinessType();
-            String fileName = fileStorage.getOriginalName().replace(",", "");
-            String sourceFilePath = fileStorage.getAbsolutePath();
-            // 1、处理以及预览doc、docx、rtf文件。使用了openOffice转换成pdf
-            if (fileType.equalsIgnoreCase(".doc") || fileType.equalsIgnoreCase(".docx")
-                    || fileType.equalsIgnoreCase(".rtf") || fileType.equalsIgnoreCase(".wps")) {
-                String destFile = FileUtil.getFileOnlinePreviewPath() + "/word.pdf";
-                File newPDFile = OfficeConverterUtil.office2Pdf(sourceFilePath, destFile);
-                previewPdf(response, newPDFile, fileName, null);
-            } else if (fileType.equalsIgnoreCase(".txt")) {
-                // 2、单独处理txt文件,转换成pdf。没有使用openOffice
-                TextConverterPdfUtil p = TextConverterPdfUtil.getInstance();
-                String pdf = FileUtil.getFileOnlinePreviewPath() + "/txt.pdf";
-                p.text2Pdf(sourceFilePath, pdf);
-                previewPdf(response, new File(pdf), fileName, null);
-            } else if (fileType.equalsIgnoreCase(".xls") || fileType.equalsIgnoreCase(".xlsx")
-                    || fileType.equalsIgnoreCase(".et") || fileType.equalsIgnoreCase(".csv")) {
-                // 3、处理Excel、使用openOffice转换成HTML
-                String destFile = FileUtil.getFileOnlinePreviewPath() + "/excel.html";
-                File htmlFile = OfficeConverterUtil.office2Pdf(sourceFilePath, destFile);
-                //2023.4.25 如果excel嵌套有图片,需要替换下文件的路径
-                htmlFile = replaceImgSrc(htmlFile);
-                previewHtmlFile(response, htmlFile);
-            } else if (fileType.equalsIgnoreCase(".pdf")) {
-                File pdfFile = new File(fileStorage.getAbsolutePath());
-                previewPdf(response, pdfFile, fileName, "original");
-            } else if (fileType.equalsIgnoreCase(".zip") || fileType.equalsIgnoreCase(".rar")) {
-                fileService.downloadFile(fileId);
-            } else {
-                // 图片的预览
-                String filePath = null;
-                if (null != fileStorage) {
-                    filePath = fileStorage.getPath();
-                }
-                model.addAttribute("filePath", filePath);
-                return PREFIX + "fileStoragePreview";
-            }
-        }
-        return null;
-    }
-
-
     /**
      * 文件下载(预览)
      *
@@ -159,107 +107,4 @@ public class FileController {
     }
 
 
-    /**
-     * 以流的方式在浏览器上查看pdf文件
-     */
-    private void previewPdf(HttpServletResponse response, File pdfFile, String fileName, String sourceType) {
-        FileInputStream inputStream;
-        try {
-            if (StringUtil.isNotEmpty(fileName)) {
-                int end = fileName.lastIndexOf(".");
-                String newName = fileName.substring(0, end);
-                if (StringUtil.isNotEmpty(newName)) {
-                    response.setHeader("Content-disposition",
-                            "filename=" + new String(newName.getBytes("gbk"), "iso8859-1") + ".pdf");
-                }
-            }
-            response.setContentType("application/pdf;charset=gb2312");
-            // 通过文件路径获得File对象
-            inputStream = new FileInputStream(pdfFile);
-            OutputStream os = response.getOutputStream();
-            int read;
-            while ((read = inputStream.read()) != -1) {
-                os.write(read);
-            }
-            os.flush();
-            inputStream.close();
-            os.close();
-        } catch (Exception e) {
-
-        }
-        if (StringUtil.isEmpty(sourceType)) {
-            if (pdfFile.exists()) {
-                pdfFile.delete();
-            }
-        }
-    }
-
-    /**
-     * 替换下文件中嵌套的图片的路径
-     *
-     * @param htmlFile
-     * @return
-     */
-    private File replaceImgSrc(File htmlFile) {
-        try {
-            Document doc = Jsoup.parse(htmlFile, "gbk");
-            Elements imgElements = doc.getElementsByTag("IMG");
-            if (imgElements != null && !imgElements.isEmpty()) {
-                for (Element img : imgElements) {
-                    String src = img.attr("SRC");
-                    if (src != null) {
-                        // img.attr("SRC", "/excelImg/" + src);
-                        File imgFile = new File(htmlFile.getParent(), src);
-                        if (imgFile.exists()) {
-                            String type = src.substring(src.lastIndexOf(".") + 1);
-                            String head = "data:image/" + type + ";base64,";
-                            img.attr("SRC", head + Base64.encode(imgFile));
-                            imgFile.delete();
-                        }
-                    }
-                }
-                String html = doc.getElementsByTag("HTML").html();
-
-                if (htmlFile.exists()) {
-                    boolean delete = htmlFile.delete();
-                    if (delete) {
-                        File newFile = new File(htmlFile.getAbsolutePath());
-                        cn.hutool.core.io.FileUtil.appendString(html, newFile, "gbk");
-                        return newFile;
-                    }
-                }
-            }
-            return htmlFile;
-
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        return htmlFile;
-    }
-
-    /**
-     * 用流的方式在浏览器上查看html文件
-     */
-    private void previewHtmlFile(HttpServletResponse response, File xmlFile) {
-        response.setContentType("text/html");
-        FileInputStream inputStream;
-        try {
-            inputStream = new FileInputStream(xmlFile);
-            OutputStream os = response.getOutputStream();
-            int read;
-            while ((read = inputStream.read()) != -1) {
-                os.write(read);
-            }
-            os.flush();
-            inputStream.close();
-            os.close();
-        } catch (Exception e) {
-            e.printStackTrace();
-            log.error("预览Excel文件出错:" + e.getMessage());
-        }
-        if (xmlFile.exists()) {
-            xmlFile.delete();
-        }
-    }
-
 }

+ 201 - 0
src/main/java/com/inkasso/factoring/file/controller/FilePreviewController.java

@@ -0,0 +1,201 @@
+package com.inkasso.factoring.file.controller;
+
+import cn.hutool.core.codec.Base64;
+import cn.hutool.core.collection.CollectionUtil;
+import com.github.pagehelper.util.StringUtil;
+import com.inkasso.adapter.enums.FileBusinessInterface;
+import com.inkasso.adapter.response.ResponseData;
+import com.inkasso.factoring.common.util.onlineConverter.OfficeConverterUtil;
+import com.inkasso.factoring.common.util.onlineConverter.TextConverterPdfUtil;
+import com.inkasso.factoring.file.entity.FileStorageDO;
+import com.inkasso.factoring.file.enums.FileTypeEnum;
+import com.inkasso.factoring.file.service.FileService;
+import com.inkasso.factoring.file.util.FileUtil;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ */
+@Controller
+@RequestMapping("system")
+public class FilePreviewController {
+
+    private Logger log = LogManager.getLogger(FilePreviewController.class);
+    private static String PREFIX = "sys/fileStorage/";
+
+    @Autowired
+    private FileService fileService;
+
+
+    /**
+     * 预览非图片的</br>
+     * 文档预览,不使用流直接输出到页面上,因为浏览器不支持这样的格式。通常word、excel都是用流下载的</br>
+     * 根据文件的类型,用不同的处理方式来预览文件
+     */
+    @RequestMapping("/fileStorage/preview")
+    public String previewTest(Long fileId, HttpServletResponse response, Model model) {
+        FileStorageDO fileStorage = fileService.getById(fileId);
+        if (null != fileStorage && StringUtil.isNotEmpty(fileStorage.getBusinessType())) {
+            String fileType = fileStorage.getType();
+            String fileName = fileStorage.getOriginalName().replace(",", "");
+            String sourceFilePath = fileStorage.getAbsolutePath();
+            // 1、处理以及预览doc、docx、rtf文件。使用了openOffice转换成pdf
+            if (fileType.equalsIgnoreCase(".doc") || fileType.equalsIgnoreCase(".docx")
+                    || fileType.equalsIgnoreCase(".rtf") || fileType.equalsIgnoreCase(".wps")) {
+                String destFile = FileUtil.getFileOnlinePreviewPath() + "/word.pdf";
+                File newPDFile = OfficeConverterUtil.office2Pdf(sourceFilePath, destFile);
+                previewPdf(response, newPDFile, fileName, null);
+            } else if (fileType.equalsIgnoreCase(".txt")) {
+                // 2、单独处理txt文件,转换成pdf。没有使用openOffice
+                TextConverterPdfUtil p = TextConverterPdfUtil.getInstance();
+                String pdf = FileUtil.getFileOnlinePreviewPath() + "/txt.pdf";
+                p.text2Pdf(sourceFilePath, pdf);
+                previewPdf(response, new File(pdf), fileName, null);
+            } else if (fileType.equalsIgnoreCase(".xls") || fileType.equalsIgnoreCase(".xlsx")
+                    || fileType.equalsIgnoreCase(".et") || fileType.equalsIgnoreCase(".csv")) {
+                // 3、处理Excel、使用openOffice转换成HTML
+                String destFile = FileUtil.getFileOnlinePreviewPath() + "/excel.html";
+                File htmlFile = OfficeConverterUtil.office2Pdf(sourceFilePath, destFile);
+                //2023.4.25 如果excel嵌套有图片,需要替换下文件的路径
+                htmlFile = replaceImgSrc(htmlFile);
+                previewHtmlFile(response, htmlFile);
+            } else if (fileType.equalsIgnoreCase(".pdf")) {
+                File pdfFile = new File(fileStorage.getAbsolutePath());
+                previewPdf(response, pdfFile, fileName, "original");
+            } else if (fileType.equalsIgnoreCase(".zip") || fileType.equalsIgnoreCase(".rar")) {
+                fileService.downloadFile(fileId);
+            } else {
+                // 图片的预览
+                String filePath = null;
+                if (null != fileStorage) {
+                    filePath = fileStorage.getPath();
+                }
+                model.addAttribute("filePath", filePath);
+                return PREFIX + "fileStoragePreview";
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 以流的方式在浏览器上查看pdf文件
+     */
+    private void previewPdf(HttpServletResponse response, File pdfFile, String fileName, String sourceType) {
+        FileInputStream inputStream;
+        try {
+            if (StringUtil.isNotEmpty(fileName)) {
+                int end = fileName.lastIndexOf(".");
+                String newName = fileName.substring(0, end);
+                if (StringUtil.isNotEmpty(newName)) {
+                    response.setHeader("Content-disposition",
+                            "filename=" + new String(newName.getBytes("gbk"), "iso8859-1") + ".pdf");
+                }
+            }
+            response.setContentType("application/pdf;charset=gb2312");
+            // 通过文件路径获得File对象
+            inputStream = new FileInputStream(pdfFile);
+            OutputStream os = response.getOutputStream();
+            int read;
+            while ((read = inputStream.read()) != -1) {
+                os.write(read);
+            }
+            os.flush();
+            inputStream.close();
+            os.close();
+        } catch (Exception e) {
+
+        }
+        if (StringUtil.isEmpty(sourceType)) {
+            if (pdfFile.exists()) {
+                pdfFile.delete();
+            }
+        }
+    }
+
+    /**
+     * 替换下文件中嵌套的图片的路径
+     *
+     * @param htmlFile
+     * @return
+     */
+    private File replaceImgSrc(File htmlFile) {
+        try {
+            Document doc = Jsoup.parse(htmlFile, "gbk");
+            Elements imgElements = doc.getElementsByTag("IMG");
+            if (imgElements != null && !imgElements.isEmpty()) {
+                for (Element img : imgElements) {
+                    String src = img.attr("SRC");
+                    if (src != null) {
+                        // img.attr("SRC", "/excelImg/" + src);
+                        File imgFile = new File(htmlFile.getParent(), src);
+                        if (imgFile.exists()) {
+                            String type = src.substring(src.lastIndexOf(".") + 1);
+                            String head = "data:image/" + type + ";base64,";
+                            img.attr("SRC", head + Base64.encode(imgFile));
+                            imgFile.delete();
+                        }
+                    }
+                }
+                String html = doc.getElementsByTag("HTML").html();
+
+                if (htmlFile.exists()) {
+                    boolean delete = htmlFile.delete();
+                    if (delete) {
+                        File newFile = new File(htmlFile.getAbsolutePath());
+                        cn.hutool.core.io.FileUtil.appendString(html, newFile, "gbk");
+                        return newFile;
+                    }
+                }
+            }
+            return htmlFile;
+
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return htmlFile;
+    }
+
+    /**
+     * 用流的方式在浏览器上查看html文件
+     */
+    private void previewHtmlFile(HttpServletResponse response, File xmlFile) {
+        response.setContentType("text/html");
+        FileInputStream inputStream;
+        try {
+            inputStream = new FileInputStream(xmlFile);
+            OutputStream os = response.getOutputStream();
+            int read;
+            while ((read = inputStream.read()) != -1) {
+                os.write(read);
+            }
+            os.flush();
+            inputStream.close();
+            os.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error("预览Excel文件出错:" + e.getMessage());
+        }
+        if (xmlFile.exists()) {
+            xmlFile.delete();
+        }
+    }
+}

+ 14 - 13
src/main/resources/application-dev.yml

@@ -7,7 +7,7 @@ upload:
 datasource:
   master:
     type: com.alibaba.druid.pool.DruidDataSource
-    url: jdbc:mysql://192.168.3.6:3106/factoring_trade_v4_online_new?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true
+    url: jdbc:mysql://192.168.3.6:3106/factoring_trade_v4?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true
     username: root
     password: root
     driver-class-name: com.mysql.cj.jdbc.Driver
@@ -102,6 +102,7 @@ kafubao:
       - purchContract/confirm/doAuth #法大大回调接口
       - user/reSetPassword    #找回密码
       - businessconsulting/businessconsulting #联系我们
+      - system/fileStorage/preview #预览
   authentication: true
   freeNum: 1
 
@@ -131,19 +132,19 @@ fdd:
   signInfoUrl: "http://192.168.3.6:8870/fdd/getSignInfo"
 
 sop:
-  getBusinessByKeyWordUrl: http://localhost:8868/api/trade/findBusinessName
-  comprehensiveRiskInvestigationUrl: http://localhost:8868/api/trade/comprehensiveRiskInvestigation
-  judgmentDocumentsUrl: http://localhost:8868/api/trade/judgmentDocuments
-  dongjiangaoRisksUrl: http://localhost:8868/api/trade/dongjiangaoRisk
-  pubStockUrl: http://localhost:8868/api/trade/pubStock
-  addBusinessUrl: http://localhost:8868/api/trade/addBusiness
-  sixSearchUrl: http://localhost:8868/api/trade/sixSearch
-  twoSearchUrl: http://localhost:8868/api/trade/twoSearch
-  getChangesUrl: http://localhost:8868/api/trade/getChanges
-  getBusinesssScoreUrl: http://localhost:8868/api/trade/getBusinesssScore
+  getBusinessByKeyWordUrl: http://192.168.3.6:8868/api/trade/findBusinessName
+  comprehensiveRiskInvestigationUrl: http://192.168.3.6:8868/api/trade/comprehensiveRiskInvestigation
+  judgmentDocumentsUrl: http://192.168.3.6:8868/api/trade/judgmentDocuments
+  dongjiangaoRisksUrl: http://192.168.3.6:8868/api/trade/dongjiangaoRisk
+  pubStockUrl: http://192.168.3.6:8868/api/trade/pubStock
+  addBusinessUrl: http://192.168.3.6:8868/api/trade/addBusiness
+  sixSearchUrl: http://192.168.3.6:8868/api/trade/sixSearch
+  twoSearchUrl: http://192.168.3.6:8868/api/trade/twoSearch
+  getChangesUrl: http://192.168.3.6:8868/api/trade/getChanges
+  getBusinesssScoreUrl: http://192.168.3.6:8868/api/trade/getBusinesssScore
   synchronizeInformation: http://192.168.3.6:8868/sys/customer/synchronize/information
-  getEnterpriseAreaUrl: http://localhost:8868/api/trade/getEnterpriseArea
-  viewLatestPlanUrl: http://localhost:8868/api/payColl/viewLatestPlan
+  getEnterpriseAreaUrl: http://192.168.3.6:8868/api/trade/getEnterpriseArea
+  viewLatestPlanUrl: http://192.168.3.6:8868/api/payColl/viewLatestPlan
 
 trade:
   biddingManagementStartProcessUrl: http://localhost:8888/api/biddingManagement/startProcess

+ 1 - 0
src/main/resources/application-prod.yml

@@ -105,6 +105,7 @@ kafubao:
       - tradeV4/purchContract/confirm/doAuth #法大大回调接口
       - tradeV4/user/reSetPassword    #找回密码
       - tradeV4/businessconsulting/businessconsulting #联系我们
+      - tradeV4/system/fileStorage/preview #预览
   authentication: true
   freeNum: 1