提交 510cd971 authored 作者: liuhaiquan's avatar liuhaiquan

Merge remote-tracking branch 'origin/v4.9_create_goods_child_20230918' into…

Merge remote-tracking branch 'origin/v4.9_create_goods_child_20230918' into v4.9_create_goods_child_20230918
...@@ -17,7 +17,8 @@ public enum OrderGoodsTruckBindEnum { ...@@ -17,7 +17,8 @@ public enum OrderGoodsTruckBindEnum {
SUCCESS(1, "正常"), SUCCESS(1, "正常"),
CANCEL(20, "取消"), CANCEL(2, "取消"),
GET(3, "已结单"),
; ;
......
...@@ -92,7 +92,10 @@ public class RabbitBeanConfig { ...@@ -92,7 +92,10 @@ public class RabbitBeanConfig {
} }
/**
* 货单挂单队列
* @return
*/
@Bean @Bean
public Queue orderGoodsOnQueue() { public Queue orderGoodsOnQueue() {
Map<String, Object> params = new HashMap<>(6); Map<String, Object> params = new HashMap<>(6);
...@@ -102,18 +105,43 @@ public class RabbitBeanConfig { ...@@ -102,18 +105,43 @@ public class RabbitBeanConfig {
} }
/** /**
* 单挂单中交换机 * 单挂单中交换机
**/ **/
@Bean @Bean
public DirectExchange orderGoodsOnExchange() { public DirectExchange orderGoodsOnExchange() {
return new DirectExchange(RabbitKeyConstants.ORDER_ON_EXCHANGE); return new DirectExchange(RabbitKeyConstants.ORDER_GOODS_ON_EXCHANGE);
} }
/** /**
* 单挂单中绑定 * 单挂单中绑定
*/ */
@Bean @Bean
public Binding orderGoodsOnExchangeBind() { public Binding orderGoodsOnExchangeBind() {
return BindingBuilder.bind(orderOnQueue()).to(orderOnExchange()).with(RabbitKeyConstants.ORDER_ON_ROUTE_KEY); return BindingBuilder.bind(orderGoodsOnQueue()).to(orderGoodsOnExchange()).with(RabbitKeyConstants.ORDER_GOODS_ON_ROUTE_KEY);
}
/**
* 死信队列:死信队列处理延迟消息货单挂单
* @return
*/
@Bean
public Queue orderGoodsOnDeadQueue() {
return new Queue(RabbitKeyConstants.ORDER_GOODS_ON_DEAD_QUEUE, true, false, false);
}
/**
* 货单挂单中交换机:死信队列处理延迟消息
**/
@Bean
public DirectExchange orderGoodsOnDeadExchange() {
return new DirectExchange(RabbitKeyConstants.ORDER_GOODS_ON_DEAD_EXCHANGE);
}
/**
* 货单挂单中绑定:死信队列处理延迟消息
*/
@Bean
public Binding orderGoodsDeadExchangeBind() {
return BindingBuilder.bind(orderGoodsOnDeadQueue()).to(orderGoodsOnDeadExchange()).with(RabbitKeyConstants.ORDER_GOODS_ON_DEAD_ROUTE_KEY);
} }
} }
package com.clx.performance.config;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.rabbit.annotation.RabbitListenerConfigurer;
import org.springframework.amqp.rabbit.config.RetryInterceptorBuilder;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistrar;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.amqp.rabbit.retry.RejectAndDontRequeueRecoverer;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.amqp.RabbitProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory;
import org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory;
import org.springframework.retry.backoff.ExponentialBackOffPolicy;
import org.springframework.retry.policy.SimpleRetryPolicy;
import org.springframework.retry.support.RetryTemplate;
//常用的三个配置如下
//1---设置手动应答(acknowledge-mode: manual)
// 2---设置生产者消息发送的确认回调机制 ( #这个配置是保证提供者确保消息推送到交换机中,不管成不成功,都会回调
// publisher-confirm-type: correlated
// #保证交换机能把消息推送到队列中
// publisher-returns: true
// template:
// #以下是rabbitmqTemplate配置
// mandatory: true)
// 3---设置重试
//TODO rabbitMQ 配置,后面压测可能会调整相关参数,未完善
@Configuration
@Order(-1)
public class RabbitConfig implements RabbitListenerConfigurer {
@Autowired
private ConnectionFactory rabbitConnectionFactory;
//@Bean 缓存连接池
//public CachingConnectionFactory rabbitConnectionFactory
@Autowired
private RabbitProperties properties;
//这里因为使用自动配置的connectionFactory,所以把自定义的connectionFactory注解掉
// 存在此名字的bean 自带的连接工厂会不加载(也就是说yml中rabbitmq下一级不生效),如果想自定义来区分开 需要改变bean 的名称
// @Bean
// public ConnectionFactory connectionFactory() throws Exception {
// //创建工厂类
// CachingConnectionFactory cachingConnectionFactory=new CachingConnectionFactory();
// //用户名
// cachingConnectionFactory.setUsername("gust");
// //密码
// cachingConnectionFactory.setPassword("gust");
// //rabbitMQ地址
// cachingConnectionFactory.setHost("127.0.0.1");
// //rabbitMQ端口
// cachingConnectionFactory.setPort(Integer.parseInt("5672"));
//
// //设置发布消息后回调
// cachingConnectionFactory.setPublisherReturns(true);
// //设置发布后确认类型,此处确认类型为交互
// cachingConnectionFactory.setPublisherConfirmType(CachingConnectionFactory.ConfirmType.CORRELATED);
//
// cachingConnectionFactory.setCacheMode(CachingConnectionFactory.CacheMode.CHANNEL);
// return cachingConnectionFactory;
// }
@Bean
public MessageHandlerMethodFactory messageHandlerMethodFactory() {
DefaultMessageHandlerMethodFactory messageHandlerMethodFactory = new DefaultMessageHandlerMethodFactory();
messageHandlerMethodFactory.setMessageConverter(consumerJackson2MessageConverter());
return messageHandlerMethodFactory;
}
@Bean
public MappingJackson2MessageConverter consumerJackson2MessageConverter() {
return new MappingJackson2MessageConverter();
}
// 存在此名字的bean 自带的容器工厂会不加载(yml下rabbitmq下的listener下的simple配置),如果想自定义来区分开 需要改变bean 的名称
// @Bean
// public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() {
// SimpleRabbitListenerContainerFactory containerFactory = new SimpleRabbitListenerContainerFactory();
// containerFactory.setConnectionFactory(rabbitConnectionFactory);
//
// // 预加载消息数量 -- QOS
// containerFactory.setPrefetchCount(1);
// // 应答模式(此处设置为手动)
// containerFactory.setAcknowledgeMode(AcknowledgeMode.MANUAL);
// //消息序列化方式
// containerFactory.setMessageConverter(new Jackson2JsonMessageConverter());
// // 设置通知调用链 (这里设置的是重试机制的调用链)
// containerFactory.setAdviceChain(
// RetryInterceptorBuilder
// .stateless()
// .recoverer(new RejectAndDontRequeueRecoverer())
// //.retryOperations(rabbitRetryTemplate())
// .build()
// );
// return containerFactory;
// }
@Bean
public SimpleMessageListenerContainer simpleMessageListenerContainer(SimpleRabbitListenerContainerFactory connectionFactory) {
SimpleMessageListenerContainer bean = connectionFactory.createListenerContainer();
return bean;
}
// 存在此名字的bean 自带的容器工厂会不加载(yml下rabbitmq下的template的配置),如果想自定义来区分开 需要改变bean 的名称
@Bean
public RabbitTemplate rabbitTemplate() {
RabbitTemplate rabbitTemplate = new RabbitTemplate(rabbitConnectionFactory);
//默认是用jdk序列化
//数据转换为json存入消息队列,方便可视化界面查看消息数据
rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
//设置开启Mandatory,才能触发回调函数,无论消息推送结果怎么样都强制调用回调函数
rabbitTemplate.setMandatory(true);
//此处设置重试template后,会再生产者发送消息的时候,调用该template中的调用链
// rabbitTemplate.setRetryTemplate(rabbitRetryTemplate());
//CorrelationData correlationData, boolean b, String s
// rabbitTemplate.setConfirmCallback(
// new BaseConfirmCallback(messageRecordComponent));
// rabbitTemplate.setReturnCallback(
// new BaseReturnCallback(messageRecordComponent));
return rabbitTemplate;
}
//重试的Template
//
// @Bean
// public ExponentialBackOffPolicy backOffPolicyByProperties() {
// ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
// long maxInterval = properties.getListener().getSimple().getRetry().getMaxInterval().getSeconds();
// long initialInterval = properties.getListener().getSimple().getRetry().getInitialInterval().getSeconds();
// double multiplier = properties.getListener().getSimple().getRetry().getMultiplier();
// // 重试间隔
// backOffPolicy.setInitialInterval(initialInterval * 1000);
// // 重试最大间隔
// backOffPolicy.setMaxInterval(maxInterval * 1000);
// // 重试间隔乘法策略
// backOffPolicy.setMultiplier(multiplier);
// return backOffPolicy;
// }
//
// @Bean
// public SimpleRetryPolicy retryPolicyByProperties() {
// SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
// int maxAttempts = properties.getListener().getSimple().getRetry().getMaxAttempts();
// retryPolicy.setMaxAttempts(maxAttempts);
// return retryPolicy;
// }
@Override
public void configureRabbitListeners(RabbitListenerEndpointRegistrar registrar) {
registrar.setMessageHandlerMethodFactory(messageHandlerMethodFactory());
}
}
\ No newline at end of file
...@@ -37,12 +37,17 @@ public class RabbitKeyConstants { ...@@ -37,12 +37,17 @@ public class RabbitKeyConstants {
//承运订单同步一部 需要手动创建对列交换机 //承运订单同步一部 需要手动创建对列交换机
public static final String CLX_PERFORMANCE_ORDER_CHILD_QUEUE = "clx_performance.order_child_queue"; public static final String CLX_PERFORMANCE_ORDER_CHILD_QUEUE = "clx_performance.order_child_queue";
public static final String ORDER_GOODS_ON_DEAD_ROUTE_KEY ="clx-order.order.goods.on.dead.route.key";
public static final String ORDER_GOODS_ON_QUEUE ="clx-order.order.goods.on.queue"; public static final String ORDER_GOODS_ON_QUEUE ="clx-order.order.goods.on.queue";
public static final String ORDER_GOODS_ON_EXCHANGE ="clx-order.order.goods.on.exchange";
public static final String ORDER_GOODS_ON_ROUTE_KEY ="clx-order.order.goods.on.route.key";
public static final String ORDER_GOODS_ON_DEAD_QUEUE ="clx-order.order.goods.on.dead.queue";
public static final String ORDER_GOODS_ON_DEAD_EXCHANGE ="clx-order.order.goods.on.dead.exchange"; public static final String ORDER_GOODS_ON_DEAD_EXCHANGE ="clx-order.order.goods.on.dead.exchange";
public static final String ORDER_GOODSON_EXCHANGE ="clx-order.order.on.exchange"; public static final String ORDER_GOODS_ON_DEAD_ROUTE_KEY ="clx-order.order.goods.on.dead.route.key";
} }
...@@ -82,7 +82,7 @@ public class CarrierOrderChildController { ...@@ -82,7 +82,7 @@ public class CarrierOrderChildController {
} }
@ApiOperation(value = "业务信息", notes = "<br>By:胡宇帆") @ApiOperation(value = "业务信息", notes = "<br>By:胡宇帆")
@PostMapping("/orderChildBussInfo") @GetMapping("/orderChildBussInfo")
public Result<OrderChildBussInfoVO> getOrderChildBussInfo(@NotBlank(message = "车牌号不能为空") String truckNo) { public Result<OrderChildBussInfoVO> getOrderChildBussInfo(@NotBlank(message = "车牌号不能为空") String truckNo) {
return Result.ok(orderChildService.getOrderChildBussInfo(truckNo)); return Result.ok(orderChildService.getOrderChildBussInfo(truckNo));
} }
......
...@@ -88,7 +88,7 @@ public class GoodsOrderController { ...@@ -88,7 +88,7 @@ public class GoodsOrderController {
FeignOrderVO orderInfo = orderFeign.getOrderInfoFeign(orderNo); FeignOrderVO orderInfo = orderFeign.getOrderInfoFeign(orderNo);
//1平台车辆 2部分平台车辆 3自有车辆 //1平台车辆 2部分平台车辆 3自有车辆
Integer truckDemand = orderInfo.getTruckDemand(); Integer truckDemand = orderInfo.getTruckDemand();
sendLazyTime = goodsOrderStrategyContext.strategyContext.get(truckDemand).goodsOrderProcess(orderGoodsParams, orderInfo); sendLazyTime = goodsOrderStrategyContext.strategyContext.get(truckDemand).goodsOrderProcess(orderGoodsParams, orderInfo, now);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
......
...@@ -39,4 +39,5 @@ public interface OrderGoodsDao extends BaseDao<OrderGoodsMapper, OrderGoods, Int ...@@ -39,4 +39,5 @@ public interface OrderGoodsDao extends BaseDao<OrderGoodsMapper, OrderGoods, Int
IPage<OrderGoodsAPPVO> exclusiveOrderPageGoodsList(OrderGoodsListPageParam orderGoodsListPageParam, List<String> orderGoodsNoList); IPage<OrderGoodsAPPVO> exclusiveOrderPageGoodsList(OrderGoodsListPageParam orderGoodsListPageParam, List<String> orderGoodsNoList);
void updateOrderGoodsStatusByOrderGoodsNo(String orderGoodsNo, Integer code);
} }
...@@ -23,7 +23,7 @@ public interface OrderGoodsTruckBindDao extends BaseDao<OrderGoodsTruckBindMappe ...@@ -23,7 +23,7 @@ public interface OrderGoodsTruckBindDao extends BaseDao<OrderGoodsTruckBindMappe
List<Integer> getTrucksByOrderGoodsNo(String orderGoodsNo); List<Integer> getTrucksByOrderGoodsNo(String orderGoodsNo);
Optional<OrderGoodsTruckBind> getByOrderGoodsNoAndTruckNo(String orderGoodsNo, String truckNo); Optional<OrderGoodsTruckBind> getByOrderGoodsNoAndTruckNo(String orderGoodsNo, String truckNo);
Optional<OrderGoodsTruckBind> getValidByOrderGoodsNoAndTruckNo(String orderGoodsNo, String truckNo); Optional<OrderGoodsTruckBind> getValidByOrderGoodsNoAndTruckNo(String truckNo);
Optional<List<OrderGoodsTruckBind>> selectListByTruckNo(List<String> truckList); Optional<List<OrderGoodsTruckBind>> selectListByTruckNo(List<String> truckList);
} }
...@@ -87,5 +87,10 @@ public class OrderGoodsDaoImpl extends BaseDaoImpl<OrderGoodsMapper, OrderGoods, ...@@ -87,5 +87,10 @@ public class OrderGoodsDaoImpl extends BaseDaoImpl<OrderGoodsMapper, OrderGoods,
return baseMapper.exclusiveOrderPageGoodsList(page, orderGoodsNoList); return baseMapper.exclusiveOrderPageGoodsList(page, orderGoodsNoList);
} }
@Override
public void updateOrderGoodsStatusByOrderGoodsNo(String orderGoodsNo, Integer code) {
baseMapper.updateOrderGoodsStatusByOrderGoodsNo(orderGoodsNo, code);
}
} }
...@@ -2,6 +2,8 @@ package com.clx.performance.dao.impl; ...@@ -2,6 +2,8 @@ package com.clx.performance.dao.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.clx.performance.dao.OrderGoodsTruckBindDao; import com.clx.performance.dao.OrderGoodsTruckBindDao;
import com.clx.performance.enums.OrderGoodsTruckBindEnum;
import com.clx.performance.enums.OrderGoodsTypeEnum;
import com.clx.performance.mapper.OrderGoodsTruckBindMapper; import com.clx.performance.mapper.OrderGoodsTruckBindMapper;
import com.clx.performance.model.OrderGoodsTruckBind; import com.clx.performance.model.OrderGoodsTruckBind;
import com.msl.common.base.Optional; import com.msl.common.base.Optional;
...@@ -50,9 +52,8 @@ public class OrderGoodsTruckBindDaoImpl extends BaseDaoImpl<OrderGoodsTruckBindM ...@@ -50,9 +52,8 @@ public class OrderGoodsTruckBindDaoImpl extends BaseDaoImpl<OrderGoodsTruckBindM
} }
@Override @Override
public Optional<OrderGoodsTruckBind> getValidByOrderGoodsNoAndTruckNo(String orderGoodsNo, String truckNo) { public Optional<OrderGoodsTruckBind> getValidByOrderGoodsNoAndTruckNo(String truckNo) {
return Optional.ofNullable(getOne(lQrWrapper() return Optional.ofNullable(getOne(lQrWrapper()
.eq(OrderGoodsTruckBind::getOrderGoodsNo, orderGoodsNo)
.eq(OrderGoodsTruckBind::getTruckNo, truckNo) .eq(OrderGoodsTruckBind::getTruckNo, truckNo)
.in(OrderGoodsTruckBind::getStatus, OrderGoodsTruckBind.Status.NORMAL.getCode()) .in(OrderGoodsTruckBind::getStatus, OrderGoodsTruckBind.Status.NORMAL.getCode())
)); ));
...@@ -61,6 +62,7 @@ public class OrderGoodsTruckBindDaoImpl extends BaseDaoImpl<OrderGoodsTruckBindM ...@@ -61,6 +62,7 @@ public class OrderGoodsTruckBindDaoImpl extends BaseDaoImpl<OrderGoodsTruckBindM
@Override @Override
public Optional<List<OrderGoodsTruckBind>> selectListByTruckNo(List<String> truckList) { public Optional<List<OrderGoodsTruckBind>> selectListByTruckNo(List<String> truckList) {
return Optional.ofNullable(baseMapper.selectList(new QueryWrapper<OrderGoodsTruckBind>().lambda() return Optional.ofNullable(baseMapper.selectList(new QueryWrapper<OrderGoodsTruckBind>().lambda()
.ne(OrderGoodsTruckBind::getStatus, OrderGoodsTruckBindEnum.Status.CANCEL.getCode())
.in(OrderGoodsTruckBind::getTruckNo,truckList).select(OrderGoodsTruckBind::getOrderGoodsNo))); .in(OrderGoodsTruckBind::getTruckNo,truckList).select(OrderGoodsTruckBind::getOrderGoodsNo)));
} }
} }
package com.clx.performance.listener;
import com.clx.order.enums.OrderEnum;
import com.clx.performance.constant.RabbitKeyConstants;
import com.clx.performance.dao.OrderGoodsDao;
import com.clx.performance.enums.OrderGoodsStatusEnum;
import com.clx.performance.model.OrderGoods;
import com.msl.common.base.Optional;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* 处理货单由状态已挂单变为挂单中
*/
@Slf4j
@Component
public class RabbitOrderGoodsStatusOnHandler {
@Autowired
private OrderGoodsDao orderGoodsDao;
@RabbitListener(queues = RabbitKeyConstants.ORDER_GOODS_ON_DEAD_QUEUE)
public void onMessage(String message) {
log.info("处理货单状态由已挂单变为挂弹中监听器执行,货单ID为{}", message);
if (StringUtils.isBlank(message)) {
return;
}
Optional<OrderGoods> optional = orderGoodsDao.getByOrderGoodsNo(message);
if (!optional.isPresent()) {
log.info("处理货单状态由已挂单变为挂单中监听器未查询到订单数据,消息为{}", message);
return;
}
OrderGoods orderGoods = optional.get();
if (OrderGoodsStatusEnum.Status.CREATED.getCode().equals(orderGoods.getOrderGoodsStatus())) {
log.info("处理货单状态由已挂单变为挂单中监听器执行,从状态{}-----变更为{}", orderGoods.getOrderGoodsStatus(), OrderGoodsStatusEnum.Status.PAYING.getName());
orderGoodsDao.updateOrderGoodsStatusByOrderGoodsNo(orderGoods.getOrderGoodsNo(), OrderGoodsStatusEnum.Status.PAYING.getCode());
}
}
}
...@@ -45,4 +45,9 @@ public interface OrderGoodsMapper extends BaseMapper<OrderGoods> { ...@@ -45,4 +45,9 @@ public interface OrderGoodsMapper extends BaseMapper<OrderGoods> {
@SelectProvider(type = OrderGoodsSqlProvider.class, method = "exclusiveOrderPageGoodsList") @SelectProvider(type = OrderGoodsSqlProvider.class, method = "exclusiveOrderPageGoodsList")
IPage<OrderGoodsAPPVO> exclusiveOrderPageGoodsList(Page<OrderGoodsAPPVO> page, List<String> param); IPage<OrderGoodsAPPVO> exclusiveOrderPageGoodsList(Page<OrderGoodsAPPVO> page, List<String> param);
@Update(" update order_goods set " +
" order_goods_status = #{code} " +
" where order_goods_no = #{orderGoodsNo}")
void updateOrderGoodsStatusByOrderGoodsNo(@Param("orderGoodsNo") String orderGoodsNo, @Param("code") Integer code);
} }
...@@ -109,9 +109,10 @@ public class OrderChildServiceImpl implements OrderChildService { ...@@ -109,9 +109,10 @@ public class OrderChildServiceImpl implements OrderChildService {
} }
// 定向 // 定向
OrderGoodsTruckBind orderGoodsTruckBind = orderGoodsTruckBindDao.getValidByOrderGoodsNoAndTruckNo(orderGoods.getOrderGoodsNo(), truckNo).orNull(); OrderGoodsTruckBind orderGoodsTruckBind = orderGoodsTruckBindDao.getValidByOrderGoodsNoAndTruckNo(truckNo).orNull();
if (Objects.equals(orderGoods.getPendingOrderWay(), OrderGoodsPendingOrderWayStatusEnum.Status.EXCLUSIVE.getCode())){ if (Objects.equals(orderGoods.getPendingOrderWay(), OrderGoodsPendingOrderWayStatusEnum.Status.EXCLUSIVE.getCode())){
if (orderGoodsTruckBind == null){throw new ServiceSystemException(PerformanceResultEnum.ORDER_CHILD_DIRECT_ORDER_TRUCK_ERROR);} if (orderGoodsTruckBind == null){throw new ServiceSystemException(PerformanceResultEnum.ORDER_CHILD_DIRECT_ORDER_TRUCK_ERROR);}
if (!Objects.equals(orderGoodsTruckBind.getOrderGoodsNo(), orderGoods.getOrderGoodsNo())){throw new ServiceSystemException(PerformanceResultEnum.ORDER_CHILD_DIRECT_ORDER_TRUCK_ERROR);}
} }
else { else {
if (orderGoodsTruckBind != null){throw new ServiceSystemException(PerformanceResultEnum.ORDER_CHILD_DIRECT_ORDER_TRUCK_ERROR1);} if (orderGoodsTruckBind != null){throw new ServiceSystemException(PerformanceResultEnum.ORDER_CHILD_DIRECT_ORDER_TRUCK_ERROR1);}
...@@ -197,9 +198,11 @@ public class OrderChildServiceImpl implements OrderChildService { ...@@ -197,9 +198,11 @@ public class OrderChildServiceImpl implements OrderChildService {
throw new ServiceSystemException(PerformanceResultEnum.ORDER_INVALID); throw new ServiceSystemException(PerformanceResultEnum.ORDER_INVALID);
} }
OrderGoodsTruckBind orderGoodsTruckBind = orderGoodsTruckBindDao.getValidByOrderGoodsNoAndTruckNo(orderGoods.getOrderGoodsNo(), param.getTruckNo()) OrderGoodsTruckBind orderGoodsTruckBind = orderGoodsTruckBindDao.getValidByOrderGoodsNoAndTruckNo(param.getTruckNo())
.orElseThrow(PerformanceResultEnum.ORDER_CHILD_DIRECT_REJECT_TRUCK_ERROR); .orElseThrow(PerformanceResultEnum.ORDER_CHILD_DIRECT_REJECT_TRUCK_ERROR);
if (!Objects.equals(orderGoodsTruckBind.getOrderGoodsNo(), orderGoods.getOrderGoodsNo())){throw new ServiceSystemException(PerformanceResultEnum.ORDER_CHILD_DIRECT_REJECT_TRUCK_ERROR);}
// 更新定向派单 // 更新定向派单
updateOrderGoodsDirectReject(orderGoodsTruckBind); updateOrderGoodsDirectReject(orderGoodsTruckBind);
...@@ -606,12 +609,14 @@ public class OrderChildServiceImpl implements OrderChildService { ...@@ -606,12 +609,14 @@ public class OrderChildServiceImpl implements OrderChildService {
image.setChildNo(orderChild.getChildNo()); image.setChildNo(orderChild.getChildNo());
image.setType(OrderChildImage.Type.LOAD.getCode()); image.setType(OrderChildImage.Type.LOAD.getCode());
image.setImage(item); image.setImage(item);
imageList.add(image);
} }
for (String item : param.getUnloadImageList()) { for (String item : param.getUnloadImageList()) {
OrderChildImage image = new OrderChildImage(); OrderChildImage image = new OrderChildImage();
image.setChildNo(orderChild.getChildNo()); image.setChildNo(orderChild.getChildNo());
image.setType(OrderChildImage.Type.UNLOAD.getCode()); image.setType(OrderChildImage.Type.UNLOAD.getCode());
image.setImage(item); image.setImage(item);
imageList.add(image);
} }
BigDecimal dif = param.getLoadNet().subtract(orderChild.getWeight()); BigDecimal dif = param.getLoadNet().subtract(orderChild.getWeight());
......
...@@ -7,5 +7,5 @@ import java.time.LocalDateTime; ...@@ -7,5 +7,5 @@ import java.time.LocalDateTime;
public interface GoodsOrderStrategy { public interface GoodsOrderStrategy {
LocalDateTime goodsOrderProcess(OrderGoodsParams orderGoodsParams, FeignOrderVO orderInfo); LocalDateTime goodsOrderProcess(OrderGoodsParams orderGoodsParams, FeignOrderVO orderInfo, LocalDateTime now);
} }
...@@ -7,6 +7,7 @@ import com.clx.order.params.OrderGoodsParams; ...@@ -7,6 +7,7 @@ import com.clx.order.params.OrderGoodsParams;
import com.clx.order.vo.feign.FeignOrderVO; import com.clx.order.vo.feign.FeignOrderVO;
import com.clx.performance.component.GoodsOrderStrategyContext; import com.clx.performance.component.GoodsOrderStrategyContext;
import com.clx.performance.component.OrderGoodsIdGenerate; import com.clx.performance.component.OrderGoodsIdGenerate;
import com.clx.performance.constant.RabbitKeyConstants;
import com.clx.performance.dao.OrderGoodsTruckBindDao; import com.clx.performance.dao.OrderGoodsTruckBindDao;
import com.clx.performance.enums.OrderGoodsStatusEnum; import com.clx.performance.enums.OrderGoodsStatusEnum;
import com.clx.performance.enums.OrderGoodsTypeEnum; import com.clx.performance.enums.OrderGoodsTypeEnum;
...@@ -20,13 +21,18 @@ import com.msl.common.utils.DateUtils; ...@@ -20,13 +21,18 @@ import com.msl.common.utils.DateUtils;
import com.msl.user.data.UserSessionData; import com.msl.user.data.UserSessionData;
import com.msl.user.utils.TokenUtil; import com.msl.user.utils.TokenUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
@Component("OneGoodsOrderStrategy") @Component("OneGoodsOrderStrategy")
@Slf4j @Slf4j
...@@ -50,12 +56,14 @@ public class OneGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe ...@@ -50,12 +56,14 @@ public class OneGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
@Autowired @Autowired
private GoodsOrderStrategyContext goodsOrderStrategyContext; private GoodsOrderStrategyContext goodsOrderStrategyContext;
@Autowired
private RabbitTemplate rabbitTemplate;
@Override @Override
public LocalDateTime goodsOrderProcess(OrderGoodsParams orderGoodsParams, FeignOrderVO orderInfo) { public LocalDateTime goodsOrderProcess(OrderGoodsParams orderGoodsParams, FeignOrderVO orderInfo, LocalDateTime now) {
String orderNo = orderGoodsParams.getOrderNo(); String orderNo = orderGoodsParams.getOrderNo();
UserSessionData loginUserInfo = TokenUtil.getLoginUserInfo(); UserSessionData loginUserInfo = TokenUtil.getLoginUserInfo();
LocalDateTime now = LocalDateTime.now();
LocalDateTime sendLazyTime = null; LocalDateTime sendLazyTime = null;
List<OrderGoodsChildParams> childParamsList = orderGoodsParams.getOrderGoodsChildParams(); List<OrderGoodsChildParams> childParamsList = orderGoodsParams.getOrderGoodsChildParams();
BigDecimal childSum = childParamsList.stream().map(OrderGoodsChildParams::getExtractWeight).reduce( BigDecimal childSum = childParamsList.stream().map(OrderGoodsChildParams::getExtractWeight).reduce(
...@@ -64,6 +72,8 @@ public class OneGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe ...@@ -64,6 +72,8 @@ public class OneGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
throw new ServiceSystemException(PerformanceResultEnum.HTTP_ERROR, "当前货单总吨数已超订单总吨数"); throw new ServiceSystemException(PerformanceResultEnum.HTTP_ERROR, "当前货单总吨数已超订单总吨数");
} }
long beginOrderGoodsId = orderGoodsIdGenerate.getOrderGoodsId(OrderGoodsTypeEnum.Status.PLATFORM.getCode(), childParamsList.size()); long beginOrderGoodsId = orderGoodsIdGenerate.getOrderGoodsId(OrderGoodsTypeEnum.Status.PLATFORM.getCode(), childParamsList.size());
Map<String, LocalDateTime> mqMap = new HashMap<>();
for (OrderGoodsChildParams child : childParamsList) { for (OrderGoodsChildParams child : childParamsList) {
if (child.getPendingOrderWay().equals(2)) { if (child.getPendingOrderWay().equals(2)) {
if (child.getNeedTruckNum() == null) { if (child.getNeedTruckNum() == null) {
...@@ -127,12 +137,15 @@ public class OneGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe ...@@ -127,12 +137,15 @@ public class OneGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
if (CollectionUtil.isNotEmpty(child.getTruckList())) { if (CollectionUtil.isNotEmpty(child.getTruckList())) {
orderGoodsTruckBindDao.saveBatchEntity(orderNo, OrderGoodsTypeEnum.Status.PLATFORM.getCode() + beginOrderGoodsId, child.getTruckList(), now); orderGoodsTruckBindDao.saveBatchEntity(orderNo, OrderGoodsTypeEnum.Status.PLATFORM.getCode() + beginOrderGoodsId, child.getTruckList(), now);
} }
mqMap.put(OrderGoodsTypeEnum.Status.PLATFORM.getCode() + beginOrderGoodsId, postedTime);
beginOrderGoodsId = beginOrderGoodsId + 1; beginOrderGoodsId = beginOrderGoodsId + 1;
orderGoodsMapper.insert(orderGoods); orderGoodsMapper.insert(orderGoods);
} }
BigDecimal subtract = orderInfo.getResidueWeight().subtract(childSum); BigDecimal subtract = orderInfo.getResidueWeight().subtract(childSum);
log.info("更新剩余订单量{}", subtract); log.info("更新剩余订单量{}", subtract);
orderFeign.updateOrderInfoResidueWeight(orderInfo.getId(), subtract); orderFeign.updateOrderInfoResidueWeight(orderInfo.getId(), subtract);
sendMq(mqMap, now);
return sendLazyTime; return sendLazyTime;
} }
...@@ -140,4 +153,33 @@ public class OneGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe ...@@ -140,4 +153,33 @@ public class OneGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
goodsOrderStrategyContext.strategyContext.put(1, this); goodsOrderStrategyContext.strategyContext.put(1, this);
} }
public void sendMq(Map<String, LocalDateTime> mqMap, LocalDateTime now) {
for (Map.Entry<String, LocalDateTime> entry : mqMap.entrySet()) {
log.info("发送货单更改挂单中延迟消息,时间:{},orderGoodsNo:{}", entry.getKey(), entry.getValue());
Message message = MessageBuilder.withBody(entry.getKey().getBytes()).build();
long epochMilli = 0L;
if (entry.getValue().isAfter(now)) {
epochMilli = entry.getValue().minusMinutes(now.getMinute()).getMinute() * 60 * 1000;
log.info("选择时间在当前时间之后,则设置延迟队列时间,时间为:{}", epochMilli);
}
if (epochMilli == 0L) {
log.info("epochMilli时间为0,时间为:{}", epochMilli);
log.info("货单更改挂单中直接发延迟队列,因为时间早于当前时间");
rabbitTemplate.send(
RabbitKeyConstants.ORDER_GOODS_ON_DEAD_EXCHANGE, RabbitKeyConstants.ORDER_GOODS_ON_DEAD_ROUTE_KEY, message
);
} else {
log.info("epochMilli时间不为0,时间为:{}", epochMilli);
log.info("货单更改挂单中发送延迟消息,因为挂单时间大于当前时间{}", epochMilli);
message.getMessageProperties().setExpiration(String.valueOf(epochMilli));
rabbitTemplate.send(
RabbitKeyConstants.ORDER_GOODS_ON_EXCHANGE, RabbitKeyConstants.ORDER_GOODS_ON_DEAD_ROUTE_KEY, message
);
}
}
}
} }
...@@ -7,6 +7,7 @@ import com.clx.order.params.OrderGoodsParams; ...@@ -7,6 +7,7 @@ import com.clx.order.params.OrderGoodsParams;
import com.clx.order.vo.feign.FeignOrderVO; import com.clx.order.vo.feign.FeignOrderVO;
import com.clx.performance.component.GoodsOrderStrategyContext; import com.clx.performance.component.GoodsOrderStrategyContext;
import com.clx.performance.component.OrderGoodsIdGenerate; import com.clx.performance.component.OrderGoodsIdGenerate;
import com.clx.performance.constant.RabbitKeyConstants;
import com.clx.performance.dao.OrderGoodsTruckBindDao; import com.clx.performance.dao.OrderGoodsTruckBindDao;
import com.clx.performance.enums.OrderGoodsStatusEnum; import com.clx.performance.enums.OrderGoodsStatusEnum;
import com.clx.performance.enums.OrderGoodsTypeEnum; import com.clx.performance.enums.OrderGoodsTypeEnum;
...@@ -20,13 +21,18 @@ import com.msl.common.utils.DateUtils; ...@@ -20,13 +21,18 @@ import com.msl.common.utils.DateUtils;
import com.msl.user.data.UserSessionData; import com.msl.user.data.UserSessionData;
import com.msl.user.utils.TokenUtil; import com.msl.user.utils.TokenUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
@Component("ThreeGoodsOrderStrategy") @Component("ThreeGoodsOrderStrategy")
@Slf4j @Slf4j
...@@ -51,12 +57,14 @@ public class ThreeGoodsOrderStrategy implements GoodsOrderStrategy, Initializing ...@@ -51,12 +57,14 @@ public class ThreeGoodsOrderStrategy implements GoodsOrderStrategy, Initializing
@Autowired @Autowired
private OrderFeign orderFeign; private OrderFeign orderFeign;
@Autowired
private RabbitTemplate rabbitTemplate;
@Override @Override
public LocalDateTime goodsOrderProcess(OrderGoodsParams orderGoodsParams, FeignOrderVO orderInfo) { public LocalDateTime goodsOrderProcess(OrderGoodsParams orderGoodsParams, FeignOrderVO orderInfo, LocalDateTime now) {
String orderNo = orderGoodsParams.getOrderNo(); String orderNo = orderGoodsParams.getOrderNo();
UserSessionData loginUserInfo = TokenUtil.getLoginUserInfo(); UserSessionData loginUserInfo = TokenUtil.getLoginUserInfo();
LocalDateTime now = LocalDateTime.now();
LocalDateTime sendLazyTime = null; LocalDateTime sendLazyTime = null;
List<OrderGoodsChildParams> childParamsList = orderGoodsParams.getOrderGoodsChildParams(); List<OrderGoodsChildParams> childParamsList = orderGoodsParams.getOrderGoodsChildParams();
BigDecimal childSum = childParamsList.stream().map(OrderGoodsChildParams::getExtractWeight).reduce( BigDecimal childSum = childParamsList.stream().map(OrderGoodsChildParams::getExtractWeight).reduce(
...@@ -67,6 +75,8 @@ public class ThreeGoodsOrderStrategy implements GoodsOrderStrategy, Initializing ...@@ -67,6 +75,8 @@ public class ThreeGoodsOrderStrategy implements GoodsOrderStrategy, Initializing
if (childParamsList.size() > 1) { if (childParamsList.size() > 1) {
throw new ServiceSystemException(PerformanceResultEnum.HTTP_ERROR, "全部自有车辆只能全部提取"); throw new ServiceSystemException(PerformanceResultEnum.HTTP_ERROR, "全部自有车辆只能全部提取");
} }
Map<String, LocalDateTime> mqMap = new HashMap<>();
long beginOrderGoodsId = orderGoodsIdGenerate.getOrderGoodsId(OrderGoodsTypeEnum.Status.PLATFORM.getCode(), childParamsList.size()); long beginOrderGoodsId = orderGoodsIdGenerate.getOrderGoodsId(OrderGoodsTypeEnum.Status.PLATFORM.getCode(), childParamsList.size());
for (OrderGoodsChildParams child : childParamsList) { for (OrderGoodsChildParams child : childParamsList) {
...@@ -122,11 +132,15 @@ public class ThreeGoodsOrderStrategy implements GoodsOrderStrategy, Initializing ...@@ -122,11 +132,15 @@ public class ThreeGoodsOrderStrategy implements GoodsOrderStrategy, Initializing
if (CollectionUtil.isNotEmpty(child.getTruckList())) { if (CollectionUtil.isNotEmpty(child.getTruckList())) {
orderGoodsTruckBindDao.saveBatchEntity(orderNo, OrderGoodsTypeEnum.Status.PLATFORM.getCode() + beginOrderGoodsId, child.getTruckList(), now); orderGoodsTruckBindDao.saveBatchEntity(orderNo, OrderGoodsTypeEnum.Status.PLATFORM.getCode() + beginOrderGoodsId, child.getTruckList(), now);
} }
mqMap.put(OrderGoodsTypeEnum.Status.PLATFORM.getCode() + beginOrderGoodsId, postedTime);
beginOrderGoodsId = beginOrderGoodsId + 1; beginOrderGoodsId = beginOrderGoodsId + 1;
orderGoodsMapper.insert(orderGoods); orderGoodsMapper.insert(orderGoods);
} }
orderFeign.updateOrderInfoResidueWeight(orderInfo.getId(),orderInfo.getResidueWeight().subtract(childSum)); orderFeign.updateOrderInfoResidueWeight(orderInfo.getId(),orderInfo.getResidueWeight().subtract(childSum));
sendMq(mqMap, now);
return sendLazyTime; return sendLazyTime;
} }
...@@ -134,4 +148,30 @@ public class ThreeGoodsOrderStrategy implements GoodsOrderStrategy, Initializing ...@@ -134,4 +148,30 @@ public class ThreeGoodsOrderStrategy implements GoodsOrderStrategy, Initializing
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
goodsOrderStrategyContext.strategyContext.put(3,this); goodsOrderStrategyContext.strategyContext.put(3,this);
} }
public void sendMq(Map<String, LocalDateTime> mqMap, LocalDateTime now) {
for (Map.Entry<String, LocalDateTime> entry : mqMap.entrySet()) {
Message message = MessageBuilder.withBody(entry.getKey().getBytes()).build();
long epochMilli = 0L;
if (entry.getValue().isAfter(now)) {
epochMilli = entry.getValue().minusMinutes(now.getMinute()).getMinute() * 60 * 1000;
log.info("选择时间在当前时间之后,则设置延迟队列时间,时间为:{}", epochMilli);
}
if (epochMilli == 0L) {
log.info("epochMilli时间为0,时间为:{}", epochMilli);
rabbitTemplate.send(
RabbitKeyConstants.ORDER_GOODS_ON_DEAD_EXCHANGE, RabbitKeyConstants.ORDER_GOODS_ON_DEAD_ROUTE_KEY, message
);
} else {
log.info("epochMilli时间不为0,时间为:{}", epochMilli);
message.getMessageProperties().setExpiration(String.valueOf(epochMilli));
rabbitTemplate.send(
RabbitKeyConstants.ORDER_GOODS_ON_EXCHANGE, RabbitKeyConstants.ORDER_GOODS_ON_DEAD_ROUTE_KEY, message
);
}
}
}
} }
...@@ -7,6 +7,7 @@ import com.clx.order.params.OrderGoodsParams; ...@@ -7,6 +7,7 @@ import com.clx.order.params.OrderGoodsParams;
import com.clx.order.vo.feign.FeignOrderVO; import com.clx.order.vo.feign.FeignOrderVO;
import com.clx.performance.component.GoodsOrderStrategyContext; import com.clx.performance.component.GoodsOrderStrategyContext;
import com.clx.performance.component.OrderGoodsIdGenerate; import com.clx.performance.component.OrderGoodsIdGenerate;
import com.clx.performance.constant.RabbitKeyConstants;
import com.clx.performance.dao.OrderGoodsTruckBindDao; import com.clx.performance.dao.OrderGoodsTruckBindDao;
import com.clx.performance.enums.OrderGoodsStatusEnum; import com.clx.performance.enums.OrderGoodsStatusEnum;
import com.clx.performance.enums.OrderGoodsTypeEnum; import com.clx.performance.enums.OrderGoodsTypeEnum;
...@@ -20,13 +21,18 @@ import com.msl.common.utils.DateUtils; ...@@ -20,13 +21,18 @@ import com.msl.common.utils.DateUtils;
import com.msl.user.data.UserSessionData; import com.msl.user.data.UserSessionData;
import com.msl.user.utils.TokenUtil; import com.msl.user.utils.TokenUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
@Component("TwoGoodsOrderStrategy") @Component("TwoGoodsOrderStrategy")
@Slf4j @Slf4j
...@@ -52,12 +58,14 @@ public class TwoGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe ...@@ -52,12 +58,14 @@ public class TwoGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
@Autowired @Autowired
private GoodsOrderStrategyContext goodsOrderStrategyContext; private GoodsOrderStrategyContext goodsOrderStrategyContext;
@Autowired
private RabbitTemplate rabbitTemplate;
@Override @Override
public LocalDateTime goodsOrderProcess(OrderGoodsParams orderGoodsParams, FeignOrderVO orderInfo) { public LocalDateTime goodsOrderProcess(OrderGoodsParams orderGoodsParams, FeignOrderVO orderInfo, LocalDateTime now) {
String orderNo = orderGoodsParams.getOrderNo(); String orderNo = orderGoodsParams.getOrderNo();
UserSessionData loginUserInfo = TokenUtil.getLoginUserInfo(); UserSessionData loginUserInfo = TokenUtil.getLoginUserInfo();
LocalDateTime now = LocalDateTime.now();
LocalDateTime sendLazyTime = null; LocalDateTime sendLazyTime = null;
List<OrderGoodsChildParams> childParamsList = orderGoodsParams.getOrderGoodsChildParams(); List<OrderGoodsChildParams> childParamsList = orderGoodsParams.getOrderGoodsChildParams();
BigDecimal childSum = childParamsList.stream().map(OrderGoodsChildParams::getExtractWeight).reduce( BigDecimal childSum = childParamsList.stream().map(OrderGoodsChildParams::getExtractWeight).reduce(
...@@ -65,6 +73,8 @@ public class TwoGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe ...@@ -65,6 +73,8 @@ public class TwoGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
if (orderInfo.getResidueWeight().compareTo(childSum) < 0) { if (orderInfo.getResidueWeight().compareTo(childSum) < 0) {
throw new ServiceSystemException(PerformanceResultEnum.HTTP_ERROR, "当前货单总吨数已超订单总吨数"); throw new ServiceSystemException(PerformanceResultEnum.HTTP_ERROR, "当前货单总吨数已超订单总吨数");
} }
Map<String, LocalDateTime> mqMap = new HashMap<>();
long beginOrderGoodsId = orderGoodsIdGenerate.getOrderGoodsId(OrderGoodsTypeEnum.Status.PLATFORM.getCode(), childParamsList.size()); long beginOrderGoodsId = orderGoodsIdGenerate.getOrderGoodsId(OrderGoodsTypeEnum.Status.PLATFORM.getCode(), childParamsList.size());
for (OrderGoodsChildParams child : childParamsList) { for (OrderGoodsChildParams child : childParamsList) {
if (child.getPendingOrderWay().equals(2)) { if (child.getPendingOrderWay().equals(2)) {
...@@ -128,11 +138,14 @@ public class TwoGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe ...@@ -128,11 +138,14 @@ public class TwoGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
if (CollectionUtil.isNotEmpty(child.getTruckList())) { if (CollectionUtil.isNotEmpty(child.getTruckList())) {
orderGoodsTruckBindDao.saveBatchEntity(orderNo, OrderGoodsTypeEnum.Status.PLATFORM.getCode() + beginOrderGoodsId, child.getTruckList(), now); orderGoodsTruckBindDao.saveBatchEntity(orderNo, OrderGoodsTypeEnum.Status.PLATFORM.getCode() + beginOrderGoodsId, child.getTruckList(), now);
} }
mqMap.put(OrderGoodsTypeEnum.Status.PLATFORM.getCode() + beginOrderGoodsId, postedTime);
beginOrderGoodsId = beginOrderGoodsId + 1; beginOrderGoodsId = beginOrderGoodsId + 1;
orderGoodsMapper.insert(orderGoods); orderGoodsMapper.insert(orderGoods);
} }
orderFeign.updateOrderInfoResidueWeight(orderInfo.getId(),orderInfo.getResidueWeight().subtract(childSum)); orderFeign.updateOrderInfoResidueWeight(orderInfo.getId(),orderInfo.getResidueWeight().subtract(childSum));
sendMq(mqMap, now);
return sendLazyTime; return sendLazyTime;
} }
...@@ -140,4 +153,30 @@ public class TwoGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe ...@@ -140,4 +153,30 @@ public class TwoGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
goodsOrderStrategyContext.strategyContext.put(2,this); goodsOrderStrategyContext.strategyContext.put(2,this);
} }
public void sendMq(Map<String, LocalDateTime> mqMap, LocalDateTime now) {
for (Map.Entry<String, LocalDateTime> entry : mqMap.entrySet()) {
Message message = MessageBuilder.withBody(entry.getKey().getBytes()).build();
long epochMilli = 0L;
if (entry.getValue().isAfter(now)) {
epochMilli = entry.getValue().minusMinutes(now.getMinute()).getMinute() * 60 * 1000;
log.info("选择时间在当前时间之后,则设置延迟队列时间,时间为:{}", epochMilli);
}
if (epochMilli == 0L) {
log.info("epochMilli时间为0,时间为:{}", epochMilli);
rabbitTemplate.send(
RabbitKeyConstants.ORDER_GOODS_ON_DEAD_EXCHANGE, RabbitKeyConstants.ORDER_GOODS_ON_DEAD_ROUTE_KEY, message
);
} else {
log.info("epochMilli时间不为0,时间为:{}", epochMilli);
message.getMessageProperties().setExpiration(String.valueOf(epochMilli));
rabbitTemplate.send(
RabbitKeyConstants.ORDER_GOODS_ON_EXCHANGE, RabbitKeyConstants.ORDER_GOODS_ON_DEAD_ROUTE_KEY, message
);
}
}
}
} }
package com.clx.performance; package com.clx.performance;
import com.clx.order.feign.OrderFeign; import com.clx.order.feign.OrderFeign;
import com.clx.performance.constant.RabbitKeyConstants;
import com.clx.performance.mapper.OrderGoodsMapper; import com.clx.performance.mapper.OrderGoodsMapper;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
...@@ -17,8 +21,15 @@ public class JobTest { ...@@ -17,8 +21,15 @@ public class JobTest {
@Autowired @Autowired
private OrderFeign orderFeign; private OrderFeign orderFeign;
@Autowired
private RabbitTemplate rabbitTemplate;
@Test @Test
public void test1() { public void test1() {
orderFeign.updateOrderInfoResidueWeight(5,new BigDecimal(32)); Message message = MessageBuilder.withBody("PT2023091900049".getBytes()).build();
message.getMessageProperties().setExpiration("10000");
rabbitTemplate.send(
RabbitKeyConstants.ORDER_GOODS_ON_EXCHANGE, RabbitKeyConstants.ORDER_GOODS_ON_ROUTE_KEY, message
);
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论