Ver código fonte

代码调整

baolei 7 meses atrás
pai
commit
3301dacca3

+ 9 - 9
08.src/Xingxi/xingxi-common/src/main/java/com/xingxi/common/mq/constant/OrderMqKey.java

@@ -40,15 +40,15 @@ public interface OrderMqKey {
      */
     String EDIT_ROUTE_FOR_DELIVERY_CANCELED = "mq.route.xingxi.order.delivery.canceled";
 
-    /**
-     * 订单售后路由KEY
-     */
-    String EDIT_ROUTE_FOR_AFTER_SALE = "mq.route.xingxi.order.after.sale";
-
-    /**
-     * 退货完成路由KEY
-     */
-    String EDIT_ROUTE_FOR_RETURNED = "mq.route.xingxi.order.returned";
+//    /**
+//     * 订单售后路由KEY
+//     */
+//    String EDIT_ROUTE_FOR_AFTER_SALE = "mq.route.xingxi.order.after.sale";
+//
+//    /**
+//     * 退货完成路由KEY
+//     */
+//    String EDIT_ROUTE_FOR_RETURNED = "mq.route.xingxi.order.returned";
 
     /**
      * 订单完成路由KEY

+ 2 - 0
08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/api/service/impl/OrderApiServiceImpl.java

@@ -37,6 +37,7 @@ import com.xingxi.common.enums.EOrderStatus;
 import com.xingxi.common.exception.BusinessException;
 import com.xingxi.common.mq.bo.order.OrderBO;
 import com.xingxi.common.mq.publisher.order.OrderCreatedMqPublisher;
+import com.xingxi.common.mq.publisher.order.OrderPayedMqPublisher;
 import com.xingxi.common.utils.DateUtils;
 import com.xingxi.common.utils.PageUtils;
 import com.xingxi.common.utils.StringUtils;
@@ -95,6 +96,7 @@ class OrderApiServiceImpl implements OrderServiceI {
     private WxApiOrderMapper wxApiOrderMapper;
 
     private final OrderCreatedMqPublisher createdMqPublisher;
+    private final OrderPayedMqPublisher orderPayedMqPublisher;
 
     @Value("${spring.application.xingxi.unifiedpay.callbackUrl}")
     private String notifyUrl;

+ 27 - 0
08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/api/service/impl/XingxiUnifiedpayCallbackServiceImpl.java

@@ -0,0 +1,27 @@
+package com.xingxi.api.service.impl;
+
+
+import com.xingxi.common.service.XingxiUnifiedpayCallbackClient;
+import com.xingxi.common.service.XingxiUnifiedpayCallbackDTO;
+import com.xingxi.unifiedpay.domain.XingxiUnifiedpayCallbackResultDTO;
+import com.xingxi.unifiedpay.open.XingxiUnifiedpayCallbackServiceI;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Component;
+
+
+@Slf4j
+@Component
+@RequiredArgsConstructor
+class XingxiUnifiedpayCallbackServiceImpl implements XingxiUnifiedpayCallbackServiceI {
+    private final XingxiUnifiedpayCallbackClient xingxiUnifiedpayCallbackClient;
+
+    @Override
+    public void callbackFollowUpProcessing(XingxiUnifiedpayCallbackResultDTO xingxiUnifiedpayCallbackResultDTO) {
+        XingxiUnifiedpayCallbackDTO xingxiUnifiedpayCallbackDTO = new XingxiUnifiedpayCallbackDTO();
+        BeanUtils.copyProperties(xingxiUnifiedpayCallbackResultDTO, xingxiUnifiedpayCallbackDTO);
+        xingxiUnifiedpayCallbackClient.execute(xingxiUnifiedpayCallbackDTO);
+    }
+
+}

+ 1 - 1
08.src/Xingxi/xingxi-pay-utils/xingxi-unifiedpay-spring-boot-starter/src/main/java/com/xingxi/unifiedpay/open/XingxiUnifiedpayCallbackServiceI.java

@@ -4,5 +4,5 @@ import com.xingxi.unifiedpay.domain.XingxiUnifiedpayCallbackResultDTO;
 
 public interface XingxiUnifiedpayCallbackServiceI {
 
-    void callbackFollowUpProcessing(XingxiUnifiedpayCallbackResultDTO biandanUnifiedpayCallbackResultDTO);
+    void callbackFollowUpProcessing(XingxiUnifiedpayCallbackResultDTO xingxiUnifiedpayCallbackResultDTO);
 }

+ 14 - 0
08.src/Xingxi/xingxi-system/src/main/java/com/xingxi/common/mapper/XingxiUnifiedpayExtMapper.java

@@ -0,0 +1,14 @@
+package com.xingxi.common.mapper;
+
+import com.xingxi.business.Order.domain.Order;
+import com.xingxi.business.Order.mapper.OrderDetailMapper;
+import com.xingxi.business.Order.mapper.OrderMapper;
+import com.xingxi.business.PaymentInfo.domain.PaymentInfo;
+import com.xingxi.business.PaymentInfo.mapper.PaymentInfoMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface XingxiUnifiedpayExtMapper extends PaymentInfoMapper, OrderMapper, OrderDetailMapper {
+    PaymentInfo selectLockPaymentInfoByOutTradeNo(String outTradeNo);
+    Order selectLockOrderByOrderId(Long orderId);
+}

+ 104 - 0
08.src/Xingxi/xingxi-system/src/main/java/com/xingxi/common/service/DefaultXingxiUnifiedpayCallbackClient.java

@@ -0,0 +1,104 @@
+package com.xingxi.common.service;
+
+import com.xingxi.business.Order.domain.Order;
+import com.xingxi.business.Order.domain.OrderDetail;
+import com.xingxi.business.PaymentInfo.domain.PaymentInfo;
+import com.xingxi.common.enums.EOrderDetailStatus;
+import com.xingxi.common.enums.EOrderStatus;
+import com.xingxi.common.mapper.XingxiUnifiedpayExtMapper;
+import com.xingxi.common.mq.bo.order.OrderBO;
+import com.xingxi.common.mq.publisher.order.OrderPayedMqPublisher;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Date;
+import java.util.List;
+
+@Slf4j
+@Component
+@RequiredArgsConstructor
+class DefaultXingxiUnifiedpayCallbackClient implements XingxiUnifiedpayCallbackClient {
+    private final OrderPayedMqPublisher orderPayedMqPublisher;
+    private final XingxiUnifiedpayExtMapper xingxiUnifiedpayExtMapper;
+
+    @Transactional
+    @Override
+    public void execute(XingxiUnifiedpayCallbackDTO biandanUnifiedpayCallbackDTO) {
+        String tradeState = biandanUnifiedpayCallbackDTO.getTradeState();
+        String outTradeNo = biandanUnifiedpayCallbackDTO.getOutTradeNo();
+        String callUnifiedpayComponent = biandanUnifiedpayCallbackDTO.getCallUnifiedpayComponent();
+
+        PaymentInfo dbPaymentInfo = xingxiUnifiedpayExtMapper.selectLockPaymentInfoByOutTradeNo(outTradeNo);
+        if (dbPaymentInfo != null && "SUCCESS".equals(tradeState)) {
+            dbPaymentInfo.setUpdateUser(callUnifiedpayComponent);
+            dbPaymentInfo.setUpdateTime(new Date());
+            updatePaymentInfo(dbPaymentInfo, biandanUnifiedpayCallbackDTO);
+            Long orderId = dbPaymentInfo.getOrderId();
+
+            // lock
+            Order dbOrder = xingxiUnifiedpayExtMapper.selectLockOrderByOrderId(orderId);
+            dbOrder.setUpdateTime(dbPaymentInfo.getUpdateTime());
+            dbOrder.setUpdateUser(dbPaymentInfo.getUpdateUser());
+
+            updateOrderStatus(dbOrder);
+            // 发送订单支付完成事件消息
+            orderPayedEvent(dbOrder);
+
+            // 发送微信订阅消息 mq异步处理
+//            WxMaMsgService msgService = wxMaService.getMsgService();
+//            msgService.sendSubscribeMsg(WxMaSubscribeMessage.builder().templateId("").build());
+        }
+    }
+
+    private void updatePaymentInfo(PaymentInfo dbPaymentInfo, XingxiUnifiedpayCallbackDTO biandanUnifiedpayCallbackDTO) {
+        String tradeState = biandanUnifiedpayCallbackDTO.getTradeState();
+        String tradeType = biandanUnifiedpayCallbackDTO.getTradeType();
+        String bankType = biandanUnifiedpayCallbackDTO.getBankType();
+        String transactionId = biandanUnifiedpayCallbackDTO.getTransactionId();
+        String callUnifiedpayComponent = biandanUnifiedpayCallbackDTO.getCallUnifiedpayComponent();
+
+        PaymentInfo updatePaymentInfo = new PaymentInfo();
+        updatePaymentInfo.setPayId(dbPaymentInfo.getPayId());
+        updatePaymentInfo.setTradeType(tradeType);
+        updatePaymentInfo.setTradeState(tradeState);
+        updatePaymentInfo.setTransactionId(transactionId);
+        updatePaymentInfo.setSuccessTime(new Date());
+        updatePaymentInfo.setPayTime(updatePaymentInfo.getSuccessTime());
+        updatePaymentInfo.setBankType(bankType);
+        updatePaymentInfo.setUpdateUser(callUnifiedpayComponent);
+        updatePaymentInfo.setUpdateTime(dbPaymentInfo.getUpdateTime());
+        xingxiUnifiedpayExtMapper.updatePaymentInfo(updatePaymentInfo);
+    }
+
+    private void updateOrderStatus(Order dbOrder) {
+        Order updateOrderStatus = new Order();
+        updateOrderStatus.setOrderId(dbOrder.getOrderId());
+        updateOrderStatus.setOrderStatus(EOrderStatus.PAYED.getVal());
+        updateOrderStatus.setUpdateUser(dbOrder.getUpdateUser());
+        updateOrderStatus.setUpdateTime(dbOrder.getUpdateTime());
+        xingxiUnifiedpayExtMapper.updateOrder(updateOrderStatus);
+
+        OrderDetail queryOrderDetail = new OrderDetail();
+        queryOrderDetail.setOrderId(dbOrder.getOrderId());
+        List<OrderDetail> orderDetails = xingxiUnifiedpayExtMapper.selectOrderDetailList(queryOrderDetail);
+        for (OrderDetail dbOrderDetail : orderDetails) {
+            OrderDetail updateOrderDetailStatus = new OrderDetail();
+            updateOrderDetailStatus.setOrderDetailId(dbOrderDetail.getOrderDetailId());
+            updateOrderDetailStatus.setOrderDetailStatus(EOrderDetailStatus.APPROVED.getVal());
+            updateOrderDetailStatus.setUpdateUser(dbOrder.getUpdateUser());
+            updateOrderDetailStatus.setUpdateTime(dbOrder.getUpdateTime());
+            xingxiUnifiedpayExtMapper.updateOrderDetail(updateOrderDetailStatus);
+        }
+    }
+
+    private void orderPayedEvent(Order orderDTO) {
+        // EDIT_ROUTE_FOR_PAYED
+        // EDIT_EXCHANGE
+        OrderBO orderBO = new OrderBO();
+        orderBO.setOrderId(orderDTO.getOrderId());
+        orderBO.setOrderNo(orderDTO.getOrderNo());
+        orderPayedMqPublisher.sendMessage(orderBO);
+    }
+}

+ 6 - 0
08.src/Xingxi/xingxi-system/src/main/java/com/xingxi/common/service/XingxiUnifiedpayCallbackClient.java

@@ -0,0 +1,6 @@
+package com.xingxi.common.service;
+
+public interface XingxiUnifiedpayCallbackClient {
+
+    void execute(XingxiUnifiedpayCallbackDTO biandanUnifiedpayCallbackDTO);
+}

+ 18 - 0
08.src/Xingxi/xingxi-system/src/main/java/com/xingxi/common/service/XingxiUnifiedpayCallbackDTO.java

@@ -0,0 +1,18 @@
+package com.xingxi.common.service;
+
+
+import lombok.Data;
+
+@Data
+public class XingxiUnifiedpayCallbackDTO {
+
+    private String tradeState;
+    private String outTradeNo;
+    private String successTimeString;
+    private String tradeType;
+    private String bankType;
+    private String attach;
+    private String transactionId;
+    private String callUnifiedpayComponent;
+    private Object originalObj;
+}