Browse Source

发送付款同步消息

fyz 3 months ago
parent
commit
6bb95fda4d

+ 8 - 0
mjava-jiuyousimu/src/main/java/com/malk/jiuyousimu/controller/DLController.java

@@ -100,6 +100,14 @@ public class DLController {
         supplierService.testPush();
         return McR.success();
     }
+
+    @PostMapping(value = "selectALLReturn")
+    McR selectAll(@RequestBody Map data) {
+//        supplierService.pushToOA();
+//        supplierService.accountPushToOA();
+        Map<String, String> stringStringMap = documentService.selectALLReturn();
+        return McR.success(stringStringMap);
+    }
     /**
      * 更新审批实例
      */

+ 8 - 1
mjava-jiuyousimu/src/main/java/com/malk/jiuyousimu/schedule/ScheduleTask.java

@@ -1,6 +1,7 @@
 package com.malk.jiuyousimu.schedule;
 
 import com.malk.jiuyousimu.service.DeptService;
+import com.malk.jiuyousimu.service.DocumentService;
 import com.malk.jiuyousimu.service.SupplierService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -21,7 +22,8 @@ public class ScheduleTask {
 
     @Autowired
     private SupplierService supplierService;
-
+    @Autowired
+    private DocumentService documentService;
 //    /**
 //     * 每天15,16点尝试下发流程
 //     */
@@ -31,5 +33,10 @@ public class ScheduleTask {
         supplierService.pushToOA();
     }
 
+    @Scheduled(cron = "0 0/5 * * * ?")
+    void viewNotice(){
+        log.info("每30分钟获取供应商数据");
+        documentService.viewNotice();
+    }
 
 }

+ 6 - 0
mjava-jiuyousimu/src/main/java/com/malk/jiuyousimu/service/DocumentService.java

@@ -30,4 +30,10 @@ public interface DocumentService {
      * @return
      */
     McR savePayment(Map processData);
+
+    void Push(String id, String userId, String title, String formId);
+
+    void viewNotice();
+
+    Map<String,String> selectALLReturn();
 }

+ 107 - 13
mjava-jiuyousimu/src/main/java/com/malk/jiuyousimu/service/Impl/DocumentServiceImpl.java

@@ -3,6 +3,7 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.google.gson.Gson;
 import com.kingdee.bos.webapi.entity.RepoRet;
+import com.kingdee.bos.webapi.entity.SuccessEntity;
 import com.kingdee.bos.webapi.sdk.K3CloudApi;
 import com.malk.jiuyousimu.entity.basic.*;
 
@@ -25,10 +26,9 @@ import org.springframework.stereotype.Service;
 
 import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+
+import static org.aspectj.bridge.MessageUtil.fail;
 
 @Service
 @Slf4j
