Browse Source

修改订单签署完成后回调修改订单信息,修改PDF模板

qxm 4 năm trước cách đây
mục cha
commit
d07d705cb5
18 tập tin đã thay đổi với 360 bổ sung50 xóa
  1. 1 1
      suishenbang-system/src/main/java/com/dgtly/system/mapper/CustomersExtMapper.java
  2. 1 1
      suishenbang-system/src/main/java/com/dgtly/system/service/ICustomersExtService.java
  3. 2 2
      suishenbang-system/src/main/java/com/dgtly/system/service/impl/CustomersExtServiceImpl.java
  4. 1 1
      suishenbang-system/src/main/resources/mapper/system/CustomersExtMapper.xml
  5. 81 20
      suishenbang-wxportal/suishenbang-wxportal-api/src/main/java/com/dgtly/wxportal/controller/EsignController.java
  6. 9 0
      suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/domain/EReceivingNote.java
  7. 72 0
      suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/domain/OrderFile.java
  8. 3 0
      suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/mapper/OrderFileMapper.java
  9. 1 1
      suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/ESignService.java
  10. 1 1
      suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/IEReceivingNoteService.java
  11. 7 1
      suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/IEsignSignService.java
  12. 2 0
      suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/IOrderFileService.java
  13. 4 2
      suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/impl/EReceivingNoteServiceImpl.java
  14. 8 8
      suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/impl/ESignServiceImpl.java
  15. 121 5
      suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/impl/EsignSignServiceImpl.java
  16. 5 0
      suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/impl/OrderFileServiceImpl.java
  17. 11 5
      suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/utils/pdf/PDFUtil.java
  18. 30 2
      suishenbang-wxportal/suishenbang-wxportal-common/src/main/resources/mapper/wxportal/OrderFileMapper.xml

+ 1 - 1
suishenbang-system/src/main/java/com/dgtly/system/mapper/CustomersExtMapper.java

@@ -65,5 +65,5 @@ public interface CustomersExtMapper
 
     String selectOrgIdByOrderId(String orderId);
 
-    String selectchainsCodeByOrderId(String orderId);
+    String selectChainsCodeByOrderId(String orderId);
 }

+ 1 - 1
suishenbang-system/src/main/java/com/dgtly/system/service/ICustomersExtService.java

@@ -77,5 +77,5 @@ public interface ICustomersExtService
      * @auther: ZhangDing
      * @date: 2020-10-20 10:05
      */
-    String selectchainsCodeByOrderId(String orderId);
+    String selectChainsCodeByOrderId(String orderId);
 }

+ 2 - 2
suishenbang-system/src/main/java/com/dgtly/system/service/impl/CustomersExtServiceImpl.java

@@ -103,7 +103,7 @@ public class CustomersExtServiceImpl implements ICustomersExtService
     }
 
     @Override
-    public String selectchainsCodeByOrderId(String orderId) {
-        return null;
+    public String selectChainsCodeByOrderId(String orderId) {
+        return customersExtMapper.selectChainsCodeByOrderId(orderId);
     }
 }

+ 1 - 1
suishenbang-system/src/main/resources/mapper/system/CustomersExtMapper.xml

@@ -53,7 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
 
     <!--根据订单id关联订单基础信息表查询经销商代号-->
-    <select id="selectchainsCodeByOrderId" resultType="java.lang.String">
+    <select id="selectChainsCodeByOrderId" resultType="java.lang.String">
         SELECT
             s.chains_code
         FROM

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

@@ -1,5 +1,6 @@
 package com.dgtly.wxportal.controller;
 
+import com.alibaba.fastjson.JSONObject;
 import com.dgtly.common.annotation.ApiPassToken;
 import com.dgtly.common.config.Global;
 import com.dgtly.common.config.ServerConfig;
@@ -16,6 +17,7 @@ import com.dgtly.wxportal.config.ESignConfig;
 import com.dgtly.wxportal.domain.ESignUpPDFModal;
 import com.dgtly.wxportal.domain.OrderFile;
 import com.dgtly.wxportal.service.*;
