Quellcode durchsuchen

订单接单,退款超时监控增加两次推送,配置系数

jyc vor 3 Wochen
Ursprung
Commit
3387a1da1e

+ 6 - 0
alien-lawyer/src/main/java/shop/alien/lawyer/service/OrderExpirationService.java

@@ -14,6 +14,12 @@ public interface OrderExpirationService {
      * @param orderNum 訂單no
      */
     void handleOrderPaymentTimeout(String orderNum);
+    /**
+     * 處理訂單待接單超時
+     *
+     * @param expiredKey 訂單no
+     */
+    void handleRefundOrderKey(String expiredKey);
 
     /**
      * 設置訂單支付超時監聽

+ 63 - 18
alien-lawyer/src/main/java/shop/alien/lawyer/service/impl/OrderExpirationServiceImpl.java

@@ -20,6 +20,7 @@ import shop.alien.lawyer.service.OrderExpirationService;
 import shop.alien.mapper.LawyerConsultationOrderMapper;
 import shop.alien.mapper.LifeNoticeMapper;
 import shop.alien.mapper.LifeUserMapper;
+import shop.alien.util.common.DateUtils;
 
 
 import javax.annotation.PostConstruct;
@@ -123,46 +124,90 @@ public class OrderExpirationServiceImpl implements OrderExpirationService, Comma
      *
      * @param expiredKey 過期的key,格式:order:payment:timeout:{orderId}
      */
-    private void handleRefundOrderKey(String expiredKey) {
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void handleRefundOrderKey(String expiredKey) {
         try {
             // 從key中提取訂單ID
             String orderNo = "";
             String refundReason = "";
             String title = "";
             String message = "";
+            //律师未接单退款
             if (expiredKey.contains(ORDER_ACCEPT_TIMEOUT_PREFIX)) {
                 orderNo = expiredKey.replace(ORDER_ACCEPT_TIMEOUT_PREFIX, "");
                 refundReason = "律师未接单超時退款";
                 title = "未接单通知";
                 message = "您的编号为" + orderNo + "的订单已到48小时未被接单,订单金额将在1-3个工作日原路返还,请注意查收。";
+
+                // 查詢訂單
+                LambdaQueryWrapper<LawyerConsultationOrder> queryWrapper = new LambdaQueryWrapper<>();
+                queryWrapper.eq(LawyerConsultationOrder::getOrderNumber, orderNo).last("LIMIT 1");
+                LawyerConsultationOrder order = orderMapper.selectOne(queryWrapper);
+
+                log.info("檢測到有訂單需要退款,訂單no: {}", orderNo);
+
+                // 處理訂單退款
+                aliController.processRefund(order.getAlipayNo(),  new BigDecimal(order.getOrderAmount()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).toString(), refundReason,"");
+
+                log.info("訂單退款成功,訂單no: {}", orderNo);
+
+                //通知
+                LifeNotice lifeNotice = buildLifeNotice(order, title, message);
+                WebSocketVo webSocketVo = buildWebSocketVo(lifeNotice);
+
+                lifeNoticeMapper.insert(lifeNotice);
+                webSocketProcess.sendMessage(lifeNotice.getReceiverId(), JSONObject.from(webSocketVo).toJSONString());
+
+                log.info("系统通知发送成功,訂單no: {}", orderNo);
+
+                LawyerConsultationOrder update = new LawyerConsultationOrder();
+                update.setId(order.getId());
+                update.setOrderStatus(5);
+                orderMapper.updateById( update);
+
             }
+            //申请退款 律师没处理
             if (expiredKey.contains(ORDER_REFUND_TIMEOUT_PREFIX)) {
                 orderNo = expiredKey.replace(ORDER_REFUND_TIMEOUT_PREFIX, "");
                 refundReason = "申请退款超时后退款";
-                title = "申请退款通知";
-                message = "您的编号为" + orderNo + "的订单,申请退款的信息已提交给律师,等待律师同意。律师同意或48小时未处理,系统会将订单金额原路返还,请注意查收。";
-            }
 
-            // 查詢訂單
-            LambdaQueryWrapper<LawyerConsultationOrder> queryWrapper = new LambdaQueryWrapper<>();
-            queryWrapper.eq(LawyerConsultationOrder::getOrderNumber, orderNo).last("LIMIT 1");
-            LawyerConsultationOrder order = orderMapper.selectOne(queryWrapper);
+                // 查詢訂單
+                LambdaQueryWrapper<LawyerConsultationOrder> queryWrapper = new LambdaQueryWrapper<>();
+                queryWrapper.eq(LawyerConsultationOrder::getOrderNumber, orderNo).last("LIMIT 1");
+                LawyerConsultationOrder order = orderMapper.selectOne(queryWrapper);
 
-            log.info("檢測到有訂單需要退款,訂單no: {}", orderNo);
+                log.info("檢測到有訂單需要退款,訂單no: {}", orderNo);
 
-            // 處理訂單退款
-            aliController.processRefund(order.getAlipayNo(),  new BigDecimal(order.getOrderAmount()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).toString(), refundReason,"");
+                // 處理訂單退款
+                aliController.processRefund(order.getAlipayNo(),  new BigDecimal(order.getOrderAmount()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).toString(), refundReason,"");
 
-            log.info("訂單退款成功,訂單no: {}", orderNo);
+                log.info("訂單退款成功,訂單no: {}", orderNo);
 
-            //通知
-            LifeNotice lifeNotice = buildLifeNotice(order, title, message);
-            WebSocketVo webSocketVo = buildWebSocketVo(lifeNotice);
+                //同意退款通知
+                LifeNotice lifeNotice = buildLifeNotice(order, "同意退款通知", "您的编号为" + orderNo + "的订单,律师已同意您的退款申请,订单金额将在1-3个工作日原路返还,请注意查收。");
+                WebSocketVo webSocketVo = buildWebSocketVo(lifeNotice);
 
-            lifeNoticeMapper.insert(lifeNotice);
-            webSocketProcess.sendMessage(lifeNotice.getReceiverId(), JSONObject.from(webSocketVo).toJSONString());
+                lifeNoticeMapper.insert(lifeNotice);
+                webSocketProcess.sendMessage(lifeNotice.getReceiverId(), JSONObject.from(webSocketVo).toJSONString());
 
-            log.info("系统通知发送成功,訂單no: {}", orderNo);
+                //退款到账通知
+                LifeNotice lifeNotice2 = buildLifeNotice(order, "退款到账通知", "您的编号为" + orderNo + "的订单,订单金额已原路返还至您的支付渠道,请查收。");
+                WebSocketVo webSocketVo2 = buildWebSocketVo(lifeNotice);
+                lifeNotice2.setCreatedTime(DateUtils.calcMinute(lifeNotice.getCreatedTime(), 2));
+
+                lifeNoticeMapper.insert(lifeNotice2);
+                webSocketProcess.sendMessage(lifeNotice2.getReceiverId(), JSONObject.from(webSocketVo2).toJSONString());
+
+                log.info("系统通知发送成功,訂單no: {}", orderNo);
+
+                LawyerConsultationOrder update = new LawyerConsultationOrder();
+                update.setId(order.getId());
+                update.setOrderStatus(5);
+                update.setApplyRefundStatus("4");
+                orderMapper.updateById(update);
+
+            }
         } catch (Exception e) {
             log.error("處理有訂單需要退款key失敗,key: {}", expiredKey, e);
         }