Browse Source

修改查询到物流信息后,更新订单信息

Yangzw 11 months ago
parent
commit
327c4eab39

+ 30 - 0
feifan-module-mall/feifan-module-trade-api/src/main/java/cn/newfeifan/mall/module/trade/enums/order/TradeOrderStateEnum.java

@@ -0,0 +1,30 @@
+package cn.newfeifan.mall.module.trade.enums.order;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+
+/**
+ * 交易订单状态枚举
+ */
+@RequiredArgsConstructor
+@Getter
+public enum TradeOrderStateEnum {
+    ON_THE_WAY("0","在途"),
+    COLLECT("1","揽收"),
+    ABNORMAL("2","疑难"),
+    RECEIVED("3","已签收"),
+    CANCEL_A_VISA("4","退签"),
+    DELIVERY("5","派件"),
+    SEND_BACK("6","退回"),
+    TRANSFER_TO("7","转投"),
+    REFUSE_TO_SIGN("14","拒签");
+
+    /**
+     * 状态值
+     */
+    private final String state;
+    /**
+     * 状态名
+     */
+    private final String name;
+}

+ 9 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/dal/dataobject/order/TradeOrderDO.java

@@ -355,4 +355,13 @@ public class TradeOrderDO extends BaseDO {
      */
     private Long combinationRecordId;
 
+    /**
+     * 订阅物流信息,未订阅是0,已订阅是1
+     */
+    private Integer subscriptionLogisticsInfo;
+    /**
+     * 物流签收时间
+     */
+    private LocalDateTime receivingTime;
+
 }

+ 46 - 1
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/framework/delivery/core/client/impl/kd100/Kd100ExpressClient.java

@@ -4,12 +4,18 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.HexUtil;
 import cn.hutool.crypto.digest.DigestUtil;
 import cn.newfeifan.mall.framework.common.util.json.JsonUtils;
+import cn.newfeifan.mall.module.trade.dal.dataobject.delivery.DeliveryExpressDO;
+import cn.newfeifan.mall.module.trade.dal.dataobject.order.TradeOrderDO;
+import cn.newfeifan.mall.module.trade.dal.mysql.delivery.DeliveryExpressMapper;
+import cn.newfeifan.mall.module.trade.dal.mysql.order.TradeOrderMapper;
+import cn.newfeifan.mall.module.trade.enums.order.TradeOrderStateEnum;
 import cn.newfeifan.mall.module.trade.framework.delivery.config.TradeExpressProperties;
 import cn.newfeifan.mall.module.trade.framework.delivery.core.client.ExpressClient;
 import cn.newfeifan.mall.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO;
 import cn.newfeifan.mall.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO;
 import cn.newfeifan.mall.module.trade.framework.delivery.core.client.dto.kd100.Kd100ExpressQueryReqDTO;
 import cn.newfeifan.mall.module.trade.framework.delivery.core.client.dto.kd100.Kd100ExpressQueryRespDTO;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.*;
@@ -17,6 +23,8 @@ import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
 import org.springframework.web.client.RestTemplate;
 
+import javax.annotation.Resource;
+import java.time.LocalDateTime;
 import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
@@ -35,11 +43,22 @@ import static cn.newfeifan.mall.module.trade.framework.delivery.core.client.conv
 @AllArgsConstructor
 public class Kd100ExpressClient implements ExpressClient {
 
+    public Kd100ExpressClient(RestTemplate restTemplate,TradeExpressProperties.Kd100Config config){
+        this.restTemplate = restTemplate;
+        this.config = config;
+    }
+
     private static final String REAL_TIME_QUERY_URL = "https://poll.kuaidi100.com/poll/query.do";
 
     private final RestTemplate restTemplate;
     private final TradeExpressProperties.Kd100Config config;
 
+    @Resource
+    private TradeOrderMapper tradeOrderMapper;
+
+    @Resource
+    private DeliveryExpressMapper deliveryExpressMapper;
+
     /**
      * 查询快递轨迹
      *
@@ -63,7 +82,33 @@ public class Kd100ExpressClient implements ExpressClient {
         if (CollUtil.isEmpty(respDTO.getTracks())) {
             return Collections.emptyList();
         }
-        return INSTANCE.convertList2(respDTO.getTracks());
+        List<ExpressTrackRespDTO> expressTrackRespDTOS = INSTANCE.convertList2(respDTO.getTracks());
+
+        //如果状态为已签收("3"),则保存到订单信息中
+        if(respDTO.getState().equals(TradeOrderStateEnum.RECEIVED.getState())){
+            updateOrder(respDTO.getExpressCompanyCode(),respDTO.getLogisticsNo(),expressTrackRespDTOS.get(0).getTime());
+        }
+        return expressTrackRespDTOS;
+    }
+
+    /**
+     * 保存订单的签收时间
+     * @param com 快递公司编码
+     * @param nu 单号
+     */
+    private void updateOrder(String com, String nu, LocalDateTime time){
+        DeliveryExpressDO deliveryExpressDO = deliveryExpressMapper.selectByCode(com);
+        TradeOrderDO tradeOrderDO = tradeOrderMapper.selectOne(new LambdaQueryWrapper<TradeOrderDO>()
+                .eq(TradeOrderDO::getLogisticsNo, nu)
+                .eq(TradeOrderDO::getLogisticsId, deliveryExpressDO.getId())
+                .isNull(TradeOrderDO::getReceivingTime)
+        );
+        if(tradeOrderDO == null){
+            return;
+        }
+        tradeOrderDO.setReceivingTime(time);
+
+        tradeOrderMapper.updateById(tradeOrderDO);
     }
 
     /**