Parcourir la source

快递100集成

qt5107 il y a 2 ans
Parent
commit
2e145fbf6b
17 fichiers modifiés avec 424 ajouts et 8 suppressions
  1. 1 1
      hx-common/code-generator/src/main/java/com/fjhx/modular/Victoriatourist.java
  2. 28 3
      hx-service-api/victoriatourist-api/src/main/java/com/fjhx/constants/logistics/LogisticsConstant.java
  3. 80 0
      hx-service-api/victoriatourist-api/src/main/java/com/fjhx/entity/logistics/LogisticsCompany.java
  4. 10 0
      hx-service-api/victoriatourist-api/src/main/java/com/fjhx/entity/logistics/LogisticsInfo.java
  5. 17 0
      hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/logistics/LogisticsCompanyEx.java
  6. 23 0
      hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/logistics/LogisticsCompanyVo.java
  7. 5 0
      hx-service/victoriatourist/pom.xml
  8. 68 0
      hx-service/victoriatourist/src/main/java/com/fjhx/config/KD100Config.java
  9. 1 2
      hx-service/victoriatourist/src/main/java/com/fjhx/config/MybatisConfig.java
  10. 33 0
      hx-service/victoriatourist/src/main/java/com/fjhx/controller/logistics/LogisticsCompanyController.java
  11. 2 1
      hx-service/victoriatourist/src/main/java/com/fjhx/controller/logistics/LogisticsInfoController.java
  12. 16 0
      hx-service/victoriatourist/src/main/java/com/fjhx/mapper/logistics/LogisticsCompanyMapper.java
  13. 5 0
      hx-service/victoriatourist/src/main/java/com/fjhx/mapper/logistics/LogisticsCompanyMapper.xml
  14. 21 0
      hx-service/victoriatourist/src/main/java/com/fjhx/service/logistics/LogisticsCompanyService.java
  15. 34 0
      hx-service/victoriatourist/src/main/java/com/fjhx/service/logistics/impl/LogisticsCompanyServiceImpl.java
  16. 12 1
      hx-service/victoriatourist/src/main/java/com/fjhx/service/logistics/impl/LogisticsInfoServiceImpl.java
  17. 68 0
      hx-service/victoriatourist/src/main/java/com/fjhx/uitl/kd100/KD100Util.java

+ 1 - 1
hx-common/code-generator/src/main/java/com/fjhx/modular/Victoriatourist.java

