Explorar el Código

新增计算应收帐日期功能

hxx hace 4 días
padre
commit
c4e9939a2c

+ 12 - 61
mjava-hengyilong/src/main/java/com/malk/hengyilong/controller/HylController.java

@@ -1,7 +1,11 @@
 package com.malk.hengyilong.controller;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.malk.server.aliwork.YDConf;
+import com.malk.server.aliwork.YDParam;
 import com.malk.server.common.McR;
+import com.malk.service.aliwork.YDClient;
 import com.malk.utils.UtilMap;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -9,6 +13,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.web.bind.annotation.*;
 import com.malk.hengyilong.service.ClientHylService;
 
+import java.util.Date;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
@@ -26,6 +31,8 @@ public class HylController {
 
     @Autowired
     private ClientHylService clientService;
+    @Autowired
+    private YDClient ydClient;
 
     //    获取客户档案信息
     @GetMapping("/getClient")
@@ -38,71 +45,15 @@ public class HylController {
         return clientService.syncClient(map);
     }
 
+//    计算账期时间
 
+    @PostMapping("/getAccountPeriod")
+    public McR getAccountPeriod(@RequestBody Map map){
+        return clientService.getAccountPeriod(map);
 
-    // 使用ConcurrentHashMap保证线程安全
-    private final ConcurrentMap<String, Long> eventList = new ConcurrentHashMap<>();
-    // 记录最后一次清理时间
-    private volatile long lastCleanTime = System.currentTimeMillis();
-    // 清理间隔时间(毫秒)
-    private static final long CLEAN_INTERVAL = 60_000;
-//    @PostMapping("/callback")
-//    public McR callback(@RequestBody Map map){
-//        System.out.println(map);
-//
-//        log.info("e签宝回调: {}", JSON.toJSONString(map));
-//
-//        //签署回调通知:SIGN_MISSON_COMPLETE   事件订阅-签署流程完成:SIGN_FLOW_FINISH
-//        String action = UtilMap.getString(map, "action");
-//        String signFlowId = UtilMap.getString(map, "signFlowId");//e签宝签署流程id
-//
-//        String info = action + "-" + signFlowId;
-//
-//        // 定期清理过期记录
-//        cleanExpiredEvents();
-//
-//        if (isCallbackProcessed(info)){
-//            log.info("info:{},重复回调,不做处理",info);
-//        }else {
-//            eventList.put(info, System.currentTimeMillis());
-//            //签署回调结束
-//            if ("SIGN_MISSON_COMPLETE".equals(action)) {
-//                int signResult = UtilMap.getInt(map, "signResult");//2 - 签署完成,4 - 拒签
-//                if (2 == signResult) {
-//                    String processInstanceId = UtilMap.getString(map, "customBizNum");//宜搭审批实例id
-//                    //自动同意审批节点
-//                    eqbService.autoAgree(signFlowId,processInstanceId);
-//                }
-//            }
-//        }
-//
-//        return McR.success();
-//    }
-
-    /**
-     * 检查并清理过期事件
-     */
-    private void cleanExpiredEvents() {
-        long currentTime = System.currentTimeMillis();
-        // 只在达到清理间隔时执行清理
-        if (currentTime - lastCleanTime > CLEAN_INTERVAL) {
-            synchronized (this) {
-                // 双重检查,避免重复清理
-                if (currentTime - lastCleanTime > CLEAN_INTERVAL) {
-                    long expirationTime = currentTime - TimeUnit.MINUTES.toMillis(1);
-                    eventList.entrySet().removeIf(entry -> entry.getValue() < expirationTime);
-                    lastCleanTime = currentTime;
-                }
-            }
-        }
     }
 
-    /**
-     * 检查该回调事件在一分钟内是否处理过
-     */
-    private boolean isCallbackProcessed(String detail) {
-        return eventList.containsKey(detail);
-    }
+
 
 
 

+ 1 - 1
mjava-hengyilong/src/main/java/com/malk/hengyilong/service/ClientHylService.java

@@ -12,6 +12,6 @@ public interface ClientHylService {
 
     McR syncClient(Map map);
     //查询所有
-    
+    McR getAccountPeriod(Map map);
 
 }

+ 104 - 4
mjava-hengyilong/src/main/java/com/malk/hengyilong/service/impl/ClientHylServiceImpl.java

@@ -1,5 +1,6 @@
 package com.malk.hengyilong.service.impl;
 
+import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -15,10 +16,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * 功能:
@@ -81,4 +79,106 @@ public class ClientHylServiceImpl implements ClientHylService {
         String clientLink = "https://gkwk0b.aliwork.com/APP_QX8IOI1D22HK3GC413L5/formDetail/FORM-GMC66781QZP16UF1NPSLG6C8ZC9G38R5V6IJM1?formInstId="+clientdetail.get("formInstanceId");
         return McR.success(clientLink);
     }
+
+    @Override
+    public McR getAccountPeriod(Map map) {
+        String formInstance = UtilMap.getString(map, "formInstance");
+        //            应收帐日期
+        String receiveDate = null;
+        try {
+
+            Map formData = ydClient.queryData(YDParam.builder()
+                    .formInstanceId(formInstance)
+                    .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
+            String settleMethod = UtilMap.getString(formData, "selectField_ml3e44b1");//结算方式
+            Long invoiceDateTimestamp = UtilMap.getLong(formData, "datefield_DMpwNIpo");//发票日期
+            int paymentDays = UtilMap.getInt(formData, "selectField_ml3e44b2");//付款天数
+            int settleDay = UtilMap.getInt(formData, "numberField_mq8yh6p6");//结算日
+            int paymentDate = UtilMap.getInt(formData, "numberField_mjl1xyz3");//付款日
+
+            if (settleMethod == null || settleMethod.trim().isEmpty()) {
+                log.warn("结算方式缺失,返回异常标记X");
+                receiveDate = "X";
+            } else {
+                Date invoiceDate = null;
+                if (invoiceDateTimestamp != null && invoiceDateTimestamp > 0) {
+                    try {
+                        invoiceDate = new Date(invoiceDateTimestamp);
+                    } catch (Exception e) {
+                        log.error("发票日期无效: {}", invoiceDateTimestamp, e);
+                        return McR.success(null);
+                    }
+                } else {
+                    log.error("发票日期为空");
+                    return McR.success(null);
+                }
+                if ("货到".equals(settleMethod)) {
+                    Date accountDate = DateUtil.offsetDay(invoiceDate, paymentDays);
+                    receiveDate = DateUtil.formatDate(accountDate);
+                    log.info("货到结算,应到帐时间: {}", receiveDate);
+                } else if ("预付".equals(settleMethod)) {
+                    receiveDate = DateUtil.formatDate(invoiceDate);
+                    log.info("预付结算,应到帐时间: {}", receiveDate);
+                } else if ("月结".equals(settleMethod)) {
+                    Calendar cal = Calendar.getInstance();
+                    cal.setTime(invoiceDate);
+                    int lastDayOfMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
+
+                    int adjustDays;
+                    if (settleDay == 0 || settleDay == 30) {
+                        adjustDays = 0;
+                    } else {
+                        adjustDays = lastDayOfMonth - settleDay;
+                    }
+                    Date baseDate = DateUtil.offsetDay(invoiceDate, adjustDays);
+                    int months = paymentDays / 30;
+                    Date dateWithPeriod = DateUtil.offsetMonth(baseDate, months);
+                    Calendar cal2 = Calendar.getInstance();
+                    cal2.setTime(dateWithPeriod);
+                    int lastDayOfResultMonth = cal2.getActualMaximum(Calendar.DAY_OF_MONTH);
+                    cal2.set(Calendar.DAY_OF_MONTH, lastDayOfResultMonth);
+                    Date monthEndDate = cal2.getTime();
+
+                    Date finalDate;
+                    if (paymentDate == 30) {
+                        finalDate = monthEndDate;
+                    } else {
+                        finalDate = DateUtil.offsetDay(monthEndDate, paymentDate);
+                    }
+
+                    receiveDate = DateUtil.formatDate(finalDate);
+                    log.info("月结结算,应到帐时间: {}", receiveDate);
+
+                } else {
+                    log.warn("未识别的结算方式: {}", settleMethod);
+                    receiveDate = "X";
+                }
+            }
+        } catch (NumberFormatException e) {
+            log.error("数字格式转换异常", e);
+            receiveDate = "X";
+        } catch (Exception e) {
+            log.error("计算应到帐时间异常", e);
+            receiveDate = "X";
+        } finally {
+            try {
+                if (!"X".equals(receiveDate) && receiveDate != null) {
+                    Date resultDate = DateUtil.parse(receiveDate);
+                    ydClient.operateData(YDParam.builder()
+                            .formInstanceId(formInstance)
+                            .updateFormDataJson(JSONObject.toJSONString(UtilMap.map("dateField_mpdpzvrv", resultDate.getTime())))
+                            .build(), YDConf.FORM_OPERATION.update);
+                    log.info("已回写应到帐时间到宜搭: {}", receiveDate);
+                } else {
+                    log.info("结果为X或null,不回写宜搭");
+                }
+                return McR.success(receiveDate);
+            } catch (Exception e) {
+                log.error("回写宜搭失败", e);
+                return McR.errorParam( e.getMessage());
+            }
+        }
+
+    }
+
 }

+ 50 - 2
mjava-hengyilong/src/main/java/com/malk/hengyilong/service/impl/EqbHylServiceImpl.java

@@ -118,8 +118,10 @@ public class EqbHylServiceImpl implements EqbHylService {
 
             reqBodyObjSign.put("signFlowConfig",signFlowConfig);
 //             3.3设置签署参与方
+//            3.3.1设置我方签署信息
             Map signer = new HashMap();
             signer.put("signerType",1);//签署方类型,0 - 个人,1 - 企业/机构,2 - 法定代表人,3 - 经办人
+            signer.put("signConfig",UtilMap.map("signOrder",1));
             Map orgSignerInfo = new HashMap();
             //企业/机构账号ID
             orgSignerInfo.put("orgId",orgId);
@@ -137,7 +139,36 @@ public class EqbHylServiceImpl implements EqbHylService {
             normalSignFieldConfig.put("freeMode",true);
             signField.put("normalSignFieldConfig",normalSignFieldConfig);
             signer.put("signFields",Arrays.asList(signField));
-            reqBodyObjSign.put("signers",Arrays.asList(signer));
+
+            List<Map> signersList = new ArrayList<>();
+            signersList.add(signer);
+//            3.3.2设置对方签署信息
+            if("需要".equals(UtilMap.getString(formData, "radioField_mqejx60u"))){
+                Map otherSigner = new HashMap();
+                otherSigner.put("signerType",1);//签署方类型,0 - 个人,1 - 企业/机构,2 - 法定代表人,3 - 经办人
+                otherSigner.put("signConfig",UtilMap.map("signOrder",2));
+                Map otherOrgSignerInfo = new HashMap();
+                //企业/机构账号名称
+                otherOrgSignerInfo.put("orgName",UtilMap.getString(formData, "textField_mqejx60w"));
+                otherOrgSignerInfo.put("orgInfo",UtilMap.map("orgIDCardNum, orgIDCardType",UtilMap.getString(formData, "textField_mqejx60x"),"CRED_ORG_USCC"));
+                //经办人信息
+                Map otherTransactorInfo = new HashMap();
+                otherTransactorInfo.put("psnAccount",UtilMap.getString(formData, "textField_mqejx60y"));//经办人账号标识,手机号或邮箱,必须配合psnName(经办人姓名)传入
+                otherTransactorInfo.put("psnInfo",UtilMap.map("psnName",UtilMap.getString(formData, "textField_ml0iaa3i")));//经办人姓名
+                otherOrgSignerInfo.put("transactorInfo",otherTransactorInfo);
+                otherSigner.put("orgSignerInfo",otherOrgSignerInfo);
+
+                Map otherSignField = new HashMap();
+                otherSignField.put("fileId",fileId);
+                otherSignField.put("customBizNum",formInstance);
+//            签章区配置项
+                Map otherSignFieldConfig = new HashMap();
+                otherSignFieldConfig.put("freeMode",true);
+                otherSignField.put("normalSignFieldConfig",otherSignFieldConfig);
+                otherSigner.put("signFields",Arrays.asList(otherSignField));
+                signersList.add(otherSigner);
+            }
+            reqBodyObjSign.put("signers",signersList);
             Map signResult = eqbPost("/v3/sign-flow/create-by-file", reqBodyObjSign);
             String signFlowId = UtilMap.getString(signResult,"signFlowId");
 
@@ -251,7 +282,7 @@ public class EqbHylServiceImpl implements EqbHylService {
 //            String productModel = productTable.get(i).containsKey("textField_mogxdk7x")?UtilMap.getString(productTable.get(i), "textField_mogxdk7x"):"";//产品型号--舍弃
             String productSize = productTable.get(i).containsKey("textField_mogxdk7y")?UtilMap.getString(productTable.get(i), "textField_mogxdk7y"):"";//产品规格
             String productNum = productTable.get(i).containsKey("numberField_mkdl67qd")?UtilMap.getString(productTable.get(i), "numberField_mkdl67qd"):"";//数量
-            String productUnit = productTable.get(i).containsKey("numberField_mkdl67qd")?UtilMap.getString(productTable.get(i), "numberField_mkdl67qd"):"";//单位
+            String productUnit = productTable.get(i).containsKey("textField_mq6g5d7g")?UtilMap.getString(productTable.get(i), "textField_mq6g5d7g"):"";//单位
             double productPrice = productTable.get(i).containsKey("numberField_mkdl67qe")?UtilMap.getDouble(productTable.get(i), "numberField_mkdl67qe"):0;//单价
             String note = productTable.get(i).containsKey("textField_mkdl67qg")?UtilMap.getString(productTable.get(i), "textField_mkdl67qg"):"";//备注
             if ("恒益隆贸易(上海)有限公司".equals(UtilMap.getString(formData, "selectField_mjmlcp4y"))) {
@@ -272,6 +303,20 @@ public class EqbHylServiceImpl implements EqbHylService {
         productDetailMap.put("componentKey", "productDetail");
         productDetailMap.put("componentValue", JSONObject.toJSONString(productDetail));
 
+            //交货方式
+        Map submitType = new HashMap();
+        submitType.put("componentKey", "submitType");
+        submitType.put("componentValue", formData.containsKey("textField_mogtxb0m")?UtilMap.getString(formData, "textField_mogtxb0m"):"");
+        //付款方式
+        Map payType = new HashMap();
+        payType.put("componentKey", "payType");
+        payType.put("componentValue", formData.containsKey("textField_mogtxb0o")?UtilMap.getString(formData, "textField_mogtxb0o"):"");
+        //送货日期
+        Map deliverDate = new HashMap();
+        deliverDate.put("componentKey", "deliverDate");
+        deliverDate.put("componentValue", formData.containsKey("textField_mogtxb0q")?UtilMap.getString(formData, "textField_mogtxb0q"):"");
+
+
         components.add(clientName);
         components.add(salesPerson);
         components.add(contactPerson);
@@ -286,6 +331,9 @@ public class EqbHylServiceImpl implements EqbHylService {
         components.add(company);
         components.add(companyEng);
         components.add(companySeal);
+        components.add(submitType);
+        components.add(payType);
+        components.add(deliverDate);
         if ("恒益隆贸易(上海)有限公司".equals(UtilMap.getString(formData, "selectField_mjmlcp4y"))) {
             reqBodyObj.put("docTemplateId", bjdHYL_docTemplateId);
         }else  if ("上海绍贺贸易有限公司".equals(UtilMap.getString(formData, "selectField_mjmlcp4y"))){

+ 7 - 1
mjava-hengyilong/src/test/java/com/malk/hengyilong/mjavahengyilong/MjavaHengyilongApplicationTests.java

@@ -32,7 +32,13 @@ class MjavaHengyilongApplicationTests {
 
     @Test
     void quotationToEqb(){
-//        McR mcR = eqbHylService.quotationToEqb(UtilMap.map("formInstance, type","5f1b8f91-2056-4fa4-a4de-2f1d9501c3c2, contract"));
+//        McR mcR = eqbHylService.quotationToEqb(UtilMap.map("formInstance, type","14033dcc-0339-4892-aafc-a348d91da635, contract"));
+    }
+
+    @Test
+    void getAccountPeriod(){
+//        McR mcR = clientHylService.getAccountPeriod(UtilMap.map("formInstance","FINST-YFI66SC1CUN6ZT27JM27V7DW8MDR2NCN11GQM36"));
+
     }
 
 }

+ 4 - 4
mjava-hengyilong/src/test/java/com/malk/hengyilong/mjavahengyilong/ToEqbTest.java

@@ -49,13 +49,13 @@ public class ToEqbTest {
 //           报价单模板文件     fileId
         String fileId ="cacddedc33ff45cea8acd4e8a8f81ac4";
 //             报价单模板文件   docTemplateId
-//        String docTemplateId ="1d2f50e82f514144b72313b1dddcb552";//恒益隆模板id
-        String docTemplateId ="e7440c3f38724b239d7e9dcf7329804a";//绍贺模板id
+        String docTemplateId ="1d2f50e82f514144b72313b1dddcb552";//恒益隆模板id
+//        String docTemplateId ="e7440c3f38724b239d7e9dcf7329804a";//绍贺模板id
 
 //             报价单模板文件   filecontentMd5
         String filecontentMd5 ="nJsZC4SzKUudj0awHel4oQ==";
 
-       //   购销合同模板文件     fileId
+//          购销合同模板文件     fileId
 //        String fileId ="c39361f5ca74466a81287f90e94f06c3";
 //        //        购销合同模板文件docTemplateId
 ////        0064564bea704fc587a249680064b98c
@@ -93,7 +93,7 @@ public class ToEqbTest {
 //        //6.2开发者使用【查询文件上传状态】接口获取填充后文件链接,通过此链接可查看填充后文件效果
 //        253a487cfc1c464190006e7b8532479f
 //b97b73a033a341129bf788281a064f43
-//        getFileInfo(appId,appKey,host,"be504ec0e51a4d61885a0339bc216561");
+        getFileInfo(appId,appKey,host,"cc1106f83a1a40b99e450eb10863bb9d");
 
 
         //基于文件发起签署