Selaa lähdekoodia

修改文件下载保存接口方式

qxm 4 vuotta sitten
vanhempi
commit
14b8e53505

+ 1 - 1
suishenbang-api/src/main/resources/application-dev.yml

@@ -120,4 +120,4 @@ esign:
 #  签署成功回调url
   signSuccessUrl: http://fanfanweb.iask.in/api/eSign/updateOrderFile
 #  下载后的PDF路径
-  fileUrl: D:/szsm/uploadPath
+  fileUrl: D:/szsm/uploadPath/

+ 46 - 10
suishenbang-api/src/test/java/test/MyTest.java

@@ -6,6 +6,8 @@ import com.dgtly.ApiApplication;
 import com.dgtly.system.domain.CustomersExt;
 import com.dgtly.system.domain.SysUser;
 import com.dgtly.wxportal.service.ESignService;
+import com.dgtly.wxportal.service.IEsignOrganRealVerifyService;
+import com.dgtly.wxportal.service.IEsignPersonRealnVerifyService;
 import com.dgtly.wxportal.service.IEsignSignService;
 import com.dgtly.wxportal.utils.ESign.ESignHttpUtil;
 import com.dgtly.wxportal.utils.ESign.ESignUploadUtil;
@@ -16,6 +18,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -23,7 +28,10 @@ import java.util.Set;
 @SpringBootTest(classes=ApiApplication.class)
 public class MyTest {
 
-
+    @Autowired
+    private IEsignPersonRealnVerifyService personRealnVerifyService;
+    @Autowired
+    private IEsignOrganRealVerifyService organRealVerifyService;
     @Autowired
     private ESignHttpUtil eSignHttpUtil;
     @Autowired
@@ -31,7 +39,7 @@ public class MyTest {
     @Autowired
     private IEsignSignService signService;
     @Test
-    public void test(){
+    public void test() throws Exception {
 
 
         //创建文件
@@ -41,12 +49,12 @@ public class MyTest {
         int result = eSignService.createPersonalAccount(user);*/
 
 
-        CustomersExt customersExt = new CustomersExt();
-        customersExt.setChainsCode("qiaoxiaomingqiye");
-        customersExt.setCreator("7303abf8d1e54308a889ee61db2639da");
-        customersExt.setCustomersName("乔小明企业");
-
-        CustomersExt result = eSignService.createThirdParty(customersExt);
+//        CustomersExt customersExt = new CustomersExt();
+//        customersExt.setChainsCode("qiaoxiaomingqiye");
+//        customersExt.setCreator("7303abf8d1e54308a889ee61db2639da");
+//        customersExt.setCustomersName("乔小明企业");
+//
+//        CustomersExt result = eSignService.createThirdParty(customersExt);
 
 
         //创建文件
@@ -54,7 +62,7 @@ public class MyTest {
         /*个人认证*/
 //        String s = personRealnVerifyService.personRealnVerify("7303abf8d1e54308a889ee61db2639da");
         /*企业认证*/
-//        String s = organRealVerifyService.organRealVerify("85cfb45c3bcb4ba5962ab56cc316c2af","2d977a3e8f14400d8ecede8d7c584813");
+        String s = organRealVerifyService.organRealVerify("60b47892094143be9288bcfa6d5ab697","7303abf8d1e54308a889ee61db2639da");
 
         /** 一步发起签署
          *
@@ -78,12 +86,40 @@ public class MyTest {
 //        /*流程归档*/
 //        String s = signService.processArchiv("0cee5f3db6f8411b9cdefb1c7175cfaf");
         /*签署文件下载*/
-        String s = signService.processDocumentDownload("c35e714481bb4a0288a81cf94bc3508e");
+//        String s = signService.processDocumentDownload("c35e714481bb4a0288a81cf94bc3508e");
+
+//        getURLResource("E:\\测试.pdf","https://esignoss.esign.cn/1111563786/19a14aab-b5d7-405c-a58d-55c337310803/%E5%90%88%E5%90%8C.pdf?Expires=1603179315&OSSAccessKeyId=LTAIdvHfiVrzDKbE&Signature=dl3hGcJ3HQ5%2FDTTN5%2F0UPajobyw%3D");
 
         System.out.println(s);
         System.out.println("111111");
 
     }
 
+    public static void getURLResource(String ourputFile,String urlStr) throws Exception {
+
+        FileWriter fw = new FileWriter(ourputFile);
+
+        PrintWriter pw = new PrintWriter(fw);
+
+        URL resourceUrl = new URL(urlStr);
+
+        InputStream content = (InputStream) resourceUrl.getContent();
+
+        BufferedReader in = new BufferedReader(new InputStreamReader(content));
+
+        String line;
+
+        while ((line = in.readLine()) != null) {
+
+            pw.println(line);
+
+        }
+
+        pw.close();
+
+        fw.close();
+    }
+
+
 
 }

+ 9 - 3
suishenbang-wxportal/suishenbang-wxportal-api/src/main/java/com/dgtly/wxportal/controller/EsignController.java

@@ -9,8 +9,10 @@ import com.dgtly.system.domain.SysUser;
 import com.dgtly.system.service.ICustomersExtService;
 import com.dgtly.system.service.ISysUserExtService;
 import com.dgtly.system.service.ISysUserService;
+import com.dgtly.wxportal.config.ESignConfig;
 import com.dgtly.wxportal.domain.OrderFile;
 import com.dgtly.wxportal.service.*;
+import com.dgtly.wxportal.utils.file.fileDownloadUtil;
 import com.sun.org.apache.xpath.internal.operations.Bool;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
@@ -49,7 +51,8 @@ public class EsignController extends ApiBaseController {
     private ICustomersExtService customersExtService;
     @Autowired
     private ESignService eSignService;
-
+    @Autowired
+    private ESignConfig eSignConfig;
     /**
      * 经销商订单签收方法
      * 没有注册就注册,注册完就认证,然后再点击签署按钮,获取经销商用户id,对应主体id
@@ -70,7 +73,7 @@ public class EsignController extends ApiBaseController {
         String userId = obj.getString("userId");
 
         String businessScene = "订单签收";
-        String fileName = "签收订单.pdf";
+        String fileName = orderId+"_签收订单.pdf";
         /*根据userId查询个人注册后accountId*/
         String signerAccountId = "";
         SysUser sysUser = userService.selectUserById(Long.parseLong(userId));
@@ -121,9 +124,12 @@ public class EsignController extends ApiBaseController {
         String flowId = obj.getString("flowId");
         String fileUrl = signService.processDocumentDownload(flowId);
 
+        /*下载保存签署后的文件,返回文件存储地址*/
+        OrderFile orderFlag = orderFileService.selectOrderFileByFlowId(flowId);
+        fileDownloadUtil.downloadFile(eSignConfig.getFileUrl(),orderFlag.getOrderId()+"_签收订单.pdf",fileUrl);
         OrderFile orderFile = new OrderFile();
         orderFile.setFlowId(flowId);
-        orderFile.setFileUrl(fileUrl);
+        orderFile.setFileUrl(eSignConfig.getFileUrl()+orderFlag.getOrderId()+"_签收订单.pdf");
         orderFileService.updateOrderFileByFlowId(orderFile);
         return AjaxResult.success();
     }

+ 7 - 0
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/mapper/OrderFileMapper.java

@@ -19,6 +19,13 @@ public interface OrderFileMapper
      * @return 订单签收文件
      */
     public OrderFile selectOrderFileById(String orderId);
+    /**
+     * 查询订单签收文件
+     *
+     * @param flowId 订单签收文件ID
+     * @return 订单签收文件
+     */
+    public OrderFile selectOrderFileByFlowId(String flowId);
 
     /**
      * 查询订单签收文件列表

+ 8 - 0
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/IOrderFileService.java

@@ -20,6 +20,14 @@ public interface IOrderFileService
      */
     public OrderFile selectOrderFileById(String orderId);
 
+    /**
+     * 查询订单签收文件
+     *
+     * @param flowId 订单签收文件ID
+     * @return 订单签收文件
+     */
+    public OrderFile selectOrderFileByFlowId(String flowId);
+
     /**
      * 查询订单签收文件列表
      * 

+ 12 - 0
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/impl/OrderFileServiceImpl.java

@@ -34,6 +34,18 @@ public class OrderFileServiceImpl implements IOrderFileService
         return orderFileMapper.selectOrderFileById(orderId);
     }
 
+    /**
+     * 查询订单签收文件
+     *
+     * @param flowId 订单签收文件ID
+     * @return 订单签收文件
+     */
+    @Override
+    public OrderFile selectOrderFileByFlowId(String flowId)
+    {
+        return orderFileMapper.selectOrderFileByFlowId(flowId);
+    }
+
     /**
      * 查询订单签收文件列表
      * 

+ 54 - 0
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/utils/file/fileDownloadUtil.java

@@ -0,0 +1,54 @@
+package com.dgtly.wxportal.utils.file;
+
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+/**
+ * @description:下载文件
+ * @author:qxm
+ * @date:2020/10/20 15:14
+ */
+public class fileDownloadUtil {
+
+    public static void downloadFile(String filePath,String fileName,String httpUrl){
+        BufferedInputStream bis=null;
+        BufferedOutputStream bos=null;
+        try {
+            URL url = new URL(httpUrl);
+            HttpURLConnection connection =  (HttpURLConnection) url.openConnection();
+            connection.setRequestMethod("GET");
+            connection.connect();
+            InputStream is = connection.getInputStream();
+
+            bis = new BufferedInputStream(is);
+
+            File file = new File(filePath+fileName);//E:\test.pdf
+            if (!file.getParentFile().exists())
+            {
+                file.getParentFile().mkdirs();
+            }
+            FileOutputStream fos = new FileOutputStream(file);
+            bos = new BufferedOutputStream(fos);
+            int b = 0;
+            byte[] byArr = new byte[1024*4];
+            while((b=bis.read(byArr))!=-1){
+                bos.write(byArr, 0, b);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }finally{
+            try {
+                if(bis!=null){
+                    bis.close();
+                }
+                if(bos!=null){
+                    bos.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+}

+ 5 - 0
suishenbang-wxportal/suishenbang-wxportal-common/src/main/resources/mapper/wxportal/OrderFileMapper.xml

@@ -58,6 +58,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectOrderFileVo"/>
         where order_id = #{orderId}
     </select>
+
+    <select id="selectOrderFileByFlowId" parameterType="String" resultMap="OrderFileResult">
+        <include refid="selectOrderFileVo"/>
+        where flow_id = #{flowId}
+    </select>
         
     <insert id="insertOrderFile" parameterType="OrderFile">
         insert into ssb_order_file