提交 38125dad authored 作者: huyufan's avatar huyufan

增加货单挂单中状态发MQ

上级 3c369893
...@@ -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(orderOnDeadQueue()).to(orderOnDeadExchange()).with(RabbitKeyConstants.ORDER_GOODS_ON_DEAD_ROUTE_KEY);
} }
} }
...@@ -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";
} }
...@@ -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);
} }
...@@ -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);
}
} }
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);
} }
...@@ -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,30 @@ public class OneGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe ...@@ -140,4 +153,30 @@ 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()) {
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_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_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_ROUTE_KEY, message
);
}
}
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论