+import com.dgtly.wxportal.utils.ESign.ESignUrl;
 import com.dgtly.wxportal.utils.file.fileDownloadUtil;
 import com.sun.org.apache.xpath.internal.operations.Bool;
 import io.swagger.annotations.Api;
@@ -23,6 +25,7 @@ import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
@@ -67,12 +70,15 @@ public class EsignController extends ApiBaseController {
      * 没有注册就注册,注册完就认证,然后再点击签署按钮,获取经销商用户id,对应主体id
      * E签宝一步发起签署
      */
-    @ApiOperation(value = "订单签收", notes = "参数:{'orderId':'xxx','userId':'xxx','deliveryNumber':'xxx','shipmentNumber':'xxx','belongTo':'xxx'}" +
+    @ApiOperation(value = "订单签收", notes = "参数:{'orderId':'xxx','userId':'xxx','deliveryNumber':'xxx','shipmentNumber':'xxx','belongTo':'xxx','redirectUrl':'xxx','wareHouseCode':'xxx','wareHouseName':'xxx'}" +
             "\n(orderId:订单编号" +
             "\n(deliveryNumber:交货单号" +
             "\n(shipmentNumber:运单号" +
             "\n(belongTo:经销商代号" +
-            "\n(userId:用户id")
+            "\n(userId:用户id" +
+            "\n(wareHouseCode:仓库代号" +
+            "\n(wareHouseName:仓库名称" +
+            "\n redirectUrl:签署完成跳转地址")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "params", paramType = "body")
     })
