Просмотр исходного кода

feat: 增加订单面单获取功能;

hanchaolong 1 месяц назад
Родитель
Сommit
d234832e30

+ 5 - 0
jd-logistics-modules/jd-logistics-system/pom.xml

@@ -102,6 +102,11 @@
             <artifactId>ECAP</artifactId>
             <version>6.9</version>
         </dependency>
+        <dependency>
+            <groupId>com.jd</groupId>
+            <artifactId>jdcloudprint</artifactId>
+            <version>1.5</version>
+        </dependency>
         <dependency>
             <groupId>com.squareup.okhttp3</groupId>
             <artifactId>okhttp</artifactId>

+ 13 - 6
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/controller/BizWaybillOrderController.java

@@ -30,9 +30,6 @@ public class BizWaybillOrderController extends BaseController
     @Autowired
     private IBizWaybillOrderService bizWaybillOrderService;
 
-    @Autowired
-    private LogisticsOrderService logisticsOrderService;
-
     /**
      * 查询运单管理列表
      */
@@ -132,8 +129,18 @@ public class BizWaybillOrderController extends BaseController
      */
     @RequiresPermissions("system:order:query")
     @GetMapping(value = "/getFeeInfo")
-    public AjaxResult getFeeInfo(@RequestParam("waybillCode") String waybillCode)
-    {
-        return success(logisticsOrderService.queryOrderFeeInfoByWaybillCode(1, waybillCode));
+    public AjaxResult getFeeInfo(@RequestParam("waybillCode") String waybillCode) {
+        return success(bizWaybillOrderService.queryOrderFeeInfo(1, waybillCode));
+    }
+
+
+    /**
+     * 获取运单pdf
+     */
+    @RequiresPermissions("system:order:query")
+    @GetMapping(value = "/getWaybillPdf")
+    public AjaxResult getWaybillPdf(@RequestParam("waybillId") Long waybillId) {
+        BizWaybillOrder bizWaybillOrder = bizWaybillOrderService.selectBizWaybillOrderByWaybillId(waybillId);
+        return success(bizWaybillOrderService.queryWaybillPdf(bizWaybillOrder));
     }
 }

+ 5 - 0
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/service/IBizWaybillOrderService.java

@@ -3,6 +3,7 @@ package com.ruoyi.logistics.service;
 import java.io.UnsupportedEncodingException;
 import java.util.List;
 
+import com.alibaba.fastjson.JSONObject;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.ruoyi.logistics.domain.BizWaybillCostDetails;
 import com.ruoyi.logistics.domain.BizWaybillOrder;
@@ -91,4 +92,8 @@ public interface IBizWaybillOrderService
      * @return 近七日每日订单统计列表
      */
     List<DailyOrderStatisticsDto> getLast7DaysOrderStatistics(BizWaybillOrder bizWaybillOrder);
+
+    JSONObject queryOrderFeeInfo(Integer orderType, String waybillCode);
+
+    JSONObject queryWaybillPdf(BizWaybillOrder bizWaybillOrder);
 }

+ 7 - 0
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/service/LogisticsOrderService.java

@@ -127,5 +127,12 @@ public class LogisticsOrderService {
         JSONObject jsonObject = logisticsService.queryOrderFeeInfo(waybillCode);
         return jsonObject;
     }
+
+    public JSONObject queryWaybillPdf(BizWaybillOrder bizWaybillOrder) {
+        // 根据订单中的物流公司类型获取对应服务
+        LogisticsService logisticsService = logisticsFactory.getLogisticsService(bizWaybillOrder.getOrderType()==1?"JD":"SF");
+        JSONObject jsonObject = logisticsService.queryWaybillPdf(bizWaybillOrder);
+        return jsonObject;
+    }
 }
 

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

@@ -62,4 +62,9 @@ public interface LogisticsService {
      */
     JSONObject queryOrderFeeInfo(String waybillCode);
 
+    /**
+     * 根据运单信息获取面单pdf
+     */
+    JSONObject queryWaybillPdf(BizWaybillOrder bizWaybillOrder);
+
 }

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

@@ -338,4 +338,16 @@ public class BizWaybillOrderServiceImpl implements IBizWaybillOrderService
         redisService.deleteObject(redisKey);
         redisService.setCacheList(redisKey, addressList);
     }
+
+    @Override
+    public JSONObject queryOrderFeeInfo(Integer orderType, String waybillCode) {
+        logisticsOrderService.queryOrderFeeInfoByWaybillCode(orderType, waybillCode);
+        return null;
+    }
+
+    @Override
+    public JSONObject queryWaybillPdf(BizWaybillOrder bizWaybillOrder) {
+        logisticsOrderService.queryWaybillPdf(bizWaybillOrder);
+        return null;
+    }
 }

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

@@ -13,10 +13,15 @@ import com.lop.open.api.sdk.domain.ECAP.CommonModifyCancelOrderApi.commonCancelO
 import com.lop.open.api.sdk.domain.ECAP.CommonQueryOrderApi.commonGetActualFeeInfoV1.CommonActualFeeRequest;
 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.domain.jdcloudprint.RenderService.render4Outer.OutputConfigDTO;
