فهرست منبع

Merge branch 'dev/2024/0506/update-app-Y' of feifan/mall-backend-app into master

接通快递100查询物流信息
Yangzw 11 ماه پیش
والد
کامیت
85cb943fab
10فایلهای تغییر یافته به همراه92 افزوده شده و 24 حذف شده
  1. 8 0
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/delivery/vo/express/DeliveryExpressExcelVO.java
  2. 23 0
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/delivery/vo/express/DeliveryExpressImportRespVO.java
  3. 15 3
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/app/delivery/AppDeliverExpressController.java
  4. 3 2
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/app/order/AppTradeOrderController.java
  5. 1 2
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/framework/delivery/config/TradeExpressProperties.java
  6. 5 2
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/framework/delivery/core/client/dto/kd100/Kd100ExpressQueryRespDTO.java
  7. 2 4
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/delivery/DeliveryExpressService.java
  8. 28 5
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/delivery/DeliveryExpressServiceImpl.java
  9. 4 3
      feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/order/TradeOrderQueryServiceImpl.java
  10. 3 3
      feifan-server/src/main/resources/application.yaml

+ 8 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/delivery/vo/express/DeliveryExpressExcelVO.java

@@ -4,7 +4,11 @@ import cn.newfeifan.mall.framework.excel.core.annotations.DictFormat;
 import cn.newfeifan.mall.framework.excel.core.convert.DictConvert;
 import cn.newfeifan.mall.module.system.enums.DictTypeConstants;
 import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
 import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
 
 import java.time.LocalDateTime;
 
@@ -12,6 +16,10 @@ import java.time.LocalDateTime;
  * 快递公司 Excel VO
  */
 @Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+@Accessors(chain = false) // 设置 chain = false,避免导入有问题
 public class DeliveryExpressExcelVO {
 
     @ExcelProperty("编号")

+ 23 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/delivery/vo/express/DeliveryExpressImportRespVO.java

@@ -0,0 +1,23 @@
+package cn.newfeifan.mall.module.trade.controller.admin.delivery.vo.express;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Builder;
+import lombok.Data;
+
+import java.util.List;
+import java.util.Map;
+
+@Schema(description = "管理后台 - 快递公司导入 Response VO")
+@Data
+@Builder
+public class DeliveryExpressImportRespVO {
+
+    @Schema(description = "创建成功的快递公司名数组", requiredMode = Schema.RequiredMode.REQUIRED)
+    private List<String> createDeliveryExpressNames;
+
+    @Schema(description = "更新成功的快递公司名数组", requiredMode = Schema.RequiredMode.REQUIRED)
+    private List<String> updateDeliveryExpressNames;
+
+    @Schema(description = "导入失败的快递公司集合,key 为快递公司名,value 为失败原因", requiredMode = Schema.RequiredMode.REQUIRED)
+    private Map<String, String> failureDeliveryExpressNames;
+}

+ 15 - 3
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/app/delivery/AppDeliverExpressController.java

@@ -2,6 +2,10 @@ package cn.newfeifan.mall.module.trade.controller.app.delivery;
 
 import cn.newfeifan.mall.framework.common.enums.CommonStatusEnum;
 import cn.newfeifan.mall.framework.common.pojo.CommonResult;
+import cn.newfeifan.mall.framework.excel.core.util.ExcelUtils;
+import cn.newfeifan.mall.framework.operatelog.core.annotations.OperateLog;
+import cn.newfeifan.mall.module.trade.controller.admin.delivery.vo.express.DeliveryExpressExcelVO;
+import cn.newfeifan.mall.module.trade.controller.admin.delivery.vo.express.DeliveryExpressImportRespVO;
 import cn.newfeifan.mall.module.trade.controller.app.delivery.vo.express.AppDeliveryExpressRespVO;
 import cn.newfeifan.mall.module.trade.convert.delivery.DeliveryExpressConvert;
 import cn.newfeifan.mall.module.trade.dal.dataobject.delivery.DeliveryExpressDO;
@@ -9,15 +13,16 @@ import cn.newfeifan.mall.module.trade.service.delivery.DeliveryExpressService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
+import java.io.IOException;
 import java.util.Comparator;
 import java.util.List;
 
 import static cn.newfeifan.mall.framework.common.pojo.CommonResult.success;
+import static cn.newfeifan.mall.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
 
 @Tag(name = "用户 App - 快递公司")
 @RestController
@@ -36,4 +41,11 @@ public class AppDeliverExpressController {
         return success(DeliveryExpressConvert.INSTANCE.convertList03(list));
     }
 
+    @PostMapping("/import-excel")
+    @Operation(summary = "导入快递公司 Excel")
+    @OperateLog(type = EXPORT)
+    public CommonResult<DeliveryExpressImportRespVO> importDeliveryExpressExcel(@RequestParam("file") MultipartFile file) throws IOException {
+        List<DeliveryExpressExcelVO> list = ExcelUtils.read(file, DeliveryExpressExcelVO.class);
+        return success(deliveryExpressService.importDeliveryExpressList(list));
+    }
 }

