|
@@ -3,10 +3,11 @@ package com.fs.erp.service.impl;
|
|
|
import cn.hutool.core.convert.Convert;
|
|
import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
import cn.hutool.http.HttpUtil;
|
|
|
-import cn.hutool.json.JSONObject;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
import com.fs.common.core.redis.RedisCache;
|
|
@@ -14,6 +15,7 @@ import com.fs.common.event.TemplateBean;
|
|
|
import com.fs.common.event.TemplateEvent;
|
|
import com.fs.common.event.TemplateEvent;
|
|
|
import com.fs.common.event.TemplateListenEnum;
|
|
import com.fs.common.event.TemplateListenEnum;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
import com.fs.common.utils.DateUtils;
|
|
|
|
|
+import com.fs.company.mapper.CompanyUserMapper;
|
|
|
import com.fs.company.service.ICompanyService;
|
|
import com.fs.company.service.ICompanyService;
|
|
|
import com.fs.erp.domain.ErpDeliverys;
|
|
import com.fs.erp.domain.ErpDeliverys;
|
|
|
import com.fs.erp.domain.ErpOrder;
|
|
import com.fs.erp.domain.ErpOrder;
|
|
@@ -63,6 +65,7 @@ import com.fs.wxwork.dto.WxWorkUserId2VidDTO;
|
|
|
import com.fs.wxwork.dto.WxWorkVid2UserIdRespDTO;
|
|
import com.fs.wxwork.dto.WxWorkVid2UserIdRespDTO;
|
|
|
import com.fs.wxwork.service.WxWorkService;
|
|
import com.fs.wxwork.service.WxWorkService;
|
|
|
import com.hc.openapi.tool.util.StringUtils;
|
|
import com.hc.openapi.tool.util.StringUtils;
|
|
|
|
|
+import com.qiniu.util.Json;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.http.util.Asserts;
|
|
import org.apache.http.util.Asserts;
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.NotNull;
|
|
@@ -166,6 +169,8 @@ public class DfOrderServiceImpl implements IErpOrderService {
|
|
|
private FsStoreProductAttrValueScrmMapper fsStoreProductAttrValueMapper;
|
|
private FsStoreProductAttrValueScrmMapper fsStoreProductAttrValueMapper;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private FsStoreOrderLogsScrmMapper fsStoreOrderLogsScrmMapper;
|
|
private FsStoreOrderLogsScrmMapper fsStoreOrderLogsScrmMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private CompanyUserMapper companyUserMapper;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public ErpOrderResponse addOrder(ErpOrder order) {
|
|
public ErpOrderResponse addOrder(ErpOrder order) {
|
|
@@ -409,15 +414,6 @@ public class DfOrderServiceImpl implements IErpOrderService {
|
|
|
if (order != null) {
|
|
if (order != null) {
|
|
|
String mailNumber = order.getDeliverySn();
|
|
String mailNumber = order.getDeliverySn();
|
|
|
Long dfAccountId = getSFAccountIndex(order.getOrderId());
|
|
Long dfAccountId = getSFAccountIndex(order.getOrderId());
|
|
|
- //积分商城逻辑
|
|
|
|
|
- if (OrderContextHolder.hasIntegralOrder()){
|
|
|
|
|
- FsIntegralOrder integralOrder = OrderContextHolder.getIntegralOrder();
|
|
|
|
|
- mailNumber = integralOrder.getDeliverySn();
|
|
|
|
|
- FsDfAccount fsDfAccount = fsDfAccountMapper.selectFsDfAccountByAccount(integralOrder.getLoginAccount());
|
|
|
|
|
- if (fsDfAccount != null)
|
|
|
|
|
- dfAccountId = fsDfAccount.getId();
|
|
|
|
|
- OrderContextHolder.clear();//清理threadlocalmap引用。
|
|
|
|
|
- }
|
|
|
|
|
if (StringUtils.isNotBlank(mailNumber) && dfAccountId != null) {
|
|
if (StringUtils.isNotBlank(mailNumber) && dfAccountId != null) {
|
|
|
try {
|
|
try {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
Map<String, Object> map = new HashMap<>();
|
|
@@ -467,6 +463,63 @@ public class DfOrderServiceImpl implements IErpOrderService {
|
|
|
return erpDeliverysResponse;
|
|
return erpDeliverysResponse;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ private ErpDeliverysResponse getDeliver2(ErpDeliverysRequest request) {
|
|
|
|
|
+ ErpDeliverysResponse erpDeliverysResponse = new ErpDeliverysResponse();
|
|
|
|
|
+ String orderCode = request.getCode();
|
|
|
|
|
+ if (StrUtil.isNotBlank(orderCode)) {
|
|
|
|
|
+ FsStoreOrderScrm order = fsStoreOrderScrmMapper.selectFsStoreOrderByOrderCode(orderCode);
|
|
|
|
|
+ if (order != null) {
|
|
|
|
|
+ String mailNumber = order.getDeliveryId();
|
|
|
|
|
+ Long dfAccountId = getSFAccountIndex(order.getId());
|
|
|
|
|
+ if (StringUtils.isNotBlank(mailNumber) && dfAccountId != null) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
+ map.put("mailNumber", mailNumber);
|
|
|
|
|
+ log.info("开始查询路由结果,参数为: {}", JSON.toJSONString(map));
|
|
|
|
|
+ String response = client.execute(RequestUrlEnum.ORDER_DELIVERY, map, dfAccountId);
|
|
|
|
|
+ if (StringUtils.isBlank(response)) {
|
|
|
|
|
+ return erpDeliverysResponse;
|
|
|
|
|
+ }
|
|
|
|
|
+ DFApiResponse dfApiResponse = JSON.parseObject(response, DFApiResponse.class);
|
|
|
|
|
+ if (dfApiResponse != null && "ok".equals(dfApiResponse.getCode())) {
|
|
|
|
|
+ dfApiResponse.setCode(mailNumber);
|
|
|
|
|
+ Object result = dfApiResponse.getResult();
|
|
|
|
|
+ String jsonStr = JSON.toJSONString(JSON.parseObject(JSONUtil.toJsonStr(result), HashMap.class).get("list"));
|
|
|
|
|
+ List<ErpDeliverys> dfDeliveryResponse = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ dfDeliveryResponse = JSON.parseArray(jsonStr, ErpDeliverys.class);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.info("查询路由结果异常: {},结果为:{}", e.getMessage(), jsonStr);
|
|
|
|
|
+ erpDeliverysResponse.setSuccess(false);
|
|
|
|
|
+ erpDeliverysResponse.setErrorDesc("未更新物流");
|
|
|
|
|
+ return erpDeliverysResponse;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dfDeliveryResponse != null && !dfDeliveryResponse.isEmpty()) {
|
|
|
|
|
+ for (ErpDeliverys deliveryResponse : dfDeliveryResponse) {
|
|
|
|
|
+ deliveryResponse.setMail_no(deliveryResponse.getMailNo());
|
|
|
|
|
+ deliveryResponse.setExpress_code(deliveryResponse.getMailNo());
|
|
|
|
|
+ deliveryResponse.setExpress_name("顺丰");
|
|
|
|
|
+ }
|
|
|
|
|
+ erpDeliverysResponse.setDeliverys(dfDeliveryResponse);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ erpDeliverysResponse.setErrorDesc(dfApiResponse.getMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ log.info("代服路由查询错误{}", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ erpDeliverysResponse.setErrorDesc("该订单不存在/顺丰账户不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ erpDeliverysResponse.setErrorDesc("未获取到原始订单号");
|
|
|
|
|
+ }
|
|
|
|
|
+ return erpDeliverysResponse;
|
|
|
|
|
+ }
|
|
|
@Override
|
|
@Override
|
|
|
public ErpDeliverysResponse getDeliverScrm(ErpDeliverysRequest request) {
|
|
public ErpDeliverysResponse getDeliverScrm(ErpDeliverysRequest request) {
|
|
|
ErpDeliverysResponse erpDeliverysResponse = new ErpDeliverysResponse();
|
|
ErpDeliverysResponse erpDeliverysResponse = new ErpDeliverysResponse();
|
|
@@ -1090,6 +1143,147 @@ public class DfOrderServiceImpl implements IErpOrderService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private String huyiBaseUrl = "https://admin.jnmyunl.com/api/open";
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void sendExpressMessageToHuYi(FsStoreOrderScrm order) {
|
|
|
|
|
+ if (order == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Long dfAccountId = getSFAccountIndex(order.getId());
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
|
+ params.put("orderNumber", order.getOrderCode());
|
|
|
|
|
+ params.put("mailNumber", order.getDeliveryId());
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ String response = client.execute(
|
|
|
|
|
+ RequestUrlEnum.ORDER_DELIVERY_STATUS, params, dfAccountId);
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isBlank(response)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ DFApiResponse apiResponse = JSON.parseObject(response, DFApiResponse.class);
|
|
|
|
|
+ if (apiResponse == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 运单不存在 → 取消
|
|
|
|
|
+ if ("运单不存在".equals(apiResponse.getMsg())) {
|
|
|
|
|
+ cancelOrderScrm(order);
|
|
|
|
|
+ log.info("代服管家 运单不存在,已取消订单:{}", response);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!"ok".equals(apiResponse.getCode())) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ DFOrderStatusResultRequest result = JSON.parseObject(JSON.toJSONString(apiResponse.getResult()), DFOrderStatusResultRequest.class);
|
|
|
|
|
+
|
|
|
|
|
+ if (result == null || result.getStatus() == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Integer status = result.getStatus();
|
|
|
|
|
+
|
|
|
|
|
+ // 已取消
|
|
|
|
|
+ if (status == 10) {
|
|
|
|
|
+ cancelOrderScrm(order);
|
|
|
|
|
+ log.info("代服管家 订单已取消:{}", response);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Object[] statusMapping = mapExpressStatus(status);
|
|
|
|
|
+ Integer deliveryStatus = (Integer) statusMapping[0];
|
|
|
|
|
+ String stateEx = (String) statusMapping[1];
|
|
|
|
|
+
|
|
|
|
|
+ FsStoreOrderScrm update = new FsStoreOrderScrm();
|
|
|
|
|
+ update.setId(order.getId());
|
|
|
|
|
+ update.setDeliveryStatus(deliveryStatus);
|
|
|
|
|
+ update.setDeliveryType(stateEx);
|
|
|
|
|
+ fsStoreOrderScrmMapper.updateFsStoreOrder(update);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 发送物流消息
|
|
|
|
|
+ aiSendExpressAt9And16(order, stateEx);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("查询物流状态异常,orderId={}", order.getId(), e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private void aiSendExpressAt9And16(FsStoreOrderScrm order, String stateEx) {
|
|
|
|
|
+ Long orderId = order.getId();
|
|
|
|
|
+ String signedKey = "ai:express:signed:sent:";
|
|
|
|
|
+ // 检查是否已签收
|
|
|
|
|
+ boolean signed = redisCache.sIsMember(signedKey, orderId.toString());
|
|
|
|
|
+ if ("301".equals(stateEx) && signed){
|
|
|
|
|
+ log.info("签收消息已发送过,跳过 - orderId: {}", orderId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ log.info("AI发送物流消息开始 - orderId: {}, orderCode: {}, 原始deliveryType: {}, 新stateEx: {}",
|
|
|
|
|
+ orderId, order.getOrderCode(), order.getDeliveryType(), stateEx);
|
|
|
|
|
+
|
|
|
|
|
+ // 调用金牛发送物流消息
|
|
|
|
|
+ Map<String, Object> body = new HashMap<>();
|
|
|
|
|
+ body.put("order", order);
|
|
|
|
|
+ body.put("stateEx", stateEx);
|
|
|
|
|
+ if ("2".equals(order.getStatus().toString())) {
|
|
|
|
|
+ ErpDeliverysRequest erpDeliverysRequest = new ErpDeliverysRequest();
|
|
|
|
|
+ erpDeliverysRequest.setCode(order.getOrderCode());
|
|
|
|
|
+ ErpDeliverysResponse express = getDeliver2(erpDeliverysRequest);
|
|
|
|
|
+ body.put("express",express);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 查询销售账号
|
|
|
|
|
+ String userName = companyUserMapper.getUserByid(order.getCompanyUserId());
|
|
|
|
|
+ if (StringUtils.isEmpty(userName)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ body.put("companyUserName", userName);
|
|
|
|
|
+ String result = HttpRequest.post(huyiBaseUrl + "/kntAiExpress")
|
|
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
|
|
+ .body(JSON.toJSONString(body))
|
|
|
|
|
+ .timeout(5000)
|
|
|
|
|
+ .execute()
|
|
|
|
|
+ .body();
|
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(result);
|
|
|
|
|
+ if (jsonObject.getInteger("code") == 200) {
|
|
|
|
|
+ // 设置已签收的发送标识
|
|
|
|
|
+ if ("301".equals(stateEx)){
|
|
|
|
|
+ redisCache.sAdd(signedKey, orderId.toString());
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.error("物流状态变更发送失败 - orderId: {}, stateEx: {}, result: {}", orderId, stateEx, result);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private Object[] mapExpressStatus(Integer status) {
|
|
|
|
|
+ switch (status) {
|
|
|
|
|
+ case 0:
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ return new Object[]{status, status.toString()};
|
|
|
|
|
+ case 3:
|
|
|
|
|
+ return new Object[]{2, "202"};
|
|
|
|
|
+ case 4:
|
|
|
|
|
+ return new Object[]{4, "4"};
|
|
|
|
|
+ case 5:
|
|
|
|
|
+ return new Object[]{4, "407"};
|
|
|
|
|
+ case 6:
|
|
|
|
|
+ return new Object[]{6, "406"};
|
|
|
|
|
+ case 9:
|
|
|
|
|
+ return new Object[]{3, "301"};
|
|
|
|
|
+ default:
|
|
|
|
|
+ return new Object[]{0, "0"};
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private void cancelOrderLive(LiveOrder order) {
|
|
private void cancelOrderLive(LiveOrder order) {
|
|
|
Integer deliveryStatus = order.getDeliveryStatus();
|
|
Integer deliveryStatus = order.getDeliveryStatus();
|
|
|
if (deliveryStatus == null || deliveryStatus == 0) {
|
|
if (deliveryStatus == null || deliveryStatus == 0) {
|