|
|
@@ -7,6 +7,9 @@ import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.fs.common.event.TemplateBean;
|
|
|
+import com.fs.common.event.TemplateEvent;
|
|
|
+import com.fs.common.event.TemplateListenEnum;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.company.service.ICompanyService;
|
|
|
import com.fs.erp.domain.ErpDeliverys;
|
|
|
@@ -27,12 +30,18 @@ import com.fs.his.service.IFsExpressService;
|
|
|
import com.fs.his.service.IFsStoreOrderLogsService;
|
|
|
import com.fs.his.service.IFsStoreOrderService;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
|
+import com.fs.hisStore.domain.FsExpressScrm;
|
|
|
import com.fs.hisStore.domain.FsStoreOrderItemScrm;
|
|
|
import com.fs.hisStore.domain.FsStoreOrderScrm;
|
|
|
import com.fs.hisStore.domain.FsStoreProductScrm;
|
|
|
+import com.fs.hisStore.enums.OrderInfoEnum;
|
|
|
+import com.fs.hisStore.enums.OrderLogEnum;
|
|
|
+import com.fs.hisStore.enums.ShipperCodeEnum;
|
|
|
import com.fs.hisStore.mapper.FsStoreOrderItemScrmMapper;
|
|
|
import com.fs.hisStore.mapper.FsStoreOrderScrmMapper;
|
|
|
import com.fs.hisStore.mapper.FsStoreProductScrmMapper;
|
|
|
+import com.fs.hisStore.service.IFsExpressScrmService;
|
|
|
+import com.fs.hisStore.service.IFsStoreOrderScrmService;
|
|
|
import com.fs.hisStore.vo.FsStoreOrderItemVO;
|
|
|
import com.fs.system.domain.SysConfig;
|
|
|
import com.fs.system.mapper.SysConfigMapper;
|
|
|
@@ -51,8 +60,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
-public class DfOrderServiceImpl implements IErpOrderService
|
|
|
-{
|
|
|
+public class DfOrderServiceImpl implements IErpOrderService {
|
|
|
// @Autowired
|
|
|
// ConfigUtil configUtil;
|
|
|
|
|
|
@@ -89,6 +97,9 @@ public class DfOrderServiceImpl implements IErpOrderService
|
|
|
@Autowired
|
|
|
private IFsStoreOrderLogsService fsStoreOrderLogsService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IFsStoreOrderScrmService fsStoreOrderScrmLogsService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ICompanyService companyService;
|
|
|
|
|
|
@@ -97,6 +108,10 @@ public class DfOrderServiceImpl implements IErpOrderService
|
|
|
|
|
|
@Autowired
|
|
|
private IFsExpressService expressService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsExpressScrmService expressScrmService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private IFsStoreOrderService fsStoreOrderService;
|
|
|
|
|
|
@@ -126,7 +141,7 @@ public class DfOrderServiceImpl implements IErpOrderService
|
|
|
String orderCode = order.getOrderCode();
|
|
|
FsStoreOrder fsStoreOrder = fsStoreOrderMapper.selectFsStoreOrderByOrderCode(orderCode);
|
|
|
FsStoreOrderDf df = fsStoreOrderDfMapper.selectFsStoreOrderDfByOrderId(fsStoreOrder.getOrderId());
|
|
|
- if (df == null){
|
|
|
+ if (df == null) {
|
|
|
return null;
|
|
|
}
|
|
|
Long dfAccountId = getSFAccountIndex(fsStoreOrder.getOrderId());
|
|
|
@@ -240,7 +255,7 @@ public class DfOrderServiceImpl implements IErpOrderService
|
|
|
if (order != null) {
|
|
|
//获取下单账户
|
|
|
FsStoreOrderDf df = fsStoreOrderDfMapper.selectFsStoreOrderDfByOrderId(order.getOrderId());
|
|
|
- if(df == null){
|
|
|
+ if (df == null) {
|
|
|
return null;
|
|
|
}
|
|
|
Long dfAccountId = getSFAccountIndex(order.getOrderId());
|
|
|
@@ -259,6 +274,34 @@ public class DfOrderServiceImpl implements IErpOrderService
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ErpOrderQueryResponse getScrmOrder(ErpOrderQueryRequert param) {
|
|
|
+ ErpOrderQueryResponse response = new ErpOrderQueryResponse();
|
|
|
+ String orderNumber = param.getCode();
|
|
|
+ if (StrUtil.isNotBlank(orderNumber)) {
|
|
|
+ FsStoreOrderScrm order = fsStoreOrderScrmMapper.selectFsStoreOrderByOrderCode(orderNumber);
|
|
|
+ if (order != null) {
|
|
|
+ //获取下单账户
|
|
|
+ FsStoreOrderDf df = fsStoreOrderDfMapper.selectFsStoreOrderDfByOrderId(order.getId());
|
|
|
+ if (df == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Long dfAccountId = getSFAccountIndex(order.getId());
|
|
|
+ if (dfAccountId != null) {
|
|
|
+ Map<String, Object> orderResultQueryParam = new HashMap<>();
|
|
|
+ orderResultQueryParam.put("orderNumber", orderNumber);
|
|
|
+ orderResultQueryParam.put("exInterfaceType", df.getStatus());
|
|
|
+ getOrderScrmResult(orderResultQueryParam, dfAccountId);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ response.setErrorDesc("该订单不存在/顺丰账户不存在");
|
|
|
+ } else {
|
|
|
+ response.setErrorDesc("未获取到原始订单号");
|
|
|
+ }
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public BaseResponse refundUpdate(ErpRefundUpdateRequest request) {
|
|
|
ErpRefundOrder erpRefundOrder = new ErpRefundOrder();
|
|
|
@@ -285,7 +328,7 @@ public class DfOrderServiceImpl implements IErpOrderService
|
|
|
try {
|
|
|
String response = client.execute(RequestUrlEnum.ORDER_DELIVERY_STATUS, map, dfAccountId);
|
|
|
DFApiResponse dfApiResponse = JSON.parseObject(response, DFApiResponse.class);
|
|
|
- if ("运单不存在".equals(dfApiResponse.getMsg())){
|
|
|
+ if ("运单不存在".equals(dfApiResponse.getMsg())) {
|
|
|
|
|
|
//查看原来物流状态
|
|
|
cancelOrder(order);
|
|
|
@@ -347,7 +390,7 @@ public class DfOrderServiceImpl implements IErpOrderService
|
|
|
Map<String, Object> config = (Map<String, Object>) JSON.parse(sysConfig.getConfigValue());
|
|
|
Object isUpdateOrder = config.get("isUpdateOrder");
|
|
|
if (isUpdateOrder == null || "1".equals(isUpdateOrder.toString())) {
|
|
|
- fsStoreOrderService.getGoods(order.getOrderId(),"物流自动");
|
|
|
+ fsStoreOrderService.getGoods(order.getOrderId(), "物流自动");
|
|
|
}
|
|
|
break;
|
|
|
case 10:
|
|
|
@@ -381,7 +424,7 @@ public class DfOrderServiceImpl implements IErpOrderService
|
|
|
order.setDeliverySn("");
|
|
|
fsStoreOrderMapper.updateFsStoreOrder(order);
|
|
|
fsStoreOrderLogsService.create(order.getOrderId(), FsStoreOrderLogEnum.UPDATE_ORDER_DF.getValue(),
|
|
|
- "运单不存在,"+FsStoreOrderLogEnum.UPDATE_ORDER_DF.getDesc());
|
|
|
+ "运单不存在," + FsStoreOrderLogEnum.UPDATE_ORDER_DF.getDesc());
|
|
|
} else {
|
|
|
//有物流信息->售后处理
|
|
|
//取消订单
|
|
|
@@ -391,7 +434,7 @@ public class DfOrderServiceImpl implements IErpOrderService
|
|
|
afterSalesParam.setOperator("代服管家");
|
|
|
fsStoreOrderService.afterSales(afterSalesParam);
|
|
|
fsStoreOrderLogsService.create(order.getOrderId(), FsStoreOrderLogEnum.REFUND_ORDER_DF.getValue(),
|
|
|
- "运单不存在,"+FsStoreOrderLogEnum.REFUND_ORDER_DF.getDesc());
|
|
|
+ "运单不存在," + FsStoreOrderLogEnum.REFUND_ORDER_DF.getDesc());
|
|
|
}
|
|
|
FsStoreOrderDf df = new FsStoreOrderDf();
|
|
|
df.setOrderId(order.getOrderId());
|
|
|
@@ -399,6 +442,7 @@ public class DfOrderServiceImpl implements IErpOrderService
|
|
|
df.setUpdateTime(new Date());
|
|
|
fsStoreOrderDfMapper.updateFsStoreOrderDf(df);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 获取erp推送参数
|
|
|
*
|
|
|
@@ -433,7 +477,7 @@ public class DfOrderServiceImpl implements IErpOrderService
|
|
|
orderResultQueryParam.put("orderNumber", order.getPlatform_code());
|
|
|
orderResultQueryParam.put("exInterfaceType", df.getStatus());
|
|
|
try {
|
|
|
- getOrderResult(orderResultQueryParam,dfAccountId);
|
|
|
+ getOrderScrmResult(orderResultQueryParam, dfAccountId);
|
|
|
} catch (Exception e) {
|
|
|
log.info("推送订单完成,查询订单问题{}", e.getMessage());
|
|
|
}
|
|
|
@@ -484,7 +528,7 @@ public class DfOrderServiceImpl implements IErpOrderService
|
|
|
orderResultQueryParam.put("orderNumber", order.getPlatform_code());
|
|
|
orderResultQueryParam.put("exInterfaceType", df.getStatus());
|
|
|
try {
|
|
|
- getOrderResult(orderResultQueryParam,dfAccountId);
|
|
|
+ getOrderResult(orderResultQueryParam, dfAccountId);
|
|
|
} catch (Exception e) {
|
|
|
log.info("推送订单完成,查询订单问题{}", e.getMessage());
|
|
|
}
|
|
|
@@ -631,7 +675,12 @@ public class DfOrderServiceImpl implements IErpOrderService
|
|
|
skuVo.setProductName(product.getProductName()); //商品名称
|
|
|
com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(item.getJsonInfo());
|
|
|
skuVo.setSkuCode(jsonObject.getString("sku")); //sku编码
|
|
|
- skuVo.setProductCode(jsonObject.getString("barCode")); //商品编号
|
|
|
+ String barCode = jsonObject.getString("barCode");
|
|
|
+ if (StringUtils.isNotBlank(barCode)) {
|
|
|
+ skuVo.setProductCode(barCode); //商品编号
|
|
|
+ } else {
|
|
|
+ skuVo.setProductCode(item.getProductId().toString()); //商品编号
|
|
|
+ }
|
|
|
skuVo.setAttributeNames(jsonObject.getString("sku")); //商品规格,格式:颜色:红色,尺寸:L码....以此类推
|
|
|
skuVo.setProductNumber(Math.toIntExact(item.getNum())); //商品预定数量
|
|
|
skuVo.setPrice(product.getPrice().doubleValue()); //商品单价
|
|
|
@@ -762,7 +811,6 @@ public class DfOrderServiceImpl implements IErpOrderService
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 获取账户索引 后续添加规则
|
|
|
*
|
|
|
@@ -809,12 +857,12 @@ public class DfOrderServiceImpl implements IErpOrderService
|
|
|
if (bspOrderResponse != null) {
|
|
|
String failMsg = bspOrderResponse.getFailMsg();
|
|
|
if (StringUtils.isNotBlank(failMsg)) {
|
|
|
- if (failMsg.equals("暂未结果, 请稍后再查")){
|
|
|
+ if (failMsg.equals("暂未结果, 请稍后再查")) {
|
|
|
return;
|
|
|
}
|
|
|
//下单失败 返回未推送状态
|
|
|
- String orderNumber = bspOrderResponse.getOrderNumber();
|
|
|
- rollBackOrder(orderNumber,failMsg);
|
|
|
+ String orderNumber = bspOrderResponse.getOrderNumber();
|
|
|
+ rollBackOrder(orderNumber, failMsg);
|
|
|
} else {
|
|
|
setExpress(bspOrderResponse);
|
|
|
}
|
|
|
@@ -840,7 +888,56 @@ public class DfOrderServiceImpl implements IErpOrderService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void rollBackOrder(String orderNumber,String failMsg) {
|
|
|
+ private void getOrderScrmResult(Map<String, Object> map, Long dfAccountId) {
|
|
|
+ try {
|
|
|
+ String status = map.get("exInterfaceType").toString();
|
|
|
+ log.info("开始查询订单结果,参数为: {}", JSON.toJSONString(map));
|
|
|
+ String response = client.execute(RequestUrlEnum.ORDER_RESULT, map, dfAccountId);
|
|
|
+ DFApiResponse dfApiResponse = JSON.parseObject(response, DFApiResponse.class);
|
|
|
+ if (dfApiResponse != null && "ok".equals(dfApiResponse.getCode())) {
|
|
|
+ log.info("查询订单结果,结果: {}", JSON.toJSONString(dfApiResponse));
|
|
|
+ Object result = dfApiResponse.getResult();
|
|
|
+ if (result != null) {
|
|
|
+ String jsonString = JSON.toJSONString(result);
|
|
|
+ //下单
|
|
|
+ if ("1".equals(status)) {
|
|
|
+ //下单结果
|
|
|
+ BspOrderResponseWrapper bspOrderResponse = JSONUtil.toBean(jsonString, BspOrderResponseWrapper.class);
|
|
|
+ if (bspOrderResponse != null) {
|
|
|
+ String failMsg = bspOrderResponse.getFailMsg();
|
|
|
+ if (StringUtils.isNotBlank(failMsg)) {
|
|
|
+ if (failMsg.equals("暂未结果, 请稍后再查")) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //下单失败 返回未推送状态
|
|
|
+ String orderNumber = bspOrderResponse.getOrderNumber();
|
|
|
+ rollBackOrderScrm(orderNumber, failMsg);
|
|
|
+ } else {
|
|
|
+ setExpressScrm(bspOrderResponse);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if ("2".equals(status)) {
|
|
|
+ //取消订单
|
|
|
+ DFCancelOrderResultResponse cancelResponse = JSONUtil.toBean(jsonString, DFCancelOrderResultResponse.class);
|
|
|
+ if (cancelResponse != null) {
|
|
|
+ if (cancelResponse.getIsCancelSuss() == 1) {
|
|
|
+ log.info("查询订单取消成功,返回结果{}", JSON.toJSONString(cancelResponse));
|
|
|
+ } else {
|
|
|
+ log.info("查询订单取消失败,返回结果{}", JSON.toJSONString(cancelResponse));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ log.info(String.format("查询订单失败,原因: %s", dfApiResponse.getMsg()));
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void rollBackOrder(String orderNumber, String failMsg) {
|
|
|
FsStoreOrder fsStoreOrder = fsStoreOrderMapper.selectFsStoreOrderByOrderCode(orderNumber);
|
|
|
FsStoreOrder tempOrder = new FsStoreOrder();
|
|
|
tempOrder.setOrderId(fsStoreOrder.getOrderId());
|
|
|
@@ -855,6 +952,21 @@ public class DfOrderServiceImpl implements IErpOrderService
|
|
|
//推送失败消息
|
|
|
}
|
|
|
|
|
|
+ private void rollBackOrderScrm(String orderNumber, String failMsg) {
|
|
|
+ FsStoreOrderScrm fsStoreOrder = fsStoreOrderScrmMapper.selectFsStoreOrderByOrderCode(orderNumber);
|
|
|
+ FsStoreOrder tempOrder = new FsStoreOrder();
|
|
|
+ tempOrder.setOrderId(fsStoreOrder.getId());
|
|
|
+ tempOrder.setExtendOrderId("");
|
|
|
+ fsStoreOrderMapper.updateFsStoreOrder(tempOrder);
|
|
|
+ FsStoreOrderDf df = new FsStoreOrderDf();
|
|
|
+ df.setOrderId(fsStoreOrder.getId());
|
|
|
+ df.setStatus(OrderInfoEnum.STATUS_1.getValue()); //回到默认
|
|
|
+ df.setFailMsg(failMsg); //失败消息
|
|
|
+ df.setUpdateTime(new Date());
|
|
|
+ fsStoreOrderDfMapper.updateFsStoreOrderDf(df);
|
|
|
+ //推送失败消息
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 顺丰会有自己的轨迹推送 不使用快递鸟(代服务管家设置推送地址)
|
|
|
*
|
|
|
@@ -926,4 +1038,79 @@ public class DfOrderServiceImpl implements IErpOrderService
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 顺丰会有自己的轨迹推送 不使用快递鸟(代服务管家设置推送地址)
|
|
|
+ *
|
|
|
+ * @param bspResponse
|
|
|
+ */
|
|
|
+ private void setExpressScrm(BspOrderResponseWrapper bspResponse) {
|
|
|
+ String orderNumber = bspResponse.getOrderNumber();
|
|
|
+ //快递单号
|
|
|
+ String mailNumber = bspResponse.getMailNumber();
|
|
|
+ //快递名字
|
|
|
+ BspOrderResponse bspOrderResponse = bspResponse.getBspResponse();
|
|
|
+ if (bspOrderResponse != null) {
|
|
|
+ AtomicBoolean flag = new AtomicBoolean(false);
|
|
|
+ List<OrderResponse> list = bspOrderResponse.getBody();
|
|
|
+ if (list != null && !list.isEmpty()) {
|
|
|
+ for (OrderResponse orderResponse : list) {
|
|
|
+ List<RlsInfo> rlsInfo = orderResponse.getRlsInfo();
|
|
|
+ if (rlsInfo != null && !rlsInfo.isEmpty()) {
|
|
|
+ for (RlsInfo info : rlsInfo) {
|
|
|
+ List<RlsDetail> rlsDetails = info.getRlsDetail();
|
|
|
+ if (rlsDetails != null && !rlsDetails.isEmpty()) {
|
|
|
+ for (RlsDetail rlsDetail : rlsDetails) {
|
|
|
+ String proCode = rlsDetail.getProCode();
|
|
|
+ if (StringUtils.isNotBlank(proCode)) {
|
|
|
+ FsStoreOrderScrm order = fsStoreOrderScrmMapper.selectFsStoreOrderByOrderCode(orderNumber);
|
|
|
+ if (order != null && order.getStatus() == OrderInfoEnum.STATUS_1.getValue()) {
|
|
|
+ FsExpressScrm express = expressScrmService.selectFsExpressByOmsCode(order.getDeliveryCode());
|
|
|
+ if (express != null) {
|
|
|
+ order.setDeliveryName(proCode);
|
|
|
+ order.setDeliverySn(express.getOmsCode());
|
|
|
+ }
|
|
|
+ order.setStatus(OrderInfoEnum.STATUS_2.getValue());
|
|
|
+ order.setDeliveryId(mailNumber);
|
|
|
+ order.setDeliverySendTime(new Date());
|
|
|
+
|
|
|
+ fsStoreOrderScrmMapper.updateFsStoreOrder(order);
|
|
|
+ fsStoreOrderScrmLogsService.create(order.getId(), FsStoreOrderLogEnum.DELIVERY_GOODS.getValue(), FsStoreOrderLogEnum.DELIVERY_GOODS.getDesc());
|
|
|
+ //订阅物流回调
|
|
|
+// String lastFourNumber = "";
|
|
|
+// if (order.getDeliverySn().equals(ShipperCodeEnum.SF.getValue())) {
|
|
|
+// lastFourNumber = order.getUserPhone();
|
|
|
+// if (lastFourNumber.length() == 11) {
|
|
|
+// lastFourNumber = StrUtil.sub(lastFourNumber, lastFourNumber.length(), -4);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// expressService.subscribeEspress(order.getOrderCode(), order.getDeliverySn(), order.getDeliveryId(), lastFourNumber);
|
|
|
+
|
|
|
+// TemplateBean templateBean = TemplateBean.builder()
|
|
|
+// .orderId(order.getId().toString())
|
|
|
+// .orderCode(order.getOrderCode().toString())
|
|
|
+// .deliveryId(order.getDeliveryId())
|
|
|
+// .deliveryName(order.getDeliveryName())
|
|
|
+// .userId(order.getUserId())
|
|
|
+// .templateType(TemplateListenEnum.TYPE_2.getValue())
|
|
|
+// .build();
|
|
|
+// publisher.publishEvent(new TemplateEvent(this, templateBean));
|
|
|
+ }
|
|
|
+ flag.set(true);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (flag.get()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|