+ 3 - 2
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/app/order/AppTradeOrderController.java

@@ -128,8 +128,9 @@ public class AppTradeOrderController {
     @Operation(summary = "获得交易订单的物流轨迹")
     @Parameter(name = "id", description = "交易订单编号")
     public CommonResult<List<AppOrderExpressTrackRespDTO>> getOrderExpressTrackList(@RequestParam("id") Long id) {
-        return success(TradeOrderConvert.INSTANCE.convertList02(
-                tradeOrderQueryService.getExpressTrackList(id, getLoginUserId())));
+        List<AppOrderExpressTrackRespDTO> data = TradeOrderConvert.INSTANCE.convertList02(
+                tradeOrderQueryService.getExpressTrackList(id, getLoginUserId()));
+        return success(data);
     }
 
     @GetMapping("/page")

+ 1 - 2
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/framework/delivery/config/TradeExpressProperties.java

@@ -23,10 +23,9 @@ public class TradeExpressProperties {
 
     /**
      * 快递客户端
-     *
      * 默认不提供,需要提醒用户配置一个快递服务商。
      */
-    private ExpressClientEnum client = ExpressClientEnum.NOT_PROVIDE;
+    private ExpressClientEnum client = ExpressClientEnum.KD_100;        //现在用的快递 100
 
     /**
      * 快递鸟配置

+ 5 - 2
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/framework/delivery/core/client/dto/kd100/Kd100ExpressQueryRespDTO.java

@@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 import lombok.Data;
 
 import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.List;
 
 import static cn.newfeifan.mall.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@@ -12,7 +13,6 @@ import static cn.newfeifan.mall.framework.common.util.date.DateUtils.TIME_ZONE_D
 
 /**
  * 快递 100 实时快递查询 Resp DTO
- *
  * 参见  <a href="https://api.kuaidi100.com/document/5f0ffb5ebc8da837cbd8aefc">快递 100 文档</a>
  *
  * @author jason
@@ -37,7 +37,6 @@ public class Kd100ExpressQueryRespDTO {
 
     /**
      * 查询结果
-     *
      * 失败返回 "false"
      */
     private String result;
@@ -60,6 +59,10 @@ public class Kd100ExpressQueryRespDTO {
          */
         @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT)
         private LocalDateTime time;
+        public void setTime(String time) {
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern(FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND);
+            this.time = LocalDateTime.parse(time,formatter);
+        }
 
         /**
          * 轨迹描述

+ 2 - 4
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/delivery/DeliveryExpressService.java

@@ -1,10 +1,7 @@
 package cn.newfeifan.mall.module.trade.service.delivery;
 
 import cn.newfeifan.mall.framework.common.pojo.PageResult;
-import cn.newfeifan.mall.module.trade.controller.admin.delivery.vo.express.DeliveryExpressCreateReqVO;
-import cn.newfeifan.mall.module.trade.controller.admin.delivery.vo.express.DeliveryExpressExportReqVO;
-import cn.newfeifan.mall.module.trade.controller.admin.delivery.vo.express.DeliveryExpressPageReqVO;
-import cn.newfeifan.mall.module.trade.controller.admin.delivery.vo.express.DeliveryExpressUpdateReqVO;
+import cn.newfeifan.mall.module.trade.controller.admin.delivery.vo.express.*;
 import cn.newfeifan.mall.module.trade.dal.dataobject.delivery.DeliveryExpressDO;
 
 import javax.validation.Valid;
@@ -79,4 +76,5 @@ public interface DeliveryExpressService {
      */
     List<DeliveryExpressDO> getDeliveryExpressListByStatus(Integer status);
 
+    DeliveryExpressImportRespVO importDeliveryExpressList(List<DeliveryExpressExcelVO> list);
 }

+ 28 - 5
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/delivery/DeliveryExpressServiceImpl.java

@@ -2,10 +2,8 @@ package cn.newfeifan.mall.module.trade.service.delivery;
 
 import cn.newfeifan.mall.framework.common.enums.CommonStatusEnum;
 import cn.newfeifan.mall.framework.common.pojo.PageResult;
-import cn.newfeifan.mall.module.trade.controller.admin.delivery.vo.express.DeliveryExpressCreateReqVO;
-import cn.newfeifan.mall.module.trade.controller.admin.delivery.vo.express.DeliveryExpressExportReqVO;
-import cn.newfeifan.mall.module.trade.controller.admin.delivery.vo.express.DeliveryExpressPageReqVO;
-import cn.newfeifan.mall.module.trade.controller.admin.delivery.vo.express.DeliveryExpressUpdateReqVO;
+import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
+import cn.newfeifan.mall.module.trade.controller.admin.delivery.vo.express.*;
 import cn.newfeifan.mall.module.trade.convert.delivery.DeliveryExpressConvert;
 import cn.newfeifan.mall.module.trade.dal.dataobject.delivery.DeliveryExpressDO;
 import cn.newfeifan.mall.module.trade.dal.mysql.delivery.DeliveryExpressMapper;
@@ -13,7 +11,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
 import javax.annotation.Resource;
-import java.util.List;
+import java.util.*;
 
 import static cn.newfeifan.mall.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.newfeifan.mall.module.trade.enums.ErrorCodeConstants.*;
@@ -111,4 +109,29 @@ public class DeliveryExpressServiceImpl implements DeliveryExpressService {
         return deliveryExpressMapper.selectListByStatus(status);
     }
 
+    @Override
+    public DeliveryExpressImportRespVO importDeliveryExpressList(List<DeliveryExpressExcelVO> list) {
+        DeliveryExpressImportRespVO respVO = DeliveryExpressImportRespVO.builder().createDeliveryExpressNames(new ArrayList<>())
+                .updateDeliveryExpressNames(new ArrayList<>()).failureDeliveryExpressNames(new LinkedHashMap<>()).build();
+        list.forEach(importDeliveryExpress -> {
+            // 判断如果不存在,在进行插入
+            DeliveryExpressDO deliveryExpressDO = deliveryExpressMapper.selectByCode(importDeliveryExpress.getCode());
+            if (deliveryExpressDO == null) {
+                deliveryExpressMapper.insert(BeanUtils.toBean(importDeliveryExpress, DeliveryExpressDO.class)
+                        .setCode(importDeliveryExpress.getCode())
+                        .setName(importDeliveryExpress.getName())
+                        .setSort(importDeliveryExpress.getSort())
+                        .setStatus(importDeliveryExpress.getStatus())
+                );
+                respVO.getCreateDeliveryExpressNames().add(importDeliveryExpress.getName());
+                return;
+            }
+            DeliveryExpressDO updateDeliveryExpress = BeanUtils.toBean(importDeliveryExpress, DeliveryExpressDO.class);
+            updateDeliveryExpress.setId(deliveryExpressDO.getId());
+            deliveryExpressMapper.updateById(updateDeliveryExpress);
+            respVO.getUpdateDeliveryExpressNames().add(importDeliveryExpress.getName());
+        });
+        return respVO;
+    }
+
 }