@@ -80,12 +86,15 @@ public class EsignController extends ApiBaseController {
     public Object dealerSign() {
 
         ParameterObject obj = getParameterObject();
-        obj.checkParameterNotNull("orderId,userId,deliveryNumber,shipmentNumber,belongTo");
+        obj.checkParameterNotNull("orderId,userId,deliveryNumber,shipmentNumber,belongTo,redirectUrl");
         String orderId = obj.getString("orderId");
         String userId = obj.getString("userId");
         String deliveryNumber = obj.getString("deliveryNumber");
         String shipmentNumber = obj.getString("shipmentNumber");
         String belongTo = obj.getString("belongTo");
+        String wareHouseCode = obj.getString("wareHouseCode");
+        String wareHouseName = obj.getString("wareHouseName");
+        String redirectUrl = obj.getString("redirectUrl");
 
 
         String businessScene = "订单签收";
@@ -99,20 +108,24 @@ public class EsignController extends ApiBaseController {
         /*根据订单id关联查询企业注册后id*/
         String authorizedAccountId =customersExtService.selectOrgIdByOrderId(orderId);
         /* 根据订单id关联查询企业代号*/
-        String chainsCode = customersExtService.selectchainsCodeByOrderId(orderId);
+//        String chainsCode = customersExtService.selectChainsCodeByOrderId(orderId);
         /*首先根据订单id-orderId查询订单是否已被签署*/
 //        OrderFile orderFlag = orderFileService.selectOrderFileById(orderId);
-             ESignUpPDFModal fileModal = eSignService.upload(deliveryNumber,shipmentNumber,belongTo,sysUser.getSysUserExt().getOrgName());
+             ESignUpPDFModal fileModal = eSignService.upload(deliveryNumber,shipmentNumber,belongTo,sysUser.getSysUserExt().getOrgName(),sysUser.getUserName());
             /*1、根据传入订单id,查询订单相关信息生成PDF,调用e签宝上传方法返回文件fileId*/
             Object fileId =fileModal.getFileId();
             /*2、调用E签宝接口一步发起流程,得到返回的流程id*/
-            String flowId = signService.oneStepFlow(businessScene, fileId.toString(),fileModal.getX(),fileModal.getY(), fileName, signerAccountId, authorizedAccountId);
+            String flowId = signService.oneStepFlow(businessScene, fileId.toString(),fileModal.getX(),fileModal.getY(), fileName, signerAccountId, authorizedAccountId,redirectUrl);
             /*3、调用E签宝获取签署地址*/
             String result = signService.processExecuteUrl(flowId, signerAccountId, authorizedAccountId);
             /*4、保存订单id和flowId*/
             OrderFile orderFile = new OrderFile();
             orderFile.setOrderId(orderId);
-            orderFile.setChainsCode(chainsCode);
+            orderFile.setDeliveryNumber(deliveryNumber);
+            orderFile.setShipmentNumber(shipmentNumber);
+            orderFile.setWareHouseCode(wareHouseCode);
+            orderFile.setWareHouseName(wareHouseName);
+            orderFile.setChainsCode(belongTo);
             orderFile.setCustomersCode(authorizedAccountId);
             orderFile.setSignerId(signerAccountId);
             orderFile.setSignerName(sysUser.getUserName());
@@ -121,12 +134,6 @@ public class EsignController extends ApiBaseController {
             return result;
     }
 
-//    @PostMapping("/testPDF")
-//    @ResponseBody
-//    public Map<String,Object> aaa(){
-//       return eSignService.upload("0583133446");
-//    }
-
 
 
     /**
@@ -142,19 +149,73 @@ public class EsignController extends ApiBaseController {
         obj.checkParameterNotNull("flowId,signResult");
         String flowId = obj.getString("flowId");
         String signResult = obj.getString("signResult");
+        OrderFile orderFlag = orderFileService.selectOrderFileByFlowId(flowId);
+
         if ("2".equals(signResult)) {
-            String fileUrl = signService.processDocumentDownload(flowId);
+
+            /*异步调用回调接口*/
+                signService.callbackNotice(orderFlag);
+                /*异步保存文件*/
+                signService.saveFile(flowId,orderFlag);
+
+
+//            String fileUrl = signService.processDocumentDownload(flowId);
             /*下载保存签署后的文件,返回文件存储地址*/
-            OrderFile orderFlag = orderFileService.selectOrderFileByFlowId(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);
+//            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);
         }
         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历史文件
+     */
+    @ApiOperation(value = "查看已签署PDF历史文件",notes = "参数:{'orderId':'xxx','deliveryNumber':'xxxx','shipmentNumber':'xxx'}" +
+            "\n(orderId:订单编号" +
+            "\n(deliveryNumber:交货单号" +
+            "\n(shipmentNumber:运单号")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "params", paramType = "body")
+    })
+    @PostMapping("getHisFile")
+    public Object getHisFile() {
+        ParameterObject obj = getParameterObject();
+        obj.checkParameterNotNull("orderId,deliveryNumber,shipmentNumber");
+        String orderId = obj.getString("orderId");
+        String deliveryNumber = obj.getString("deliveryNumber");
+        String shipmentNumber = obj.getString("shipmentNumber");
+        OrderFile orderFile = orderFileService.selectOrderFileByParam(orderId,deliveryNumber,shipmentNumber);
+        if(orderFile != null){
+            return AjaxResult.success().putKV("url",serverConfig.getUrl()+orderFile.getFileUrl());
+        }else{
+            return AjaxResult.success("文件不存在");
+        }
+
+    }
 
     @ApiOperation(value = "E签宝个人认证", notes = "参数:{'userId':'XXXXXXX','redirectUrl':'xxxx'}" +
             "\n(userId:待认证用户id" +

+ 9 - 0
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/domain/EReceivingNote.java

@@ -41,6 +41,7 @@ public class EReceivingNote extends BaseEntity {
     private String belongTo;
     //  经销商名称
     private String customerName;
+    private String agent;
 
 
     public String getOrderNumber() {
@@ -122,4 +123,12 @@ public class EReceivingNote extends BaseEntity {
     public void setCustomerName(String customerName) {
         this.customerName = customerName;
     }
+
+    public String getAgent() {
+        return agent;
+    }
+
+    public void setAgent(String agent) {
+        this.agent = agent;
+    }
 }

+ 72 - 0
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/domain/OrderFile.java

@@ -19,6 +19,30 @@ public class OrderFile extends BaseEntity
     @Excel(name = "订单id")
     private String orderId;
 
+    /** 交货单号 */
+    @Excel(name = "交货单号")
+    private String deliveryNumber;
+
+    /** 运单号 */
+    @Excel(name = "运单号")
+    private String shipmentNumber;
+
+    /** 仓库代号 */
+    @Excel(name = "仓库代号")
+    private String wareHouseCode;
+
+    /** 仓库名称 */
+    @Excel(name = "仓库名称")
+    private String wareHouseName;
+
+    /** 回调code */
+    @Excel(name = "回调code")
+    private String code;
+
+    /** 回调message */
+    @Excel(name = "回调message")
+    private String message;
+
     /** 经销商代号 */
     @Excel(name = "经销商代号")
     private String chainsCode;
@@ -127,6 +151,54 @@ public class OrderFile extends BaseEntity
         this.chainsName = chainsName;
     }
 
+    public String getDeliveryNumber() {
+        return deliveryNumber;
+    }
+
+    public void setDeliveryNumber(String deliveryNumber) {
+        this.deliveryNumber = deliveryNumber;
+    }
+
+    public String getShipmentNumber() {
+        return shipmentNumber;
+    }
+
+    public void setShipmentNumber(String shipmentNumber) {
+        this.shipmentNumber = shipmentNumber;
+    }
+
+    public String getWareHouseCode() {
+        return wareHouseCode;
+    }
+
+    public void setWareHouseCode(String wareHouseCode) {
+        this.wareHouseCode = wareHouseCode;
+    }
+
+    public String getWareHouseName() {
+        return wareHouseName;
+    }
+
+    public void setWareHouseName(String wareHouseName) {
+        this.wareHouseName = wareHouseName;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
     @Override
     public String toString() {
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

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

@@ -1,6 +1,7 @@
 package com.dgtly.wxportal.mapper;
 
 import com.dgtly.wxportal.domain.OrderFile;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -68,4 +69,6 @@ public interface OrderFileMapper
     public int deleteOrderFileByIds(String[] orderIds);
 
     int updateOrderFileByFlowId(OrderFile orderFile);
+
+    public OrderFile selectOrderFileByParam(@Param("orderId")String orderId, @Param("deliveryNumber")String deliveryNumber, @Param("shipmentNumber")String shipmentNumber);
 }

+ 1 - 1
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/ESignService.java

@@ -25,7 +25,7 @@ public interface ESignService {
    * @param customerName 经销商名和曾
    * @return
    */
-  ESignUpPDFModal upload(String deliveryNumber, String shipmentNumber, String belongTo, String customerName);
+  ESignUpPDFModal upload(String deliveryNumber, String shipmentNumber, String belongTo, String customerName,String userName);
 
 
      String verificationUser();

+ 1 - 1
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/IEReceivingNoteService.java

@@ -25,7 +25,7 @@ public interface IEReceivingNoteService {
      * @return
      */
     EReceivingNote selectEReceivingNote(String deliveryNumber,String shipmentNumber,String belongTo
-            ,String customerName);
+            ,String customerName,String userName);
 
 
 }

+ 7 - 1
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/IEsignSignService.java

@@ -1,5 +1,7 @@
 package com.dgtly.wxportal.service;
 
+import com.dgtly.wxportal.domain.OrderFile;
+
 /**
  * @description:签署服务API
  * @author:qxm
@@ -13,7 +15,7 @@ public interface IEsignSignService {
      * @author: qxm
      * @date: 2020/10/12 16:05
      */
-    public String oneStepFlow(String businessScene, String fileId,float posX,float posY, String fileName, String signerAccountId, String authorizedAccountId);
+    public String oneStepFlow(String businessScene, String fileId,float posX,float posY, String fileName, String signerAccountId, String authorizedAccountId,String redirectUrl);
 
     /**
      * @description: 开启签署流程
@@ -59,4 +61,8 @@ public interface IEsignSignService {
      * @date: 2020/10/12 16:05
      */
     public String processDocumentDownload(String flowId);
+
+    void callbackNotice(OrderFile orderFlag);
+
+    void saveFile(String flowId, OrderFile orderFlag);
 }

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

@@ -69,4 +69,6 @@ public interface IOrderFileService
     public int deleteOrderFileById(String orderId);
 
     public int updateOrderFileByFlowId(OrderFile orderFile);
+
+    OrderFile selectOrderFileByParam(String orderId, String deliveryNumber, String shipmentNumber);
 }

+ 4 - 2
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/impl/EReceivingNoteServiceImpl.java

@@ -41,20 +41,22 @@ public class EReceivingNoteServiceImpl implements IEReceivingNoteService {
 
     @Override
     public EReceivingNote selectEReceivingNote(String deliveryNumber,String shipmentNumber,String belongTo
-                                                                 ,String customerName ) {
+                                                                 ,String customerName,String userName) {
         String url = cloudPath +confirmUrl;
         String queryStr = "?deliveryNumber=%s&shipmentNumber=%s&belongTo=%s";
         queryStr = new Formatter().format(queryStr,deliveryNumber,shipmentNumber,belongTo).toString();
         url = url+queryStr;
         String str= "";
         EReceivingNote receivingNote ;
+
         try{
             str = restTemplate.getForObject(url, String.class);
             System.out.println(str);
             JSONObject json = JSONObject.parseObject(str);
             if(json.getInteger("code")==200){
                  receivingNote = json.getObject("data",EReceivingNote.class);
-
+                receivingNote.setCustomerName(customerName);
+                receivingNote.setAgent(userName);
             }else{
                 throw new BaseException("order",json.getString("message"));
             }

+ 8 - 8
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/impl/ESignServiceImpl.java

@@ -52,9 +52,9 @@ public class ESignServiceImpl implements ESignService {
     private IEReceivingNoteService iMetaHanaSalesOrderService;
 
     @Override
-    public ESignUpPDFModal upload(String deliveryNumber,String shipmentNumber,String belongTo,String customerName) {
+    public ESignUpPDFModal upload(String deliveryNumber,String shipmentNumber,String belongTo,String customerName,String userName) {
 
-        EReceivingNote receivingNote = iMetaHanaSalesOrderService.selectEReceivingNote(deliveryNumber,shipmentNumber,belongTo,customerName);
+        EReceivingNote receivingNote = iMetaHanaSalesOrderService.selectEReceivingNote(deliveryNumber,shipmentNumber,belongTo,customerName,userName);
         Map<String,Object> map = new HashMap<>();
         //创建PDF
         ESignUpPDFModal fileModal = creatPdf(receivingNote);
@@ -192,7 +192,7 @@ public class ESignServiceImpl implements ESignService {
             file.createNewFile();
 
             PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
-            writer.setPageEvent(new Watermark("我是水印"));// 水印
+//            writer.setPageEvent(new Watermark("我是水印"));// 水印
 //                writer.setPageEvent(new MyHeaderFooter());// 页眉/页脚
 
             // 3.打开文档
@@ -212,11 +212,11 @@ public class ESignServiceImpl implements ESignService {
             e.printStackTrace();
         }
         //计算宽高
-        Float fosX = 240F;
-        Float fosY = 620F;
-        for (int i =0;i<size;i++){
-           fosY = fosY-11f;
-        }
+        Float fosX = 310F;
+        Float fosY = 520F;
+//        for (int i =0;i<size;i++){
+//           fosY = fosY-11f;
+//        }
         res.setX(fosX);
         res.setY(fosY);
         res.setFilePath(fileUrl);

+ 121 - 5
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/impl/EsignSignServiceImpl.java

@@ -2,14 +2,28 @@ package com.dgtly.wxportal.service.impl;
 
 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.http.HttpUtils;
 import com.dgtly.system.domain.*;
 import com.dgtly.wxportal.config.ESignConfig;
+import com.dgtly.wxportal.domain.OrderFile;
 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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestClientException;
+import org.springframework.web.client.RestTemplate;
 
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -20,11 +34,21 @@ import java.util.List;
  */
 @Service
 public class EsignSignServiceImpl implements IEsignSignService {
+
+    private static final Logger logger = LoggerFactory.getLogger(EsignSignServiceImpl.class);
+
     @Autowired
     private ESignHttpUtil eSignHttpUtil;
     @Autowired
     private ESignConfig eSignConfig;
-
+    @Autowired
+    private IOrderFileService orderFileService;
+    @Autowired
+    private RestTemplate restTemplate;
+    @Value(value = "${ruoyi.cloudPath}")
+    private String cloudPath;
+    //完成收货回调
+    private String confirmUrl="order/order/deliver-quantity-confirm/confirmCollect";
     /**
      * @description: 一步发起签署
      * @param: [copierAccountId, fileId, fileName, signerAccountId]
@@ -37,8 +61,8 @@ public class EsignSignServiceImpl implements IEsignSignService {
      * @date: 2020/10/13 9:15
      */
     @Override
-    public String oneStepFlow(String businessScene, String fileId,float posX,float posY, String fileName, String signerAccountId,String authorizedAccountId) {
-        JSONObject json = buildParam(businessScene, fileId,posX,posY, fileName, signerAccountId,authorizedAccountId);
+    public String oneStepFlow(String businessScene, String fileId,float posX,float posY, String fileName, String signerAccountId,String authorizedAccountId,String redirectUrl) {
+        JSONObject json = buildParam(businessScene, fileId,posX,posY, fileName, signerAccountId,authorizedAccountId,redirectUrl);
         JSONObject jsonObject = eSignHttpUtil.doPostGetJson(ESignUrl.CreateFlowOneStepUrl,json);
         JSONObject result = (JSONObject)jsonObject.get("data");
         return result.get("flowId").toString();
@@ -121,6 +145,51 @@ public class EsignSignServiceImpl implements IEsignSignService {
         return result.get("fileUrl").toString();
     }
 
+    @Override
+    @Async
+    public void callbackNotice(OrderFile orderFlag) {
+        try {
+            String param;
+            if (orderFlag.getWareHouseCode()!=null&&orderFlag.getWareHouseName()!=null){
+                param = "?shipmentNumber="+orderFlag.getShipmentNumber()+"&belongTo="+orderFlag.getChainsCode()+"&wareHouseCode="+orderFlag.getWareHouseCode()+"&wareHouseName="+orderFlag.getWareHouseName();
+//                param = "shipmentNumber="+orderFlag.getShipmentNumber()+"&belongTo="+orderFlag.getChainsCode()+"&wareHouseCode="+orderFlag.getWareHouseCode()+"&wareHouseName="+orderFlag.getWareHouseName();
+            }else{
+                param = "?shipmentNumber="+orderFlag.getShipmentNumber()+"&belongTo="+orderFlag.getChainsCode();
+//                param = "shipmentNumber="+orderFlag.getShipmentNumber()+"&belongTo="+orderFlag.getChainsCode();
+            }
+//            String url =cloudPath+confirmUrl;
+            String url =cloudPath+confirmUrl+param;
+            String str = restTemplate.getForObject(url, String.class);
+            System.out.println(str);
+            JSONObject result = JSONObject.parseObject(str);
+//        JSONObject result = (JSONObject) JSONObject.parse(HttpUtils.sendGet(url,param));
+
+            /*保存回调消息*/
+            OrderFile orderFile = new OrderFile();
+            orderFile.setFlowId(orderFlag.getFlowId());
+            orderFile.setCode(result.get("code").toString());
+            orderFile.setMessage(result.get("message").toString());
+            orderFileService.updateOrderFileByFlowId(orderFile);
+        } catch (RestClientException e) {
+            e.printStackTrace();
+            logger.error("查询基础订单详情报错",e);
+            throw e;
+        }
+    }
+
+    @Override
+    @Async
+    public void saveFile(String flowId, OrderFile orderFlag) {
+//        System.out.println("executeAysncTask1 method: 执行异步保存{} -------"+ i);
+        String fileUrl = processDocumentDownload(flowId);
+        /*下载保存签署后的文件,返回文件存储地址*/
+        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);
+    }
+
     /**
      * @description 模拟构建一步发起请求参数
      *              <p>
@@ -133,7 +202,7 @@ public class EsignSignServiceImpl implements IEsignSignService {
      *              <p>
      *
      */
-    private  JSONObject buildParam(String businessScene, String fileId,float posX,float posY, String fileName, String signerAccountId,String authorizedAccountId) {
+    private  JSONObject buildParam(String businessScene, String fileId,float posX,float posY, String fileName, String signerAccountId,String authorizedAccountId,String redirectUrl) {
         // 附件信息列表 这里模拟没有附件的情况
         List<Attachment> attachments = new ArrayList<>();
 
@@ -150,7 +219,7 @@ public class EsignSignServiceImpl implements IEsignSignService {
 
         // 流程配置,可以不配置,使用默认配置
         String noticeDeveloperUrl = eSignConfig.getSignSuccessUrl();//回调通知URL
-        FlowConfigInfo flowConfigInfo = new FlowConfigInfo(noticeDeveloperUrl, "1,2", "", null);
+        FlowConfigInfo flowConfigInfo = new FlowConfigInfo(noticeDeveloperUrl, "1,2", redirectUrl, null);
         FlowInfo flowInfo = new FlowInfo(true,true,businessScene,flowConfigInfo);
 
         // 签署方信息
@@ -202,4 +271,51 @@ public class EsignSignServiceImpl implements IEsignSignService {
         json.put("signers", signers);
         return json;
     }
+
+    /**
+     * @description: 下载文件
+     * @param: [filePath, fileName, httpUrl]
+     * @return: void
+     * @author: qxm      
+     * @date: 2020/10/27 9:58
+     */ 
+    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/java/com/dgtly/wxportal/service/impl/OrderFileServiceImpl.java

@@ -113,4 +113,9 @@ public class OrderFileServiceImpl implements IOrderFileService
         orderFile.setUpdateTime(DateUtils.getNowDate());
         return orderFileMapper.updateOrderFileByFlowId(orderFile);
     }
+
+    @Override
+    public OrderFile selectOrderFileByParam(String orderId, String deliveryNumber, String shipmentNumber) {
+        return orderFileMapper.selectOrderFileByParam(orderId,deliveryNumber,shipmentNumber);
+    }
 }

+ 11 - 5
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/utils/pdf/PDFUtil.java

@@ -253,12 +253,18 @@ public class PDFUtil {
         Paragraph p1 = new Paragraph();
         p1.add(new Chunk(new LineSeparator()));
         document.add(p1);
-        Paragraph paragraph1 = new Paragraph("客户名称: " +receivingNote.getCustomerName()+"                           " +
-        "                                                     订单号: " +receivingNote.getOrderNumber()+"", namefont);
+        Paragraph paragraph1 = new Paragraph("客户名称: " +receivingNote.getCustomerName() +"                           " +
+        "                                                     运单号: " +receivingNote.getShipmentNumber(), namefont);
         paragraph1.setLeading(20f); //行间距
         paragraph1.setSpacingBefore(5f); //设置段落上空白
         paragraph1.setSpacingAfter(5f); //设置段落下空白
         document.add(paragraph1);
+        Paragraph paragraph2 = new Paragraph( "收货地址: " +receivingNote.getShipToAddress()+"                           " +
+                "                                                     经办人: " +receivingNote.getAgent(), namefont);
+        paragraph2.setLeading(20f); //行间距
+        paragraph2.setSpacingBefore(5f); //设置段落上空白
+        paragraph2.setSpacingAfter(5f); //设置段落下空白
+        document.add(paragraph2);
         /*Paragraph paragraphNumber = new Paragraph("订单号: " +docNumber+"", textfont);
         paragraphNumber.setLeading(20f); //行间距
         paragraphNumber.setSpacingBefore(5f); //设置段落上空白
@@ -307,7 +313,7 @@ public class PDFUtil {
 
             }
             for (ConfirmCollectOtherDeliveryModel otherLine : receivingNote.getOtherDeliveryModels()) {
-                table.addCell(createCell("同运单交货单:" + otherLine.getDeliveryNumber() + "   重量:" + otherLine.getWeight(), keyfont, Element.ALIGN_CENTER, 4));
+                table.addCell(createCell("订单号: "+receivingNote.getOrderNumber()+"  交货单号:  " + otherLine.getDeliveryNumber() + "   重量:" + otherLine.getWeight(), keyfont, Element.ALIGN_LEFT, 4));
                 for (ConfirmCollectLineDetailModel line : otherLine.getDeliveryLineDetail()) {
                     table.addCell(createCell(line.getMaterialName(), textfont));
                     table.addCell(createCell(line.getSizeDim(), textfont));
@@ -322,12 +328,12 @@ public class PDFUtil {
 
 
 
-        paragraph = new Paragraph("收货单位及经办人(盖章):", namefont);
+        /*paragraph = new Paragraph("收货单位及经办人(盖章):", namefont);
         paragraph.setAlignment(0); //设置文字居中 0靠左   1,居中     2,靠右
         paragraph.setLeading(20f); //行间距
         paragraph.setSpacingBefore(20f); //设置段落上空白
         paragraph.setSpacingAfter(10f); //设置段落下空白
-        document.add(paragraph);
+        document.add(paragraph);*/
 
         return size;
     }

+ 30 - 2
suishenbang-wxportal/suishenbang-wxportal-common/src/main/resources/mapper/wxportal/OrderFileMapper.xml

@@ -6,6 +6,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     
     <resultMap type="OrderFile" id="OrderFileResult">
         <result property="orderId"    column="order_id"    />
+        <result property="deliveryNumber"    column="delivery_number"    />
+        <result property="shipmentNumber"    column="shipment_number"    />
+        <result property="wareHouseCode"    column="ware_house_code"    />
+        <result property="wareHouseName"    column="ware_house_name"    />
+        <result property="code"    column="code"    />
+        <result property="message"    column="message"    />
         <result property="flowId"    column="flow_id"    />
         <result property="chainsCode"    column="chains_code"    />
         <result property="chainsName"    column="chainsName"    />
@@ -21,7 +27,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectOrderFileVo">
-        select order_id, flow_id,chains_code,customers_code,signer_id,signer_name, file_url, create_by, create_time, update_by, update_time, is_delete from ssb_order_file
+        select order_id,delivery_number,shipment_number,ware_house_code,ware_house_name,code,message, flow_id,chains_code,customers_code,signer_id,signer_name, file_url, create_by, create_time, update_by, update_time, is_delete from ssb_order_file
     </sql>
 
     <select id="selectOrderFileList" parameterType="OrderFile" resultMap="OrderFileResult">
@@ -60,11 +66,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectOrderFileVo"/>
         where flow_id = #{flowId}
     </select>
-        
+    <select id="selectOrderFileByParam" resultMap="OrderFileResult">
+        <include refid="selectOrderFileVo"/>
+        where order_id = #{orderId}
+            and delivery_number = #{deliveryNumber}
+            and shipment_number = #{shipmentNumber}
+            and file_url is not null
+            group by order_id,delivery_number,shipment_number
+    </select>
+
     <insert id="insertOrderFile" parameterType="OrderFile">
         insert into ssb_order_file
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="orderId != null">order_id,</if>
+            <if test="deliveryNumber != null">delivery_number,</if>
+            <if test="shipmentNumber != null">shipment_number,</if>
+            <if test="wareHouseCode != null">ware_house_code,</if>
+            <if test="wareHouseName != null">ware_house_name,</if>
+            <if test="code != null">code,</if>
+            <if test="message != null">message,</if>
             <if test="flowId != null">flow_id,</if>
             <if test="chainsCode != null">chains_code,</if>
             <if test="customersCode != null">customers_code,</if>
@@ -79,6 +99,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="orderId != null">#{orderId},</if>
+            <if test="deliveryNumber != null">#{deliveryNumber},</if>
+            <if test="shipmentNumber != null">#{shipmentNumber},</if>
+            <if test="wareHouseCode != null">#{wareHouseCode},</if>
+            <if test="wareHouseName != null">#{wareHouseName},</if>
+            <if test="code != null">#{code},</if>
+            <if test="message != null">#{message},</if>
             <if test="flowId != null">#{flowId},</if>
             <if test="chainsCode != null">#{chainsCode},</if>
             <if test="customersCode != null">#{customersCode},</if>
@@ -118,6 +144,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="signerId != null">signer_id = #{signerId},</if>
             <if test="signerName != null">signer_name = #{signerName},</if>
             <if test="fileUrl != null">file_url = #{fileUrl},</if>
+            <if test="code != null">code = #{code},</if>
+            <if test="message != null">message = #{message},</if>
             <if test="createBy != null">create_by = #{createBy},</if>
             <if test="createTime != null">create_time = #{createTime},</if>
             <if test="updateBy != null">update_by = #{updateBy},</if>