Procházet zdrojové kódy

修改文件生成路径按照日期生成

qxm před 4 roky
rodič
revize
298fbeefec

+ 0 - 20
suishenbang-wxportal/suishenbang-wxportal-api/src/main/java/com/dgtly/wxportal/controller/EsignController.java

@@ -175,26 +175,6 @@ public class EsignController extends ApiBaseController {
         return AjaxResult.success();
     }
 
-    /*@Async
-    public String notice(OrderFile orderFlag){
-        JSONObject json = new JSONObject();
-//        json.put("flowId", flowId);
-        JSONObject jsonObject = eSignHttpUtil.doGetGetJson(ESignUrl.ProcessExecuteSignersUrl, json,flowId);
-        return jsonObject.toJSONString();
-        return "";
-    }
-
-
-    @Async
-    public void saveFlle(String flowId,OrderFile orderFlag){
-        String fileUrl = signService.processDocumentDownload(flowId);
-        *//*下载保存签署后的文件,返回文件存储地址*//*
-        fileDownloadUtil.downloadFile(Global.getPdfPath(), orderFlag.getOrderId() + "_签收订单.pdf", fileUrl);
-        OrderFile orderFile = new OrderFile();
-        orderFile.setFlowId(flowId);
-        orderFile.setFileUrl(Constants.RESOURCE_PREFIX+"/"+"pdf/"+orderFlag.getOrderId() + "_签收订单.pdf");
-        orderFileService.updateOrderFileByFlowId(orderFile);
-    }*/
 
     /**
      * 查看已签署PDF历史文件

+ 6 - 0
suishenbang-wxportal/suishenbang-wxportal-common/pom.xml

@@ -33,5 +33,11 @@
             <artifactId>itext-asian</artifactId>
             <version>5.2.0</version>
         </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-test</artifactId>
+            <version>5.2.4.RELEASE</version>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 </project>

+ 24 - 4
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/impl/EsignSignServiceImpl.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.dgtly.common.config.Global;
 import com.dgtly.common.constant.Constants;
+import com.dgtly.common.utils.file.FileUploadUtils;
 import com.dgtly.common.utils.http.HttpUtils;
 import com.dgtly.system.domain.*;
 import com.dgtly.wxportal.config.ESignConfig;
@@ -12,14 +13,17 @@ import com.dgtly.wxportal.service.IEsignSignService;
 import com.dgtly.wxportal.service.IOrderFileService;
 import com.dgtly.wxportal.utils.ESign.ESignHttpUtil;
 import com.dgtly.wxportal.utils.ESign.ESignUrl;
+import org.apache.poi.util.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.mock.web.MockMultipartFile;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestClientException;
 import org.springframework.web.client.RestTemplate;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.io.*;
 import java.net.HttpURLConnection;
@@ -199,10 +203,11 @@ public class EsignSignServiceImpl implements IEsignSignService {
 //        System.out.println("executeAysncTask1 method: 执行异步保存{} -------"+ i);
         String fileUrl = processDocumentDownload(flowId);
         /*下载保存签署后的文件,返回文件存储地址*/
-        downloadFile(Global.getPdfPath(), orderFlag.getOrderId() + "_签收订单.pdf", fileUrl);
+        String refile = downloadFile(Global.getPdfPath(), orderFlag.getOrderId() + "_签收订单.pdf", fileUrl);
         OrderFile orderFile = new OrderFile();
         orderFile.setFlowId(flowId);
-        orderFile.setFileUrl(Constants.RESOURCE_PREFIX+"/"+"pdf/"+orderFlag.getOrderId() + "_签收订单.pdf");
+//        orderFile.setFileUrl(Constants.RESOURCE_PREFIX+"/"+"pdf/"+orderFlag.getOrderId() + "_签收订单.pdf");
+        orderFile.setFileUrl(refile);
         orderFileService.updateOrderFileByFlowId(orderFile);
     }
 
@@ -295,9 +300,10 @@ public class EsignSignServiceImpl implements IEsignSignService {
      * @author: qxm      
      * @date: 2020/10/27 9:58
      */ 
-    public static void downloadFile(String filePath,String fileName,String httpUrl){
+    public String downloadFile(String filePath,String fileName,String httpUrl){
         BufferedInputStream bis=null;
         BufferedOutputStream bos=null;
+        FileInputStream inputStream=null;
         try {
             URL url = new URL(httpUrl);
             HttpURLConnection connection =  (HttpURLConnection) url.openConnection();
@@ -306,7 +312,6 @@ public class EsignSignServiceImpl implements IEsignSignService {
             InputStream is = connection.getInputStream();
 
             bis = new BufferedInputStream(is);
-
             File file = new File(filePath+"/"+fileName);//E:\test.pdf
             if (!file.getParentFile().exists())
             {
@@ -319,8 +324,16 @@ public class EsignSignServiceImpl implements IEsignSignService {
             while((b=bis.read(byArr))!=-1){
                 bos.write(byArr, 0, b);
             }
+
+            inputStream = new FileInputStream(file);
+            MultipartFile multipartFile = new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(inputStream));
+            FileUploadUtils.extractFilename(multipartFile);
+            String uploadPath = FileUploadUtils.upload(Global.getPdfPath(), multipartFile);
+            return uploadPath;
+
         } catch (Exception e) {
             e.printStackTrace();
+            return null;
         }finally{
             try {
                 if(bis!=null){
@@ -329,6 +342,13 @@ public class EsignSignServiceImpl implements IEsignSignService {
                 if(bos!=null){
                     bos.close();
                 }
+                if(inputStream!=null){
+                    inputStream.close();
+                }
+                File file1 = new File(filePath+"/"+fileName);
+                if (!file1.isDirectory()) {
+                    file1.delete();
+                }
             } catch (IOException e) {
                 e.printStackTrace();
             }