+ 4 - 3
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/order/TradeOrderQueryServiceImpl.java

@@ -206,7 +206,6 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
 
     /**
      * 查询物流轨迹
-     *
      * 缓存的目的:考虑及时性要求不高,但是每次调用需要钱
      *
      * @param code           快递公司编码
@@ -218,8 +217,10 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
             condition = "#result != null")
     public List<ExpressTrackRespDTO> getExpressTrackList(String code, String logisticsNo, String receiverMobile) {
         return expressClientFactory.getDefaultExpressClient().getExpressTrackList(
-                new ExpressTrackQueryReqDTO().setExpressCode(code).setLogisticsNo(logisticsNo)
-                        .setPhone(receiverMobile));
+                new ExpressTrackQueryReqDTO().setExpressCode(code)
+                        .setLogisticsNo(logisticsNo)
+                        .setPhone(receiverMobile)
+        );
     }
 
 

+ 3 - 3
feifan-server/src/main/resources/application.yaml

@@ -253,13 +253,13 @@ feifan:
       receive-expire-time: 14d # 收货的过期时间
       comment-expire-time: 7d # 评论的过期时间
     express:
-      client: kd_niao
+      client: KD_100
       kd-niao:
         api-key: cb022f1e-48f1-4c4a-a723-9001ac9676b8
         business-id: 1809751
       kd100:
-        key: pLXUGAwK5305
-        customer: E77DF18BE109F454A5CD319E44BF5177
+        key: vAeIErtY7248
+        customer: 7FA4F892DB920F6EB6DEACF31D6B0D4F
 
 debug: false