|
@@ -1,23 +1,19 @@
|
|
|
-package com.fs.kingbos.service.impl;
|
|
|
+package com.fs.erp.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.PropertyNamingStrategy;
|
|
|
-import com.alibaba.fastjson.parser.ParserConfig;
|
|
|
import com.fs.common.config.FSSysConfig;
|
|
|
import com.fs.common.exception.ServiceException;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
-import com.fs.erp.dto.ErpOrderResponse;
|
|
|
-import com.fs.erp.dto.wdt.ErpWdtApiResponse;
|
|
|
-import com.fs.kingbos.domian.*;
|
|
|
-import com.fs.kingbos.enums.OrderStatusEnum;
|
|
|
-import com.fs.kingbos.service.K9OrderService;
|
|
|
-import com.fs.kingbos.util.SignUtil;
|
|
|
-import com.fs.kingbos.util.UrlUtil;
|
|
|
+import com.fs.erp.domain.*;
|
|
|
+import com.fs.erp.dto.*;
|
|
|
+import com.fs.erp.service.IErpOrderService;
|
|
|
+import com.fs.erp.utils.SignUtils;
|
|
|
+import com.fs.erp.utils.UrlUtils;
|
|
|
+import com.fs.his.config.FsErpConfig;
|
|
|
+import com.fs.his.utils.ConfigUtil;
|
|
|
import com.fs.store.domain.FsStoreOrder;
|
|
|
import com.fs.store.domain.FsStoreOrderItem;
|
|
|
import com.fs.store.dto.FsStoreCartDTO;
|
|
@@ -29,28 +25,24 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-
|
|
|
-import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
-import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-import static com.fs.kingbos.enums.OrderStatusEnum.CANCELLED;
|
|
|
-import static com.fs.kingbos.enums.OrderStatusEnum.NO_DELIVERED;
|
|
|
+import static com.fs.erp.enums.KbOrderStatusEnum.CANCELLED;
|
|
|
+import static com.fs.erp.enums.KbOrderStatusEnum.NO_DELIVERED;
|
|
|
+
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
-public class K9OrderServiceImpl implements K9OrderService {
|
|
|
+public class K9OrderServiceImpl implements IErpOrderService {
|
|
|
public final static Logger logger = LoggerFactory.getLogger(K9OrderServiceImpl.class);
|
|
|
@Autowired
|
|
|
- FSSysConfig sysConfig;
|
|
|
+ ConfigUtil configUtil;
|
|
|
@Autowired
|
|
|
private FsStoreOrderMapper fsStoreOrderMapper;
|
|
|
@Autowired
|
|
@@ -58,43 +50,118 @@ public class K9OrderServiceImpl implements K9OrderService {
|
|
|
@Autowired
|
|
|
private FsStoreProductMapper productMapper;
|
|
|
@Override
|
|
|
- public KingbosOrderResponse addOrder(KingbosOrderRequest request) {
|
|
|
- JSONObject param = JSONUtil.createObj();
|
|
|
- param.set("key", "OL");
|
|
|
- param.set("data", request.getData());
|
|
|
- param.set("d1_data", request.getD1_data());
|
|
|
- String timeStep = System.currentTimeMillis() + "";
|
|
|
- logger.info("zyp \n【金博网络订单推送参数】:"+param);
|
|
|
- String sign = SignUtil.sign(param.toString(),sysConfig.getKingbosSecret(), sysConfig.getKingbosan(), timeStep);
|
|
|
- String url = UrlUtil.getUrl(sysConfig.getKingbosUrl(),sign, timeStep);
|
|
|
- String json = param.toString();
|
|
|
- String result = HttpUtil.post(url, json);
|
|
|
- logger.info("zyp \n【金博网络订单推送返回】:"+result);
|
|
|
- KingbosOrderResponse response = JSONUtil.toBean(result, KingbosOrderResponse.class);
|
|
|
- return response;
|
|
|
+ /**
|
|
|
+ * 推送erp订单
|
|
|
+ */
|
|
|
+ public ErpOrderResponse addOrder(ErpOrder order) {
|
|
|
+ return addOmsOrder(order.getPlatform_code());
|
|
|
}
|
|
|
|
|
|
|
|
|
- //运单号已获取到
|
|
|
+ /**
|
|
|
+ * 退款
|
|
|
+ * @param order
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ErpOrderResponse refundOrder(ErpRefundOrder order){
|
|
|
+ if (order != null){
|
|
|
+ String deliverySn = order.getDeliverySn();
|
|
|
+ String orderCode = order.getTrade_platform_code();
|
|
|
+ if (StringUtils.isNotBlank(orderCode)){
|
|
|
+ if (StringUtils.isBlank(deliverySn)){
|
|
|
+ //未获取订单号
|
|
|
+ return refundOmsOrder2(orderCode);
|
|
|
+ } else {
|
|
|
+ //已获取订单号
|
|
|
+ return refundOrder1(orderCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private KingbosRefundOrderRequest getKingbosRefundOrderRequest(String orderCode) {
|
|
|
+ FsStoreOrder order = fsStoreOrderMapper.selectFsStoreOrderByOrderCode(orderCode);
|
|
|
+ if (order != null){
|
|
|
+ logger.debug("【金博网络退货单】开始构建订单数据,订单号: {}", orderCode);
|
|
|
+ KingbosRefundOrderRequest request = new KingbosRefundOrderRequest();
|
|
|
+ KingbosRefundOrderData data = new KingbosRefundOrderData();
|
|
|
+ data.setCorderSource("MALL");
|
|
|
+ String extendOrderId = order.getExtendOrderId();
|
|
|
+ data.setCasId(extendOrderId);
|
|
|
+ data.setCoId(extendOrderId);
|
|
|
+ request.setData(data);
|
|
|
+ // 3. 构建订单明细数据
|
|
|
+ List<KingbosRefundOrderD1Data> d1Datas = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ List<KingbosRefundOrderD1Data> d1_data = new ArrayList<>();
|
|
|
+ FsStoreOrderItem query = new FsStoreOrderItem();
|
|
|
+ query.setOrderId(order.getId());
|
|
|
+ List<FsStoreOrderItem> orderItems = storeOrderItemService.selectFsStoreOrderItemList(query);
|
|
|
+
|
|
|
+
|
|
|
+ d1_data = orderItems.stream()
|
|
|
+ .map(item -> buildRefundOrderDetailItem(extendOrderId))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ request.setD1_data(d1_data);
|
|
|
+ logger.info("【金博网络退货单】订单明细数据构建完成,明细数量: {}", d1Datas.size());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ErpDeliverysResponse getDeliver(ErpDeliverysRequest param) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
- public KingbosOrderResponse refundOrder(KingbosRefundOrderRequest request) {
|
|
|
+ public ErpOrderQueryResponse getOrder(ErpOrderQueryRequert param) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BaseResponse refundUpdate(ErpRefundUpdateRequest param) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 退款 运单号已获取到
|
|
|
+ * @param orderCode
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private ErpOrderResponse refundOrder1(String orderCode) {
|
|
|
+ KingbosRefundOrderRequest request = getKingbosRefundOrderRequest(orderCode);
|
|
|
+ FsErpConfig erpConfig = configUtil.getErpConfig();
|
|
|
JSONObject param = JSONUtil.createObj();
|
|
|
param.set("key", "WR");
|
|
|
param.set("data", request.getData());
|
|
|
param.set("d1_data", request.getD1_data());
|
|
|
String timeStep = System.currentTimeMillis() + "";
|
|
|
- String sign = SignUtil.sign(param.toString(),sysConfig.getKingbosSecret(), sysConfig.getKingbosan(), timeStep);
|
|
|
- String url = UrlUtil.getUrl(sysConfig.getKingbosUrl(),sign, timeStep);
|
|
|
+ String sign = SignUtils.sign(param.toString(),erpConfig.getKingbosSecret(), erpConfig.getKingbosan(), timeStep);
|
|
|
+ String url = UrlUtils.getUrl(erpConfig.getKingbosUrl(),sign, timeStep);
|
|
|
String result = HttpUtil.post(url, param.toString());
|
|
|
logger.info("zyp \n【金博网络退货单】:"+result);
|
|
|
KingbosOrderResponse response = JSONUtil.toBean(result, KingbosOrderResponse.class);
|
|
|
- return response;
|
|
|
+ log.info("订单推送成功: {}", response);
|
|
|
+ ErpOrderResponse erpOrderResponse = new ErpOrderResponse();
|
|
|
+ erpOrderResponse.setCode(response.getCbilid());
|
|
|
+ return erpOrderResponse;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public ErpOrderResponse addOmsOrder(Long orderId) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 退款 运单号未获取到 改状态
|
|
|
+ * @param orderCode 订单编号
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private ErpOrderResponse refundOmsOrder2(String orderCode) {
|
|
|
try {
|
|
|
- KingbosOrderResponse response = this.createOmsOrder(orderId, NO_DELIVERED.getCode());
|
|
|
+ KingbosOrderResponse response = createOmsOrder(orderCode, CANCELLED.getCode());
|
|
|
if (response.getIsSuccess()){
|
|
|
log.info("订单推送成功: {}", response);
|
|
|
ErpOrderResponse erpOrderResponse = new ErpOrderResponse();
|
|
@@ -109,11 +176,14 @@ public class K9OrderServiceImpl implements K9OrderService {
|
|
|
return new ErpOrderResponse();
|
|
|
}
|
|
|
|
|
|
- //运单号未获取到 改状态
|
|
|
- @Override
|
|
|
- public ErpOrderResponse refundOmsOrder(Long orderId) {
|
|
|
+ /**
|
|
|
+ * 通过订单编号推送订单 解析金博结果
|
|
|
+ * @param orderCode
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private ErpOrderResponse addOmsOrder(String orderCode) {
|
|
|
try {
|
|
|
- KingbosOrderResponse response = this.createOmsOrder(orderId, CANCELLED.getCode());
|
|
|
+ KingbosOrderResponse response = this.createOmsOrder(orderCode, NO_DELIVERED.getCode());
|
|
|
if (response.getIsSuccess()){
|
|
|
log.info("订单推送成功: {}", response);
|
|
|
ErpOrderResponse erpOrderResponse = new ErpOrderResponse();
|
|
@@ -129,11 +199,18 @@ public class K9OrderServiceImpl implements K9OrderService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private KingbosOrderResponse createOmsOrder(Long orderId,String orderStatus){
|
|
|
- logger.info("【金博网络订单】开始创建订单,订单ID: {}", orderId);
|
|
|
+ /**
|
|
|
+ * 组装参数得到金博结果
|
|
|
+ * @param orderCode
|
|
|
+ * @param orderStatus
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private KingbosOrderResponse createOmsOrder(String orderCode,String orderStatus){
|
|
|
+ logger.info("【金博网络订单】开始创建订单,订单Code: {}", orderCode);
|
|
|
try {
|
|
|
// 1. 获取订单信息并验证
|
|
|
- FsStoreOrder order = fsStoreOrderMapper.selectFsStoreOrderById(orderId);
|
|
|
+ FsStoreOrder order = fsStoreOrderMapper.selectFsStoreOrderByOrderCode(orderCode);
|
|
|
+ logger.info("【金博网络订单】订单信息获取成功,订单id: {}", order.getId());
|
|
|
logger.info("【金博网络订单】订单信息获取成功,订单号: {}", order.getOrderCode());
|
|
|
|
|
|
// 2. 构建金博订单数据
|
|
@@ -157,13 +234,20 @@ public class K9OrderServiceImpl implements K9OrderService {
|
|
|
// logger.error("【金博网络订单】创建订单失败,订单ID: {}, 错误信息: {}", orderId, response.getErrmsg());
|
|
|
// }
|
|
|
} catch (Exception e) {
|
|
|
- logger.error("【金博网络订单】创建订单失败,订单ID: {}, 错误信息: {}", orderId, e.getMessage(), e);
|
|
|
+ logger.error("【金博网络订单】创建订单失败,订单Code: {}, 错误信息: {}", orderCode, e.getMessage(), e);
|
|
|
throw e;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 组装订单推送参数
|
|
|
+ * @param order
|
|
|
+ * @param orderStatus
|
|
|
+ * @return
|
|
|
+ */
|
|
|
private KingbosOrderData buildKingbosOrderData(FsStoreOrder order,String orderStatus) {
|
|
|
+ FsErpConfig erpConfig = configUtil.getErpConfig();
|
|
|
logger.debug("【金博网络订单】开始构建订单数据,订单号: {}", order.getOrderCode());
|
|
|
KingbosOrderData data = new KingbosOrderData();
|
|
|
// 设置基础信息
|
|
@@ -201,8 +285,8 @@ public class K9OrderServiceImpl implements K9OrderService {
|
|
|
setReceiverInfo(data, order);
|
|
|
|
|
|
// 设置仓库信息
|
|
|
- data.setCwarehouse_code(sysConfig.getCwarehouseCode());
|
|
|
- data.setCwarehouse_name(sysConfig.getCwarehouseName());
|
|
|
+ data.setCwarehouse_code(erpConfig.getCwarehouseCode());
|
|
|
+ data.setCwarehouse_name(erpConfig.getCwarehouseName());
|
|
|
|
|
|
// 设置货到付款信息
|
|
|
if (!order.getPayType().equals("1")) {
|
|
@@ -254,6 +338,13 @@ public class K9OrderServiceImpl implements K9OrderService {
|
|
|
return d1Datas;
|
|
|
}
|
|
|
|
|
|
+ private KingbosRefundOrderD1Data buildRefundOrderDetailItem(String orderId) {
|
|
|
+ KingbosRefundOrderD1Data item = new KingbosRefundOrderD1Data();
|
|
|
+ item.setCasId(orderId);
|
|
|
+ item.setCorderSource("MALL");
|
|
|
+ return item;
|
|
|
+ }
|
|
|
+
|
|
|
private KingbosOrderD1Data buildOrderDetailItem(FsStoreOrderItem orderItem, String orderId) {
|
|
|
FsStoreCartDTO cartDTO = JSONUtil.toBean(orderItem.getJsonInfo(), FsStoreCartDTO.class);
|
|
|
BigDecimal quantity = new BigDecimal(orderItem.getNum());
|
|
@@ -274,6 +365,12 @@ public class K9OrderServiceImpl implements K9OrderService {
|
|
|
return item;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 发送请求
|
|
|
+ * @param data
|
|
|
+ * @param d1Datas
|
|
|
+ * @return
|
|
|
+ */
|
|
|
private KingbosOrderResponse sendOrderRequest(KingbosOrderData data, List<KingbosOrderD1Data> d1Datas) {
|
|
|
logger.info("【金博网络订单】开始发送订单请求,金博订单号: {}", data.getCo_id());
|
|
|
KingbosOrderRequest request = new KingbosOrderRequest();
|
|
@@ -281,7 +378,7 @@ public class K9OrderServiceImpl implements K9OrderService {
|
|
|
request.setD1_data(d1Datas);
|
|
|
|
|
|
try {
|
|
|
- KingbosOrderResponse response = this.addOrder(request);
|
|
|
+ KingbosOrderResponse response = addErpOrder(request);
|
|
|
logger.info("【金博网络订单】订单请求发送成功,金博订单号: {}, 响应结果: {}", data.getCo_id(), response);
|
|
|
return response;
|
|
|
} catch (Exception e) {
|
|
@@ -289,4 +386,21 @@ public class K9OrderServiceImpl implements K9OrderService {
|
|
|
throw e;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private KingbosOrderResponse addErpOrder(KingbosOrderRequest request) {
|
|
|
+ FsErpConfig erpConfig = configUtil.getErpConfig();
|
|
|
+ JSONObject param = JSONUtil.createObj();
|
|
|
+ param.set("key", "OL");
|
|
|
+ param.set("data", request.getData());
|
|
|
+ param.set("d1_data", request.getD1_data());
|
|
|
+ String timeStep = System.currentTimeMillis() + "";
|
|
|
+ logger.info("zyp \n【金博网络订单推送参数】:"+param);
|
|
|
+ String sign = SignUtils.sign(param.toString(),erpConfig.getKingbosSecret(), erpConfig.getKingbosan(), timeStep);
|
|
|
+ String url = UrlUtils.getUrl(erpConfig.getKingbosUrl(),sign, timeStep);
|
|
|
+ String json = param.toString();
|
|
|
+ String result = HttpUtil.post(url, json);
|
|
|
+ logger.info("zyp \n【金博网络订单推送返回】:"+result);
|
|
|
+ KingbosOrderResponse response = JSONUtil.toBean(result, KingbosOrderResponse.class);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
}
|