mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-14 13:42:07 +08:00
cad拆单多租户信息透传异常修复
This commit is contained in:
-16
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package org.springframework.messaging.handler.invocation;
|
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.context.OrganContextHolder;
|
||||||
import com.cf.imes.framework.organ.core.util.OrganUtils;
|
import com.cf.imes.framework.organ.core.util.OrganUtils;
|
||||||
import org.springframework.core.DefaultParameterNameDiscoverer;
|
import org.springframework.core.DefaultParameterNameDiscoverer;
|
||||||
@@ -35,7 +33,6 @@ import java.lang.reflect.Type;
|
|||||||
import java.util.Arrays;
|
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_ORGAN_ID;
|
||||||
import static com.cf.imes.framework.web.core.util.WebFrameworkUtils.HEADER_PEEK;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extension of {@link HandlerMethod} that invokes the underlying method with
|
* Extension of {@link HandlerMethod} that invokes the underlying method with
|
||||||
@@ -125,7 +122,6 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
|||||||
// 注意:如下是本类的改动点!!!
|
// 注意:如下是本类的改动点!!!
|
||||||
// 情况一:无组织编号的情况
|
// 情况一:无组织编号的情况
|
||||||
Long organId= parseorganId(message);
|
Long organId= parseorganId(message);
|
||||||
parsePeek(message);
|
|
||||||
if (organId == null) {
|
if (organId == null) {
|
||||||
return doInvoke(args);
|
return doInvoke(args);
|
||||||
}
|
}
|
||||||
@@ -153,18 +149,6 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
|||||||
throw new IllegalArgumentException("未知的数据类型:" + organId);
|
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
|
* Get the method argument values for the current message, checking the provided
|
||||||
* argument values and falling back to the configured argument resolvers.
|
* argument values and falling back to the configured argument resolvers.
|
||||||
|
|||||||
+1
@@ -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_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 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 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 服务端 -->
|
<artifactId>spring-boot-admin-starter-server</artifactId> <!-- 实现 Spring Boot Admin Server 服务端 -->
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 三方云服务相关 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.cf.imes</groupId>
|
|
||||||
<artifactId>cf-spring-boot-starter-file</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.cf.imes</groupId>
|
<groupId>com.cf.imes</groupId>
|
||||||
<artifactId>cf-spring-boot-starter-mq</artifactId>
|
<artifactId>cf-spring-boot-starter-mq</artifactId>
|
||||||
@@ -205,10 +199,6 @@
|
|||||||
<groupId>com.cf.imes</groupId>
|
<groupId>com.cf.imes</groupId>
|
||||||
<artifactId>cf-spring-boot-starter-biz-operatelog</artifactId>
|
<artifactId>cf-spring-boot-starter-biz-operatelog</artifactId>
|
||||||
</include>
|
</include>
|
||||||
<include>
|
|
||||||
<groupId>com.cf.imes</groupId>
|
|
||||||
<artifactId>cf-spring-boot-starter-biz-organ</artifactId>
|
|
||||||
</include>
|
|
||||||
<include>
|
<include>
|
||||||
<groupId>com.cf.imes</groupId>
|
<groupId>com.cf.imes</groupId>
|
||||||
<artifactId>cf-spring-boot-starter-excel</artifactId>
|
<artifactId>cf-spring-boot-starter-excel</artifactId>
|
||||||
@@ -281,7 +271,29 @@
|
|||||||
<!-- 将依赖放到target/lib目录下 -->
|
<!-- 将依赖放到target/lib目录下 -->
|
||||||
<outputDirectory>target/lib</outputDirectory>
|
<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>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
|
|||||||
+11
@@ -1,7 +1,9 @@
|
|||||||
package com.cf.imes.module.plan.service.orderImport.consumer;
|
package com.cf.imes.module.plan.service.orderImport.consumer;
|
||||||
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
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.organ.core.context.OrganContextHolder;
|
||||||
import com.cf.imes.framework.redis.constants.RedisKeyConstants;
|
import com.cf.imes.framework.redis.constants.RedisKeyConstants;
|
||||||
import com.cf.imes.framework.redis.util.RedisLockUtil;
|
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.amqp.support.AmqpHeaders;
|
||||||
import org.springframework.messaging.handler.annotation.Header;
|
import org.springframework.messaging.handler.annotation.Header;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.thymeleaf.util.StringUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -22,6 +25,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static com.cf.imes.framework.mq.rabbitmq.constant.RabbitMqConstants.ORDER_IMPORT_DEAD_LETTER_QUEUE;
|
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)
|
@RabbitListener(queues = ORDER_IMPORT_DEAD_LETTER_QUEUE)
|
||||||
public void receive(String message,
|
public void receive(String message,
|
||||||
Channel channel,
|
Channel channel,
|
||||||
|
@Header(value = "peek", required = false) String peek,
|
||||||
@Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag,
|
@Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag,
|
||||||
@Header(value = "x-death", required = false) List<Map<String, Object>> xDeath) throws IOException {
|
@Header(value = "x-death", required = false) List<Map<String, Object>> xDeath) throws IOException {
|
||||||
log.info("====================【生产单导入收到死信消息:{}】====================", message);
|
log.info("====================【生产单导入收到死信消息:{}】====================", message);
|
||||||
// 手动确认消息
|
// 手动确认消息
|
||||||
channel.basicAck(deliveryTag, false);
|
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();
|
Long organId = OrganContextHolder.getOrganId();
|
||||||
|
|
||||||
String deadLetterReason = getDeadLetterReason(xDeath);
|
String deadLetterReason = getDeadLetterReason(xDeath);
|
||||||
|
|||||||
+17
-3
@@ -1,6 +1,7 @@
|
|||||||
package com.cf.imes.module.plan.service.orderImport.consumer;
|
package com.cf.imes.module.plan.service.orderImport.consumer;
|
||||||
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.cf.imes.framework.common.exception.ServiceException;
|
import com.cf.imes.framework.common.exception.ServiceException;
|
||||||
import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil;
|
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.stereotype.Component;
|
||||||
import org.springframework.transaction.TransactionDefinition;
|
import org.springframework.transaction.TransactionDefinition;
|
||||||
import org.springframework.transaction.TransactionStatus;
|
import org.springframework.transaction.TransactionStatus;
|
||||||
|
import org.thymeleaf.util.StringUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
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_FAIL;
|
||||||
import static com.cf.imes.module.plan.enums.ErrorCodeConstants.ORDER_IMPORT_ORGANID_NOT_EXISTS;
|
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拆单消费者
|
* webcad拆单消费者
|
||||||
@@ -108,7 +111,10 @@ public class WebCadOrderImportConsumer {
|
|||||||
private DataSourceTransactionManager transactionManager;
|
private DataSourceTransactionManager transactionManager;
|
||||||
|
|
||||||
@RabbitListener(queues = "#{@orderImportWebCadQueueName}")
|
@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);
|
log.info("====================【webcad异步拆单收到消息:{}】====================", message);
|
||||||
|
|
||||||
Long organId = null;
|
Long organId = null;
|
||||||
@@ -122,6 +128,12 @@ public class WebCadOrderImportConsumer {
|
|||||||
if (ObjectUtil.isNull(organId)) {
|
if (ObjectUtil.isNull(organId)) {
|
||||||
throw ServiceExceptionUtil.exception(ORDER_IMPORT_ORGANID_NOT_EXISTS);
|
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);
|
OrderImportTaskDO orderImportTaskDO = confirmOrderImport(taskId);
|
||||||
if (ObjectUtil.isNull(orderImportTaskDO)) {
|
if (ObjectUtil.isNull(orderImportTaskDO)) {
|
||||||
@@ -137,18 +149,21 @@ public class WebCadOrderImportConsumer {
|
|||||||
// 提交事务
|
// 提交事务
|
||||||
transactionManager.commit(transactionStatus);
|
transactionManager.commit(transactionStatus);
|
||||||
} catch (ServiceException se) {
|
} catch (ServiceException se) {
|
||||||
|
String seMessage = se.getMessage();
|
||||||
|
log.error(seMessage);
|
||||||
// 回滚事务
|
// 回滚事务
|
||||||
if (transactionStatus != null) {
|
if (transactionStatus != null) {
|
||||||
transactionManager.rollback(transactionStatus);
|
transactionManager.rollback(transactionStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新任务状态
|
// 更新任务状态
|
||||||
orderImportTaskService.updateServiceExceptionTaskStatus(taskId, organId, se.getMessage());
|
orderImportTaskService.updateServiceExceptionTaskStatus(taskId, organId, seMessage);
|
||||||
|
|
||||||
nackSent = true;
|
nackSent = true;
|
||||||
// 确认消息进入死信队列
|
// 确认消息进入死信队列
|
||||||
channel.basicNack(deliveryTag, false, false);
|
channel.basicNack(deliveryTag, false, false);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
log.error(ORDER_IMPORT_FAIL.getMsg(), e);
|
||||||
// 回滚事务
|
// 回滚事务
|
||||||
if (transactionStatus != null) {
|
if (transactionStatus != null) {
|
||||||
transactionManager.rollback(transactionStatus);
|
transactionManager.rollback(transactionStatus);
|
||||||
@@ -160,7 +175,6 @@ public class WebCadOrderImportConsumer {
|
|||||||
nackSent = true;
|
nackSent = true;
|
||||||
// 确认消息进入死信队列
|
// 确认消息进入死信队列
|
||||||
channel.basicNack(deliveryTag, false, false);
|
channel.basicNack(deliveryTag, false, false);
|
||||||
log.error(ORDER_IMPORT_FAIL.getMsg(), e);
|
|
||||||
} finally {
|
} finally {
|
||||||
// 手动确认消息接收
|
// 手动确认消息接收
|
||||||
if (!nackSent) {
|
if (!nackSent) {
|
||||||
|
|||||||
Reference in New Issue
Block a user