|
|
@@ -1,23 +1,42 @@
|
|
|
package com.ruoyi.logistics.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.lop.open.api.sdk.DefaultDomainApiClient;
|
|
|
import com.lop.open.api.sdk.LopException;
|
|
|
import com.lop.open.api.sdk.domain.ECAP.CommonCreateOrderApi.commonCheckPreCreateOrderV1.CommonCreateOrderRequest;
|
|
|
import com.lop.open.api.sdk.domain.ECAP.CommonCreateOrderApi.commonCheckPreCreateOrderV1.CommonProductInfo;
|
|
|
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.plugin.LopPlugin;
|
|
|
import com.lop.open.api.sdk.plugin.factory.OAuth2PluginFactory;
|
|
|
+import com.lop.open.api.sdk.request.ECAP.EcapV1OrdersCancelLopRequest;
|
|
|
import com.lop.open.api.sdk.request.ECAP.EcapV1OrdersCreateLopRequest;
|
|
|
+import com.lop.open.api.sdk.request.ECAP.EcapV1OrdersModifyLopRequest;
|
|
|
import com.lop.open.api.sdk.request.ECAP.EcapV1OrdersPrecheckLopRequest;
|
|
|
+import com.lop.open.api.sdk.response.ECAP.EcapV1OrdersCancelLopResponse;
|
|
|
import com.lop.open.api.sdk.response.ECAP.EcapV1OrdersCreateLopResponse;
|
|
|
+import com.lop.open.api.sdk.response.ECAP.EcapV1OrdersModifyLopResponse;
|
|
|
import com.lop.open.api.sdk.response.ECAP.EcapV1OrdersPrecheckLopResponse;
|
|
|
+import com.ruoyi.common.core.exception.ServiceException;
|
|
|
+import com.ruoyi.common.core.utils.DateUtils;
|
|
|
+import com.ruoyi.common.core.utils.StringUtils;
|
|
|
import com.ruoyi.logistics.config.JDExpressConfig;
|
|
|
-import com.ruoyi.logistics.domain.LogisticsOrder;
|
|
|
+import com.ruoyi.logistics.constant.JDDictConstants;
|
|
|
+import com.ruoyi.logistics.constant.SysConfigConstants;
|
|
|
+import com.ruoyi.logistics.domain.BizWaybillOrder;
|
|
|
import com.ruoyi.logistics.service.LogisticsService;
|
|
|
+import com.ruoyi.system.service.ISysConfigService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class JDLogisticsService implements LogisticsService {
|
|
|
@@ -25,27 +44,40 @@ public class JDLogisticsService implements LogisticsService {
|
|
|
@Autowired
|
|
|
private JDExpressConfig jdExpressConfig;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysConfigService sysConfigService;
|
|
|
+
|
|
|
@Override
|
|
|
- public String precheckOrder() {
|
|
|
- log.info("调用京东开放平台订单预校验接口");
|
|
|
+ public JSONObject precheckOrder(BizWaybillOrder bizWaybillOrder) {
|
|
|
+ log.info("京东开放平台订单预校验接口,入参:{}", 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);
|
|
|
|
|
|
- //入参对象(请记得更换为自己要使用的接口入参对象)
|
|
|
+ //入参对象
|
|
|
EcapV1OrdersPrecheckLopRequest request = new EcapV1OrdersPrecheckLopRequest();
|
|
|
|
|
|
- //设置入参(请记得更换为自己要使用的接口入参)
|
|
|
+ //发货人
|
|
|
Contact senderContact = new Contact();
|
|
|
- senderContact.setFullAddress("河北省廊坊市广阳区万庄镇中心小学");
|
|
|
+ senderContact.setName(bizWaybillOrder.getSenderName());
|
|
|
+ senderContact.setMobile(bizWaybillOrder.getSenderPhone());
|
|
|
+ senderContact.setFullAddress(bizWaybillOrder.getSenderProvince() + bizWaybillOrder.getSenderCity() + bizWaybillOrder.getSenderCounty() + bizWaybillOrder.getSenderAddress());
|
|
|
+
|
|
|
+ //收货人
|
|
|
Contact receiverContact = new Contact();
|
|
|
- receiverContact.setFullAddress("河北省廊坊市广阳区万庄镇中心小学");
|
|
|
+ receiverContact.setName(bizWaybillOrder.getReceiverName());
|
|
|
+ receiverContact.setMobile(bizWaybillOrder.getReceiverPhone());
|
|
|
+ receiverContact.setFullAddress(bizWaybillOrder.getReceiverProvince() + bizWaybillOrder.getReceiverCity() + bizWaybillOrder.getReceiverCounty() + bizWaybillOrder.getReceiverAddress());
|
|
|
+
|
|
|
CommonCreateOrderRequest requestDTO = new CommonCreateOrderRequest();
|
|
|
requestDTO.setOrderOrigin(1);
|
|
|
- requestDTO.setCustomerCode("010K****20");
|
|
|
+ requestDTO.setCustomerCode(sysConfigService.selectConfigByKey(SysConfigConstants.JD_LOGISTICS_CUSTOMERCODE));
|
|
|
+
|
|
|
CommonProductInfo productInfo = new CommonProductInfo();
|
|
|
- productInfo.setProductCode("ed-m-0001");
|
|
|
+ productInfo.setProductCode(bizWaybillOrder.getProductCode());
|
|
|
+
|
|
|
requestDTO.setProductsReq(productInfo);
|
|
|
requestDTO.setReceiverContact(receiverContact);
|
|
|
requestDTO.setSenderContact(senderContact);
|
|
|
@@ -56,36 +88,70 @@ public class JDLogisticsService implements LogisticsService {
|
|
|
LopPlugin lopPlugin = OAuth2PluginFactory.produceLopPlugin(jdExpressConfig.getAppKey(), jdExpressConfig.getAppSecret(), jdExpressConfig.getAccessToken());
|
|
|
request.addLopPlugin(lopPlugin);
|
|
|
|
|
|
+ log.info("京东开放平台订单预校验接口,请求参数:{}", request);
|
|
|
EcapV1OrdersPrecheckLopResponse response = client.execute(request);
|
|
|
+ log.info("京东开放平台订单预校验接口,响应结果:{}", response);
|
|
|
+
|
|
|
+ if (response.getCode().equals("0")) {
|
|
|
+ result.put("success", true);
|
|
|
+ result.put("msg", "");
|
|
|
+ } else {
|
|
|
+ result.put("success", false);
|
|
|
+ result.put("msg", "京东开放平台订单预校验!失败原因:" + response.getMsg());
|
|
|
+ }
|
|
|
} catch (LopException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ log.error("京东开放平台订单预校验接口异常:{}", e);
|
|
|
+ throw new ServiceException("京东开放平台订单预校验接口异常");
|
|
|
}
|
|
|
- return "";
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String createOrder(LogisticsOrder logisticsOrder) {
|
|
|
- log.info("调用京东开放平台订单预校验接口");
|
|
|
+ public JSONObject createOrder(BizWaybillOrder bizWaybillOrder) {
|
|
|
+ log.info("京东开放平台下单接口,入参:{}", 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);
|
|
|
|
|
|
- //入参对象(请记得更换为自己要使用的接口入参对象)
|
|
|
+ //入参对象
|
|
|
EcapV1OrdersCreateLopRequest request = new EcapV1OrdersCreateLopRequest();
|
|
|
|
|
|
- //设置入参(请记得更换为自己要使用的接口入参)
|
|
|
+ //发货人
|
|
|
com.lop.open.api.sdk.domain.ECAP.CommonCreateOrderApi.commonCreateOrderV1.Contact senderContact = new com.lop.open.api.sdk.domain.ECAP.CommonCreateOrderApi.commonCreateOrderV1.Contact();
|
|
|
- senderContact.setFullAddress("河北省廊坊市广阳区万庄镇中心小学");
|
|
|
+ senderContact.setFullAddress(bizWaybillOrder.getSenderProvince() + bizWaybillOrder.getSenderCity() + bizWaybillOrder.getSenderCounty() + bizWaybillOrder.getSenderAddress());
|
|
|
+
|
|
|
+ //收货人
|
|
|
com.lop.open.api.sdk.domain.ECAP.CommonCreateOrderApi.commonCreateOrderV1.Contact receiverContact = new com.lop.open.api.sdk.domain.ECAP.CommonCreateOrderApi.commonCreateOrderV1.Contact();
|
|
|
- receiverContact.setFullAddress("河北省廊坊市广阳区万庄镇中心小学");
|
|
|
+ receiverContact.setFullAddress(bizWaybillOrder.getReceiverProvince() + bizWaybillOrder.getReceiverCity() + bizWaybillOrder.getReceiverCounty() + bizWaybillOrder.getReceiverAddress());
|
|
|
+
|
|
|
+ //订单信息
|
|
|
com.lop.open.api.sdk.domain.ECAP.CommonCreateOrderApi.commonCreateOrderV1.CommonCreateOrderRequest requestDTO = new com.lop.open.api.sdk.domain.ECAP.CommonCreateOrderApi.commonCreateOrderV1.CommonCreateOrderRequest();
|
|
|
- requestDTO.setOrderOrigin(1);
|
|
|
- requestDTO.setCustomerCode("010K****20");
|
|
|
+ requestDTO.setOrderId(bizWaybillOrder.getWaybillNo());
|
|
|
+ requestDTO.setOrderOrigin(getOrderOrigin(bizWaybillOrder.getProductCode()));
|
|
|
+ requestDTO.setCustomerCode(sysConfigService.selectConfigByKey(SysConfigConstants.JD_LOGISTICS_CUSTOMERCODE));
|
|
|
+ requestDTO.setSettleType(3);
|
|
|
+ requestDTO.setPickupStartTime(bizWaybillOrder.getPickupTime().getTime());
|
|
|
+ requestDTO.setPickupEndTime(DateUtils.addHours(bizWaybillOrder.getPickupTime(), 1).getTime());
|
|
|
+ requestDTO.setPickupType(1);
|
|
|
+
|
|
|
+ //产品信息
|
|
|
com.lop.open.api.sdk.domain.ECAP.CommonCreateOrderApi.commonCreateOrderV1.CommonProductInfo productInfo = new com.lop.open.api.sdk.domain.ECAP.CommonCreateOrderApi.commonCreateOrderV1.CommonProductInfo();
|
|
|
- productInfo.setProductCode("ed-m-0001");
|
|
|
+ productInfo.setProductCode(bizWaybillOrder.getProductCode());
|
|
|
+ productInfo.setAddedProducts(getAddedProducts(requestDTO.getOrderOrigin(), bizWaybillOrder.getAddedService()));
|
|
|
+
|
|
|
+
|
|
|
+ //货物信息
|
|
|
+ List<CommonCargoInfo> cargoes = new ArrayList<>();
|
|
|
+ CommonCargoInfo cargoInfo = new CommonCargoInfo();
|
|
|
+ cargoInfo.setName(bizWaybillOrder.getGoodsName());
|
|
|
+ cargoInfo.setQuantity(bizWaybillOrder.getGoodsQty().intValue());
|
|
|
+ cargoInfo.setWeight(bizWaybillOrder.getGoodsWeight());
|
|
|
+ cargoInfo.setVolume(bizWaybillOrder.getGoodsVolume());
|
|
|
+ cargoes.add(cargoInfo);
|
|
|
+
|
|
|
+ requestDTO.setCargoes(cargoes);
|
|
|
requestDTO.setProductsReq(productInfo);
|
|
|
requestDTO.setReceiverContact(receiverContact);
|
|
|
requestDTO.setSenderContact(senderContact);
|
|
|
@@ -96,12 +162,280 @@ public class JDLogisticsService implements LogisticsService {
|
|
|
LopPlugin lopPlugin = OAuth2PluginFactory.produceLopPlugin(jdExpressConfig.getAppKey(), jdExpressConfig.getAppSecret(), jdExpressConfig.getAccessToken());
|
|
|
request.addLopPlugin(lopPlugin);
|
|
|
|
|
|
+ log.info("京东开放平台下单接口,请求参数:{}", request);
|
|
|
EcapV1OrdersCreateLopResponse response = client.execute(request);
|
|
|
+ log.info("京东开放平台下单接口,响应结果:{}", response);
|
|
|
+
|
|
|
+ if (response.getCode().equals("0")) {
|
|
|
+ result.put("success", true);
|
|
|
+ result.put("msg", "");
|
|
|
+ } else {
|
|
|
+ result.put("success", false);
|
|
|
+ result.put("msg", "京东开放平台下单!失败原因:" + response.getMsg());
|
|
|
+ }
|
|
|
+ } catch (LopException e) {
|
|
|
+ log.error("京东开放平台下单接口异常:{}", e);
|
|
|
+ throw new ServiceException("京东开放平台下单接口异常");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject cancelOrder(BizWaybillOrder bizWaybillOrder) {
|
|
|
+ log.info("京东开放平台取消订单接口,入参:{}", 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);
|
|
|
+
|
|
|
+ //入参对象
|
|
|
+ EcapV1OrdersCancelLopRequest request = new EcapV1OrdersCancelLopRequest();
|
|
|
+
|
|
|
+ //取消订单入参对象
|
|
|
+ CommonOrderCancelRequest commonOrderCancelRequest = new CommonOrderCancelRequest();
|
|
|
+ commonOrderCancelRequest.setWaybillCode(bizWaybillOrder.getExternalWaybillNo());
|
|
|
+ commonOrderCancelRequest.setCustomerOrderId(bizWaybillOrder.getWaybillNo());
|
|
|
+ commonOrderCancelRequest.setOrderOrigin(1);
|
|
|
+ commonOrderCancelRequest.setCustomerCode(sysConfigService.selectConfigByKey(SysConfigConstants.JD_LOGISTICS_CUSTOMERCODE));
|
|
|
+ commonOrderCancelRequest.setCancelReason("取消原因");
|
|
|
+ commonOrderCancelRequest.setCancelReasonCode("1");
|
|
|
+ commonOrderCancelRequest.setCancelType(1);
|
|
|
+
|
|
|
+ request.setRequest(commonOrderCancelRequest);
|
|
|
+
|
|
|
+ //设置插件,必须的操作,不同类型的应用入参不同,请看入参注释,公共参数按顺序分别为AppKey、AppSecret、AccessToken
|
|
|
+ //使用开放平台ISV/自研商家应用调用接口
|
|
|
+ LopPlugin lopPlugin = OAuth2PluginFactory.produceLopPlugin(jdExpressConfig.getAppKey(), jdExpressConfig.getAppSecret(), jdExpressConfig.getAccessToken());
|
|
|
+ request.addLopPlugin(lopPlugin);
|
|
|
+
|
|
|
+ log.info("京东开放平台取消订单接口,请求参数:{}", request);
|
|
|
+ EcapV1OrdersCancelLopResponse response = client.execute(request);
|
|
|
+ log.info("京东开放平台取消订单接口,响应结果:{}", response);
|
|
|
+
|
|
|
+ if (response.getCode().equals("0")) {
|
|
|
+ result.put("success", true);
|
|
|
+ result.put("msg", "");
|
|
|
+ } else {
|
|
|
+ result.put("success", false);
|
|
|
+ result.put("msg", "京东开放平台取消订单!失败原因:" + response.getMsg());
|
|
|
+ }
|
|
|
+ } catch (LopException e) {
|
|
|
+ log.error("京东开放平台取消订单接口异常:{}", e);
|
|
|
+ throw new ServiceException("京东开放平台取消订单接口异常");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject modifyOrder(BizWaybillOrder bizWaybillOrder) {
|
|
|
+ log.info("京东开放平台修改订单接口,入参:{}", 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);
|
|
|
+
|
|
|
+ //入参对象
|
|
|
+ EcapV1OrdersModifyLopRequest request = new EcapV1OrdersModifyLopRequest();
|
|
|
+
|
|
|
+ //发货人
|
|
|
+ com.lop.open.api.sdk.domain.ECAP.CommonModifyCancelOrderApi.commonModifyOrderV1.Contact senderContact = new com.lop.open.api.sdk.domain.ECAP.CommonModifyCancelOrderApi.commonModifyOrderV1.Contact();
|
|
|
+ senderContact.setFullAddress(bizWaybillOrder.getSenderProvince() + bizWaybillOrder.getSenderCity() + bizWaybillOrder.getSenderCounty() + bizWaybillOrder.getSenderAddress());
|
|
|
+
|
|
|
+ //收货人
|
|
|
+ com.lop.open.api.sdk.domain.ECAP.CommonModifyCancelOrderApi.commonModifyOrderV1.Contact receiverContact = new com.lop.open.api.sdk.domain.ECAP.CommonModifyCancelOrderApi.commonModifyOrderV1.Contact();
|
|
|
+ receiverContact.setFullAddress(bizWaybillOrder.getReceiverProvince() + bizWaybillOrder.getReceiverCity() + bizWaybillOrder.getReceiverCounty() + bizWaybillOrder.getReceiverAddress());
|
|
|
+
|
|
|
+ //订单信息
|
|
|
+ com.lop.open.api.sdk.domain.ECAP.CommonModifyCancelOrderApi.commonModifyOrderV1.CommonModifyCancelOrderRequest requestDTO = new com.lop.open.api.sdk.domain.ECAP.CommonModifyCancelOrderApi.commonModifyOrderV1.CommonModifyCancelOrderRequest();
|
|
|
+ requestDTO.setOrderId(bizWaybillOrder.getWaybillNo());
|
|
|
+ requestDTO.setOrderOrigin(1);
|
|
|
+ requestDTO.setCustomerCode(sysConfigService.selectConfigByKey(SysConfigConstants.JD_LOGISTICS_CUSTOMERCODE));
|
|
|
+ requestDTO.setSettleType(3);
|
|
|
+ requestDTO.setPickupStartTime(bizWaybillOrder.getPickupTime().getTime());
|
|
|
+ requestDTO.setPickupEndTime(DateUtils.addHours(bizWaybillOrder.getPickupTime(), 1).getTime());
|
|
|
+
|
|
|
+ //产品信息
|
|
|
+ com.lop.open.api.sdk.domain.ECAP.CommonModifyCancelOrderApi.commonModifyOrderV1.CommonProductInfoRequest productInfo = new com.lop.open.api.sdk.domain.ECAP.CommonModifyCancelOrderApi.commonModifyOrderV1.CommonProductInfoRequest();
|
|
|
+ productInfo.setProductCode(bizWaybillOrder.getProductCode());
|
|
|
+
|
|
|
+ //货物信息
|
|
|
+ List<com.lop.open.api.sdk.domain.ECAP.CommonModifyCancelOrderApi.commonModifyOrderV1.CommonCargoInfo> cargoes = new ArrayList<>();
|
|
|
+ com.lop.open.api.sdk.domain.ECAP.CommonModifyCancelOrderApi.commonModifyOrderV1.CommonCargoInfo cargoInfo = new com.lop.open.api.sdk.domain.ECAP.CommonModifyCancelOrderApi.commonModifyOrderV1.CommonCargoInfo();
|
|
|
+ cargoInfo.setName(bizWaybillOrder.getGoodsName());
|
|
|
+ cargoInfo.setQuantity(bizWaybillOrder.getGoodsQty().intValue());
|
|
|
+ cargoInfo.setWeight(bizWaybillOrder.getGoodsWeight());
|
|
|
+ cargoInfo.setVolume(bizWaybillOrder.getGoodsVolume());
|
|
|
+ cargoes.add(cargoInfo);
|
|
|
+
|
|
|
+ //扩展信息
|
|
|
+ Map<String, String> extendProps = new HashMap<>();
|
|
|
+ extendProps.put("autoSubscribe", "1");
|
|
|
+ extendProps.put("universalFeePush", "1");
|
|
|
+
|
|
|
+ requestDTO.setExtendProps(extendProps);
|
|
|
+ requestDTO.setCargoes(cargoes);
|
|
|
+ requestDTO.setProductsReq(productInfo);
|
|
|
+ requestDTO.setReceiverContact(receiverContact);
|
|
|
+ requestDTO.setSenderContact(senderContact);
|
|
|
+ request.setRequest(requestDTO);
|
|
|
+
|
|
|
+ //设置插件,必须的操作,不同类型的应用入参不同,请看入参注释,公共参数按顺序分别为AppKey、AppSecret、AccessToken
|
|
|
+ //使用开放平台ISV/自研商家应用调用接口
|
|
|
+ LopPlugin lopPlugin = OAuth2PluginFactory.produceLopPlugin(jdExpressConfig.getAppKey(), jdExpressConfig.getAppSecret(), jdExpressConfig.getAccessToken());
|
|
|
+ request.addLopPlugin(lopPlugin);
|
|
|
+
|
|
|
+ log.info("京东开放平台修改订单接口,请求参数:{}", request);
|
|
|
+ EcapV1OrdersModifyLopResponse response = client.execute(request);
|
|
|
+ log.info("京东开放平台修改订单接口,响应结果:{}", response);
|
|
|
+
|
|
|
+ if (response.getCode().equals("0")) {
|
|
|
+ result.put("success", true);
|
|
|
+ result.put("msg", "");
|
|
|
+ } else {
|
|
|
+ result.put("success", false);
|
|
|
+ result.put("msg", "京东开放平台修改订单!失败原因:" + response.getMsg());
|
|
|
+ }
|
|
|
} catch (LopException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ log.error("京东开放平台修改订单接口异常:{}", e);
|
|
|
+ throw new ServiceException("京东开放平台修改订单接口异常");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Integer getOrderOrigin(String productCode) {
|
|
|
+ int orderOrigin = 1;
|
|
|
+ if (productCode.equals(JDDictConstants.PRODUCT_CODE_ED_M_0001) || productCode.equals(JDDictConstants.PRODUCT_CODE_ED_M_0002)) {
|
|
|
+ orderOrigin = 1;
|
|
|
+ } else if (productCode.equals(JDDictConstants.PRODUCT_CODE_FR_M_0004)) {
|
|
|
+ orderOrigin = 4;
|
|
|
+ }
|
|
|
+ return orderOrigin;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 增值服务配置映射表
|
|
|
+ private static final Map<Integer, Map<String, ProductConfig>> SERVICE_CONFIG_MAP = new HashMap<>();
|
|
|
+
|
|
|
+ static {
|
|
|
+ // 订单来源为1的配置
|
|
|
+ Map<String, ProductConfig> origin1Config = new HashMap<>();
|
|
|
+ origin1Config.put("isPack", new ProductConfig("ed-a-0002", true));
|
|
|
+ origin1Config.put("guaranteeMoney", new ProductConfig("ed-a-0010", true));
|
|
|
+ origin1Config.put("isReceiptCollect", new ProductConfig("ed-a-0011", false));
|
|
|
+ SERVICE_CONFIG_MAP.put(1, origin1Config);
|
|
|
+
|
|
|
+ // 订单来源为4的配置
|
|
|
+ Map<String, ProductConfig> origin4Config = new HashMap<>();
|
|
|
+ origin4Config.put("isPack", new ProductConfig("fr-a-0002", true));
|
|
|
+ origin4Config.put("guaranteeMoney", new ProductConfig("fr-a-0007", true));
|
|
|
+ origin4Config.put("isReceiptCollect", new ProductConfig("fr-a-0005", false));
|
|
|
+ SERVICE_CONFIG_MAP.put(4, origin4Config);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 产品配置类
|
|
|
+ */
|
|
|
+ private static class ProductConfig {
|
|
|
+ private final String productCode;
|
|
|
+ private final boolean hasAttrs;
|
|
|
+
|
|
|
+ public ProductConfig(String productCode, boolean hasAttrs) {
|
|
|
+ this.productCode = productCode;
|
|
|
+ this.hasAttrs = hasAttrs;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getProductCode() {
|
|
|
+ return productCode;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isHasAttrs() {
|
|
|
+ return hasAttrs;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 封装增值服务参数
|
|
|
+ * @param orderOrigin 订单来源
|
|
|
+ * @param addedService 增值服务JSON字符串
|
|
|
+ * @return 增值服务产品列表
|
|
|
+ */
|
|
|
+ private List<com.lop.open.api.sdk.domain.ECAP.CommonCreateOrderApi.commonCreateOrderV1.CommonProductInfo> getAddedProducts(Integer orderOrigin, String addedService) {
|
|
|
+ if (StringUtils.isBlank(addedService)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject addedJson = JSON.parseObject(addedService);
|
|
|
+ List<com.lop.open.api.sdk.domain.ECAP.CommonCreateOrderApi.commonCreateOrderV1.CommonProductInfo> addedProducts = new ArrayList<>();
|
|
|
+
|
|
|
+ // 获取当前订单来源的配置
|
|
|
+ Map<String, ProductConfig> configMap = SERVICE_CONFIG_MAP.get(orderOrigin);
|
|
|
+ if (configMap == null) {
|
|
|
+ return addedProducts;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 遍历配置中的所有增值服务键
|
|
|
+ for (Map.Entry<String, ProductConfig> entry : configMap.entrySet()) {
|
|
|
+ String serviceKey = entry.getKey();
|
|
|
+ ProductConfig config = entry.getValue();
|
|
|
+
|
|
|
+ // 检查JSON中是否包含该增值服务
|
|
|
+ if (addedJson.containsKey(serviceKey)) {
|
|
|
+ com.lop.open.api.sdk.domain.ECAP.CommonCreateOrderApi.commonCreateOrderV1.CommonProductInfo addedProduct =
|
|
|
+ createProductInfo(config.getProductCode(), config.isHasAttrs() ?
|
|
|
+ addedJson.getString(serviceKey) : null);
|
|
|
+ addedProducts.add(addedProduct);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return addedProducts;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建产品信息对象
|
|
|
+ * @param productCode 产品编码
|
|
|
+ * @param attrValue 属性值(可为空)
|
|
|
+ * @return 产品信息对象
|
|
|
+ */
|
|
|
+ private com.lop.open.api.sdk.domain.ECAP.CommonCreateOrderApi.commonCreateOrderV1.CommonProductInfo
|
|
|
+ createProductInfo(String productCode, String attrValue) {
|
|
|
+ com.lop.open.api.sdk.domain.ECAP.CommonCreateOrderApi.commonCreateOrderV1.CommonProductInfo addedProduct =
|
|
|
+ new com.lop.open.api.sdk.domain.ECAP.CommonCreateOrderApi.commonCreateOrderV1.CommonProductInfo();
|
|
|
+ addedProduct.setProductCode(productCode);
|
|
|
+
|
|
|
+ // 如果需要设置属性,则添加属性
|
|
|
+ if (attrValue != null) {
|
|
|
+ addedProduct.setProductAttrs(getProductAttrs(productCode, attrValue));
|
|
|
+ }
|
|
|
+
|
|
|
+ return addedProduct;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取产品属性
|
|
|
+ * @param productCode 产品编码
|
|
|
+ * @param value 属性值
|
|
|
+ * @return 产品属性映射
|
|
|
+ */
|
|
|
+ private Map<String, String> getProductAttrs(String productCode, String value) {
|
|
|
+ Map<String, String> productAttrs = new HashMap<>();
|
|
|
+
|
|
|
+ switch (productCode) {
|
|
|
+ case "ed-a-0002":
|
|
|
+ case "fr-a-0002":
|
|
|
+ productAttrs.put("guaranteeMoney", value);
|
|
|
+ break;
|
|
|
+ case "ed-a-0010":
|
|
|
+ productAttrs.put("reReceiveMode", "[\"electronic\"]");
|
|
|
+ productAttrs.put("reReceiveType", "[\"electronicStubForm\"]");
|
|
|
+ break;
|
|
|
+ case "fr-a-0007":
|
|
|
+ productAttrs.put("reReceiveMode", "[\"electronic\"]");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return null;
|
|
|
}
|
|
|
- return "";
|
|
|
+
|
|
|
+ return productAttrs;
|
|
|
}
|
|
|
}
|