Commit fe281fad282aa37177b165c24bdf31a4f6f2b1c5
1 parent
767330ab
feat(adopt): 新增金蝶客户同步功能
- 添加 AbstractCustomer、ContactCO 和 CustomerCO 模型类 - 修改 AdoptMessageController 支持金蝶客户同步接口参数 - 在 AdoptMessageServiceImpl 中实现金蝶数据映射逻辑 - 增加系统类型判断与异常处理机制 - 优化消息体构造方式,支持不同系统的数据转换
Showing
5 changed files
with
100 additions
and
13 deletions
tax-adopt/src/main/java/com/diligrp/tax/adopt/api/AdoptMessageController.java
| @@ -32,9 +32,13 @@ public class AdoptMessageController { | @@ -32,9 +32,13 @@ public class AdoptMessageController { | ||
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | /** | 34 | /** |
| 35 | - * 完全同步客户 | 35 | + * 完全同步客户(金蝶) |
| 36 | * | 36 | * |
| 37 | - * @param file 文件 | 37 | + * @param file 文件 |
| 38 | + * @param group 群 | ||
| 39 | + * @param entity 实体 | ||
| 40 | + * @param pipelineCode 管道代码 | ||
| 41 | + * @param documentType 文档类型 | ||
| 38 | * @return {@link Message }<{@link ? }> | 42 | * @return {@link Message }<{@link ? }> |
| 39 | */ | 43 | */ |
| 40 | @PostMapping("/fullySyncCustomer/{group}/{entity}/{pipelineCode}/{documentType}") | 44 | @PostMapping("/fullySyncCustomer/{group}/{entity}/{pipelineCode}/{documentType}") |
tax-adopt/src/main/java/com/diligrp/tax/adopt/model/AbstractCustomer.java
0 → 100644
tax-adopt/src/main/java/com/diligrp/tax/adopt/model/ContactCO.java
0 → 100644
| 1 | +package com.diligrp.tax.adopt.model; | ||
| 2 | + | ||
| 3 | +import lombok.Getter; | ||
| 4 | +import lombok.Setter; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * @Author: zhangmeiyang | ||
| 8 | + * @CreateTime: 2025-11-19 15:46 | ||
| 9 | + * @Version: todo | ||
| 10 | + */ | ||
| 11 | +@Getter | ||
| 12 | +@Setter | ||
| 13 | +public class ContactCO { | ||
| 14 | + private String contactName; | ||
| 15 | + private String contactPhone; | ||
| 16 | + private String contactAddress; | ||
| 17 | +} |
tax-adopt/src/main/java/com/diligrp/tax/adopt/model/CustomerCO.java
0 → 100644
| 1 | +package com.diligrp.tax.adopt.model; | ||
| 2 | + | ||
| 3 | +import lombok.Getter; | ||
| 4 | +import lombok.Setter; | ||
| 5 | + | ||
| 6 | +import java.util.List; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * @Author: zhangmeiyang | ||
| 10 | + * @CreateTime: 2025-11-19 15:30 | ||
| 11 | + * @Version: todo | ||
| 12 | + */ | ||
| 13 | +@Getter | ||
| 14 | +@Setter | ||
| 15 | +public class CustomerCO extends AbstractCustomer { | ||
| 16 | + private String customerCode; | ||
| 17 | + private String customerName; | ||
| 18 | + private String customerShortName; | ||
| 19 | + private String customerInvoiceTitle; | ||
| 20 | + private String legalPerson; | ||
| 21 | + private String idNumber; | ||
| 22 | + private String country; | ||
| 23 | + private String provincial; | ||
| 24 | + private String address; | ||
| 25 | + private String registerAddress; | ||
| 26 | + private String telephone; | ||
| 27 | + private List<ContactCO> contacts; | ||
| 28 | +} |
tax-adopt/src/main/java/com/diligrp/tax/adopt/service/impl/AdoptMessageServiceImpl.java
| 1 | package com.diligrp.tax.adopt.service.impl; | 1 | package com.diligrp.tax.adopt.service.impl; |
| 2 | 2 | ||
| 3 | +import com.diligrp.tax.adopt.model.AbstractCustomer; | ||
| 4 | +import com.diligrp.tax.adopt.model.ContactCO; | ||
| 5 | +import com.diligrp.tax.adopt.model.CustomerCO; | ||
| 3 | import com.diligrp.tax.adopt.model.ReceiveMessageCO; | 6 | import com.diligrp.tax.adopt.model.ReceiveMessageCO; |
| 4 | import com.diligrp.tax.adopt.service.AdoptMessageService; | 7 | import com.diligrp.tax.adopt.service.AdoptMessageService; |
| 5 | import com.diligrp.tax.adopt.util.ExcelUtils; | 8 | import com.diligrp.tax.adopt.util.ExcelUtils; |
| @@ -11,6 +14,7 @@ import com.diligrp.tax.central.service.ITaxTenantService; | @@ -11,6 +14,7 @@ import com.diligrp.tax.central.service.ITaxTenantService; | ||
| 11 | import com.diligrp.tax.central.type.TaxSystemType; | 14 | import com.diligrp.tax.central.type.TaxSystemType; |
| 12 | import com.diligrp.tax.central.utils.AdoptUtils; | 15 | import com.diligrp.tax.central.utils.AdoptUtils; |
| 13 | import com.diligrp.tax.central.utils.JsonUtils; | 16 | import com.diligrp.tax.central.utils.JsonUtils; |
| 17 | +import com.fasterxml.jackson.core.type.TypeReference; | ||
| 14 | import lombok.AllArgsConstructor; | 18 | import lombok.AllArgsConstructor; |
| 15 | import org.apache.commons.io.FilenameUtils; | 19 | import org.apache.commons.io.FilenameUtils; |
| 16 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; | 20 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| @@ -67,23 +71,42 @@ public class AdoptMessageServiceImpl implements AdoptMessageService { | @@ -67,23 +71,42 @@ public class AdoptMessageServiceImpl implements AdoptMessageService { | ||
| 67 | var book = switch (extension) { | 71 | var book = switch (extension) { |
| 68 | case "xlsx" -> new XSSFWorkbook(inputStream); | 72 | case "xlsx" -> new XSSFWorkbook(inputStream); |
| 69 | case "xls" -> new HSSFWorkbook(inputStream); | 73 | case "xls" -> new HSSFWorkbook(inputStream); |
| 70 | - default -> throw new TaxAgentServiceException(TaxSystemType.BUSINESS_MATCHES_ARE_INCORRECT, "未支持的文件格式"); | 74 | + default -> throw new TaxAgentServiceException(TaxSystemType.ABNORMAL_PARAMETERS, "未支持的文件格式"); |
| 71 | }; | 75 | }; |
| 72 | List<Map<String, Object>> list = ExcelUtils.processSheet(book); | 76 | List<Map<String, Object>> list = ExcelUtils.processSheet(book); |
| 73 | Optional<TenantPipeline> pipelineOptional = taxTenantService.findByTenantAndPipelineCode(group, entity, pipelineCode); | 77 | Optional<TenantPipeline> pipelineOptional = taxTenantService.findByTenantAndPipelineCode(group, entity, pipelineCode); |
| 74 | TenantPipeline pipeline = pipelineOptional.orElseThrow(() -> new TaxAgentServiceException(TaxSystemType.NO_MATCHING_SET_OF_ACCOUNTS_FOUND, "未找到匹配账套")); | 78 | TenantPipeline pipeline = pipelineOptional.orElseThrow(() -> new TaxAgentServiceException(TaxSystemType.NO_MATCHING_SET_OF_ACCOUNTS_FOUND, "未找到匹配账套")); |
| 75 | - list.forEach(map -> { | ||
| 76 | - ReceiveMessageCO receiveMessageCO = new ReceiveMessageCO(); | ||
| 77 | - receiveMessageCO.setMsgBody(map); | ||
| 78 | - receiveMessageCO.setGroup(group); | ||
| 79 | - receiveMessageCO.setEntity(entity); | ||
| 80 | - receiveMessageCO.setPipelineCode(pipelineCode); | ||
| 81 | - receiveMessageCO.setSystemType(pipeline.getSystemType().code); | ||
| 82 | - receiveMessageCO.setDocumentType(documentType); | ||
| 83 | - rabbitTemplate.convertAndSend(NORMAL_EXCHANGE, NORMAL_ROUTING, JsonUtils.toJsonString(receiveMessageCO)); | ||
| 84 | - }); | 79 | + list.forEach(map -> rabbitTemplate.convertAndSend(NORMAL_EXCHANGE, NORMAL_ROUTING, JsonUtils.toJsonString(getReceiveMessageCO(group, entity, pipelineCode, documentType, map, pipeline)))); |
| 85 | } catch (IOException e) { | 80 | } catch (IOException e) { |
| 86 | throw new TaxAgentServiceException(e.getMessage()); | 81 | throw new TaxAgentServiceException(e.getMessage()); |
| 87 | } | 82 | } |
| 88 | } | 83 | } |
| 84 | + | ||
| 85 | + private static ReceiveMessageCO getReceiveMessageCO(String group, String entity, String pipelineCode, String documentType, Map<String, Object> map, TenantPipeline pipeline) { | ||
| 86 | + var msgBody = switch (pipeline.getSystemType()) { | ||
| 87 | + case KING_DEE -> kingdeeMap(map); | ||
| 88 | + case YONG_YOU -> throw new TaxAgentServiceException(TaxSystemType.ABNORMAL_PARAMETERS, "未支持的系统形式"); | ||
| 89 | + }; | ||
| 90 | + ReceiveMessageCO receiveMessageCO = new ReceiveMessageCO(); | ||
| 91 | + AbstractCustomer abstractCustomer = JsonUtils.convertValue(map, AbstractCustomer.class); | ||
| 92 | + receiveMessageCO.setSystemDataId(abstractCustomer.getSystemDataId()); | ||
| 93 | + receiveMessageCO.setGroup(group); | ||
| 94 | + receiveMessageCO.setEntity(entity); | ||
| 95 | + receiveMessageCO.setPipelineCode(pipelineCode); | ||
| 96 | + receiveMessageCO.setSystemType(pipeline.getSystemType().code); | ||
| 97 | + receiveMessageCO.setDocumentType(documentType); | ||
| 98 | + receiveMessageCO.setMsgBody(msgBody); | ||
| 99 | + return receiveMessageCO; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + private static Map<String, Object> kingdeeMap(Map<String, Object> map) { | ||
| 103 | + CustomerCO customerCO = JsonUtils.convertValue(map, CustomerCO.class); | ||
| 104 | + var contact = new ContactCO(); | ||
| 105 | + contact.setContactName(customerCO.getCustomerName()); | ||
| 106 | + contact.setContactPhone(customerCO.getTelephone()); | ||
| 107 | + contact.setContactAddress(customerCO.getAddress()); | ||
| 108 | + customerCO.setContacts(List.of(contact)); | ||
| 109 | + return JsonUtils.convertValue(customerCO, new TypeReference<>() { | ||
| 110 | + }); | ||
| 111 | + } | ||
| 89 | } | 112 | } |