@@ -44,6 +44,8 @@ public class DocumentServiceImpl implements DocumentService {
     private DDClient_Contacts ddClient_contacts;
     @Autowired
     private DDClient_Personnel ddClientPersonnel;
+    @Autowired
+    private DDClient_Notice ddClient_notice;
     @Value("${dingtalk.appKey}")
     private String APP_EKY;
     @Value("${dingtalk.appSecret}")
@@ -130,6 +132,7 @@ public class DocumentServiceImpl implements DocumentService {
     private static final Map<String,String> PAYMENT_RETURN = new HashMap<>();
     private static final Map<String,String> TRIP_RETURN = new HashMap<>();
     private static final Map<String,String> COST_RETURN = new HashMap<>();
+    private static final Map<String,String> ALL_RETURN = new HashMap<>();
 
     /**
      * 差旅费报销单
@@ -305,8 +308,6 @@ public class DocumentServiceImpl implements DocumentService {
                 Submit submit = new Submit();
                 submit.setIds(id);
 
-                TRIP_RETURN.put(id,"");
-
                 //提交
                 String resultJson2 = client.submit(formId, JSONObject.toJSONString(submit));
                 RepoRet repoRet2 = gson.fromJson(resultJson2, RepoRet.class);
@@ -318,7 +319,10 @@ public class DocumentServiceImpl implements DocumentService {
                     //审核
                     String resultJson3 = client.audit(formId,JSONObject.toJSONString(audit));
                     RepoRet repoRet3 = gson.fromJson(resultJson3, RepoRet.class);
-                    kingDeeService.isTrue(repoRet3);
+                    if (kingDeeService.isTrue(repoRet3)){
+                        Thread.sleep(3000);
+                        Push(id,userId,UtilMap.getString(mainData,"标题"),"ER_ExpReimbursement_Travel");
+                    }
                 }
             }
         } catch (Exception e) {
@@ -446,8 +450,6 @@ public class DocumentServiceImpl implements DocumentService {
                 Submit submit = new Submit();
                 submit.setIds(id);
 
-                COST_RETURN.put(id,"");
-
                 //提交
                 String resultJson2 = client.submit(formId, JSONObject.toJSONString(submit));
                 RepoRet repoRet2 = gson.fromJson(resultJson2, RepoRet.class);
@@ -459,7 +461,10 @@ public class DocumentServiceImpl implements DocumentService {
                     //审核
                     String resultJson3 = client.audit(formId,JSONObject.toJSONString(audit));
                     RepoRet repoRet3 = gson.fromJson(resultJson3, RepoRet.class);
-                    kingDeeService.isTrue(repoRet3);
+                    if (kingDeeService.isTrue(repoRet3)){
+                        Thread.sleep(3000);
+                        Push(id,userId,UtilMap.getString(mainData,"标题"),"ER_ExpReimbursement");
+                    }
                 }
             }
         } catch (Exception e) {
@@ -588,8 +593,6 @@ public class DocumentServiceImpl implements DocumentService {
             if (kingDeeService.isTrue(repoRet)){
                 String id = repoRet.getResult().getId();
 
-                PAYMENT_RETURN.put(id,"");
-
                 Submit submit = new Submit();
                 submit.setIds(id);
                 //提交
@@ -603,7 +606,10 @@ public class DocumentServiceImpl implements DocumentService {
                     //审核
                     String resultJson3 = client.audit(formId,JSONObject.toJSONString(audit));
                     RepoRet repoRet3 = gson.fromJson(resultJson3, RepoRet.class);
-                    kingDeeService.isTrue(repoRet3);
+                    if (kingDeeService.isTrue(repoRet3)){
+                        Thread.sleep(3000);
+                        Push(id,userId,UtilMap.getString(mainData,"标题"),"AP_Payable");
+                    }
                 }
             }
         } catch (Exception e) {
@@ -612,4 +618,92 @@ public class DocumentServiceImpl implements DocumentService {
 
         return McR.success();
     }
+
+    @Override
+    public void Push(String id, String userId, String title, String formId){
+        K3CloudApi client = new K3CloudApi(kingDeeService.initIden());
+        Push push = new Push();
+        push.setIds(id);
+//         push.setTargetBillTypeId("FKDLX01_SYS");
+        push.setTargetFormId("AP_PAYBILL");
+        push.setIsEnableDefaultRule(true);
+        push.setIsDraftWhenSaveFail(true);
+
+        try {
+            String resultJson = client.push(formId, JSON.toJSONString(push));
+            Gson gson = new Gson();
+            //对返回结果进行解析和校验
+            RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
+            if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
+                List<SuccessEntity> successEntitys = repoRet.getResult().getResponseStatus().getSuccessEntitys();
+                successEntitys.forEach(e->{
+                    String key = e.getId() + "~" + userId + "~" + title;
+                    ALL_RETURN.put(key,null);
+                });
+                System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
+                log.info("接口返回结果:{}",gson.toJson(repoRet.getResult()));
+            } else {
+                fail("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
+                log.error("下推失败id:{},title:{},AP_Payable:{}",id,title,formId);
+            }
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+    }
+
+    @Override
+    public void viewNotice(){
+        K3CloudApi client = new K3CloudApi(kingDeeService.initIden());
+
+        ALL_RETURN.forEach((k,v)->{
+            String[] split = k.split("~");
+            View view = new View();
+            view.setId(split[0]);
+//        view.setNumber("AP00000505");
+//        view.setId("100551.0");
+//        String formId = "AP_Payable";
+//            view.setNumber("FKD00000072");
+            String formId = "AP_PAYBILL";
+            try {
+                String resultJson = client.view(formId, JSON.toJSONString(view));
+                Gson gson = new Gson();
+                //对返回结果进行解析和校验
+                RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
+                if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
+                    JSONObject jsonObject = JSONObject.parseObject(repoRet.getResult().getResult().toString());
+                    JSONArray jsonArray = JSONArray.parseArray(jsonObject.get("PAYBILLENTRY").toString());
+                    boolean isAllPay = true;
+                    for (int i = 0; i < jsonArray.size(); i++) {
+                        JSONObject sonObject = JSONObject.parseObject(jsonArray.get(i).toString());
+                        String fbankmsg = sonObject.get("FBANKMSG").toString();
+                        if (!fbankmsg.contains("交易成功")){
+                            isAllPay = false;
+                            break;
+                        }
+                    }
+                    if (isAllPay){
+                        String content = "你有一条标题为"+split[2]+"单据已完成付款";
+                        Map<String, Object> msg = UtilMap.map("msgtype, text", "text", UtilMap.map("content", content));
+                        ddClient_notice.sendNotification(ddClient.getAccessToken(), Arrays.asList(split[1]),null,false,msg);
+
+                        ALL_RETURN.remove(k);
+                    }
+                    System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
+                    log.info("接口返回结果:{}",gson.toJson(repoRet.getResult()));
+                } else {
+                    fail("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
+                }
+            } catch (Exception e) {
+                fail(e.getMessage());
+            }
+
+        });
+    }
+
+    @Override
+    public Map<String,String> selectALLReturn(){
+        log.info("所有发送信息的key:{}",ALL_RETURN);
+        return ALL_RETURN;
+    }
+
 }

+ 7 - 5
mjava-jiuyousimu/src/main/java/com/malk/jiuyousimu/service/Impl/SupplierServiceImpl.java

@@ -338,15 +338,17 @@ public class SupplierServiceImpl implements SupplierService {
         }
     }
 
+
+
     @Override
     public void testPush(){
         K3CloudApi client = new K3CloudApi(kingDeeService.initIden());
-         Push push = new Push();
-         push.setIds("100551");
+        Push push = new Push();
+        push.setIds("100551");
 //         push.setTargetBillTypeId("FKDLX01_SYS");
-         push.setTargetFormId("AP_PAYBILL");
-         push.setIsEnableDefaultRule(true);
-         push.setIsDraftWhenSaveFail(true);
+        push.setTargetFormId("AP_PAYBILL");
+        push.setIsEnableDefaultRule(true);
+        push.setIsDraftWhenSaveFail(true);
 
 //        view.setNumber("AP00000505");
 //        view.setId("100551.0");