+import com.lop.open.api.sdk.domain.jdcloudprint.RenderService.render4Outer.PrintDataDTO;
+import com.lop.open.api.sdk.domain.jdcloudprint.RenderService.render4Outer.QueryRenderDTO;
 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.*;
+import com.lop.open.api.sdk.request.jdcloudprint.CloudPrintRenderLopRequest;
 import com.lop.open.api.sdk.response.ECAP.*;
+import com.lop.open.api.sdk.response.jdcloudprint.CloudPrintRenderLopResponse;
 import com.ruoyi.common.core.exception.ServiceException;
 import com.ruoyi.common.core.utils.DateUtils;
 import com.ruoyi.common.core.utils.StringUtils;
@@ -699,4 +704,67 @@ public class JDLogisticsService  implements LogisticsService {
         }
         return result;
     }
+
+    @Override
+    public JSONObject queryWaybillPdf(BizWaybillOrder bizWaybillOrder) {
+        log.info("京东开放平台根据运单信息查询面单pdf接口,入参:{}", bizWaybillOrder);
+        JSONObject result = new JSONObject();
+        try {
+            //设置接口域名(有的对接方案同时支持生产和沙箱环境,有的仅支持生产,具体以对接方案中的【API文档-请求地址】为准),生产域名:https://api.jdl.com 预发环境域名:https://uat-api.jdl.com
+            //DefaultDomainApiClient对象全局只需要创建一次
+            DefaultDomainApiClient client = new DefaultDomainApiClient(jdExpressConfig.getServerUrl(),500,15000);
+
+            //入参对象
+            CloudPrintRenderLopRequest request = new CloudPrintRenderLopRequest();
+
+            QueryRenderDTO queryRenderDTO = new QueryRenderDTO();
+            if (getOrderOrigin(bizWaybillOrder.getProductCode()) == 1) {
+                queryRenderDTO.setCustomerCode(sysConfigService.selectConfigByKey(SysConfigConstants.JD_LOGISTICS_CUSTOMERCODE));
+                queryRenderDTO.setTemplateCode("jdkd100x113");
+            } else {
+                queryRenderDTO.setCustomerCode(sysConfigService.selectConfigByKey(SysConfigConstants.JD_LOGISTICS_BUSINESSUNITCODE));
+                queryRenderDTO.setTemplateCode("jdky100x113");
+            }
+//            queryRenderDTO.setOperator(sysConfigService.selectConfigByKey(SysConfigConstants.JD_LOGISTICS_OPERATOR));
+            queryRenderDTO.setTaskId(bizWaybillOrder.getWaybillNo());
+
+            List<PrintDataDTO> printDataDTOList = new ArrayList<>();
+            PrintDataDTO printDataDTO = new PrintDataDTO();
+            printDataDTOList.add(printDataDTO);
+            queryRenderDTO.setPrintData(printDataDTOList);
+
+            List<OutputConfigDTO> outputConfigDTOList = new ArrayList<>();
+            OutputConfigDTO outputConfigDTO = new OutputConfigDTO();
+            outputConfigDTOList.add(outputConfigDTO);
+            queryRenderDTO.setOutputConfig(outputConfigDTOList);
+
+            request.setQueryRenderDTO(queryRenderDTO);
+
+            //设置插件,必须的操作,不同类型的应用入参不同,请看入参注释,公共参数按顺序分别为AppKey、AppSecret、AccessToken
+            //使用开放平台ISV/自研商家应用调用接口
+            LopPlugin lopPlugin = OAuth2PluginFactory.produceLopPlugin(jdExpressConfig.getAppKey(), jdExpressConfig.getAppSecret(), jdExpressConfig.getAccessToken());
+            request.addLopPlugin(lopPlugin);
+
+            log.info("京东开放平台根据运单信息查询面单pdf接口,请求参数:{}", JSON.toJSONString(request));
+            CloudPrintRenderLopResponse response = client.execute(request);
+            log.info("京东开放平台根据运单信息查询面单pdf接口,响应结果:{}", JSON.toJSONString(response));
+
+            if (response.getCode().equals("0")) {
+                if (response.getPrintResultDTO().getCode() == 0) {
+                    result.put("success", true);
+                    result.put("msg", response.getPrintResultDTO().getResult());
+                } else {
+                    result.put("success", false);
+                    result.put("msg", "京东开放平台根据运单信息查询面单pdf接口!失败原因:" + response.getPrintResultDTO().getMsg());
+                }
+            } else {
+                result.put("success", false);
+                result.put("msg", "京东开放平台根据运单信息查询面单pdf接口!失败原因:" + response.getMsg());
+            }
+        } catch (LopException e) {
+            log.error("京东开放平台根据运单信息查询面单pdf接口异常:{}", e);
+            throw new ServiceException("京东开放平台根据运单信息查询面单pdf接口异常");
+        }
+        return result;
+    }
 }

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

@@ -359,4 +359,9 @@ public class SFLogisticsService implements LogisticsService {
     public JSONObject queryOrderFeeInfo(String waybillCode) {
         return null;
     }
+
+    @Override
+    public JSONObject queryWaybillPdf(BizWaybillOrder bizWaybillOrder) {
+        return null;
+    }
 }