Commit a285a3c84638a7c06d7d812aeb3142495d592ef3

Authored by zhangmeiyang
1 parent c29bc71d

feat(kingdee): 实现金蝶连接管理器及上下文支持- 新增 AbstractConnectionManager 抽象类,用于统一连接管理器接口

- 新增 KingDeeConnectionManager 实现类,负责创建金蝶 API 连接- 新增 ConnectionContext 类,用于注册和管理各类连接管理器- 修改 Sender 接口及其子类,将连接对象作为参数传入 send 方法- 更新 ProxyProcessor,通过上下文获取连接并传递给 Sender
- 移除废弃的 ConnectionIdentity 接口及相关实现
- 重构 TenantPipeline 类,优化配置映射结构
- 调整 MessageContext 中 tenantId 类型为 Long,并迁移 Context 至 domain 包
- 更新 ProcessorChain 和相关处理器方法签名以适配 MessageContext- 在 TenantStorageContext 中增加事件发布逻辑以支持租户数据加载- 添加 NO_MATCHING_SET_OF_ACCOUNTS_FOUND 错误码- 修改日志配置中 springProperty 的 scope 属性值为 messageContext
Showing 22 changed files with 167 additions and 127 deletions
tax-boot/src/main/java/com/diligrp/tax/boot/receiver/TaxReceiver.java
1 1 package com.diligrp.tax.boot.receiver;
2 2  
3   -import com.diligrp.tax.central.context.Context;
  3 +import com.diligrp.tax.central.domain.MessageContext;
