|
|
@@ -6,6 +6,8 @@ import com.fs.common.utils.PhoneUtils;
|
|
|
import com.fs.express.FsStoreDeliversService;
|
|
|
import com.fs.express.IExpressService;
|
|
|
import com.fs.express.dto.DeliveryDTO;
|
|
|
+import com.fs.live.domain.LiveOrder;
|
|
|
+import com.fs.live.service.ILiveOrderService;
|
|
|
import com.fs.store.domain.FsStoreDelivers;
|
|
|
import com.fs.store.domain.FsStoreOrder;
|
|
|
import com.fs.store.dto.ExpressInfoDTO;
|
|
|
@@ -14,6 +16,7 @@ import com.fs.store.mapper.FsStoreDeliversMapper;
|
|
|
import com.fs.store.service.IFsExpressService;
|
|
|
import com.fs.store.service.IFsStoreOrderService;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.apache.http.util.Asserts;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -22,10 +25,7 @@ import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -45,6 +45,9 @@ public class FsStoreDeliversServiceImpl implements FsStoreDeliversService {
|
|
|
@Autowired
|
|
|
private IFsExpressService expressService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ILiveOrderService liveOrderService;
|
|
|
+
|
|
|
@Override
|
|
|
public FsStoreDelivers findById(Integer id) {
|
|
|
return fsStoreDeliversMapper.findById(id);
|
|
|
@@ -71,12 +74,17 @@ public class FsStoreDeliversServiceImpl implements FsStoreDeliversService {
|
|
|
|
|
|
@Override
|
|
|
public List<FsStoreDelivers> findByOrderId(Long orderId) {
|
|
|
- return fsStoreDeliversMapper.findByOrderId(orderId);
|
|
|
+ return fsStoreDeliversMapper.findByOrderIdWithType(orderId,0);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<FsStoreDelivers> findByOrderIdWithType(Long orderId, Integer type) {
|
|
|
+ return fsStoreDeliversMapper.findByOrderIdWithType(orderId,type);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void finishOrder(Long orderId) {
|
|
|
- List<FsStoreDelivers> byOrderId = fsStoreDeliversMapper.findByOrderId(orderId);
|
|
|
+ List<FsStoreDelivers> byOrderId = fsStoreDeliversMapper.findByOrderIdWithType(orderId,0);
|
|
|
Set<Integer> orderStatusSet = byOrderId.stream().map(FsStoreDelivers::getStatus)
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
@@ -98,6 +106,37 @@ public class FsStoreDeliversServiceImpl implements FsStoreDeliversService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void finishOrder(Long orderId, Integer type) {
|
|
|
+
|
|
|
+ List<FsStoreDelivers> byOrderId = fsStoreDeliversMapper.findByOrderIdWithType(orderId,type);
|
|
|
+ Set<Integer> orderStatusSet = byOrderId.stream().map(FsStoreDelivers::getStatus)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+
|
|
|
+ Set<Integer> orderStateExSet = byOrderId.stream().map(FsStoreDelivers::getStateEx)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 如果订单都是已经签收
|
|
|
+ Set<Integer> finishStatusExSet = new HashSet<>();
|
|
|
+ finishStatusExSet.add(301);
|
|
|
+ finishStatusExSet.add(302);
|
|
|
+ finishStatusExSet.add(304);
|
|
|
+ finishStatusExSet.add(311);
|
|
|
+
|
|
|
+ // orderStatusSet 必须都为3
|
|
|
+ if (orderStatusSet.size() == 1 && orderStatusSet.contains(3) && finishStatusExSet.containsAll(orderStateExSet)) {
|
|
|
+ // 订单完成
|
|
|
+ if(ObjectUtil.equal(type,0)) {
|
|
|
+ orderService.finishOrder(orderId);
|
|
|
+ } else if (ObjectUtil.equal(type,1)){
|
|
|
+ liveOrderService.finishOrder(orderId);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void syncDeliverInfo(Long orderId) {
|
|
|
logger.info("开始同步订单发货信息, 订单ID: {}", orderId);
|
|
|
@@ -150,6 +189,70 @@ public class FsStoreDeliversServiceImpl implements FsStoreDeliversService {
|
|
|
logger.info("同步订单发货信息完成, 订单ID: {}", orderId);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void syncDeliverInfo(Long orderId, Integer type) {
|
|
|
+ logger.info("开始同步订单发货信息, 订单ID: {}", orderId);
|
|
|
+ String orderCode,userPhone;
|
|
|
+ if(ObjectUtil.equal(type,0)){
|
|
|
+ FsStoreOrder order = orderService.selectFsStoreOrderById(orderId);
|
|
|
+ Asserts.notNull(order,String.format("订单号 %d 类型: %d 未被找到!",orderId,type));
|
|
|
+
|
|
|
+ orderCode = order.getOrderCode();
|
|
|
+ userPhone = order.getUserPhone();
|
|
|
+ } else if(ObjectUtil.equal(type,1)){
|
|
|
+
|
|
|
+ LiveOrder liveOrder = liveOrderService.selectLiveOrderByOrderId(String.valueOf(orderId));
|
|
|
+ Asserts.notNull(liveOrder,String.format("订单号 %d 类型: %d 未被找到!",orderId,type));
|
|
|
+ orderCode = liveOrder.getOrderCode();
|
|
|
+ userPhone = liveOrder.getUserPhone();
|
|
|
+ } else {
|
|
|
+ throw new IllegalArgumentException("物流订单类型未被支持!请联系管理员!");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ logger.info("查询到订单信息, 订单号: {}", orderCode);
|
|
|
+ List<FsStoreDelivers> byOrderId = fsStoreDeliversMapper.findByOrderId(orderId);
|
|
|
+ if (byOrderId.isEmpty()) {
|
|
|
+ logger.info("订单没有发货信息, 订单ID: {}", orderId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (FsStoreDelivers fsStoreDelivers : byOrderId) {
|
|
|
+ if (ObjectUtil.isNotEmpty(fsStoreDelivers.getDeliverId())) {
|
|
|
+ logger.info("开始处理发货单, 发货单ID: {}, 快递单号: {}", fsStoreDelivers.getDeliverId(), fsStoreDelivers.getDeliverSn());
|
|
|
+ String lastFourNumber = "";
|
|
|
+ if (StringUtils.equals(fsStoreDelivers.getDeliverSn(), ShipperCodeEnum.SF.getValue())) {
|
|
|
+ lastFourNumber = PhoneUtils.getLastFourNum(userPhone);
|
|
|
+ logger.info("顺丰快递,获取手机号后四位: {}", lastFourNumber);
|
|
|
+ }
|
|
|
+ ExpressInfoDTO dto = null;
|
|
|
+ try {
|
|
|
+ // 记录HTTP请求前的信息
|
|
|
+ logger.info("开始调用快递查询接口, 订单号: {}, 快递公司编码: {}, 快递单号: {}, 手机号后四位: {}",
|
|
|
+ orderCode, fsStoreDelivers.getDeliverId(), fsStoreDelivers.getDeliverSn(), lastFourNumber);
|
|
|
+ dto = expressService.getExpressInfo(orderCode,
|
|
|
+ fsStoreDelivers.getDeliverSn(), fsStoreDelivers.getDeliverId(), lastFourNumber);
|
|
|
+ // 假设expressService.getExpressInfo内部进行了HTTP请求,你需要在expressService内部打印更详细的日志
|
|
|
+ // 这里只记录返回结果
|
|
|
+ if (ObjectUtil.isNotNull(dto)) {
|
|
|
+ logger.info("快递查询接口调用成功, 订单号: {}, 快递状态: {}, 扩展状态: {}",
|
|
|
+ orderCode, dto.getState(), dto.getStateEx());
|
|
|
+ fsStoreDelivers.setStatus(Integer.valueOf(dto.getState()));
|
|
|
+ fsStoreDelivers.setStateEx(Integer.valueOf(dto.getStateEx()));
|
|
|
+ } else {
|
|
|
+ logger.warn("快递查询接口调用成功,但返回结果为空, 订单号: {}", orderCode);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("快递查询接口调用失败, 订单号: {}, 快递单号: {}, 错误信息: {}", orderCode, fsStoreDelivers.getDeliverSn(), e.getMessage(), e);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ logger.info("发货单信息中快递ID为空, 跳过处理, 发货单ID: {}", fsStoreDelivers.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fsStoreDeliversMapper.updateBatch(byOrderId);
|
|
|
+ logger.info("同步订单发货信息完成, 订单ID: {}", orderId);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public FsStoreDelivers findByOrderCodeAndDeliverId(String deliverId) {
|
|
|
return fsStoreDeliversMapper.findByDeliverId(deliverId);
|