diff --git a/cf-framework/cf-spring-boot-starter-biz-organ/src/main/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethod.java b/cf-framework/cf-spring-boot-starter-biz-organ/src/main/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethod.java index 6b8d61c3c..782280514 100644 --- a/cf-framework/cf-spring-boot-starter-biz-organ/src/main/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethod.java +++ b/cf-framework/cf-spring-boot-starter-biz-organ/src/main/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethod.java @@ -16,8 +16,6 @@ package org.springframework.messaging.handler.invocation; -import cn.hutool.core.util.ObjectUtil; -import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; import com.cf.imes.framework.organ.core.context.OrganContextHolder; import com.cf.imes.framework.organ.core.util.OrganUtils; import org.springframework.core.DefaultParameterNameDiscoverer; @@ -35,7 +33,6 @@ import java.lang.reflect.Type; import java.util.Arrays; import static com.cf.imes.framework.web.core.util.WebFrameworkUtils.HEADER_ORGAN_ID; -import static com.cf.imes.framework.web.core.util.WebFrameworkUtils.HEADER_PEEK; /** * Extension of {@link HandlerMethod} that invokes the underlying method with @@ -125,7 +122,6 @@ public class InvocableHandlerMethod extends HandlerMethod { // 注意:如下是本类的改动点!!! // 情况一:无组织编号的情况 Long organId= parseorganId(message); - parsePeek(message); if (organId == null) { return doInvoke(args); } @@ -153,18 +149,6 @@ public class InvocableHandlerMethod extends HandlerMethod { throw new IllegalArgumentException("未知的数据类型:" + organId); } - /** - * 头部带有多数据源,透传 - * - * @param message - */ - private void parsePeek(Message message) { - Object peek = message.getHeaders().get(HEADER_PEEK); - if (ObjectUtil.isNotNull(peek)) { - DynamicDataSourceContextHolder.push(peek.toString()); - } - } - /** * Get the method argument values for the current message, checking the provided * argument values and falling back to the configured argument resolvers. diff --git a/cf-module-prod-plan/cf-module-prod-plan-api/src/main/java/com/cf/imes/module/plan/enums/ErrorCodeConstants.java b/cf-module-prod-plan/cf-module-prod-plan-api/src/main/java/com/cf/imes/module/plan/enums/ErrorCodeConstants.java index 283b5189f..d7a799882 100644 --- a/cf-module-prod-plan/cf-module-prod-plan-api/src/main/java/com/cf/imes/module/plan/enums/ErrorCodeConstants.java +++ b/cf-module-prod-plan/cf-module-prod-plan-api/src/main/java/com/cf/imes/module/plan/enums/ErrorCodeConstants.java @@ -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, "导入失败:数据源不存在,请检查消息可靠性"); } diff --git a/cf-module-prod-plan/cf-module-prod-plan-biz/pom.xml b/cf-module-prod-plan/cf-module-prod-plan-biz/pom.xml index eb9e52472..7b39b3ffb 100644 --- a/cf-module-prod-plan/cf-module-prod-plan-biz/pom.xml +++ b/cf-module-prod-plan/cf-module-prod-plan-biz/pom.xml @@ -142,12 +142,6 @@ spring-boot-admin-starter-server - - - com.cf.imes - cf-spring-boot-starter-file - - com.cf.imes cf-spring-boot-starter-mq @@ -205,10 +199,6 @@ com.cf.imes cf-spring-boot-starter-biz-operatelog - - com.cf.imes - cf-spring-boot-starter-biz-organ - com.cf.imes cf-spring-boot-starter-excel @@ -281,7 +271,29 @@ target/lib - com.cf.imes + + + 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 + diff --git a/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/consumer/OrderImportDeadLetterConsumer.java b/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/consumer/OrderImportDeadLetterConsumer.java index e79ced481..6418c86e2 100644 --- a/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/consumer/OrderImportDeadLetterConsumer.java +++ b/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/consumer/OrderImportDeadLetterConsumer.java @@ -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> 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); diff --git a/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/consumer/WebCadOrderImportConsumer.java b/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/consumer/WebCadOrderImportConsumer.java index 6c62a165a..1724d0003 100644 --- a/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/consumer/WebCadOrderImportConsumer.java +++ b/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/consumer/WebCadOrderImportConsumer.java @@ -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) {