Commit d28ad9a8fd6048a153d9950c30a29032aaf3aaea

Authored by zhangmeiyang
1 parent 39a9b760

refactor(kingdee): 优化金蝶发送逻辑并统一审计方法

- 移除冗余的 JSON 转换逻辑,直接传递 mapping 对象
- 新增 auditSend 方法支持 BaseMapping 参数类型
- 提取重复发送校验逻辑到 Sender 基类的 validMapping 方法
- 删除无用的第三方 ID 字段定义
- 统一异常处理和日志记录方式
- 优化代码结构和减少不必要的导入包
- 增强类型安全性和可维护性
tax-central/src/main/java/com/diligrp/tax/central/domain/proxy/kingdee/ReceiptProxy.java
... ... @@ -12,6 +12,5 @@ import lombok.Setter;
12 12 @Setter
13 13 @Getter
14 14 public class ReceiptProxy extends BaseProxy {
15   - private String thirdPartyId;
16 15 private String thirdPartyCode;
17 16 }
... ...
tax-central/src/main/java/com/diligrp/tax/central/domain/proxy/kingdee/ReceivableProxy.java
... ... @@ -12,6 +12,5 @@ import lombok.Setter;
12 12 @Setter
13 13 @Getter
14 14 public class ReceivableProxy extends BaseProxy {
15   - private String thirdPartyId;
16 15 private String thirdPartyCode;
17 16 }
... ...
tax-central/src/main/java/com/diligrp/tax/central/domain/proxy/kingdee/RefundProxy.java
... ... @@ -12,6 +12,5 @@ import lombok.Setter;
12 12 @Setter
13 13 @Getter
14 14 public class RefundProxy extends BaseProxy {
15   - private String thirdPartyId;
16 15 private String thirdPartyCode;
17 16 }
... ...
tax-proxy/src/main/java/com/diligrp/tax/proxy/demarcate/Sender.java
... ... @@ -2,8 +2,14 @@ package com.diligrp.tax.proxy.demarcate;
2 2  
3 3 import com.diligrp.tax.central.domain.BaseMapping;
4 4 import com.diligrp.tax.central.domain.BaseProxy;
  5 +import com.diligrp.tax.central.exception.TaxAgentServiceException;
5 6 import com.diligrp.tax.central.type.DocumentType;
  7 +import com.diligrp.tax.central.type.TaxSystemType;
  8 +import com.diligrp.tax.proxy.helper.KingDeeHelper;
6 9 import com.kingdee.bos.webapi.entity.IdentifyInfo;
  10 +import com.kingdee.bos.webapi.sdk.K3CloudApi;
  11 +
  12 +import java.util.List;
7 13  
8 14 /**
9 15 * @Author: zhangmeiyang
... ... @@ -26,4 +32,18 @@ public abstract class Sender<T extends BaseProxy> {
26 32 * @return {@link T }
27 33 */
28 34 public abstract T send(BaseMapping mappingObject, IdentifyInfo identifyInfo);
  35 +
  36 +
  37 + /**
  38 + * @param identifyInfo 识别信息
  39 + * @param mapping 映射
  40 + */
  41 + protected void validMapping(IdentifyInfo identifyInfo, BaseMapping mapping) {
  42 + if (!mapping.getVerifyInformation().isEmpty() && !mapping.getReturnKeys().isEmpty()){
  43 + List<Object> infos = KingDeeHelper.querySend(mapping, markDocument().value, new K3CloudApi(identifyInfo));
  44 + if (!infos.isEmpty()) {
  45 + throw new TaxAgentServiceException(TaxSystemType.REPEAT_SENDING);
  46 + }
  47 + }
  48 + }
