Commit bb29b34e2e22570430ce8e431c85571286cc6734
1 parent
0f11c8e8
refactor(kingdee): 提取成功响应验证逻辑到公共方法
- 在 Sender 基类中新增 validSuccess 方法统一处理空成功实体情况 - 移除 ReceiptSender、ReceivableSender 和 RefundSender 中重复的空列表检查代码 - 引入 JsonUtils 和 MessageFormat 用于构建详细的错误消息 - 当远程调用返回空的成功实体列表时,抛出带有错误详情的异常
Showing
4 changed files
with
21 additions
and
9 deletions
tax-proxy/src/main/java/com/diligrp/tax/proxy/demarcate/Sender.java
| ... | ... | @@ -8,9 +8,13 @@ import com.diligrp.tax.central.type.TaxSystemType; |
| 8 | 8 | import com.diligrp.tax.central.utils.JsonUtils; |
| 9 | 9 | import com.diligrp.tax.proxy.helper.KingDeeHelper; |
| 10 | 10 | import com.kingdee.bos.webapi.entity.IdentifyInfo; |
| 11 | +import com.kingdee.bos.webapi.entity.RepoRet; | |
| 12 | +import com.kingdee.bos.webapi.entity.SuccessEntity; | |
| 11 | 13 | import com.kingdee.bos.webapi.sdk.K3CloudApi; |
| 12 | 14 | import lombok.extern.slf4j.Slf4j; |
| 13 | 15 | |
| 16 | +import java.text.MessageFormat; | |
| 17 | +import java.util.ArrayList; | |
| 14 | 18 | import java.util.List; |
| 15 | 19 | import java.util.Optional; |
| 16 | 20 | |
| ... | ... | @@ -51,4 +55,12 @@ public abstract class Sender<T extends BaseProxy> { |
| 51 | 55 | }); |
| 52 | 56 | }); |
| 53 | 57 | } |
| 58 | + | |
| 59 | + protected void validSuccess(ArrayList<SuccessEntity> successEntity, RepoRet<?> repoRet) { | |
| 60 | + if (successEntity.isEmpty()) { | |
| 61 | + var errorArrayJson = JsonUtils.toJsonString(repoRet.getResult().getResponseStatus().getErrors()); | |
| 62 | + String format = MessageFormat.format("{0}, caused by: {1}", TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL.message, errorArrayJson); | |
| 63 | + throw new TaxAgentServiceException(TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL, format); | |
| 64 | + } | |
| 65 | + } | |
| 54 | 66 | } | ... | ... |
tax-proxy/src/main/java/com/diligrp/tax/proxy/demarcate/kingdee/ReceiptSender.java
| ... | ... | @@ -6,6 +6,7 @@ import com.diligrp.tax.central.domain.proxy.kingdee.ReceiptProxy; |
| 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; | |
| 9 | 10 | import com.diligrp.tax.proxy.demarcate.Sender; |
| 10 | 11 | import com.diligrp.tax.proxy.helper.KingDeeHelper; |
| 11 | 12 | import com.kingdee.bos.webapi.entity.IdentifyInfo; |
| ... | ... | @@ -13,6 +14,7 @@ import com.kingdee.bos.webapi.entity.RepoRet; |
| 13 | 14 | import com.kingdee.bos.webapi.entity.SuccessEntity; |
| 14 | 15 | import org.springframework.stereotype.Component; |
| 15 | 16 | |
| 17 | +import java.text.MessageFormat; | |
| 16 | 18 | import java.util.ArrayList; |
| 17 | 19 | |
| 18 | 20 | /** |
| ... | ... | @@ -34,9 +36,7 @@ public class ReceiptSender extends Sender<ReceiptProxy> { |
| 34 | 36 | validMapping(identifyInfo, mapping); |
| 35 | 37 | RepoRet<?> repoRet = KingDeeHelper.auditSend(mapping, identifyInfo, markDocument().value); |
| 36 | 38 | ArrayList<SuccessEntity> successEntity = repoRet.getResult().getResponseStatus().getSuccessEntitys(); |
| 37 | - if (successEntity.isEmpty()) { | |
| 38 | - throw new TaxAgentServiceException(TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL); | |
| 39 | - } | |
| 39 | + validSuccess(successEntity, repoRet); | |
| 40 | 40 | SuccessEntity first = successEntity.getFirst(); |
| 41 | 41 | var proxy = new ReceiptProxy(); |
| 42 | 42 | proxy.setThirdPartyId(first.getId()); | ... | ... |
tax-proxy/src/main/java/com/diligrp/tax/proxy/demarcate/kingdee/ReceivableSender.java
| ... | ... | @@ -6,6 +6,7 @@ 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; | |
| 9 | 10 | import com.diligrp.tax.proxy.demarcate.Sender; |
| 10 | 11 | import com.diligrp.tax.proxy.helper.KingDeeHelper; |
| 11 | 12 | import com.kingdee.bos.webapi.entity.IdentifyInfo; |
| ... | ... | @@ -13,6 +14,7 @@ import com.kingdee.bos.webapi.entity.RepoRet; |
| 13 | 14 | import com.kingdee.bos.webapi.entity.SuccessEntity; |
| 14 | 15 | import org.springframework.stereotype.Component; |
| 15 | 16 | |
| 17 | +import java.text.MessageFormat; | |
| 16 | 18 | import java.util.ArrayList; |
| 17 | 19 | |
| 18 | 20 | /** |
| ... | ... | @@ -34,9 +36,7 @@ public class ReceivableSender extends Sender<ReceivableProxy> { |
| 34 | 36 | validMapping(identifyInfo, mapping); |
| 35 | 37 | RepoRet<?> repoRet = KingDeeHelper.auditSend(mapping, identifyInfo, markDocument().value); |
| 36 | 38 | ArrayList<SuccessEntity> successEntity = repoRet.getResult().getResponseStatus().getSuccessEntitys(); |
| 37 | - if (successEntity.isEmpty()) { | |
| 38 | - throw new TaxAgentServiceException(TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL); | |
| 39 | - } | |
| 39 | + validSuccess(successEntity, repoRet); | |
| 40 | 40 | SuccessEntity first = successEntity.getFirst(); |
| 41 | 41 | var proxy = new ReceivableProxy(); |
| 42 | 42 | proxy.setThirdPartyId(first.getId()); | ... | ... |
tax-proxy/src/main/java/com/diligrp/tax/proxy/demarcate/kingdee/RefundSender.java
| ... | ... | @@ -6,6 +6,7 @@ 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; | |
| 9 | 10 | import com.diligrp.tax.proxy.demarcate.Sender; |
| 10 | 11 | import com.diligrp.tax.proxy.helper.KingDeeHelper; |
| 11 | 12 | import com.kingdee.bos.webapi.entity.IdentifyInfo; |
| ... | ... | @@ -13,6 +14,7 @@ import com.kingdee.bos.webapi.entity.RepoRet; |
| 13 | 14 | import com.kingdee.bos.webapi.entity.SuccessEntity; |
| 14 | 15 | import org.springframework.stereotype.Component; |
| 15 | 16 | |
| 17 | +import java.text.MessageFormat; | |
| 16 | 18 | import java.util.ArrayList; |
| 17 | 19 | |
| 18 | 20 | /** |
| ... | ... | @@ -34,9 +36,7 @@ public class RefundSender extends Sender<RefundProxy> { |
| 34 | 36 | validMapping(identifyInfo, mapping); |
| 35 | 37 | RepoRet<?> repoRet = KingDeeHelper.auditSend(mapping, identifyInfo, markDocument().value); |
| 36 | 38 | ArrayList<SuccessEntity> successEntity = repoRet.getResult().getResponseStatus().getSuccessEntitys(); |
| 37 | - if (successEntity.isEmpty()) { | |
| 38 | - throw new TaxAgentServiceException(TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL); | |
| 39 | - } | |
| 39 | + validSuccess(successEntity, repoRet); | |
| 40 | 40 | SuccessEntity first = successEntity.getFirst(); |
| 41 | 41 | var proxy = new RefundProxy(); |
| 42 | 42 | proxy.setThirdPartyId(first.getId()); | ... | ... |