4 4 import com.diligrp.tax.central.process.ProcessorChain;
5 5 import com.diligrp.tax.central.type.StatusType;
6 6 import com.diligrp.tax.central.type.SystemType;
... ... @@ -20,7 +20,6 @@ import java.io.PrintWriter;
20 20 import java.io.StringWriter;
21 21 import java.nio.charset.StandardCharsets;
22 22 import java.util.Map;
23   -import java.util.Optional;
24 23  
25 24 import static com.diligrp.tax.boot.queue.TaxAutoPush.*;
26 25  
... ... @@ -47,7 +46,7 @@ public class TaxReceiver {
47 46 public void receiveMessage(Channel channel, Message message) throws IOException {
48 47 var content = new String(message.getBody(), StandardCharsets.UTF_8);
49 48 log.info("tax-agent收到消息:{}", content);
50   - Context ctx = JsonUtils.fromJsonString(content, Context.class);
  49 + MessageContext ctx = JsonUtils.fromJsonString(content, MessageContext.class);
51 50 try {
52 51 handle(ctx);
53 52 channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
... ... @@ -59,13 +58,13 @@ public class TaxReceiver {
59 58 }
60 59 }
61 60  
62   - private void handle(Context ctx) {
63   - Context context = processorChainMap.get(SystemType.from(ctx.getSystemType())).startProcess(ctx);
64   - context.setStatus(StatusType.SUCCESS.code);
  61 + private void handle(MessageContext ctx) {
  62 + MessageContext messageContext = processorChainMap.get(SystemType.from(ctx.getSystemType())).startProcess(ctx);
  63 + messageContext.setStatus(StatusType.SUCCESS.code);
65 64 //TODO write to db
66 65 }
67 66  
68   - private void recordError(Exception e, Context ctx) {
  67 + private void recordError(Exception e, MessageContext ctx) {
69 68 StringWriter sw = new StringWriter();
70 69 PrintWriter pw = new PrintWriter(sw);
71 70 e.printStackTrace(pw);
... ...
tax-boot/src/main/resources/logback-spring.xml
... ... @@ -5,7 +5,7 @@
5 5 <!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径 -->
6 6 <property name="LOG_HOME" value="logs"/>
7 7 <!-- springProperty读取springboot配置属性 -->
8   - <springProperty scope="context" name="build.profile.id" source="spring.profiles.active"/>
  8 + <springProperty scope="messageContext" name="build.profile.id" source="spring.profiles.active"/>
9 9 <statusListener class="ch.qos.logback.core.status.NopStatusListener"/>
10 10 <!-- 日志控制台输出 -->
11 11 <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
... ...
tax-central/src/main/java/com/diligrp/tax/central/context/ConnectionContext.java 0 → 100644
  1 +package com.diligrp.tax.central.context;
  2 +
  3 +import com.diligrp.tax.central.manager.AbstractConnectionManager;
  4 +import com.diligrp.tax.central.type.SystemType;
  5 +import jakarta.annotation.Resource;
  6 +import org.springframework.beans.factory.DisposableBean;
  7 +import org.springframework.beans.factory.InitializingBean;
  8 +import org.springframework.stereotype.Component;
  9 +
  10 +import java.util.List;
  11 +import java.util.Map;
  12 +import java.util.concurrent.ConcurrentHashMap;
  13 +
  14 +/**
  15 + * @Author: zhangmeiyang
  16 + * @CreateTime: 2025-11-06 15:02
  17 + * @Version: todo
  18 + */
  19 +@Component
  20 +public class ConnectionContext implements InitializingBean, DisposableBean {
  21 +
  22 + public static final Map<SystemType, AbstractConnectionManager<?>> CONNECTION_MAP = new ConcurrentHashMap<>();
  23 +
  24 + @Resource
  25 + private List<AbstractConnectionManager<?>> connectionManagers;
  26 +
  27 + @Override
  28 + public void destroy() throws Exception {
  29 +
  30 + }
  31 +
  32 + @Override
  33 + public void afterPropertiesSet() throws Exception {
  34 + connectionManagers.forEach(c -> CONNECTION_MAP.put(c.markSystemType(), c));
  35 + }
  36 +}
... ...
tax-central/src/main/java/com/diligrp/tax/central/context/TenantStorageContext.java
1 1 package com.diligrp.tax.central.context;
2 2  
  3 +import com.diligrp.tax.central.event.RestoreTenantEvent;
3 4 import com.diligrp.tax.central.model.TenantPipeline;
4 5 import com.diligrp.tax.central.model.TenantPipelineConfig;
5 6 import com.diligrp.tax.central.service.ITenantTaxService;
  7 +import com.diligrp.tax.central.type.DocumentType;
6 8 import com.diligrp.tax.central.type.SystemType;
7 9 import jakarta.annotation.Resource;
  10 +import org.springframework.beans.factory.DisposableBean;
  11 +import org.springframework.beans.factory.InitializingBean;
  12 +import org.springframework.context.ApplicationEventPublisher;
8 13 import org.springframework.stereotype.Component;
9 14  
10 15 import java.util.List;
... ... @@ -20,10 +25,12 @@ import java.util.stream.Collectors;
20 25 * @Version: todo
21 26 */
22 27 @Component
23   -public class TenantStorageContext {
  28 +public class TenantStorageContext implements InitializingBean, DisposableBean {
24 29  
25 30 @Resource
26 31 private ITenantTaxService tenantTaxService;
  32 + @Resource
  33 + private ApplicationEventPublisher publisher;
27 34  
28 35 private static final ConcurrentHashMap<Long, Map<SystemType, Map<String, TenantPipeline>>> TENANT_PIPELINE_MAP = new ConcurrentHashMap<>();
29 36  
... ... @@ -32,14 +39,11 @@ public class TenantStorageContext {
32 39 Map<SystemType, Map<String, TenantPipeline>> tenantPipelineMap = TENANT_PIPELINE_MAP.get(tenantId);
33 40 Optional.ofNullable(tenantPipelineMap).ifPresent(map -> {
34 41 Map<String, TenantPipeline> pipelineMap = map.get(systemType);
35   - Optional.ofNullable(pipelineMap).ifPresent(e -> {
36   - pipeline.set(pipelineMap.get(pipelineCode));
37   - });
  42 + Optional.ofNullable(pipelineMap).ifPresent(e -> pipeline.set(pipelineMap.get(pipelineCode)));
38 43 });
39 44 return Optional.of(pipeline.get());
40 45 }
41 46  
42   -
43 47 public void loadTenantPipeline() {
44 48 List<TenantPipeline> taxPipelineVOS = tenantTaxService.listAllEnablePipeline();
45 49 Optional.ofNullable(taxPipelineVOS).ifPresent(pipelines -> {
... ... @@ -60,10 +64,19 @@ public class TenantStorageContext {
60 64 });
61 65 }
62 66  
63   -
64 67 private TenantPipeline loadConfig(TenantPipeline tenantPipeline) {
65 68 List<TenantPipelineConfig> list = tenantTaxService.listByPipelineId(tenantPipeline.getId());
66   - tenantPipeline.setTenantPipelineConfigs(list);
  69 + tenantPipeline.setTenantPipelineConfigs(list.stream().collect(Collectors.toMap(k -> DocumentType.from(k.getDocumentType()), v -> v)));
67 70 return tenantPipeline;
68 71 }
  72 +
  73 + @Override
  74 + public void destroy() throws Exception {
  75 +
  76 + }
  77 +
  78 + @Override
  79 + public void afterPropertiesSet() throws Exception {
  80 + publisher.publishEvent(new RestoreTenantEvent(this));
  81 + }
69 82 }
... ...
tax-central/src/main/java/com/diligrp/tax/central/domain/BaseMapping.java
1 1 package com.diligrp.tax.central.domain;
2 2  
  3 +import com.diligrp.tax.central.model.TenantPipeline;
3 4 import lombok.Getter;
4 5 import lombok.Setter;
5 6  
6   -import java.util.Set;
7   -
8 7 /**
9 8 * @Author: zhangmeiyang
10 9 * @CreateTime: 2025-10-30 17:25
... ... @@ -15,5 +14,4 @@ import java.util.Set;
15 14 public abstract class BaseMapping {
16 15 private String verifyInformation;
17 16 private String returnKeys;
18   - private Set<String> accountSet;
19 17 }
... ...
tax-central/src/main/java/com/diligrp/tax/central/context/Context.java renamed to tax-central/src/main/java/com/diligrp/tax/central/domain/MessageContext.java
1   -package com.diligrp.tax.central.context;
  1 +package com.diligrp.tax.central.domain;
2 2  
3   -import com.diligrp.tax.central.domain.BaseDocument;
4   -import com.diligrp.tax.central.domain.BaseMapping;
5   -import com.diligrp.tax.central.domain.BaseProxy;
6 3 import lombok.Getter;
7 4 import lombok.Setter;
8 5  
9 6 @Setter
10 7 @Getter
11   -public class Context {
  8 +public class MessageContext {
12 9 /**
13 10 * 开放 ID
14 11 */
... ... @@ -16,7 +13,7 @@ public class Context {
16 13 /**
17 14 * 租户 ID
18 15 */
19   - private String tenantId;
  16 + private Long tenantId;
20 17 /**
21 18 * 消息信息
22 19 */
... ...
tax-central/src/main/java/com/diligrp/tax/central/interfaces/ConnectionIdentity.java deleted 100644 → 0
1   -package com.diligrp.tax.central.interfaces;
2   -
3   -public interface ConnectionIdentity<T> {
4   -
5   - T getIdentity();
6   -}
tax-central/src/main/java/com/diligrp/tax/central/manager/AbstractConnectionManager.java 0 → 100644
  1 +package com.diligrp.tax.central.manager;
  2 +
  3 +import com.diligrp.tax.central.model.TenantPipeline;
  4 +import com.diligrp.tax.central.type.SystemType;
  5 +
  6 +public abstract class AbstractConnectionManager<T> {
  7 +
  8 + public abstract SystemType markSystemType();
  9 +
  10 + public abstract T getConnection(TenantPipeline tenantPipeline);
  11 +}
... ...
tax-central/src/main/java/com/diligrp/tax/central/manager/impl/KingDeeConnectionManager.java 0 → 100644
  1 +package com.diligrp.tax.central.manager.impl;
  2 +
  3 +import com.diligrp.tax.central.manager.AbstractConnectionManager;
  4 +import com.diligrp.tax.central.model.TenantPipeline;
  5 +import com.diligrp.tax.central.type.SystemType;
  6 +import com.diligrp.tax.central.utils.JsonUtils;
  7 +import com.kingdee.bos.webapi.entity.IdentifyInfo;
  8 +import com.kingdee.bos.webapi.sdk.K3CloudApi;
  9 +import org.springframework.stereotype.Component;
  10 +
  11 +/**
  12 + * @Author: zhangmeiyang
  13 + * @CreateTime: 2025-11-06 14:59
  14 + * @Version: todo
  15 + */
  16 +@Component
  17 +public class KingDeeConnectionManager extends AbstractConnectionManager<K3CloudApi> {
  18 + @Override
  19 + public SystemType markSystemType() {
  20 + return SystemType.KING_DEE;
  21 + }
  22 +
  23 + @Override
  24 + public K3CloudApi getConnection(TenantPipeline tenantPipeline) {
  25 + IdentifyInfo identifyInfo = JsonUtils.convertValue(tenantPipeline.getParams(), IdentifyInfo.class);
  26 + return new K3CloudApi(identifyInfo);
  27 + }
  28 +}
... ...
tax-central/src/main/java/com/diligrp/tax/central/model/TenantPipeline.java
1 1 package com.diligrp.tax.central.model;
2 2  
3   -import com.diligrp.tax.central.interfaces.ConnectionIdentity;
  3 +import com.diligrp.tax.central.type.DocumentType;
4 4 import com.diligrp.tax.central.type.SystemType;
5   -import com.diligrp.tax.central.utils.JsonUtils;
6   -import com.kingdee.bos.webapi.entity.IdentifyInfo;
7 5 import lombok.Builder;
8 6 import lombok.Getter;
9 7 import lombok.Setter;
10 8  
11   -import java.util.List;
12 9 import java.util.Map;
13 10  
14 11 /**
... ... @@ -19,17 +16,12 @@ import java.util.Map;
19 16 @Setter
20 17 @Getter
21 18 @Builder
22   -public class TenantPipeline implements ConnectionIdentity<IdentifyInfo> {
  19 +public class TenantPipeline {
23 20 private Long id;
24 21 private Long tenantId;
25 22 private SystemType systemType;
26 23 private String name;
27 24 private String code;
28 25 private Map<String, Object> params;
29   - private List<TenantPipelineConfig> tenantPipelineConfigs;
30   -
31   - @Override
32   - public IdentifyInfo getIdentity() {
33   - return JsonUtils.convertValue(params, IdentifyInfo.class);
34   - }
  26 + private Map<DocumentType, TenantPipelineConfig> tenantPipelineConfigs;
35 27 }
... ...
tax-central/src/main/java/com/diligrp/tax/central/process/Processor.java
1 1 package com.diligrp.tax.central.process;
2 2  
3   -import com.diligrp.tax.central.context.Context;
  3 +import com.diligrp.tax.central.domain.MessageContext;
4 4  
5 5  
6 6 /**
... ... @@ -14,10 +14,10 @@ public interface Processor {
14 14 /**
15 15 * 处理请求
16 16 *
17   - * @param context 输入上下文
  17 + * @param messageContext 输入上下文
18 18 * @return 输出上下文
19 19 */
20   - Context process(Context context);
  20 + MessageContext process(MessageContext messageContext);
21 21  
22 22  
23 23 /**
... ...
tax-central/src/main/java/com/diligrp/tax/central/process/ProcessorChain.java
1 1 package com.diligrp.tax.central.process;
2 2  
3   -import com.diligrp.tax.central.context.Context;
  3 +import com.diligrp.tax.central.domain.MessageContext;
4 4  
5 5 import java.util.Comparator;
6 6 import java.util.List;
... ... @@ -22,7 +22,7 @@ public class ProcessorChain {
22 22 /**
23 23 * 类型安全的流式处理
24 24 */
25   - public Context startProcess(Context context) {
26   - return processors.stream().reduce(context, (ctx, processor) -> processor.process(ctx), (ctx1, ctx2) -> ctx2);
  25 + public MessageContext startProcess(MessageContext messageContext) {
  26 + return processors.stream().reduce(messageContext, (ctx, processor) -> processor.process(ctx), (ctx1, ctx2) -> ctx2);
27 27 }
28 28 }
... ...
tax-central/src/main/java/com/diligrp/tax/central/type/TaxSystemType.java
... ... @@ -16,6 +16,7 @@ public enum TaxSystemType {
16 16 BUSINESS_MATCHES_ARE_INCORRECT(5005, "业务匹配不正确"),
17 17 REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL(5006, "远程服务调用异常"),
18 18 INVALID_HTTP_REQUEST_PARAMS(5007, "无效的http请求参数"),
  19 + NO_MATCHING_SET_OF_ACCOUNTS_FOUND(5008, "未找到匹配账套"),
19 20 ;
20 21 public final int code;
21 22 public final String message;
... ...
tax-doc/src/main/java/com/diligrp/tax/doc/process/kingdee/InitializeProcessor.java
1 1 package com.diligrp.tax.doc.process.kingdee;
2 2  
3   -import com.diligrp.tax.central.context.Context;
  3 +import com.diligrp.tax.central.domain.MessageContext;
4 4 import com.diligrp.tax.central.exception.TaxAgentServiceException;
5 5 import com.diligrp.tax.central.process.AbstractProcessor;
6 6 import com.diligrp.tax.central.type.DocumentType;
... ... @@ -25,14 +25,14 @@ import org.springframework.stereotype.Component;
25 25 public class InitializeProcessor extends AbstractProcessor {
26 26  
27 27 @Override
28   - public Context process(Context context) {
29   - DocumentType from = DocumentType.from(context.getDocumentType());
30   - SystemType system = SystemType.from(context.getSystemType());
  28 + public MessageContext process(MessageContext messageContext) {
  29 + DocumentType from = DocumentType.from(messageContext.getDocumentType());
  30 + SystemType system = SystemType.from(messageContext.getSystemType());
31 31 if (!system.documentTypes.contains(from)) {
32 32 throw new TaxAgentServiceException(TaxSystemType.BUSINESS_MATCHES_ARE_INCORRECT);
33 33 }
34 34 Builder<?> builder = DocumentContext.CONTEXT.get(from);
35   - context.setDocumentObject(builder.build(context.getMsgBody()));
36   - return context;
  35 + messageContext.setDocumentObject(builder.build(messageContext.getMsgBody()));
  36 + return messageContext;
37 37 }
38 38 }
... ...
tax-map/src/main/java/com/diligrp/tax/mapping/process/kingdee/MappingProcessor.java
1 1 package com.diligrp.tax.mapping.process.kingdee;
2 2  
3   -import com.diligrp.tax.central.context.Context;
  3 +import com.diligrp.tax.central.domain.MessageContext;
4 4 import com.diligrp.tax.central.domain.BaseMapping;
5 5 import com.diligrp.tax.central.exception.TaxAgentServiceException;
6 6 import com.diligrp.tax.central.process.AbstractProcessor;
... ... @@ -27,17 +27,17 @@ import java.util.Map;
27 27 public class MappingProcessor extends AbstractProcessor {
28 28  
29 29 @Override
30   - public Context process(Context context) {
31   - DocumentType from = DocumentType.from(context.getDocumentType());
32   - SystemType system = SystemType.from(context.getSystemType());
  30 + public MessageContext process(MessageContext messageContext) {
  31 + DocumentType from = DocumentType.from(messageContext.getDocumentType());
  32 + SystemType system = SystemType.from(messageContext.getSystemType());
33 33 if (!system.documentTypes.contains(from)) {
34 34 throw new TaxAgentServiceException(TaxSystemType.BUSINESS_MATCHES_ARE_INCORRECT);
35 35 }
36 36 Transformer<?> transformer = MappingContext.CONTEXT.get(from);
37   - BaseMapping transform = transformer.transform(context.getDocumentObject());
38   - context.setMappingObject(transform);
  37 + BaseMapping transform = transformer.transform(messageContext.getDocumentObject());
  38 + messageContext.setMappingObject(transform);
39 39 Map<String,Object> map = JsonUtils.convertValue(transform, new TypeReference<>() {});
40 40 log.info("转换结果,{}", JsonUtils.toJsonString(map));
41   - return context;
  41 + return messageContext;
42 42 }
43 43 }
... ...
tax-proxy/src/main/java/com/diligrp/tax/proxy/demarcate/Sender.java
... ... @@ -3,6 +3,7 @@ package com.diligrp.tax.proxy.demarcate;
3 3 import com.diligrp.tax.central.domain.BaseMapping;
4 4 import com.diligrp.tax.central.domain.BaseProxy;
5 5 import com.diligrp.tax.central.type.DocumentType;
  6 +import com.kingdee.bos.webapi.sdk.K3CloudApi;
6 7  
7 8 /**
8 9 * @Author: zhangmeiyang
... ... @@ -21,7 +22,8 @@ public abstract class Sender&lt;T extends BaseProxy&gt; {
21 22 * 变换
22 23 *
23 24 * @param mappingObject 映射对象
  25 + * @param connection
24 26 * @return {@link T }
25 27 */
26   - public abstract T send(BaseMapping mappingObject);
  28 + public abstract T send(BaseMapping mappingObject, K3CloudApi connection);
27 29 }
... ...
tax-proxy/src/main/java/com/diligrp/tax/proxy/demarcate/kingdee/CustomerSender.java
... ... @@ -35,30 +35,22 @@ public class CustomerSender extends Sender&lt;CustomerProxy&gt; {
35 35 }
36 36  
37 37 @Override
38   - public CustomerProxy send(BaseMapping mappingObject) {
39   - var identifyInfo = new IdentifyInfo();
40   - identifyInfo.setAppId("293965_6+dDWztPVvgY1X1vX67BzbyEyLSc2tqL");
41   - identifyInfo.setUserName("市场");
42   - identifyInfo.setServerUrl("http://120.46.151.190/k3cloud/");
43   - identifyInfo.setAppSecret("a384eaabf599461aa05d89ce4c366d27");
44   - identifyInfo.setdCID("66435fe720f1d3");
45   - K3CloudApi kingDeeApi = KingDeeHelper.getKingDeeApi(identifyInfo);
46   - //TODO 账套获取
  38 + public CustomerProxy send(BaseMapping mappingObject, K3CloudApi connection) {
47 39 CustomerMapping mapping = (CustomerMapping) mappingObject;
48 40 List<FT_BD_CUSTLOCATION> contacts = mapping.getFT_BD_CUSTLOCATION();
49 41 contacts.forEach(contact -> {
50 42 Map<String, Object> model = JsonUtils.convertValue(contact, new TypeReference<>() {
51 43 });
52   - RepoRet<?> repoRet = KingDeeHelper.nonAuditSend(model, kingDeeApi, "BD_CommonContact");
  44 + RepoRet<?> repoRet = KingDeeHelper.nonAuditSend(model, connection, "BD_CommonContact");
53 45 SuccessEntity first = repoRet.getResult().getResponseStatus().getSuccessEntitys().getFirst();
54 46 contact.getFContactId().setFNUMBER(first.getNumber());
55 47 });
56 48 // 联系人新增
57 49 Optional.ofNullable(mapping.getFCUSTID())
58 50 .filter(e -> !e.isEmpty())
59   - .ifPresent(e -> KingDeeHelper.unAuditSend(e, kingDeeApi, markDocument().value));
  51 + .ifPresent(e -> KingDeeHelper.unAuditSend(e, connection, markDocument().value));
60 52 RepoRet<?> repoRet = KingDeeHelper.auditSend(JsonUtils.convertValue(mapping, new TypeReference<>() {
61   - }), kingDeeApi, markDocument().value);
  53 + }), connection, markDocument().value);
62 54 //联系人新增和更新完成
63 55 ArrayList<SuccessEntity> successEntity = repoRet.getResult().getResponseStatus().getSuccessEntitys();
64 56 if (successEntity.isEmpty()) {
... ...
tax-proxy/src/main/java/com/diligrp/tax/proxy/demarcate/kingdee/ReceiptSender.java
... ... @@ -2,9 +2,7 @@ package com.diligrp.tax.proxy.demarcate.kingdee;
2 2  
3 3 import com.diligrp.tax.central.domain.BaseMapping;
4 4 import com.diligrp.tax.central.domain.mapping.kingdee.ReceiptMapping;
5   -import com.diligrp.tax.central.domain.mapping.kingdee.ReceivableMapping;
6 5 import com.diligrp.tax.central.domain.proxy.kingdee.ReceiptProxy;
7   -import com.diligrp.tax.central.domain.proxy.kingdee.ReceivableProxy;
8 6 import com.diligrp.tax.central.exception.TaxAgentServiceException;
9 7 import com.diligrp.tax.central.type.DocumentType;
10 8 import com.diligrp.tax.central.type.TaxSystemType;
... ... @@ -36,24 +34,13 @@ public class ReceiptSender extends Sender&lt;ReceiptProxy&gt; {
36 34 }
37 35  
38 36 @Override
39   - public ReceiptProxy send(BaseMapping mappingObject) {
  37 + public ReceiptProxy send(BaseMapping mappingObject, K3CloudApi connection) {
40 38 ReceiptMapping mapping = (ReceiptMapping) mappingObject;
41   -// Set<String> accountSet = mapping.getAccountSet();
42   - //TODO 获取账套信息并找到发送的IdentityInfo
43   - var identifyInfo = new IdentifyInfo();
44   - identifyInfo.setAppId("293965_6+dDWztPVvgY1X1vX67BzbyEyLSc2tqL");
45   - identifyInfo.setUserName("市场");
46   - identifyInfo.setServerUrl("http://120.46.151.190/k3cloud/");
47   - identifyInfo.setAppSecret("a384eaabf599461aa05d89ce4c366d27");
48   - identifyInfo.setdCID("66435fe720f1d3");
49   - K3CloudApi api = KingDeeHelper.getKingDeeApi(identifyInfo);
50   - List<Object> infos = KingDeeHelper.querySend(mapping, markDocument().value, identifyInfo);
  39 + List<Object> infos = KingDeeHelper.querySend(mapping, markDocument().value, connection);
51 40 if (!infos.isEmpty()) {
52 41 throw new TaxAgentServiceException(TaxSystemType.REPEAT_SENDING);
53 42 }
54   - Map<String, Object> model = JsonUtils.convertValue(mapping, new TypeReference<>() {
55   - });
56   - RepoRet<?> repoRet = KingDeeHelper.auditSend(model, api, markDocument().value);
  43 + RepoRet<?> repoRet = KingDeeHelper.auditSend(JsonUtils.convertValue(mapping, new TypeReference<>() {}), connection, markDocument().value);
57 44 ArrayList<SuccessEntity> successEntity = repoRet.getResult().getResponseStatus().getSuccessEntitys();
58 45 if (successEntity.isEmpty()) {
59 46 throw new TaxAgentServiceException(TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL);
... ...
tax-proxy/src/main/java/com/diligrp/tax/proxy/demarcate/kingdee/ReceivableSender.java
... ... @@ -32,24 +32,15 @@ public class ReceivableSender extends Sender&lt;ReceivableProxy&gt; {
32 32 }
33 33  
34 34 @Override
35   - public ReceivableProxy send(BaseMapping mappingObject) {
  35 + public ReceivableProxy send(BaseMapping mappingObject, K3CloudApi connection) {
36 36 ReceivableMapping mapping = (ReceivableMapping) mappingObject;
37   -// Set<String> accountSet = mapping.getAccountSet();
38   - //TODO 获取账套信息并找到发送的IdentityInfo
39   - var identifyInfo = new IdentifyInfo();
40   - identifyInfo.setAppId("293965_6+dDWztPVvgY1X1vX67BzbyEyLSc2tqL");
41   - identifyInfo.setUserName("市场");
42   - identifyInfo.setServerUrl("http://120.46.151.190/k3cloud/");
43   - identifyInfo.setAppSecret("a384eaabf599461aa05d89ce4c366d27");
44   - identifyInfo.setdCID("66435fe720f1d3");
45   - K3CloudApi api = KingDeeHelper.getKingDeeApi(identifyInfo);
46   - List<Object> infos = KingDeeHelper.querySend(mapping, markDocument().value, identifyInfo);
  37 + List<Object> infos = KingDeeHelper.querySend(mapping, markDocument().value, connection);
47 38 if (!infos.isEmpty()) {
48 39 throw new TaxAgentServiceException(TaxSystemType.REPEAT_SENDING);
49 40 }
50 41 Map<String, Object> model = JsonUtils.convertValue(mapping, new TypeReference<>() {
51 42 });
52   - RepoRet<?> repoRet = KingDeeHelper.auditSend(model, api, markDocument().value);
  43 + RepoRet<?> repoRet = KingDeeHelper.auditSend(model, connection, markDocument().value);
53 44 ArrayList<SuccessEntity> successEntity = repoRet.getResult().getResponseStatus().getSuccessEntitys();
54 45 if (successEntity.isEmpty()) {
55 46 throw new TaxAgentServiceException(TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL);
... ...
tax-proxy/src/main/java/com/diligrp/tax/proxy/demarcate/kingdee/RefundSender.java
... ... @@ -34,24 +34,13 @@ public class RefundSender extends Sender&lt;RefundProxy&gt; {
34 34 }
35 35  
36 36 @Override
37   - public RefundProxy send(BaseMapping mappingObject) {
  37 + public RefundProxy send(BaseMapping mappingObject, K3CloudApi connection) {
38 38 RefundMapping mapping = (RefundMapping) mappingObject;
39   -// Set<String> accountSet = mapping.getAccountSet();
40   - //TODO 获取账套信息并找到发送的IdentityInfo
41   - var identifyInfo = new IdentifyInfo();
42   - identifyInfo.setAppId("293965_6+dDWztPVvgY1X1vX67BzbyEyLSc2tqL");
43   - identifyInfo.setUserName("市场");
44   - identifyInfo.setServerUrl("http://120.46.151.190/k3cloud/");
45   - identifyInfo.setAppSecret("a384eaabf599461aa05d89ce4c366d27");
46   - identifyInfo.setdCID("66435fe720f1d3");
47   - K3CloudApi api = KingDeeHelper.getKingDeeApi(identifyInfo);
48   - List<Object> infos = KingDeeHelper.querySend(mapping, markDocument().value, identifyInfo);
  39 + List<Object> infos = KingDeeHelper.querySend(mapping, markDocument().value, connection);
49 40 if (!infos.isEmpty()) {
50 41 throw new TaxAgentServiceException(TaxSystemType.REPEAT_SENDING);
51 42 }
52   - Map<String, Object> model = JsonUtils.convertValue(mapping, new TypeReference<>() {
53   - });
54   - RepoRet<?> repoRet = KingDeeHelper.auditSend(model, api, markDocument().value);
  43 + RepoRet<?> repoRet = KingDeeHelper.auditSend(JsonUtils.convertValue(mapping, new TypeReference<>() {}), connection, markDocument().value);
55 44 ArrayList<SuccessEntity> successEntity = repoRet.getResult().getResponseStatus().getSuccessEntitys();
56 45 if (successEntity.isEmpty()) {
57 46 throw new TaxAgentServiceException(TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL);
... ...
tax-proxy/src/main/java/com/diligrp/tax/proxy/helper/KingDeeHelper.java
... ... @@ -124,10 +124,9 @@ public class KingDeeHelper {
124 124 }
125 125 }
126 126  
127   - public static <T extends BaseMapping> List<Object> querySend(T t, String formId, IdentifyInfo identifyInfo) {
  127 + public static <T extends BaseMapping> List<Object> querySend(T t, String formId, K3CloudApi kingDeeApi) {
128 128 var filterString = t.getVerifyInformation();
129 129 var fieldKeys = t.getReturnKeys();
130   - K3CloudApi kingDeeApi = getKingDeeApi(identifyInfo);
131 130 return querySend(formId, filterString, fieldKeys, kingDeeApi);
132 131 }
133 132  
... ...
tax-proxy/src/main/java/com/diligrp/tax/proxy/process/kingdee/ProxyProcessor.java
1 1 package com.diligrp.tax.proxy.process.kingdee;
2 2  
3   -import com.diligrp.tax.central.context.Context;
  3 +import com.diligrp.tax.central.context.ConnectionContext;
  4 +import com.diligrp.tax.central.context.TenantStorageContext;
4 5 import com.diligrp.tax.central.domain.BaseProxy;
  6 +import com.diligrp.tax.central.domain.MessageContext;
  7 +import com.diligrp.tax.central.exception.TaxAgentServiceException;
  8 +import com.diligrp.tax.central.manager.AbstractConnectionManager;
  9 +import com.diligrp.tax.central.model.TenantPipeline;
5 10 import com.diligrp.tax.central.process.AbstractProcessor;
6 11 import com.diligrp.tax.central.type.DocumentType;
7   -import com.diligrp.tax.central.utils.JsonUtils;
  12 +import com.diligrp.tax.central.type.SystemType;
  13 +import com.diligrp.tax.central.type.TaxSystemType;
8 14 import com.diligrp.tax.proxy.context.ProxyContext;
  15 +import com.kingdee.bos.webapi.sdk.K3CloudApi;
9 16 import lombok.extern.slf4j.Slf4j;
10 17 import org.springframework.core.annotation.Order;
11 18 import org.springframework.stereotype.Component;
12 19  
  20 +import java.util.Optional;
  21 +
13 22 /**
14 23 * 代理发送处理器
15 24 * 将Map<String, Object>发送到目标系统
... ... @@ -20,13 +29,15 @@ import org.springframework.stereotype.Component;
20 29 public class ProxyProcessor extends AbstractProcessor {
21 30  
22 31 @Override
23   - public Context process(Context context) {
24   - log.info("开始发送代理请求");
25   - log.info("base-document,{}", JsonUtils.toJsonString(context.getDocumentObject()));
26   - log.info("base-mapping,{}", JsonUtils.toJsonString(context.getMappingObject()));
27   - DocumentType from = DocumentType.from(context.getDocumentType());
28   - BaseProxy send = ProxyContext.CONTEXT.get(from).send(context.getMappingObject());
29   - context.setProxyObject(send);
30   - return context;
  32 + public MessageContext process(MessageContext messageContext) {
  33 + DocumentType from = DocumentType.from(messageContext.getDocumentType());
  34 + SystemType systemType = SystemType.from(messageContext.getSystemType());
  35 + Optional<TenantPipeline> option = TenantStorageContext.getTenantPipeline(messageContext.getTenantId(), systemType, from.value);
  36 + TenantPipeline pipeline = option.orElseThrow(() -> new TaxAgentServiceException(TaxSystemType.NO_MATCHING_SET_OF_ACCOUNTS_FOUND));
  37 + AbstractConnectionManager<?> abstractConnectionManager = ConnectionContext.CONNECTION_MAP.get(systemType);
  38 + K3CloudApi connection = (K3CloudApi) abstractConnectionManager.getConnection(pipeline);
  39 + BaseProxy send = ProxyContext.CONTEXT.get(from).send(messageContext.getMappingObject(), connection);
  40 + messageContext.setProxyObject(send);
  41 + return messageContext;
31 42 }
32 43 }
... ...