Commit f45f595b531ab9d4ef1da0c6432f809a38a7e0bb
1 parent
27c00a4b
feat(tax): 新增映射错误处理机制并优化租户服务
- 新增 TaxMappingError 实体及对应仓储和服务实现 - 新增 ITaxMappingErrorService 接口用于处理映射错误记录-重构 TaxReceiveService,分离错误记录逻辑至独立服务 - 移除 TenantTaxService 类,功能合并到 TaxTenantService 并实现 ITaxTenantService 接口 - 调整 TenantStorageContext 使用 ITaxTenantService 接口而非具体实现 - 更新 ITaxPipelineMappingService 接口签名和依赖引用- 删除 TaxPipelineMapping 和 TaxPipelineMappingCreate 中的 errorMessage 字段 - CustomerBuilder 中补充设置 systemDataId 字段 - TaxReceiver 中调整消息预处理方式,直接使用 MessageContext 参数传递 -优化 MyBatis XML 映射文件,移除对 errorMessage 字段的操作 - 表结构同步删除 tax_pipeline_mapping 表中的 error_message 字段
Showing
17 changed files
with
321 additions
and
128 deletions
tax-boot/src/main/java/com/diligrp/tax/boot/receiver/TaxReceiver.java
| ... | ... | @@ -4,6 +4,7 @@ import com.diligrp.tax.boot.service.TaxReceiveService; |
| 4 | 4 | import com.diligrp.tax.central.domain.MessageContext; |
| 5 | 5 | import com.diligrp.tax.central.process.ProcessorChain; |
| 6 | 6 | import com.diligrp.tax.central.type.SystemType; |
| 7 | +import com.diligrp.tax.central.utils.JsonUtils; | |
| 7 | 8 | import com.rabbitmq.client.Channel; |
| 8 | 9 | import jakarta.annotation.Resource; |
| 9 | 10 | import lombok.extern.slf4j.Slf4j; |
| ... | ... | @@ -51,7 +52,8 @@ public class TaxReceiver { |
| 51 | 52 | log.info("tax-agent收到消息:{}", content); |
| 52 | 53 | MessageContext ctx = null; |
| 53 | 54 | try { |
| 54 | - ctx = taxReceiveService.messagePreHandle(content); | |
| 55 | + ctx = JsonUtils.fromJsonString(content, MessageContext.class); | |
| 56 | + taxReceiveService.messagePreHandle(ctx); | |
| 55 | 57 | var trans = processorChainMap.get(SystemType.from(ctx.getSystemType())).startProcess(ctx); |
| 56 | 58 | taxReceiveService.recordMapping(trans); |
| 57 | 59 | channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); | ... | ... |
tax-boot/src/main/java/com/diligrp/tax/boot/service/TaxReceiveService.java
| ... | ... | @@ -4,15 +4,16 @@ import com.diligrp.tax.central.context.TenantStorageContext; |
| 4 | 4 | import com.diligrp.tax.central.domain.MessageContext; |
| 5 | 5 | import com.diligrp.tax.central.exception.TaxAgentServiceException; |
| 6 | 6 | import com.diligrp.tax.central.model.TaxPipelineMappingCreate; |
| 7 | +import com.diligrp.tax.central.model.TaxPipelineMappingError; | |
| 7 | 8 | import com.diligrp.tax.central.model.TenantPipeline; |
| 8 | 9 | import com.diligrp.tax.central.model.TenantTaxPipelineMapping; |
| 10 | +import com.diligrp.tax.central.service.ITaxMappingErrorService; | |
| 9 | 11 | import com.diligrp.tax.central.service.ITaxPipelineMappingService; |
| 10 | -import com.diligrp.tax.central.service.ITenantTaxService; | |
| 12 | +import com.diligrp.tax.central.service.ITaxTenantService; | |
| 11 | 13 | import com.diligrp.tax.central.type.DocumentType; |
| 12 | 14 | import com.diligrp.tax.central.type.MappingStateType; |
| 13 | 15 | import com.diligrp.tax.central.type.SystemType; |
| 14 | 16 | import com.diligrp.tax.central.type.TaxSystemType; |
| 15 | -import com.diligrp.tax.central.utils.JsonUtils; | |
| 16 | 17 | import jakarta.annotation.Resource; |
| 17 | 18 | import org.springframework.stereotype.Service; |
| 18 | 19 | import org.springframework.transaction.annotation.Transactional; |
| ... | ... | @@ -30,14 +31,19 @@ import java.util.Optional; |
| 30 | 31 | public class TaxReceiveService { |
| 31 | 32 | |
| 32 | 33 | @Resource |
| 33 | - private ITenantTaxService tenantTaxService; | |
| 34 | + private ITaxTenantService tenantTaxService; | |
| 34 | 35 | |
| 35 | 36 | @Resource |
| 36 | 37 | private ITaxPipelineMappingService taxPipelineMappingService; |
| 37 | 38 | |
| 39 | + @Resource | |
| 40 | + private ITaxMappingErrorService taxMappingErrorService; | |
| 41 | + | |
| 42 | + @Resource | |
| 43 | + private TenantStorageContext tenantStorageContext; | |
| 44 | + | |
| 38 | 45 | |
| 39 | - public MessageContext messagePreHandle(String content) { | |
| 40 | - MessageContext ctx = JsonUtils.fromJsonString(content, MessageContext.class); | |
| 46 | + public void messagePreHandle(MessageContext ctx) { | |
| 41 | 47 | Long tenantId = tenantTaxService.getTenantId(ctx.getGroup(), ctx.getEntity()); |
| 42 | 48 | ctx.setTenantId(tenantId); |
| 43 | 49 | DocumentType from = DocumentType.from(ctx.getDocumentType()); |
| ... | ... | @@ -46,13 +52,13 @@ public class TaxReceiveService { |
| 46 | 52 | // 校验业务类型和系统类型 |
| 47 | 53 | ctx.setDocumentTypeEnum(from); |
| 48 | 54 | ctx.setSystemTypeEnum(system); |
| 49 | - Optional<TenantPipeline> option = TenantStorageContext.getTenantPipeline(ctx.getTenantId(), system, ctx.getPipelineCode()); | |
| 55 | + // 获取租户管道 | |
| 56 | + Optional<TenantPipeline> option = tenantStorageContext.getTenantPipeline(ctx.getTenantId(), system, ctx.getPipelineCode()); | |
| 50 | 57 | TenantPipeline pipeline = option.orElseThrow(() -> new TaxAgentServiceException(TaxSystemType.NO_MATCHING_SET_OF_ACCOUNTS_FOUND)); |
| 51 | 58 | //获取租户账套 |
| 52 | 59 | ctx.setTenantPipeline(pipeline); |
| 53 | 60 | //获取租户id |
| 54 | 61 | ctx.setTenantId(tenantTaxService.getTenantId(ctx.getGroup(), ctx.getEntity())); |
| 55 | - return ctx; | |
| 56 | 62 | } |
| 57 | 63 | |
| 58 | 64 | @Transactional |
| ... | ... | @@ -81,19 +87,17 @@ public class TaxReceiveService { |
| 81 | 87 | |
| 82 | 88 | @Transactional |
| 83 | 89 | public void recordMappingError(Exception e, MessageContext ctx) { |
| 84 | - StringWriter sw = new StringWriter(); | |
| 85 | - PrintWriter pw = new PrintWriter(sw); | |
| 86 | - e.printStackTrace(pw); | |
| 87 | - TaxPipelineMappingCreate create = new TaxPipelineMappingCreate(); | |
| 88 | - create.setTenantId(ctx.getTenantId()); | |
| 89 | - create.setPipelineId(ctx.getTenantPipeline().getId()); | |
| 90 | - create.setDocumentType(ctx.getDocumentType()); | |
| 91 | - create.setSystemDataId(ctx.getSystemDataId()); | |
| 92 | - create.setPipelineDataId(ctx.getPipelineDataId()); | |
| 93 | - create.setOriginData(ctx.getMsgBody()); | |
| 94 | - create.setState(MappingStateType.SYNC_FAILED.value); | |
| 95 | - create.setErrorMessage(sw.toString()); | |
| 96 | - taxPipelineMappingService.insert(create); | |
| 90 | + TaxPipelineMappingError error = new TaxPipelineMappingError(); | |
| 91 | + error.setGroup(ctx.getGroup()); | |
| 92 | + error.setEntity(ctx.getEntity()); | |
| 93 | + error.setDocumentType(ctx.getDocumentType()); | |
| 94 | + error.setSystemType(ctx.getSystemType()); | |
| 95 | + error.setSystemDataId(ctx.getSystemDataId()); | |
| 96 | + error.setPipelineCode(ctx.getPipelineCode()); | |
| 97 | + error.setOriginData(ctx.getMsgBody()); | |
| 98 | + error.setState(MappingStateType.SYNC_FAILED.value); | |
| 99 | + error.setErrorMessage(e.getMessage()); | |
| 100 | + taxMappingErrorService.insert(error); | |
| 97 | 101 | } |
| 98 | 102 | |
| 99 | 103 | } | ... | ... |
tax-central/src/main/java/com/diligrp/tax/central/context/TenantStorageContext.java
| ... | ... | @@ -3,22 +3,20 @@ package com.diligrp.tax.central.context; |
| 3 | 3 | import com.diligrp.tax.central.event.RestoreTenantEvent; |
| 4 | 4 | import com.diligrp.tax.central.model.TenantPipeline; |
| 5 | 5 | import com.diligrp.tax.central.model.TenantPipelineConfig; |
| 6 | -import com.diligrp.tax.central.service.ITenantTaxService; | |
| 6 | +import com.diligrp.tax.central.service.ITaxTenantService; | |
| 7 | 7 | import com.diligrp.tax.central.type.DocumentType; |
| 8 | 8 | import com.diligrp.tax.central.type.SystemType; |
| 9 | 9 | import jakarta.annotation.Resource; |
| 10 | 10 | import lombok.extern.slf4j.Slf4j; |
| 11 | -import org.springframework.beans.factory.DisposableBean; | |
| 12 | -import org.springframework.beans.factory.InitializingBean; | |
| 13 | 11 | import org.springframework.boot.CommandLineRunner; |
| 14 | 12 | import org.springframework.context.ApplicationEventPublisher; |
| 15 | 13 | import org.springframework.stereotype.Component; |
| 16 | 14 | |
| 17 | 15 | import java.util.List; |
| 18 | 16 | import java.util.Map; |
| 17 | +import java.util.Objects; | |
| 19 | 18 | import java.util.Optional; |
| 20 | 19 | import java.util.concurrent.ConcurrentHashMap; |
| 21 | -import java.util.concurrent.atomic.AtomicReference; | |
| 22 | 20 | import java.util.stream.Collectors; |
| 23 | 21 | |
| 24 | 22 | /** |
| ... | ... | @@ -31,20 +29,22 @@ import java.util.stream.Collectors; |
| 31 | 29 | public class TenantStorageContext implements CommandLineRunner { |
| 32 | 30 | |
| 33 | 31 | @Resource |
| 34 | - private ITenantTaxService tenantTaxService; | |
| 32 | + private ITaxTenantService tenantTaxService; | |
| 35 | 33 | @Resource |
| 36 | 34 | private ApplicationEventPublisher publisher; |
| 37 | 35 | |
| 38 | 36 | private static final ConcurrentHashMap<Long, Map<SystemType, Map<String, TenantPipeline>>> TENANT_PIPELINE_MAP = new ConcurrentHashMap<>(); |
| 39 | 37 | |
| 40 | - public static Optional<TenantPipeline> getTenantPipeline(Long tenantId, SystemType systemType, String pipelineCode) { | |
| 41 | - AtomicReference<TenantPipeline> pipeline = new AtomicReference<>(); | |
| 42 | - Map<SystemType, Map<String, TenantPipeline>> tenantPipelineMap = TENANT_PIPELINE_MAP.get(tenantId); | |
| 43 | - Optional.ofNullable(tenantPipelineMap).ifPresent(map -> { | |
| 44 | - Map<String, TenantPipeline> pipelineMap = map.get(systemType); | |
| 45 | - Optional.ofNullable(pipelineMap).ifPresent(e -> pipeline.set(pipelineMap.get(pipelineCode))); | |
| 46 | - }); | |
| 47 | - return Optional.of(pipeline.get()); | |
| 38 | + public Optional<TenantPipeline> getTenantPipeline(Long tenantId, SystemType systemType, String pipelineCode) { | |
| 39 | + var tpMap = TENANT_PIPELINE_MAP.get(tenantId); | |
| 40 | + if (Objects.isNull(tpMap)) { | |
| 41 | + return Optional.empty(); | |
| 42 | + } | |
| 43 | + Map<String, TenantPipeline> pipelineMap = tpMap.get(systemType); | |
| 44 | + if (Objects.isNull(pipelineMap)) { | |
| 45 | + return Optional.empty(); | |
| 46 | + } | |
| 47 | + return Optional.ofNullable(pipelineMap.get(pipelineCode)); | |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | public void loadTenantPipeline() { | ... | ... |
tax-central/src/main/java/com/diligrp/tax/central/model/TaxPipelineMappingCreate.java
tax-central/src/main/java/com/diligrp/tax/central/model/TaxPipelineMappingError.java
0 → 100644
| 1 | +package com.diligrp.tax.central.model; | |
| 2 | + | |
| 3 | +import jakarta.validation.constraints.NotEmpty; | |
| 4 | +import jakarta.validation.constraints.NotNull; | |
| 5 | +import lombok.Getter; | |
| 6 | +import lombok.Setter; | |
| 7 | + | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * @Author: zhangmeiyang | |
| 12 | + * @CreateTime: 2025-11-10 14:30 | |
| 13 | + * @Version: todo | |
| 14 | + */ | |
| 15 | +@Getter | |
| 16 | +@Setter | |
| 17 | +public class TaxPipelineMappingError { | |
| 18 | + /** | |
| 19 | + * id | |
| 20 | + */ | |
| 21 | + private Long id; | |
| 22 | + /** | |
| 23 | + * 分组 | |
| 24 | + */ | |
| 25 | + @NotEmpty | |
| 26 | + private String group; | |
| 27 | + /** | |
| 28 | + * 实体 | |
| 29 | + */ | |
| 30 | + @NotEmpty | |
| 31 | + private String entity; | |
| 32 | + /** | |
| 33 | + * 租户账套编码 | |
| 34 | + */ | |
| 35 | + @NotEmpty | |
| 36 | + private String pipelineCode; | |
| 37 | + /** | |
| 38 | + * 文档类型 | |
| 39 | + */ | |
| 40 | + @NotEmpty | |
| 41 | + private String documentType; | |
| 42 | + /** | |
| 43 | + * 系统类型 | |
| 44 | + */ | |
| 45 | + @NotEmpty | |
| 46 | + private String systemType; | |
| 47 | + /** | |
| 48 | + * 同步系统数据唯一键 | |
| 49 | + */ | |
| 50 | + @NotEmpty | |
| 51 | + private String systemDataId; | |
| 52 | + /** | |
| 53 | + * 原始发送数据 | |
| 54 | + */ | |
| 55 | + @NotEmpty | |
| 56 | + private String originData; | |
| 57 | + /** | |
| 58 | + * 同步状态 | |
| 59 | + */ | |
| 60 | + @NotNull | |
| 61 | + private Integer state; | |
| 62 | + /** | |
| 63 | + * 错误信息 | |
| 64 | + */ | |
| 65 | + private String errorMessage; | |
| 66 | +} | ... | ... |
tax-central/src/main/java/com/diligrp/tax/central/model/TenantTaxPipelineMapping.java
tax-central/src/main/java/com/diligrp/tax/central/service/ITaxMappingErrorService.java
0 → 100644
| 1 | +package com.diligrp.tax.central.service; | |
| 2 | + | |
| 3 | +import com.diligrp.tax.central.model.TaxPipelineMappingError; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * @Author: zhangmeiyang | |
| 7 | + * @CreateTime: 2025-11-10 14:29 | |
| 8 | + * @Version: todo | |
| 9 | + */ | |
| 10 | +public interface ITaxMappingErrorService { | |
| 11 | + | |
| 12 | + /** | |
| 13 | + * 插入 | |
| 14 | + * | |
| 15 | + * @param error 错误 | |
| 16 | + */ | |
| 17 | + void insert(TaxPipelineMappingError error); | |
| 18 | +} | ... | ... |
tax-central/src/main/java/com/diligrp/tax/central/service/ITaxPipelineMappingService.java
| 1 | 1 | package com.diligrp.tax.central.service; |
| 2 | 2 | |
| 3 | -import com.diligrp.tax.central.domain.MessageContext; | |
| 4 | 3 | import com.diligrp.tax.central.model.TaxPipelineMappingCreate; |
| 5 | 4 | import com.diligrp.tax.central.model.TenantTaxPipelineMapping; |
| 6 | -import org.springframework.validation.annotation.Validated; | |
| 7 | 5 | |
| 8 | 6 | import java.util.Optional; |
| 9 | 7 | |
| ... | ... | @@ -18,7 +16,7 @@ public interface ITaxPipelineMappingService { |
| 18 | 16 | * @param systemDataId 系统数据 ID |
| 19 | 17 | * @return {@link Optional }<{@link TenantTaxPipelineMapping }> |
| 20 | 18 | */ |
| 21 | - Optional<TenantTaxPipelineMapping> findByPipelineIdAndDocumentTypeAndSystemDataId(Long tenantId,Long pipelineId,String documentType,String systemDataId); | |
| 19 | + Optional<TenantTaxPipelineMapping> findByPipelineIdAndDocumentTypeAndSystemDataId(Long tenantId, Long pipelineId, String documentType, String systemDataId); | |
| 22 | 20 | |
| 23 | 21 | /** |
| 24 | 22 | * 插入 | ... | ... |
tax-central/src/main/java/com/diligrp/tax/central/service/ITenantTaxService.java renamed to tax-central/src/main/java/com/diligrp/tax/central/service/ITaxTenantService.java
tax-doc/src/main/java/com/diligrp/tax/doc/demarcate/kingdee/CustomerBuilder.java
| ... | ... | @@ -50,7 +50,10 @@ public class CustomerBuilder extends Builder<StandardCustomer> { |
| 50 | 50 | Optional.ofNullable(list).ifPresent(ts -> configureDefaultData(customer, ts)); |
| 51 | 51 | //查询数据库的客户信息 如果存在 赋值id |
| 52 | 52 | Optional<TenantTaxPipelineMapping> dbOptions = taxPipelineMappingService.findByPipelineIdAndDocumentTypeAndSystemDataId(pipeline.getTenantId(), pipeline.getId(), markDocument().value, systemDataId); |
| 53 | - dbOptions.ifPresent(e -> customer.setCustomerId(e.getPipelineDataId())); | |
| 53 | + dbOptions.ifPresent(e -> { | |
| 54 | + customer.setCustomerId(e.getPipelineDataId()); | |
| 55 | + customer.setSystemDataId(e.getSystemDataId()); | |
| 56 | + }); | |
| 54 | 57 | return customer; |
| 55 | 58 | } |
| 56 | 59 | ... | ... |
tax-storage/src/main/java/com/diligrp/tax/storage/domain/TaxMappingError.java
0 → 100644
| 1 | +package com.diligrp.tax.storage.domain; | |
| 2 | + | |
| 3 | +import com.baomidou.mybatisplus.annotation.IdType; | |
| 4 | +import com.baomidou.mybatisplus.annotation.TableField; | |
| 5 | +import com.baomidou.mybatisplus.annotation.TableId; | |
| 6 | +import com.baomidou.mybatisplus.annotation.TableName; | |
| 7 | +import jakarta.validation.constraints.NotEmpty; | |
| 8 | +import jakarta.validation.constraints.NotNull; | |
| 9 | +import lombok.Getter; | |
| 10 | +import lombok.Setter; | |
| 11 | + | |
| 12 | +import java.time.LocalDateTime; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * @Author: zhangmeiyang | |
| 16 | + * @CreateTime: 2025-11-10 14:42 | |
| 17 | + * @Version: todo | |
| 18 | + */ | |
| 19 | +@Setter | |
| 20 | +@Getter | |
| 21 | +@TableName(value = "tax_mapping_error") | |
| 22 | +public class TaxMappingError { | |
| 23 | + /** | |
| 24 | + * id | |
| 25 | + */ | |
| 26 | + @TableId(type = IdType.AUTO) | |
| 27 | + private Long id; | |
| 28 | + /** | |
| 29 | + * 分组 | |
| 30 | + */ | |
| 31 | + @TableField(value = "`group`") | |
| 32 | + private String group; | |
| 33 | + /** | |
| 34 | + * 实体 | |
| 35 | + */ | |
| 36 | + @TableField(value = "entity") | |
| 37 | + private String entity; | |
| 38 | + /** | |
| 39 | + * 租户账套编码 | |
| 40 | + */ | |
| 41 | + @TableField(value = "pipeline_code") | |
| 42 | + private String pipelineCode; | |
| 43 | + /** | |
| 44 | + * 文档类型 | |
| 45 | + */ | |
| 46 | + @TableField(value = "document_type") | |
| 47 | + private String documentType; | |
| 48 | + /** | |
| 49 | + * 系统类型 | |
| 50 | + */ | |
| 51 | + @TableField(value = "system_type") | |
| 52 | + private String systemType; | |
| 53 | + /** | |
| 54 | + * 同步系统数据唯一键 | |
| 55 | + */ | |
| 56 | + @TableField(value = "system_data_id") | |
| 57 | + private String systemDataId; | |
| 58 | + /** | |
| 59 | + * 原始发送数据 | |
| 60 | + */ | |
| 61 | + @TableField(value = "origin_data") | |
| 62 | + private String originData; | |
| 63 | + /** | |
| 64 | + * 同步状态 | |
| 65 | + */ | |
| 66 | + @TableField(value = "state") | |
| 67 | + private Integer state; | |
| 68 | + /** | |
| 69 | + * 错误信息 | |
| 70 | + */ | |
| 71 | + @TableField(value = "error_message") | |
| 72 | + private String errorMessage; | |
| 73 | + /** | |
| 74 | + * 创建时间 | |
| 75 | + */ | |
| 76 | + @TableField("created_time") | |
| 77 | + private LocalDateTime createdTime; | |
| 78 | + /** | |
| 79 | + * 修改时间 | |
| 80 | + */ | |
| 81 | + @TableField("modified_time") | |
| 82 | + private LocalDateTime modifiedTime; | |
| 83 | + | |
| 84 | +} | ... | ... |
tax-storage/src/main/java/com/diligrp/tax/storage/domain/TaxPipelineMapping.java
tax-storage/src/main/java/com/diligrp/tax/storage/repo/TaxMappingErrorRepository.java
0 → 100644
| 1 | +package com.diligrp.tax.storage.repo; | |
| 2 | + | |
| 3 | +import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |
| 4 | +import com.diligrp.tax.storage.domain.TaxMappingError; | |
| 5 | +import org.springframework.stereotype.Repository; | |
| 6 | + | |
| 7 | +@Repository | |
| 8 | +public interface TaxMappingErrorRepository extends BaseMapper<TaxMappingError> { | |
| 9 | +} | ... | ... |
tax-storage/src/main/java/com/diligrp/tax/storage/service/TaxMappingErrorService.java
0 → 100644
| 1 | +package com.diligrp.tax.storage.service; | |
| 2 | + | |
| 3 | +import com.diligrp.tax.central.model.TaxPipelineMappingError; | |
| 4 | +import com.diligrp.tax.central.service.ITaxMappingErrorService; | |
| 5 | +import com.diligrp.tax.central.utils.JsonUtils; | |
| 6 | +import com.diligrp.tax.storage.domain.TaxMappingError; | |
| 7 | +import com.diligrp.tax.storage.repo.TaxMappingErrorRepository; | |
| 8 | +import jakarta.annotation.Resource; | |
| 9 | +import org.springframework.stereotype.Service; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * @Author: zhangmeiyang | |
| 13 | + * @CreateTime: 2025-11-10 14:41 | |
| 14 | + * @Version: todo | |
| 15 | + */ | |
| 16 | +@Service | |
| 17 | +public class TaxMappingErrorService implements ITaxMappingErrorService { | |
| 18 | + | |
| 19 | + @Resource | |
| 20 | + private TaxMappingErrorRepository taxMappingErrorRepository; | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * 插入 | |
| 24 | + * | |
| 25 | + * @param error 错误 | |
| 26 | + */ | |
| 27 | + @Override | |
| 28 | + public void insert(TaxPipelineMappingError error) { | |
| 29 | + TaxMappingError save = JsonUtils.convertValue(error, TaxMappingError.class); | |
| 30 | + taxMappingErrorRepository.insert(save); | |
| 31 | + } | |
| 32 | +} | ... | ... |
tax-storage/src/main/java/com/diligrp/tax/storage/service/TaxTenantService.java
| ... | ... | @@ -4,16 +4,26 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| 4 | 4 | import com.baomidou.mybatisplus.core.metadata.IPage; |
| 5 | 5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| 6 | 6 | import com.diligrp.tax.central.exception.TaxAgentServiceException; |
| 7 | +import com.diligrp.tax.central.model.TenantPipeline; | |
| 8 | +import com.diligrp.tax.central.model.TenantPipelineConfig; | |
| 9 | +import com.diligrp.tax.central.service.ITaxTenantService; | |
| 10 | +import com.diligrp.tax.central.type.SystemType; | |
| 11 | +import com.diligrp.tax.central.type.TaxSystemType; | |
| 7 | 12 | import com.diligrp.tax.central.utils.JsonUtils; |
| 13 | +import com.diligrp.tax.storage.domain.TaxPipeline; | |
| 14 | +import com.diligrp.tax.storage.domain.TaxPipelineConfig; | |
| 8 | 15 | import com.diligrp.tax.storage.domain.TaxTenant; |
| 9 | 16 | import com.diligrp.tax.storage.model.co.TaxTenantCO; |
| 10 | 17 | import com.diligrp.tax.storage.model.vo.TaxTenantVO; |
| 18 | +import com.diligrp.tax.storage.repo.TaxPipelineConfigRepository; | |
| 19 | +import com.diligrp.tax.storage.repo.TaxPipelineRepository; | |
| 11 | 20 | import com.diligrp.tax.storage.repo.TaxTenantRepository; |
| 12 | 21 | import com.diligrp.tax.storage.type.StateType; |
| 13 | 22 | import jakarta.annotation.Resource; |
| 14 | 23 | import org.springframework.stereotype.Service; |
| 15 | 24 | import org.springframework.transaction.annotation.Transactional; |
| 16 | 25 | |
| 26 | +import java.util.List; | |
| 17 | 27 | import java.util.Optional; |
| 18 | 28 | |
| 19 | 29 | /** |
| ... | ... | @@ -23,12 +33,65 @@ import java.util.Optional; |
| 23 | 33 | * @date 2025/11/05 |
| 24 | 34 | */ |
| 25 | 35 | @Service |
| 26 | -public class TaxTenantService { | |
| 36 | +public class TaxTenantService implements ITaxTenantService { | |
| 27 | 37 | |
| 28 | 38 | @Resource |
| 29 | 39 | private TaxTenantRepository taxTenantRepository; |
| 30 | 40 | @Resource |
| 31 | 41 | private DynamicTaxPipelineMappingService dynamicTaxPipelineMappingService; |
| 42 | + @Resource | |
| 43 | + private TaxPipelineRepository taxPipelineRepository; | |
| 44 | + @Resource | |
| 45 | + private TaxPipelineConfigRepository taxPipelineConfigRepository; | |
| 46 | + | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * 获取租户 ID | |
| 50 | + * | |
| 51 | + * @param group 群 | |
| 52 | + * @param entity 实体 | |
| 53 | + * @return {@link Long } | |
| 54 | + */ | |
| 55 | + @Override | |
| 56 | + public Long getTenantId(String group, String entity) { | |
| 57 | + LambdaQueryWrapper<TaxTenant> queryWrapper = new LambdaQueryWrapper<>(); | |
| 58 | + queryWrapper.eq(TaxTenant::getGroup, group); | |
| 59 | + queryWrapper.eq(TaxTenant::getEntity, entity); | |
| 60 | + TaxTenant taxTenant = taxTenantRepository.selectOne(queryWrapper); | |
| 61 | + return Optional.ofNullable(taxTenant).orElseThrow(() -> new TaxAgentServiceException(TaxSystemType.NO_TENANT_INFORMATION_FOUND)).getId(); | |
| 62 | + } | |
| 63 | + | |
| 64 | + /** | |
| 65 | + * 列出所有启用管道 | |
| 66 | + * | |
| 67 | + * @return {@link List }<{@link TenantPipeline }> | |
| 68 | + */ | |
| 69 | + @Override | |
| 70 | + public List<TenantPipeline> listAllEnablePipeline() { | |
| 71 | + LambdaQueryWrapper<TaxPipeline> queryWrapper = new LambdaQueryWrapper<>(); | |
| 72 | + queryWrapper.eq(TaxPipeline::getState, StateType.ENABLE.value); | |
| 73 | + List<TaxPipeline> taxPipelines = taxPipelineRepository.selectList(queryWrapper); | |
| 74 | + return taxPipelines.stream().map(taxPipeline -> { | |
| 75 | + TenantPipeline pipeline = JsonUtils.convertValue(taxPipeline, TenantPipeline.class); | |
| 76 | + pipeline.setSystemType(SystemType.from(taxPipeline.getSystemCode())); | |
| 77 | + return pipeline; | |
| 78 | + }).toList(); | |
| 79 | + } | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * 按管道 ID 列出 | |
| 83 | + * | |
| 84 | + * @param pipelineId | |
| 85 | + * @return {@link List }<{@link TenantPipelineConfig }> | |
| 86 | + */ | |
| 87 | + @Override | |
| 88 | + public List<TenantPipelineConfig> listByPipelineId(Long pipelineId) { | |
| 89 | + LambdaQueryWrapper<TaxPipelineConfig> queryWrapper = new LambdaQueryWrapper<>(); | |
| 90 | + queryWrapper.eq(TaxPipelineConfig::getPipelineId, pipelineId); | |
| 91 | + List<TaxPipelineConfig> taxPipelineConfigs = taxPipelineConfigRepository.selectList(queryWrapper); | |
| 92 | + return taxPipelineConfigs.stream().map(taxPipelineConfig -> JsonUtils.convertValue(taxPipelineConfig, TenantPipelineConfig.class)).toList(); | |
| 93 | + } | |
| 94 | + | |
| 32 | 95 | |
| 33 | 96 | /** |
| 34 | 97 | * 获取租户 | ... | ... |
tax-storage/src/main/java/com/diligrp/tax/storage/service/TenantTaxService.java deleted
100644 → 0
| 1 | -package com.diligrp.tax.storage.service; | |
| 2 | - | |
| 3 | -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
| 4 | -import com.diligrp.tax.central.exception.TaxAgentServiceException; | |
| 5 | -import com.diligrp.tax.central.model.TenantPipeline; | |
| 6 | -import com.diligrp.tax.central.model.TenantPipelineConfig; | |
| 7 | -import com.diligrp.tax.central.service.ITenantTaxService; | |
| 8 | -import com.diligrp.tax.central.type.SystemType; | |
| 9 | -import com.diligrp.tax.central.type.TaxSystemType; | |
| 10 | -import com.diligrp.tax.central.utils.JsonUtils; | |
| 11 | -import com.diligrp.tax.storage.domain.TaxPipeline; | |
| 12 | -import com.diligrp.tax.storage.domain.TaxPipelineConfig; | |
| 13 | -import com.diligrp.tax.storage.domain.TaxTenant; | |
| 14 | -import com.diligrp.tax.storage.repo.TaxPipelineConfigRepository; | |
| 15 | -import com.diligrp.tax.storage.repo.TaxPipelineRepository; | |
| 16 | -import com.diligrp.tax.storage.repo.TaxTenantRepository; | |
| 17 | -import com.diligrp.tax.storage.type.StateType; | |
| 18 | -import jakarta.annotation.Resource; | |
| 19 | -import org.springframework.stereotype.Service; | |
| 20 | - | |
| 21 | -import java.util.List; | |
| 22 | -import java.util.Optional; | |
| 23 | - | |
| 24 | -/** | |
| 25 | - * @Author: zhangmeiyang | |
| 26 | - * @CreateTime: 2025-11-06 14:32 | |
| 27 | - * @Version: todo | |
| 28 | - */ | |
| 29 | -@Service | |
| 30 | -public class TenantTaxService implements ITenantTaxService { | |
| 31 | - | |
| 32 | - @Resource | |
| 33 | - private TaxTenantRepository taxTenantRepository; | |
| 34 | - | |
| 35 | - @Resource | |
| 36 | - private TaxPipelineRepository taxPipelineRepository; | |
| 37 | - | |
| 38 | - @Resource | |
| 39 | - private TaxPipelineConfigRepository taxPipelineConfigRepository; | |
| 40 | - | |
| 41 | - @Override | |
| 42 | - public Long getTenantId(String group, String entity) { | |
| 43 | - LambdaQueryWrapper<TaxTenant> queryWrapper = new LambdaQueryWrapper<>(); | |
| 44 | - queryWrapper.eq(TaxTenant::getGroup, group); | |
| 45 | - queryWrapper.eq(TaxTenant::getEntity, entity); | |
| 46 | - TaxTenant taxTenant = taxTenantRepository.selectOne(queryWrapper); | |
| 47 | - return Optional.ofNullable(taxTenant).orElseThrow(() -> new TaxAgentServiceException(TaxSystemType.NO_TENANT_INFORMATION_FOUND)).getId(); | |
| 48 | - } | |
| 49 | - | |
| 50 | - @Override | |
| 51 | - public List<TenantPipeline> listAllEnablePipeline() { | |
| 52 | - LambdaQueryWrapper<TaxPipeline> queryWrapper = new LambdaQueryWrapper<>(); | |
| 53 | - queryWrapper.eq(TaxPipeline::getState, StateType.ENABLE.value); | |
| 54 | - List<TaxPipeline> taxPipelines = taxPipelineRepository.selectList(queryWrapper); | |
| 55 | - return taxPipelines.stream().map(taxPipeline -> { | |
| 56 | - TenantPipeline pipeline = JsonUtils.convertValue(taxPipeline, TenantPipeline.class); | |
| 57 | - pipeline.setSystemType(SystemType.from(taxPipeline.getSystemCode())); | |
| 58 | - return pipeline; | |
| 59 | - }).toList(); | |
| 60 | - } | |
| 61 | - | |
| 62 | - @Override | |
| 63 | - public List<TenantPipelineConfig> listByPipelineId(Long pipelineId) { | |
| 64 | - LambdaQueryWrapper<TaxPipelineConfig> queryWrapper = new LambdaQueryWrapper<>(); | |
| 65 | - queryWrapper.eq(TaxPipelineConfig::getPipelineId, pipelineId); | |
| 66 | - List<TaxPipelineConfig> taxPipelineConfigs = taxPipelineConfigRepository.selectList(queryWrapper); | |
| 67 | - return taxPipelineConfigs.stream().map(taxPipelineConfig -> JsonUtils.convertValue(taxPipelineConfig, TenantPipelineConfig.class)).toList(); | |
| 68 | - } | |
| 69 | -} |
tax-storage/src/main/resources/com/diligrp/tax/storage/repo/TaxPipelineMappingRepository.xml
| ... | ... | @@ -9,7 +9,7 @@ |
| 9 | 9 | , pipeline_data_id |
| 10 | 10 | , origin_data |
| 11 | 11 | , state |
| 12 | - , error_message) | |
| 12 | + ) | |
| 13 | 13 | VALUES |
| 14 | 14 | ( #{pipelineId} |
| 15 | 15 | , #{documentType} |
| ... | ... | @@ -17,7 +17,7 @@ |
| 17 | 17 | , #{pipelineDataId} |
| 18 | 18 | , #{originData} |
| 19 | 19 | , #{state} |
| 20 | - , #{errorMessage}) | |
| 20 | + ) | |
| 21 | 21 | </insert> |
| 22 | 22 | <update id="updateStatus"> |
| 23 | 23 | UPDATE |
| ... | ... | @@ -36,7 +36,6 @@ |
| 36 | 36 | , pipeline_data_id |
| 37 | 37 | , origin_data |
| 38 | 38 | , state |
| 39 | - , error_message | |
| 40 | 39 | , created_Time |
| 41 | 40 | , modified_Time |
| 42 | 41 | FROM |
| ... | ... | @@ -58,7 +57,6 @@ |
| 58 | 57 | , pipeline_data_id |
| 59 | 58 | , origin_data |
| 60 | 59 | , state |
| 61 | - , error_message | |
| 62 | 60 | , created_Time |
| 63 | 61 | , modified_Time |
| 64 | 62 | FROM |
| ... | ... | @@ -80,7 +78,6 @@ |
| 80 | 78 | `system_data_id` varchar(50) NOT NULL COMMENT '系统数据ID', |
| 81 | 79 | `pipeline_data_id` varchar(50) NOT NULL COMMENT '账套数据ID', |
| 82 | 80 | `origin_data` json NOT NULL COMMENT '原始数据', |
| 83 | - `error_message` text NULL COMMENT '错误信息', | |
| 84 | 81 | `state` tinyint NOT NULL COMMENT '状态 0=已同步,1=同步失败,2=同步重试', |
| 85 | 82 | `created_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
| 86 | 83 | `modified_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', | ... | ... |