Selaa lähdekoodia

feat: 京东根据二维码查询运单号;京东根据运单号查询运单详情;

hanchaolong 2 päivää sitten
vanhempi
commit
0d0cad67ac

+ 8 - 3
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/front/controller/MonthQRCodeController.java

@@ -1,6 +1,7 @@
 package com.ruoyi.front.controller;
 
 import com.alibaba.fastjson.JSONObject;
+import com.ruoyi.common.core.exception.ServiceException;
 import com.ruoyi.common.core.web.domain.AjaxResult;
 import com.ruoyi.logistics.service.LogisticsOrderService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -15,8 +16,12 @@ public class MonthQRCodeController {
     @Autowired
     private LogisticsOrderService logisticsOrderService;
 
-    public AjaxResult qrcode(@RequestParam String channelCode) {
-        JSONObject jd = logisticsOrderService.getQRCode(channelCode);
-        return AjaxResult.success(jd);
+    @RequestMapping
+    public AjaxResult qrcode(@RequestParam("orderType") Integer orderType) {
+        JSONObject jsonObject = logisticsOrderService.getQRCode(orderType);
+        if(!jsonObject.getBooleanValue("success")){
+            throw new ServiceException("获取二维码失败! 原因:"+jsonObject.getString("msg"));
+        }
+        return AjaxResult.success(jsonObject.getString("msg"));
     }
 }

+ 1 - 0
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/controller/BizWaybillCostDetailsController.java

@@ -38,6 +38,7 @@ public class BizWaybillCostDetailsController extends BaseController
     /**
      * 查询运单明细列表
      */
+    @RequiresPermissions("system:costDetails:list")
     @GetMapping("/list")
     public TableDataInfo list(BizWaybillCostDetails bizWaybillCostDetails)
     {

+ 14 - 2
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/service/LogisticsOrderService.java

@@ -39,13 +39,25 @@ public class LogisticsOrderService {
         return cancelOrder;
     }
 
-    public JSONObject getQRCode(String channelCode) {
+    public JSONObject getQRCode(Integer orderType) {
         // 根据订单中的物流公司类型获取对应服务
-        LogisticsService logisticsService = logisticsFactory.getLogisticsService(channelCode);
+        LogisticsService logisticsService = logisticsFactory.getLogisticsService(orderType==1?"JD":"SF");
         JSONObject qrCode = logisticsService.getMonthQRCode();
         return qrCode;
     }
 
+    public JSONObject queryOrderByQRCode(Integer orderType, String qrCode) {
+        // 根据订单中的物流公司类型获取对应服务
+        LogisticsService logisticsService = logisticsFactory.getLogisticsService(orderType==1?"JD":"SF");
+        JSONObject jsonObject = logisticsService.queryOrderByQRCode(qrCode);
+        return jsonObject;
+    }
 
+    public JSONObject queryOrderDetailByWaybillCode(Integer orderType, String waybillCode) {
+        // 根据订单中的物流公司类型获取对应服务
+        LogisticsService logisticsService = logisticsFactory.getLogisticsService(orderType==1?"JD":"SF");
+        JSONObject jsonObject = logisticsService.queryOrderDetailByWaybillCode(waybillCode);
+        return jsonObject;
+    }
 }
 

+ 9 - 0
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/service/LogisticsService.java

@@ -47,5 +47,14 @@ public interface LogisticsService {
      */
     JSONObject getMonthQRCode();
 
+    /**
+     * 根据二维码查询
+     */
+    JSONObject queryOrderByQRCode(String qrCode);
+
+    /**
+     * 根据运单号查询订单详情
+     */
+    JSONObject queryOrderDetailByWaybillCode(String waybillCode);
 
 }

+ 97 - 1
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/service/impl/JDLogisticsService.java

@@ -10,6 +10,8 @@ import com.lop.open.api.sdk.domain.ECAP.CommonCreateOrderApi.commonCheckPreCreat
 import com.lop.open.api.sdk.domain.ECAP.CommonCreateOrderApi.commonCheckPreCreateOrderV1.Contact;
 import com.lop.open.api.sdk.domain.ECAP.CommonCreateOrderApi.commonCreateOrderV1.CommonCargoInfo;
 import com.lop.open.api.sdk.domain.ECAP.CommonModifyCancelOrderApi.commonCancelOrderV1.CommonOrderCancelRequest;
+import com.lop.open.api.sdk.domain.ECAP.CommonQueryOrderApi.commonGetOrderByMonthSettleQRV1.CommonMonthSettleQRQueryRequest;
+import com.lop.open.api.sdk.domain.ECAP.CommonQueryOrderApi.commonGetOrderInfoV1.CommonOrderInfoRequest;
 import com.lop.open.api.sdk.plugin.LopPlugin;
 import com.lop.open.api.sdk.plugin.factory.OAuth2PluginFactory;
 import com.lop.open.api.sdk.request.ECAP.*;
@@ -524,7 +526,7 @@ public class JDLogisticsService  implements LogisticsService {
             if (response.getCode().equals("0")) {
                 if (response.getResponse().getCode() == 0) {
                     result.put("success", true);
-                    result.put("msg", "");
+                    result.put("msg", response.getResponse().getData().getVerifyMessage());
                 } else {
                     result.put("success", false);
                     result.put("msg", "京东开放平台获取商家二维码!失败原因:" + response.getResponse().getMsg());
@@ -539,4 +541,98 @@ public class JDLogisticsService  implements LogisticsService {
         }
         return result;
     }
+
+    @Override
+    public JSONObject queryOrderByQRCode(String qrCode) {
+        log.info("京东开放平台根据二维码查询运单接口,入参:{}", qrCode);
+        JSONObject result = new JSONObject();
+        try {
+            //设置接口域名(有的对接方案同时支持生产和沙箱环境,有的仅支持生产,具体以对接方案中的【API文档-请求地址】为准),生产域名:https://api.jdl.com 预发环境域名:https://uat-api.jdl.com
+            //DefaultDomainApiClient对象全局只需要创建一次
+            DefaultDomainApiClient client = new DefaultDomainApiClient(jdExpressConfig.getServerUrl(),500,15000);
+
+            //入参对象
+            CommonqueryorderapiCommongetorderbymonthsettleqrv1LopRequest request = new CommonqueryorderapiCommongetorderbymonthsettleqrv1LopRequest();
+
+            CommonMonthSettleQRQueryRequest requestDTO = new CommonMonthSettleQRQueryRequest();
+            requestDTO.setCustomerCode(sysConfigService.selectConfigByKey(SysConfigConstants.JD_LOGISTICS_CUSTOMERCODE));
+            requestDTO.setMonthSettleQR(qrCode);
+            requestDTO.setAppKey(jdExpressConfig.getAppKey());
+
+            request.setRequest(requestDTO);
+
+            //设置插件,必须的操作,不同类型的应用入参不同,请看入参注释,公共参数按顺序分别为AppKey、AppSecret、AccessToken
+            //使用开放平台ISV/自研商家应用调用接口
+            LopPlugin lopPlugin = OAuth2PluginFactory.produceLopPlugin(jdExpressConfig.getAppKey(), jdExpressConfig.getAppSecret(), jdExpressConfig.getAccessToken());
+            request.addLopPlugin(lopPlugin);
+
+            log.info("京东开放平台根据二维码查询运单接口,请求参数:{}", JSON.toJSONString(request));
+            CommonqueryorderapiCommongetorderbymonthsettleqrv1LopResponse response = client.execute(request);
+            log.info("京东开放平台根据二维码查询运单接口,响应结果:{}", JSON.toJSONString(response));
+
+            if (response.getCode().equals("0")) {
+                if (response.getResponse().getCode() == 0) {
+                    result.put("success", true);
+                    result.put("msg", response.getResponse().getData().getWaybillQRVerifyInfoList());
+                } else {
+                    result.put("success", false);
+                    result.put("msg", "京东开放平台根据二维码查询运单接口!失败原因:" + response.getResponse().getMsg());
+                }
+            } else {
+                result.put("success", false);
+                result.put("msg", "京东开放平台根据二维码查询运单接口!失败原因:" + response.getMsg());
+            }
+        } catch (LopException e) {
+            log.error("京东开放平台根据二维码查询运单接口异常:{}", e);
+            throw new ServiceException("京东开放平台根据二维码查询运单接口异常");
+        }
+        return result;
+    }
+
+    @Override
+    public JSONObject queryOrderDetailByWaybillCode(String waybillCode) {
+        log.info("京东开放平台根据运单号查询运单详情接口,入参:{}", waybillCode);
+        JSONObject result = new JSONObject();
+        try {
+            //设置接口域名(有的对接方案同时支持生产和沙箱环境,有的仅支持生产,具体以对接方案中的【API文档-请求地址】为准),生产域名:https://api.jdl.com 预发环境域名:https://uat-api.jdl.com
+            //DefaultDomainApiClient对象全局只需要创建一次
+            DefaultDomainApiClient client = new DefaultDomainApiClient(jdExpressConfig.getServerUrl(),500,15000);
+
+            //入参对象
+            EcapV1OrdersDetailsQueryLopRequest request = new EcapV1OrdersDetailsQueryLopRequest();
+
+            CommonOrderInfoRequest requestDTO = new CommonOrderInfoRequest();
+            requestDTO.setCustomerCode(sysConfigService.selectConfigByKey(SysConfigConstants.JD_LOGISTICS_CUSTOMERCODE));
+            requestDTO.setBusinessUnitCode(sysConfigService.selectConfigByKey(SysConfigConstants.JD_LOGISTICS_BUSINESSUNITCODE));
+            requestDTO.setWaybillCode(waybillCode);
+
+            request.setRequest(requestDTO);
+
+            //设置插件,必须的操作,不同类型的应用入参不同,请看入参注释,公共参数按顺序分别为AppKey、AppSecret、AccessToken
+            //使用开放平台ISV/自研商家应用调用接口
+            LopPlugin lopPlugin = OAuth2PluginFactory.produceLopPlugin(jdExpressConfig.getAppKey(), jdExpressConfig.getAppSecret(), jdExpressConfig.getAccessToken());
+            request.addLopPlugin(lopPlugin);
+
+            log.info("京东开放平台根据运单号查询运单详情接口,请求参数:{}", JSON.toJSONString(request));
+            EcapV1OrdersDetailsQueryLopResponse response = client.execute(request);
+            log.info("京东开放平台根据运单号查询运单详情接口,响应结果:{}", JSON.toJSONString(response));
+
+            if (response.getCode().equals("0")) {
+                if (response.getResult().getCode() == 0) {
+                    result.put("success", true);
+                    result.put("msg", response.getResult().getData());
+                } else {
+                    result.put("success", false);
+                    result.put("msg", "京东开放平台根据运单号查询运单详情接口!失败原因:" + response.getResult().getMsg());
+                }
+            } else {
+                result.put("success", false);
+                result.put("msg", "京东开放平台根据运单号查询运单详情接口!失败原因:" + response.getMsg());
+            }
+        } catch (LopException e) {
+            log.error("京东开放平台根据运单号查询运单详情接口:{}", e);
+            throw new ServiceException("京东开放平台获取商家二维码接口异常");
+        }
+        return result;
+    }
 }

+ 10 - 0
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/service/impl/SFLogisticsService.java

@@ -344,4 +344,14 @@ public class SFLogisticsService implements LogisticsService {
     public JSONObject getMonthQRCode() {
         return null;
     }
+
+    @Override
+    public JSONObject queryOrderByQRCode(String qrCode) {
+        return null;
+    }
+
+    @Override
+    public JSONObject queryOrderDetailByWaybillCode(String waybillCode) {
+        return null;
+    }
 }