Commit 0f11c8e8529cfe9219fe1cab6ebea29688958ae1
1 parent
d134d9e6
feat(storage): 新增映射错误管理功能
- 添加 MappingErrorApi 控制器,提供分页查询和重试接口 - 实现 MappingErrorService 的分页及消息重发逻辑 - 引入 MappingErrorCO 和 MappingErrorVO 数据传输对象 - 更新生产字段配置中的固定值参数 - 集成 RabbitMQ 消息队列用于重新推送失败的消息 - 使用 MyBatis Plus 进行数据库操作和分页处理 - 添加事务注解确保数据一致性
Showing
5 changed files
with
192 additions
and
2 deletions
doc/生产字段配置.md
| @@ -1704,7 +1704,7 @@ PLAT_WITHDRAW(11, "平台提现"); | @@ -1704,7 +1704,7 @@ PLAT_WITHDRAW(11, "平台提现"); | ||
| 1704 | "documentType": "AR_RECEIVEBILL", | 1704 | "documentType": "AR_RECEIVEBILL", |
| 1705 | "configKey": "bankCardNumber", | 1705 | "configKey": "bankCardNumber", |
| 1706 | "settingFieldType": 0, | 1706 | "settingFieldType": 0, |
| 1707 | - "fixedValue": "000002" | 1707 | + "fixedValue": "000001" |
| 1708 | } | 1708 | } |
| 1709 | ``` | 1709 | ``` |
| 1710 | 1710 | ||
| @@ -1943,7 +1943,7 @@ PLAT_WITHDRAW(11, "平台提现"); | @@ -1943,7 +1943,7 @@ PLAT_WITHDRAW(11, "平台提现"); | ||
| 1943 | "documentType": "AR_REFUNDBILL", | 1943 | "documentType": "AR_REFUNDBILL", |
| 1944 | "configKey": "bankCardNumber", | 1944 | "configKey": "bankCardNumber", |
| 1945 | "settingFieldType": 0, | 1945 | "settingFieldType": 0, |
| 1946 | - "fixedValue": "000002" | 1946 | + "fixedValue": "000001" |
| 1947 | } | 1947 | } |
| 1948 | ``` | 1948 | ``` |
| 1949 | 1949 |
tax-storage/src/main/java/com/diligrp/tax/storage/controller/MappingErrorApi.java
0 → 100644
| 1 | +package com.diligrp.tax.storage.controller; | ||
| 2 | + | ||
| 3 | +import com.diligrp.tax.central.message.Message; | ||
| 4 | +import com.diligrp.tax.central.message.Valid; | ||
| 5 | +import com.diligrp.tax.storage.model.co.MappingErrorCO; | ||
| 6 | +import com.diligrp.tax.storage.service.MappingErrorService; | ||
| 7 | +import jakarta.annotation.Resource; | ||
| 8 | +import org.springframework.validation.annotation.Validated; | ||
| 9 | +import org.springframework.web.bind.annotation.PathVariable; | ||
| 10 | +import org.springframework.web.bind.annotation.RequestBody; | ||
| 11 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 12 | +import org.springframework.web.bind.annotation.RestController; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * @Author: zhangmeiyang | ||
| 16 | + * @CreateTime: 2025-12-11 15:38 | ||
| 17 | + * @Version: todo | ||
| 18 | + */ | ||
| 19 | +@RestController | ||
| 20 | +@RequestMapping("/tax/tenant/mappingError") | ||
| 21 | +public class MappingErrorApi { | ||
| 22 | + | ||
| 23 | + @Resource | ||
| 24 | + private MappingErrorService mappingErrorService; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 分页 | ||
| 28 | + * | ||
| 29 | + * @param co 科罗拉多 | ||
| 30 | + * @return {@link Message }<{@link ? }> | ||
| 31 | + */ | ||
| 32 | + @RequestMapping("/page") | ||
| 33 | + public Message<?> page(@RequestBody @Validated(value = {Valid.Read.class}) MappingErrorCO co) { | ||
| 34 | + return Message.success(mappingErrorService.page(co)); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 重试 | ||
| 39 | + * | ||
| 40 | + * @param id 身份证 | ||
| 41 | + * @return {@link Message }<{@link ? }> | ||
| 42 | + */ | ||
| 43 | + @RequestMapping("/retry/{id}") | ||
| 44 | + public Message<?> retry(@PathVariable("id") Long id) { | ||
| 45 | + mappingErrorService.retry(id); | ||
| 46 | + return Message.success(); | ||
| 47 | + } | ||
| 48 | +} |
tax-storage/src/main/java/com/diligrp/tax/storage/model/co/MappingErrorCO.java
0 → 100644
| 1 | +package com.diligrp.tax.storage.model.co; | ||
| 2 | + | ||
| 3 | +import com.diligrp.tax.central.message.PageQuery; | ||
| 4 | +import com.diligrp.tax.central.message.Valid; | ||
| 5 | +import jakarta.validation.constraints.NotEmpty; | ||
| 6 | +import lombok.Getter; | ||
| 7 | +import lombok.Setter; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * @Author: zhangmeiyang | ||
| 11 | + * @CreateTime: 2025-12-11 15:41 | ||
| 12 | + * @Version: todo | ||
| 13 | + */ | ||
| 14 | +@Getter | ||
| 15 | +@Setter | ||
| 16 | +public class MappingErrorCO extends PageQuery { | ||
| 17 | + @NotEmpty(message = "group不能为空", groups = {Valid.Read.class}) | ||
| 18 | + private String group; | ||
| 19 | + @NotEmpty(message = "entity不能为空", groups = {Valid.Read.class}) | ||
| 20 | + private String entity; | ||
| 21 | + @NotEmpty(message = "pipelineCode不能为空", groups = {Valid.Read.class}) | ||
| 22 | + private String pipelineCode; | ||
| 23 | + @NotEmpty(message = "systemType不能为空", groups = {Valid.Read.class}) | ||
| 24 | + private String systemType; | ||
| 25 | +} |
tax-storage/src/main/java/com/diligrp/tax/storage/model/vo/MappingErrorVO.java
0 → 100644
| 1 | +package com.diligrp.tax.storage.model.vo; | ||
| 2 | + | ||
| 3 | +import lombok.Getter; | ||
| 4 | +import lombok.Setter; | ||
| 5 | + | ||
| 6 | +import java.time.LocalDateTime; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * @Author: zhangmeiyang | ||
| 10 | + * @CreateTime: 2025-12-11 15:45 | ||
| 11 | + * @Version: todo | ||
| 12 | + */ | ||
| 13 | +@Getter | ||
| 14 | +@Setter | ||
| 15 | +public class MappingErrorVO { | ||
| 16 | + /** | ||
| 17 | + * id | ||
| 18 | + */ | ||
| 19 | + private Long id; | ||
| 20 | + /** | ||
| 21 | + * 分组 | ||
| 22 | + */ | ||
| 23 | + private String group; | ||
| 24 | + /** | ||
| 25 | + * 实体 | ||
| 26 | + */ | ||
| 27 | + private String entity; | ||
| 28 | + /** | ||
| 29 | + * 租户账套编码 | ||
| 30 | + */ | ||
| 31 | + private String pipelineCode; | ||
| 32 | + /** | ||
| 33 | + * 文档类型 | ||
| 34 | + */ | ||
| 35 | + private String documentType; | ||
| 36 | + /** | ||
| 37 | + * 系统类型 | ||
| 38 | + */ | ||
| 39 | + private String systemType; | ||
| 40 | + /** | ||
| 41 | + * 同步系统数据唯一键 | ||
| 42 | + */ | ||
| 43 | + private String systemDataId; | ||
| 44 | + /** | ||
| 45 | + * 原始发送数据 | ||
| 46 | + */ | ||
| 47 | + private String originData; | ||
| 48 | + /** | ||
| 49 | + * 同步状态 | ||
| 50 | + */ | ||
| 51 | + private Integer state; | ||
| 52 | + /** | ||
| 53 | + * 错误信息 | ||
| 54 | + */ | ||
| 55 | + private String errorMessage; | ||
| 56 | + /** | ||
| 57 | + * 创建时间 | ||
| 58 | + */ | ||
| 59 | + private LocalDateTime createdTime; | ||
| 60 | + /** | ||
| 61 | + * 修改时间 | ||
| 62 | + */ | ||
| 63 | + private LocalDateTime modifiedTime; | ||
| 64 | +} |
tax-storage/src/main/java/com/diligrp/tax/storage/service/MappingErrorService.java
| 1 | package com.diligrp.tax.storage.service; | 1 | package com.diligrp.tax.storage.service; |
| 2 | 2 | ||
| 3 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
| 4 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
| 5 | +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||
| 6 | +import com.diligrp.tax.central.domain.MessageContext; | ||
| 3 | import com.diligrp.tax.central.model.PipelineMappingErrorDO; | 7 | import com.diligrp.tax.central.model.PipelineMappingErrorDO; |
| 4 | import com.diligrp.tax.central.service.IMappingErrorService; | 8 | import com.diligrp.tax.central.service.IMappingErrorService; |
| 9 | +import com.diligrp.tax.central.type.MappingStateType; | ||
| 10 | +import com.diligrp.tax.central.type.SystemType; | ||
| 5 | import com.diligrp.tax.central.utils.JsonUtils; | 11 | import com.diligrp.tax.central.utils.JsonUtils; |
| 6 | import com.diligrp.tax.storage.domain.MappingError; | 12 | import com.diligrp.tax.storage.domain.MappingError; |
| 13 | +import com.diligrp.tax.storage.model.co.MappingErrorCO; | ||
| 14 | +import com.diligrp.tax.storage.model.vo.MappingErrorVO; | ||
| 7 | import com.diligrp.tax.storage.repo.MappingErrorRepository; | 15 | import com.diligrp.tax.storage.repo.MappingErrorRepository; |
| 16 | +import com.fasterxml.jackson.core.type.TypeReference; | ||
| 8 | import jakarta.annotation.Resource; | 17 | import jakarta.annotation.Resource; |
| 18 | +import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
| 9 | import org.springframework.stereotype.Service; | 19 | import org.springframework.stereotype.Service; |
| 20 | +import org.springframework.transaction.annotation.Transactional; | ||
| 21 | + | ||
| 22 | +import static com.diligrp.tax.central.queue.TaxAutoPush.NORMAL_EXCHANGE; | ||
| 23 | +import static com.diligrp.tax.central.queue.TaxAutoPush.NORMAL_ROUTING; | ||
| 10 | 24 | ||
| 11 | /** | 25 | /** |
| 12 | * @Author: zhangmeiyang | 26 | * @Author: zhangmeiyang |
| @@ -19,14 +33,53 @@ public class MappingErrorService implements IMappingErrorService { | @@ -19,14 +33,53 @@ public class MappingErrorService implements IMappingErrorService { | ||
| 19 | @Resource | 33 | @Resource |
| 20 | private MappingErrorRepository mappingErrorRepository; | 34 | private MappingErrorRepository mappingErrorRepository; |
| 21 | 35 | ||
| 36 | + @Resource | ||
| 37 | + private RabbitTemplate rabbitTemplate; | ||
| 38 | + | ||
| 22 | /** | 39 | /** |
| 23 | * 插入 | 40 | * 插入 |
| 24 | * | 41 | * |
| 25 | * @param error 错误 | 42 | * @param error 错误 |
| 26 | */ | 43 | */ |
| 27 | @Override | 44 | @Override |
| 45 | + @Transactional | ||
| 28 | public void insert(PipelineMappingErrorDO error) { | 46 | public void insert(PipelineMappingErrorDO error) { |
| 29 | MappingError save = JsonUtils.convertValue(error, MappingError.class); | 47 | MappingError save = JsonUtils.convertValue(error, MappingError.class); |
| 30 | mappingErrorRepository.insert(save); | 48 | mappingErrorRepository.insert(save); |
| 31 | } | 49 | } |
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * 分页查询 | ||
| 53 | + * | ||
| 54 | + * @param co 科罗拉多 | ||
| 55 | + * @return {@link IPage }<{@link MappingErrorVO }> | ||
| 56 | + */ | ||
| 57 | + public IPage<MappingErrorVO> page(MappingErrorCO co) { | ||
| 58 | + Page<MappingError> page = new Page<>(co.getPageNumber(), co.getPageSize()); | ||
| 59 | + SystemType.validateSystemType(co.getSystemType()); | ||
| 60 | + LambdaQueryWrapper<MappingError> queryWrapper = new LambdaQueryWrapper<>(); | ||
| 61 | + queryWrapper.eq(MappingError::getGroup, co.getGroup()); | ||
| 62 | + queryWrapper.eq(MappingError::getEntity, co.getEntity()); | ||
| 63 | + queryWrapper.eq(MappingError::getPipelineCode, co.getPipelineCode()); | ||
| 64 | + queryWrapper.eq(MappingError::getSystemType, co.getSystemType()); | ||
| 65 | + Page<MappingError> pages = mappingErrorRepository.selectPage(page, queryWrapper); | ||
| 66 | + return pages.convert(e -> JsonUtils.convertValue(e, MappingErrorVO.class)); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + @Transactional | ||
| 70 | + public void retry(Long id) { | ||
| 71 | + MappingError error = mappingErrorRepository.selectById(id); | ||
| 72 | + MessageContext ctx = new MessageContext(); | ||
| 73 | + ctx.setSystemDataId(error.getSystemDataId()); | ||
| 74 | + ctx.setGroup(error.getGroup()); | ||
| 75 | + ctx.setEntity(error.getEntity()); | ||
| 76 | + ctx.setPipelineCode(error.getPipelineCode()); | ||
| 77 | + ctx.setDocumentType(error.getDocumentType()); | ||
| 78 | + ctx.setSystemType(error.getSystemType()); | ||
| 79 | + ctx.setMsgBody(JsonUtils.fromJsonString(error.getOriginData(), new TypeReference<>() {})); | ||
| 80 | + String messageJson = JsonUtils.toJsonString(ctx); | ||
| 81 | + rabbitTemplate.convertAndSend(NORMAL_EXCHANGE, NORMAL_ROUTING, messageJson); | ||
| 82 | + error.setState(MappingStateType.SYNC_RETRY.value); | ||
| 83 | + mappingErrorRepository.updateById(error); | ||
| 84 | + } | ||
| 32 | } | 85 | } |