29 49 }
... ...
tax-proxy/src/main/java/com/diligrp/tax/proxy/demarcate/kingdee/CustomerSender.java
... ... @@ -41,10 +41,10 @@ public class CustomerSender extends Sender&lt;CustomerProxy&gt; {
41 41 mapping.setFT_BD_CUSTLOCATION(handleContact(identifyInfo, mapping));
42 42 // 联系人新增
43 43 Optional.ofNullable(mapping.getFCUSTID()).filter(e -> !e.isEmpty()).ifPresent(e -> KingDeeHelper.unAuditSend(e, new K3CloudApi(identifyInfo), markDocument().value));
44   - RepoRet<?> repoRet = KingDeeHelper.auditSend(JsonUtils.convertValue(mapping, new TypeReference<>() {}), new K3CloudApi(identifyInfo), markDocument().value);
  44 + RepoRet<?> repoRet = KingDeeHelper.auditSend(mapping, identifyInfo, markDocument().value);
45 45 //联系人新增和更新完成
46 46 ArrayList<SuccessEntity> successEntity = repoRet.getResult().getResponseStatus().getSuccessEntitys();
47   - Optional.ofNullable(successEntity).filter(e -> !e.isEmpty()).orElseThrow(()->new TaxAgentServiceException(TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL));
  47 + Optional.ofNullable(successEntity).filter(e -> !e.isEmpty()).orElseThrow(() -> new TaxAgentServiceException(TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL));
48 48 SuccessEntity first = successEntity.getFirst();
49 49 var proxy = new CustomerProxy();
50 50 proxy.setThirdPartyId(first.getId());
... ... @@ -53,16 +53,17 @@ public class CustomerSender extends Sender&lt;CustomerProxy&gt; {
53 53  
54 54 private List<FT_BD_CUSTLOCATION> handleContact(IdentifyInfo identifyInfo, CustomerMapping mapping) {
55 55 List<FT_BD_CUSTLOCATION> contacts = mapping.getFT_BD_CUSTLOCATION();
56   - return contacts.stream().map(contact -> customerConvert(contact,identifyInfo)).toList();
  56 + return contacts.stream().map(contact -> customerConvert(contact, identifyInfo)).toList();
57 57 }
58 58  
59   - private FT_BD_CUSTLOCATION customerConvert(FT_BD_CUSTLOCATION contact,IdentifyInfo identifyInfo) {
  59 + private FT_BD_CUSTLOCATION customerConvert(FT_BD_CUSTLOCATION contact, IdentifyInfo identifyInfo) {
60 60 var customerLocation = new FT_BD_CUSTLOCATION();
61 61 customerLocation.setFBizAddress(contact.getFBizAddress());
62 62 customerLocation.setFCompanyType(contact.getFCompanyType());
63 63 customerLocation.setFMOBILEPHONE(contact.getFMOBILEPHONE());
64 64 customerLocation.setFName(contact.getFName());
65   - Map<String, Object> model = JsonUtils.convertValue(customerLocation, new TypeReference<>() {});
  65 + Map<String, Object> model = JsonUtils.convertValue(customerLocation, new TypeReference<>() {
  66 + });
66 67 RepoRet<?> repoRet = KingDeeHelper.nonAuditSend(model, new K3CloudApi(identifyInfo), "BD_CommonContact");
67 68 SuccessEntity first = repoRet.getResult().getResponseStatus().getSuccessEntitys().getFirst();
68 69 var res = new FT_BD_CUSTLOCATION();
... ...
tax-proxy/src/main/java/com/diligrp/tax/proxy/demarcate/kingdee/ReceiptSender.java
... ... @@ -36,12 +36,8 @@ public class ReceiptSender extends Sender&lt;ReceiptProxy&gt; {
36 36 @Override
37 37 public ReceiptProxy send(BaseMapping mappingObject, IdentifyInfo identifyInfo) {
38 38 ReceiptMapping mapping = (ReceiptMapping) mappingObject;
39   - List<Object> infos = KingDeeHelper.querySend(mapping, markDocument().value, new K3CloudApi(identifyInfo));
40   - if (!infos.isEmpty()) {
41   - throw new TaxAgentServiceException(TaxSystemType.REPEAT_SENDING);
42   - }
43   - RepoRet<?> repoRet = KingDeeHelper.auditSend(JsonUtils.convertValue(mapping, new TypeReference<>() {
44   - }), new K3CloudApi(identifyInfo), markDocument().value);
  39 + validMapping(identifyInfo, mapping);
  40 + RepoRet<?> repoRet = KingDeeHelper.auditSend(mapping, identifyInfo, markDocument().value);
45 41 ArrayList<SuccessEntity> successEntity = repoRet.getResult().getResponseStatus().getSuccessEntitys();
46 42 if (successEntity.isEmpty()) {
47 43 throw new TaxAgentServiceException(TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL);
... ...
tax-proxy/src/main/java/com/diligrp/tax/proxy/demarcate/kingdee/ReceivableSender.java
... ... @@ -6,17 +6,14 @@ import com.diligrp.tax.central.domain.proxy.kingdee.ReceivableProxy;
6 6 import com.diligrp.tax.central.exception.TaxAgentServiceException;
7 7 import com.diligrp.tax.central.type.DocumentType;
8 8 import com.diligrp.tax.central.type.TaxSystemType;
9   -import com.diligrp.tax.central.utils.JsonUtils;
10 9 import com.diligrp.tax.proxy.demarcate.Sender;
11 10 import com.diligrp.tax.proxy.helper.KingDeeHelper;
12   -import com.fasterxml.jackson.core.type.TypeReference;
13 11 import com.kingdee.bos.webapi.entity.IdentifyInfo;
14 12 import com.kingdee.bos.webapi.entity.RepoRet;
15 13 import com.kingdee.bos.webapi.entity.SuccessEntity;
16   -import com.kingdee.bos.webapi.sdk.K3CloudApi;
17 14 import org.springframework.stereotype.Component;
18 15  
19   -import java.util.*;
  16 +import java.util.ArrayList;
20 17  
21 18 /**
22 19 * @Author: zhangmeiyang
... ... @@ -34,13 +31,8 @@ public class ReceivableSender extends Sender&lt;ReceivableProxy&gt; {
34 31 @Override
35 32 public ReceivableProxy send(BaseMapping mappingObject, IdentifyInfo identifyInfo) {
36 33 ReceivableMapping mapping = (ReceivableMapping) mappingObject;
37   - List<Object> infos = KingDeeHelper.querySend(mapping, markDocument().value, new K3CloudApi(identifyInfo));
38   - if (!infos.isEmpty()) {
39   - throw new TaxAgentServiceException(TaxSystemType.REPEAT_SENDING);
40   - }
41   - Map<String, Object> model = JsonUtils.convertValue(mapping, new TypeReference<>() {
42   - });
43   - RepoRet<?> repoRet = KingDeeHelper.auditSend(model, new K3CloudApi(identifyInfo), markDocument().value);
  34 + validMapping(identifyInfo, mapping);
  35 + RepoRet<?> repoRet = KingDeeHelper.auditSend(mapping, identifyInfo, markDocument().value);
44 36 ArrayList<SuccessEntity> successEntity = repoRet.getResult().getResponseStatus().getSuccessEntitys();
45 37 if (successEntity.isEmpty()) {
46 38 throw new TaxAgentServiceException(TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL);
... ...
tax-proxy/src/main/java/com/diligrp/tax/proxy/demarcate/kingdee/RefundSender.java
... ... @@ -6,19 +6,14 @@ import com.diligrp.tax.central.domain.proxy.kingdee.RefundProxy;
6 6 import com.diligrp.tax.central.exception.TaxAgentServiceException;
7 7 import com.diligrp.tax.central.type.DocumentType;
8 8 import com.diligrp.tax.central.type.TaxSystemType;
9   -import com.diligrp.tax.central.utils.JsonUtils;
10 9 import com.diligrp.tax.proxy.demarcate.Sender;
11 10 import com.diligrp.tax.proxy.helper.KingDeeHelper;
12   -import com.fasterxml.jackson.core.type.TypeReference;
13 11 import com.kingdee.bos.webapi.entity.IdentifyInfo;
14 12 import com.kingdee.bos.webapi.entity.RepoRet;
15 13 import com.kingdee.bos.webapi.entity.SuccessEntity;
16   -import com.kingdee.bos.webapi.sdk.K3CloudApi;
17 14 import org.springframework.stereotype.Component;
18 15  
19 16 import java.util.ArrayList;
20   -import java.util.List;
21   -import java.util.Map;
22 17  
23 18 /**
24 19 * @Author: zhangmeiyang
... ... @@ -36,12 +31,8 @@ public class RefundSender extends Sender&lt;RefundProxy&gt; {
36 31 @Override
37 32 public RefundProxy send(BaseMapping mappingObject, IdentifyInfo identifyInfo) {
38 33 RefundMapping mapping = (RefundMapping) mappingObject;
39   - List<Object> infos = KingDeeHelper.querySend(mapping, markDocument().value, new K3CloudApi(identifyInfo));
40   - if (!infos.isEmpty()) {
41   - throw new TaxAgentServiceException(TaxSystemType.REPEAT_SENDING);
42   - }
43   - RepoRet<?> repoRet = KingDeeHelper.auditSend(JsonUtils.convertValue(mapping, new TypeReference<>() {
44   - }), new K3CloudApi(identifyInfo), markDocument().value);
  34 + validMapping(identifyInfo, mapping);
  35 + RepoRet<?> repoRet = KingDeeHelper.auditSend(mapping, identifyInfo, markDocument().value);
45 36 ArrayList<SuccessEntity> successEntity = repoRet.getResult().getResponseStatus().getSuccessEntitys();
46 37 if (successEntity.isEmpty()) {
47 38 throw new TaxAgentServiceException(TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL);
... ...
tax-proxy/src/main/java/com/diligrp/tax/proxy/helper/KingDeeHelper.java
... ... @@ -6,6 +6,7 @@ import com.diligrp.tax.central.type.TaxSystemType;
6 6 import com.diligrp.tax.central.utils.JsonUtils;
7 7 import com.diligrp.tax.proxy.message.KingDeeQuery;
8 8 import com.diligrp.tax.proxy.message.KingDeeSubmit;
  9 +import com.fasterxml.jackson.core.type.TypeReference;
9 10 import com.google.gson.Gson;
10 11 import com.kingdee.bos.webapi.entity.*;
11 12 import com.kingdee.bos.webapi.sdk.K3CloudApi;
... ... @@ -74,6 +75,32 @@ public class KingDeeHelper {
74 75 }
75 76 }
76 77  
  78 + /**
  79 + * 审计发送
  80 + *
  81 + * @param mapping 映射
  82 + * @param identifyInfo 识别信息
  83 + * @param formId 表单 ID
  84 + * @return {@link RepoRet }<{@link ? }>
  85 + */
  86 + public static RepoRet<?> auditSend(BaseMapping mapping, IdentifyInfo identifyInfo, String formId) {
  87 + var message = new KingDeeSubmit();
  88 + message.setModel(JsonUtils.convertValue(mapping, new TypeReference<>() {}));
  89 + message.setIsAutoSubmitAndAudit(true);
  90 + message.setIsAutoAdjustField(true);
  91 + var body = JsonUtils.toJsonString(message);
  92 + try {
  93 + log.info("kingdee auditSend: {}", body);
  94 + String res;
  95 + K3CloudApi api = getKingDeeApi(identifyInfo);
  96 + res = api.save(formId, body);
  97 + log.info("金蝶审核接口完成,formId={},res={}", formId, res);
  98 + return getRepoRet(res);
  99 + } catch (Exception e) {
  100 + log.error("金蝶审核接口调用异常", e);
  101 + throw new TaxAgentServiceException(TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL, e);
  102 + }
  103 + }
77 104  
78 105 /**
79 106 * 审计发送
... ...