|
@@ -1,25 +1,62 @@
|
|
|
package com.xingxi.mq.consumer.order;
|
|
package com.xingxi.mq.consumer.order;
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
|
|
+import com.xingxi.business.Order.domain.Order;
|
|
|
|
|
+import com.xingxi.business.Order.domain.OrderDetail;
|
|
|
|
|
+import com.xingxi.business.Order.service.IOrderDetailService;
|
|
|
|
|
+import com.xingxi.business.Order.service.IOrderService;
|
|
|
|
|
+import com.xingxi.business.PaymentInfo.domain.PaymentInfo;
|
|
|
|
|
+import com.xingxi.business.PaymentInfo.service.IPaymentInfoService;
|
|
|
|
|
+import com.xingxi.business.ProdInventory.mapper.ProdInventoryBillMapper;
|
|
|
|
|
+import com.xingxi.business.ProdInventory.mapper.ProdInventoryMapper;
|
|
|
|
|
+import com.xingxi.common.enums.EDelFlag;
|
|
|
|
|
+import com.xingxi.common.enums.EOrderDetailStatus;
|
|
|
|
|
+import com.xingxi.common.enums.EOrderStatus;
|
|
|
|
|
+import com.xingxi.common.mq.bo.order.OrderBO;
|
|
|
import com.xingxi.common.mq.constant.OrderMqKey;
|
|
import com.xingxi.common.mq.constant.OrderMqKey;
|
|
|
import com.xingxi.common.mq.core.AbstractRabbitConsumer;
|
|
import com.xingxi.common.mq.core.AbstractRabbitConsumer;
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
|
import com.rabbitmq.client.Channel;
|
|
import com.rabbitmq.client.Channel;
|
|
|
|
|
+import com.xingxi.common.utils.DateUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.amqp.core.Binding;
|
|
import org.springframework.amqp.core.Binding;
|
|
|
import org.springframework.amqp.core.Message;
|
|
import org.springframework.amqp.core.Message;
|
|
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Component
|
|
@Component
|
|
|
public class OrderCloseConsumer extends AbstractRabbitConsumer {
|
|
public class OrderCloseConsumer extends AbstractRabbitConsumer {
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private IOrderService orderService;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private IOrderDetailService orderDetailService;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private IPaymentInfoService paymentInfoService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ProdInventoryBillMapper prodInventoryBillMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ProdInventoryMapper prodInventoryMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private WxPayService wxPayService;
|
|
|
|
|
+
|
|
|
@Bean(OrderMqKey.EDIT_QUEUE_DELAY_FOR_UNPAID)
|
|
@Bean(OrderMqKey.EDIT_QUEUE_DELAY_FOR_UNPAID)
|
|
|
@Override
|
|
@Override
|
|
|
protected List<Binding> getBindingList() {
|
|
protected List<Binding> getBindingList() {
|
|
|
- long xmTtl = 10 * 60 * 1000;
|
|
|
|
|
|
|
+ long xmTtl = 15 * 60 * 1000;
|
|
|
return Lists.newArrayList(
|
|
return Lists.newArrayList(
|
|
|
this.bindDelay(OrderMqKey.EDIT_EXCHANGE_DELAY,
|
|
this.bindDelay(OrderMqKey.EDIT_EXCHANGE_DELAY,
|
|
|
OrderMqKey.EDIT_QUEUE_DELAY_FOR_UNPAID,
|
|
OrderMqKey.EDIT_QUEUE_DELAY_FOR_UNPAID,
|
|
@@ -35,6 +72,97 @@ public class OrderCloseConsumer extends AbstractRabbitConsumer {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public boolean execute(String body, Channel channel, Message message) throws Exception {
|
|
public boolean execute(String body, Channel channel, Message message) throws Exception {
|
|
|
|
|
+ log.info("订单关闭MQ,处理推送的订单数据【{}】.", body);
|
|
|
|
|
+
|
|
|
|
|
+ OrderBO orderBO = JSON.parseObject(body, OrderBO.class);
|
|
|
|
|
+
|
|
|
|
|
+ Date nowDate = DateUtils.getNowDate();
|
|
|
|
|
+ String opName = "订单关闭MQ";
|
|
|
|
|
+
|
|
|
|
|
+ if(orderBO == null || orderBO.getOrderId() == null || orderBO.getOrderId() == 0L) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 如果没有支付成功就取消
|
|
|
|
|
+ Order orgOrder = orderService.selectOrderByOrderId(orderBO.getOrderId());
|
|
|
|
|
+ if(orgOrder == null) {
|
|
|
|
|
+ log.info("订单关闭MQ,订单【{}】的信息不存在,不做处理.", orderBO.getOrderNo());
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!EOrderStatus.ORDERED.getVal().equals(orgOrder.getOrderStatus())) {
|
|
|
|
|
+ log.info("订单关闭MQ,订单【{}】的订单状态为【{}】,非【{}】不做处理.", orgOrder.getOrderNo(), orgOrder.getOrderStatus(), EOrderStatus.ORDERED.getDesc());
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 支付信息
|
|
|
|
|
+ PaymentInfo spi = new PaymentInfo();
|
|
|
|
|
+ spi.setOrderId(orgOrder.getOrderId());
|
|
|
|
|
+ spi.setDelFlag(EDelFlag.NO.getVal());
|
|
|
|
|
+
|
|
|
|
|
+ List<PaymentInfo> paymentInfoList = paymentInfoService.selectPaymentInfoList(spi);
|
|
|
|
|
+
|
|
|
|
|
+ if(CollectionUtils.isNotEmpty(paymentInfoList)){
|
|
|
|
|
+ PaymentInfo pi = paymentInfoList.get(0);
|
|
|
|
|
+ if(pi != null) {
|
|
|
|
|
+ // 查询是否支付成功 TODO
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 如果支付成功并且微信支付没有回调成功就在这里退款 TODO
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 取消主订单
|
|
|
|
|
+ Order order = new Order();
|
|
|
|
|
+ order.setOrderId(orgOrder.getOrderId());
|
|
|
|
|
+ order.setOrderStatus(EOrderStatus.CANCELLED.getVal());
|
|
|
|
|
+ order.setCancelTime(nowDate);
|
|
|
|
|
+ order.setUpdateUser(opName);
|
|
|
|
|
+ order.setUpdateTime(nowDate);
|
|
|
|
|
+ orderService.updateOrder(order);
|
|
|
|
|
+
|
|
|
|
|
+ // 取消子订单
|
|
|
|
|
+ OrderDetail sod = new OrderDetail();
|
|
|
|
|
+ sod.setOrderId(order.getOrderId());
|
|
|
|
|
+ List<OrderDetail> orderDetails = orderDetailService.selectOrderDetailList(sod);
|
|
|
|
|
+ for (OrderDetail od : orderDetails) {
|
|
|
|
|
+ //将订单明细设为已取消
|
|
|
|
|
+ OrderDetail updateDetail = new OrderDetail();
|
|
|
|
|
+ updateDetail.setOrderDetailId(od.getOrderDetailId());
|
|
|
|
|
+ updateDetail.setOrderDetailStatus(EOrderDetailStatus.CANCELLED.getVal());
|
|
|
|
|
+ updateDetail.setUpdateUser(opName);
|
|
|
|
|
+ updateDetail.setUpdateTime(nowDate);
|
|
|
|
|
+ orderDetailService.updateOrderDetail(updateDetail);
|
|
|
|
|
+
|
|
|
|
|
+ //减少锁库,恢复库存
|
|
|
|
|
+// ProdStockVo sps = new ProdStockVo();
|
|
|
|
|
+// sps.setProdId(od.getProdId());
|
|
|
|
|
+// sps.setPprId(od.getPprId());
|
|
|
|
|
+// sps.setVendorId(od.getVendorId());
|
|
|
|
|
+//
|
|
|
|
|
+// ProdStockVo ps = prodInventoryMapper.selectProdStockVoByUnionId(sps);
|
|
|
|
|
+// sps.setStockId(ps.getStockId());
|
|
|
|
|
+// sps.setAvailQty(od.getBuyQty());
|
|
|
|
|
+// sps.setOrderId(orgOrder.getOrderId());
|
|
|
|
|
+// sps.setOrderNo(orgOrder.getOrderNo());
|
|
|
|
|
+// sps.setBillType(EStockBillType.IN.getVal());
|
|
|
|
|
+// sps.setBillKind(EStockBillKind.IN_CANCEL.getVal());
|
|
|
|
|
+// sps.setUpdateUser(opName);
|
|
|
|
|
+// sps.setUpdateTime(nowDate);
|
|
|
|
|
+// prodStockVoService.updateProdStockQty(sps);
|
|
|
|
|
+// prodInventoryMapper.
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+// // 关闭支付信息
|
|
|
|
|
+// PaymentInfo upi = new PaymentInfo();
|
|
|
|
|
+// upi.setOrderId(orgOrder.getOrderId());
|
|
|
|
|
+// upi.setTradeState(EOrderStatus.CANCELLED.getVal());
|
|
|
|
|
+// upi.setUpdateUser(opName);
|
|
|
|
|
+// upi.setUpdateTime(nowDate);
|
|
|
|
|
+// paymentInfoService.updateOrderStatusByOrderId(upi);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("订单关闭MQ,订单【{}】数据处理完成.", orgOrder.getOrderNo());
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|