@@ -12,7 +12,7 @@ public class Victoriatourist {
         CodeGenerator.MODULAR_NAME = "victoriatourist";
 
         // 需要生成的表名称,多表用,隔开
-        CodeGenerator.INCLUDE = "order_sales_details";
+        CodeGenerator.INCLUDE = "logistics_company";
 
         // mysql连接
         CodeGenerator.MYSQL_URL = "36.134.91.96:17330";

+ 28 - 3
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/constants/logistics/LogisticsConstant.java

@@ -8,11 +8,36 @@ public interface LogisticsConstant {
     /**
      * 状态
      */
-    class LogisticsStatus {
+    class Status {
         //未完成
-        public static final Integer status_0 = 0;
+        public static final Integer STATUS_0 = 0;
         //已完成
-        public static final Integer status_1 = 1;
+        public static final Integer STATUS_1 = 1;
     }
 
+    /**
+     * 物流状态(快递100的状态)
+     */
+    class KD100Status {
+        //在途
+        public static final Integer STATUS_0 = 0;
+        //揽收
+        public static final Integer STATUS_1 = 1;
+        //疑难
+        public static final Integer STATUS_2 = 2;
+        //签收
+        public static final Integer STATUS_3 = 3;
+        //退签
+        public static final Integer STATUS_4 = 4;
+        //派件
+        public static final Integer STATUS_5 = 5;
+        //退回
+        public static final Integer STATUS_6 = 6;
+        //转投
+        public static final Integer STATUS_7 = 7;
+        //清关
+        public static final Integer STATUS_8 = 8;
+        //拒签
+        public static final Integer STATUS_14 = 14;
+    }
 }

+ 80 - 0
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/entity/logistics/LogisticsCompany.java

@@ -0,0 +1,80 @@
+package com.fjhx.entity.logistics;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.fjhx.base.BaseEntity;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.Date;
+
+/**
+ * <p>
+ * 物流公司
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class LogisticsCompany extends BaseEntity {
+
+    /**
+     * 编码
+     */
+    private String code;
+
+    /**
+     * 名称
+     */
+    private String name;
+
+    /**
+     * 类型
+     */
+    private String type;
+
+    /**
+     * 排序
+     */
+    private Integer sort;
+
+    /**
+     * 逻辑删除 0未删除 1已删除
+     */
+    @TableField(fill = FieldFill.INSERT)
+    @TableLogic
+    private Integer delFlag;
+
+    /**
+     * 租户id
+     */
+    @TableField(exist = false)
+    private String tenantId;
+
+    /**
+     * 创建时间
+     */
+    @TableField(exist = false)
+    private Date createTime;
+
+    /**
+     * 更新时间
+     */
+    @TableField(exist = false)
+    private Date updateTime;
+
+    /**
+     * 创建人
+     */
+    @TableField(exist = false)
+    private Long createUser;
+
+    /**
+     * 更新人
+     */
+    @TableField(exist = false)
+    private Long updateUser;
+}

+ 10 - 0
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/entity/logistics/LogisticsInfo.java

@@ -38,6 +38,16 @@ public class LogisticsInfo extends BaseEntity {
     private Integer status;
 
     /**
+     * 物流公司编码
+     */
+    private String logisticsCompanyCode;
+
+    /**
+     * 物流状态(快递100的状态)
+     */
+    private Integer logisticsStatus;
+
+    /**
      * 逻辑删除 0未删除 1已删除
      */
     @TableField(fill = FieldFill.INSERT)

+ 17 - 0
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/logistics/LogisticsCompanyEx.java

@@ -0,0 +1,17 @@
+package com.fjhx.params.logistics;
+
+import com.fjhx.entity.logistics.LogisticsCompany;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 物流公司
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class LogisticsCompanyEx extends LogisticsCompany {
+
+}

+ 23 - 0
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/logistics/LogisticsCompanyVo.java

@@ -0,0 +1,23 @@
+package com.fjhx.params.logistics;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.fjhx.entity.logistics.LogisticsCompany;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 物流公司
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class LogisticsCompanyVo extends LogisticsCompany {
+
+    /**
+     * 关键字
+     */
+    @TableField(exist = false)
+    private String keyword;
+}

+ 5 - 0
hx-service/victoriatourist/pom.xml

@@ -38,6 +38,11 @@
             <artifactId>service-flow-api</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>com.github.kuaidi100-api</groupId>
+            <artifactId>sdk</artifactId>
+            <version>1.0.11</version>
+        </dependency>
     </dependencies>
 
 </project>

+ 68 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/config/KD100Config.java

@@ -0,0 +1,68 @@
+package com.fjhx.config;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Description:
+ * @ClassName: RFIDClientConfig
+ * @Author: linqt
+ * @Date: 2022/3/17 10:55
+ * @Version: 1.0
+ */
+@Component
+@ConfigurationProperties(prefix = "spring.kd100")
+public class KD100Config {
+
+    /**
+     * 授权key
+     */
+    private static String key;
+
+    /**
+     * customer
+     */
+    private static String customer;
+
+    /**
+     * secret
+     */
+    private static String secret;
+
+    /**
+     * userid
+     */
+    private static String userid;
+
+    public static String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        KD100Config.key = key;
+    }
+
+    public static String getCustomer() {
+        return customer;
+    }
+
+    public void setCustomer(String customer) {
+        KD100Config.customer = customer;
+    }
+
+    public static String getSecret() {
+        return secret;
+    }
+
+    public void setSecret(String secret) {
+        KD100Config.secret = secret;
+    }
+
+    public static String getUserid() {
+        return userid;
+    }
+
+    public void setUserid(String userid) {
+        KD100Config.userid = userid;
+    }
+}

+ 1 - 2
hx-service/victoriatourist/src/main/java/com/fjhx/config/MybatisConfig.java

@@ -13,7 +13,6 @@ import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 
 @Configuration
@@ -22,7 +21,7 @@ public class MybatisConfig {
     /**
      * 排除租户表集合
      */
-    private static final List<String> excludeTenantTableName = Collections.emptyList();
+    private static final List<String> excludeTenantTableName = Arrays.asList("logistics_company");
 
     /**
      * 租户插件

+ 33 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/controller/logistics/LogisticsCompanyController.java

@@ -0,0 +1,33 @@
+package com.fjhx.controller.logistics;
+
+import com.fjhx.params.logistics.LogisticsCompanyVo;
+import com.fjhx.service.logistics.LogisticsCompanyService;
+import org.springblade.core.tool.api.R;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ * 物流公司 前端控制器
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+@RestController
+@RequestMapping("/logistics/company")
+public class LogisticsCompanyController {
+
+    @Autowired
+    private LogisticsCompanyService logisticsCompanyService;
+
+    @PostMapping("/select")
+    public R select(@RequestBody LogisticsCompanyVo logisticsCompanyVo) {
+        return R.success(logisticsCompanyService.select(logisticsCompanyVo));
+    }
+
+}
+

+ 2 - 1
hx-service/victoriatourist/src/main/java/com/fjhx/controller/logistics/LogisticsInfoController.java

@@ -2,6 +2,7 @@ package com.fjhx.controller.logistics;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.constants.StatusConstant;
+import com.fjhx.constants.logistics.LogisticsConstant;
 import com.fjhx.entity.logistics.LogisticsInfo;
 import com.fjhx.params.logistics.LogisticsInfoVo;
 import com.fjhx.service.logistics.LogisticsInfoService;
@@ -56,7 +57,7 @@ public class LogisticsInfoController {
 
     @PostMapping("/list")
     public R list() {
-        List<LogisticsInfo> list = logisticsInfoService.list(q -> q.eq(LogisticsInfo::getStatus, StatusConstant.NO));
+        List<LogisticsInfo> list = logisticsInfoService.list(q -> q.eq(LogisticsInfo::getStatus, StatusConstant.NO).eq(LogisticsInfo::getLogisticsStatus, LogisticsConstant.KD100Status.STATUS_3));
         return R.success(list);
     }
 

+ 16 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/mapper/logistics/LogisticsCompanyMapper.java

@@ -0,0 +1,16 @@
+package com.fjhx.mapper.logistics;
+
+import com.fjhx.entity.logistics.LogisticsCompany;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ * 物流公司 Mapper 接口
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+public interface LogisticsCompanyMapper extends BaseMapper<LogisticsCompany> {
+
+}

+ 5 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/mapper/logistics/LogisticsCompanyMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fjhx.mapper.logistics.LogisticsCompanyMapper">
+
+</mapper>

+ 21 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/service/logistics/LogisticsCompanyService.java

@@ -0,0 +1,21 @@
+package com.fjhx.service.logistics;
+
+import com.fjhx.base.BaseService;
+import com.fjhx.entity.logistics.LogisticsCompany;
+import com.fjhx.params.logistics.LogisticsCompanyVo;
+
+import java.util.List;
+
+/**
+ * <p>
+ * 物流公司 服务类
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+public interface LogisticsCompanyService extends BaseService<LogisticsCompany> {
+
+    List<LogisticsCompany> select(LogisticsCompanyVo logisticsCompanyVo);
+
+}

+ 34 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/service/logistics/impl/LogisticsCompanyServiceImpl.java

@@ -0,0 +1,34 @@
+package com.fjhx.service.logistics.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fjhx.entity.logistics.LogisticsCompany;
+import com.fjhx.mapper.logistics.LogisticsCompanyMapper;
+import com.fjhx.params.logistics.LogisticsCompanyVo;
+import com.fjhx.service.logistics.LogisticsCompanyService;
+import org.springblade.core.tenant.annotation.TenantIgnore;
+import org.springblade.core.tool.utils.Func;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * <p>
+ * 物流公司 服务实现类
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+@Service
+public class LogisticsCompanyServiceImpl extends ServiceImpl<LogisticsCompanyMapper, LogisticsCompany> implements LogisticsCompanyService {
+
+    @TenantIgnore
+    @Override
+    public List<LogisticsCompany> select(LogisticsCompanyVo logisticsCompanyVo) {
+        return lambdaQuery()
+                .and(Func.isNotEmpty(logisticsCompanyVo.getKeyword()), o -> o.apply("instr(`code`, '" + logisticsCompanyVo.getKeyword() + "') > 0").or().apply("instr(`name`, '" + logisticsCompanyVo.getKeyword() + "') > 0"))
+                .orderByAsc(LogisticsCompany::getSort)
+                .list();
+    }
+
+}

+ 12 - 1
hx-service/victoriatourist/src/main/java/com/fjhx/service/logistics/impl/LogisticsInfoServiceImpl.java

@@ -1,5 +1,6 @@
 package com.fjhx.service.logistics.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.constants.logistics.LogisticsConstant;
@@ -8,8 +9,10 @@ import com.fjhx.mapper.logistics.LogisticsInfoMapper;
 import com.fjhx.params.logistics.LogisticsInfoVo;
 import com.fjhx.service.logistics.LogisticsDetailsService;
 import com.fjhx.service.logistics.LogisticsInfoService;
+import com.fjhx.uitl.kd100.KD100Util;
 import com.fjhx.utils.FileClientUtil;
 import com.fjhx.utils.wrapperUtil.IWrapper;
+import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.tool.utils.Func;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -47,7 +50,15 @@ public class LogisticsInfoServiceImpl extends ServiceImpl<LogisticsInfoMapper, L
     @Transactional(rollbackFor = {Exception.class})
     @Override
     public void add(LogisticsInfoVo logisticsInfoVo) {
-        logisticsInfoVo.setStatus(LogisticsConstant.LogisticsStatus.status_0);
+        if (Func.isAnyBlank(logisticsInfoVo.getLogisticsCompanyCode(), logisticsInfoVo.getCode())) {
+            throw new ServiceException("物流信息不能为空");
+        }
+
+        //查询快递100的物流信息
+        JSONObject result = KD100Util.queryTrack(logisticsInfoVo.getLogisticsCompanyCode(), logisticsInfoVo.getCode());
+        logisticsInfoVo.setLogisticsStatus(result.getInteger("state"));
+
+        logisticsInfoVo.setStatus(LogisticsConstant.Status.STATUS_0);
         save(logisticsInfoVo);
 
         logisticsInfoVo.getDetails().forEach(o -> {

+ 68 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/uitl/kd100/KD100Util.java

@@ -0,0 +1,68 @@
+package com.fjhx.uitl.kd100;
+
+import com.alibaba.fastjson.JSONObject;
+import com.fjhx.config.KD100Config;
+import com.google.gson.Gson;
+import com.kuaidi100.sdk.api.QueryTrack;
+import com.kuaidi100.sdk.core.IBaseClient;
+import com.kuaidi100.sdk.pojo.HttpResult;
+import com.kuaidi100.sdk.request.QueryTrackParam;
+import com.kuaidi100.sdk.request.QueryTrackReq;
+import com.kuaidi100.sdk.utils.SignUtils;
+import lombok.extern.log4j.Log4j2;
+import org.apache.commons.lang3.StringUtils;
+import org.springblade.core.log.exception.ServiceException;
+import org.springblade.core.tool.api.ResultCode;
+import org.springblade.core.tool.utils.Func;
+
+@Log4j2
+public class KD100Util {
+
+    /**
+     * 实时快递查询接口
+     *
+     * @param com 快递公司编码
+     * @param num 快递单号
+     * @return
+     */
+    public static JSONObject queryTrack(String com, String num) {
+        HttpResult result = new HttpResult();
+        try {
+            QueryTrackReq queryTrackReq = new QueryTrackReq();
+            QueryTrackParam queryTrackParam = new QueryTrackParam();
+            queryTrackParam.setCom(com);
+            queryTrackParam.setNum(num);
+            String param = new Gson().toJson(queryTrackParam);
+
+            queryTrackReq.setParam(param);
+            queryTrackReq.setCustomer(KD100Config.getCustomer());
+            queryTrackReq.setSign(SignUtils.querySign(param, KD100Config.getKey(), KD100Config.getCustomer()));
+
+            IBaseClient baseClient = new QueryTrack();
+            result = baseClient.execute(queryTrackReq);
+        } catch (Exception e) {
+            log.error(e.toString());
+            throw new ServiceException("请求第三方快递信息异常,请联系管理员!");
+        }
+        return parseData(result);
+    }
+
+    /**
+     * 解析数据
+     *
+     * @param result 数据结果
+     * @return
+     */
+    private static JSONObject parseData(HttpResult result) {
+        if (Func.isNotEmpty(result) && result.getStatus() == ResultCode.SUCCESS.getCode()) {
+            JSONObject body = JSONObject.parseObject(result.getBody());
+            if (Func.isNotEmpty(body.get("message")) && StringUtils.equalsIgnoreCase(body.getString("message"), "ok")) {
+                return body;
+            } else {
+                throw new ServiceException("操作失败,原因:物流信息【" + body.getString("message") + "】,请稍后重试!");
+            }
+        } else {
+            throw new ServiceException("物流信息查询失败,请稍后重试,或者联系管理员!");
+        }
+    }
+}