cad拆单多租户信息透传异常修复

This commit is contained in:
gaoqr
2025-05-14 17:52:43 +08:00
parent 47d473fc2d
commit 7e6758fc04
5 changed files with 52 additions and 30 deletions
@@ -21,4 +21,5 @@ public class ErrorCodeConstants {
public static final ErrorCode WEBCAD_ORDER_IMPORT_ORDER_PLATENUM_CHECK_ERROR = new ErrorCode(1_005_000_011, "导入失败:生产单【{}】下板件数量已达到{}片,无法继续导入");
public static final ErrorCode WEBCAD_ORDER_IMPORT_ORDER_PLATENUM_REACH_THRESHOLD_ERROR = new ErrorCode(1_005_000_012, "部分导入成功,生产单【{}】下板件数量已达到{}片,本次拆单超出部分不计入生产单");
public static final ErrorCode ORDER_IMPORT_PLATE_GOODS_NOMATCH_ERROR = new ErrorCode(1_005_000_013, "导入失败,板材库中无板材匹配,商品编码:{},商品名称:{},材质:{},颜色:{},厚度:{},品牌:{}");
public static final ErrorCode WEBCAD_ORDER_IMPORT_PEEK_NOT_EXIST_ERROR = new ErrorCode(1_005_000_014, "导入失败:数据源不存在,请检查消息可靠性");
}
@@ -142,12 +142,6 @@
<artifactId>spring-boot-admin-starter-server</artifactId> <!-- 实现 Spring Boot Admin Server 服务端 -->
</dependency>
<!-- 三方云服务相关 -->
<dependency>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-file</artifactId>
</dependency>
<dependency>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-mq</artifactId>
@@ -205,10 +199,6 @@
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-biz-operatelog</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-biz-organ</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-excel</artifactId>
@@ -281,7 +271,29 @@
<!-- 将依赖放到target/lib目录下 -->
<outputDirectory>target/lib</outputDirectory>
<!-- 排除自身的代码包-->
<excludeGroupIds>com.cf.imes</excludeGroupIds>
<!-- <excludeGroupIds>com.cf.imes</excludeGroupIds>-->
<excludeArtifactIds>
cf-common,
cf-module-infra-api,
cf-module-prod-plan-api,
cf-module-system-api,
cf-spring-boot-starter-banner,
cf-spring-boot-starter-biz-error-code,
cf-spring-boot-starter-biz-operatelog,
cf-spring-boot-starter-excel,
cf-spring-boot-starter-monitor,
cf-spring-boot-starter-mybatis,
cf-spring-boot-starter-redis,
cf-spring-boot-starter-rpc,
cf-spring-boot-starter-security,
cf-spring-boot-starter-web,
cf-spring-boot-starter-mq,
cf-spring-boot-starter-elasticsearch,
cf-module-prod-executor-api,
cf-spring-boot-starter-biz-id,
cf-spring-boot-starter-biz-dict,
cf-spring-boot-starter-test
</excludeArtifactIds>
</configuration>
</execution>
</executions>
@@ -1,7 +1,9 @@
package com.cf.imes.module.plan.service.orderImport.consumer;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil;
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
import com.cf.imes.framework.redis.constants.RedisKeyConstants;
import com.cf.imes.framework.redis.util.RedisLockUtil;
@@ -15,6 +17,7 @@ import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;
import org.thymeleaf.util.StringUtils;
import javax.annotation.Resource;
import java.io.IOException;
@@ -22,6 +25,7 @@ import java.util.List;
import java.util.Map;
import static com.cf.imes.framework.mq.rabbitmq.constant.RabbitMqConstants.ORDER_IMPORT_DEAD_LETTER_QUEUE;
import static com.cf.imes.module.plan.enums.ErrorCodeConstants.WEBCAD_ORDER_IMPORT_PEEK_NOT_EXIST_ERROR;
/**
* 生产单导入死信队列消费
@@ -45,12 +49,19 @@ public class OrderImportDeadLetterConsumer {
@RabbitListener(queues = ORDER_IMPORT_DEAD_LETTER_QUEUE)
public void receive(String message,
Channel channel,
@Header(value = "peek", required = false) String peek,
@Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag,
@Header(value = "x-death", required = false) List<Map<String, Object>> xDeath) throws IOException {
log.info("====================【生产单导入收到死信消息:{}】====================", message);
// 手动确认消息
channel.basicAck(deliveryTag, false);
if (StringUtils.isEmpty(peek)) {
throw ServiceExceptionUtil.exception(WEBCAD_ORDER_IMPORT_PEEK_NOT_EXIST_ERROR);
} else {
DynamicDataSourceContextHolder.push(peek);
}
Long organId = OrganContextHolder.getOrganId();
String deadLetterReason = getDeadLetterReason(xDeath);
@@ -1,6 +1,7 @@
package com.cf.imes.module.plan.service.orderImport.consumer;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil;
@@ -35,11 +36,13 @@ import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.thymeleaf.util.StringUtils;
import javax.annotation.Resource;
import static com.cf.imes.module.plan.enums.ErrorCodeConstants.ORDER_IMPORT_FAIL;
import static com.cf.imes.module.plan.enums.ErrorCodeConstants.ORDER_IMPORT_ORGANID_NOT_EXISTS;
import static com.cf.imes.module.plan.enums.ErrorCodeConstants.WEBCAD_ORDER_IMPORT_PEEK_NOT_EXIST_ERROR;
/**
* webcad拆单消费者
@@ -108,7 +111,10 @@ public class WebCadOrderImportConsumer {
private DataSourceTransactionManager transactionManager;
@RabbitListener(queues = "#{@orderImportWebCadQueueName}")
public void orderImport(String message, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) throws Exception {
public void orderImport(String message,
Channel channel,
@Header(value = "peek", required = false) String peek,
@Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) throws Exception {
log.info("====================【webcad异步拆单收到消息:{}】====================", message);
Long organId = null;
@@ -122,6 +128,12 @@ public class WebCadOrderImportConsumer {
if (ObjectUtil.isNull(organId)) {
throw ServiceExceptionUtil.exception(ORDER_IMPORT_ORGANID_NOT_EXISTS);
}
if (StringUtils.isEmpty(peek)) {
throw ServiceExceptionUtil.exception(WEBCAD_ORDER_IMPORT_PEEK_NOT_EXIST_ERROR);
} else {
DynamicDataSourceContextHolder.push(peek);
}
// 确认任务,更新状态为消费成功,没有找到任务中断后续消费
OrderImportTaskDO orderImportTaskDO = confirmOrderImport(taskId);
if (ObjectUtil.isNull(orderImportTaskDO)) {
@@ -137,18 +149,21 @@ public class WebCadOrderImportConsumer {
// 提交事务
transactionManager.commit(transactionStatus);
} catch (ServiceException se) {
String seMessage = se.getMessage();
log.error(seMessage);
// 回滚事务
if (transactionStatus != null) {
transactionManager.rollback(transactionStatus);
}
// 更新任务状态
orderImportTaskService.updateServiceExceptionTaskStatus(taskId, organId, se.getMessage());
orderImportTaskService.updateServiceExceptionTaskStatus(taskId, organId, seMessage);
nackSent = true;
// 确认消息进入死信队列
channel.basicNack(deliveryTag, false, false);
} catch (Exception e) {
log.error(ORDER_IMPORT_FAIL.getMsg(), e);
// 回滚事务
if (transactionStatus != null) {
transactionManager.rollback(transactionStatus);
@@ -160,7 +175,6 @@ public class WebCadOrderImportConsumer {
nackSent = true;
// 确认消息进入死信队列
channel.basicNack(deliveryTag, false, false);
log.error(ORDER_IMPORT_FAIL.getMsg(), e);
} finally {
// 手动确认消息接收
if (!nackSent) {