|
@@ -1,12 +1,19 @@
|
|
|
package com.sckw.transport.dubbo;
|
|
package com.sckw.transport.dubbo;
|
|
|
|
|
|
|
|
-import com.sckw.core.model.constant.NumberConstant;
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.sckw.core.exception.BusinessException;
|
|
import com.sckw.core.exception.BusinessException;
|
|
|
|
|
+import com.sckw.core.model.constant.Global;
|
|
|
|
|
+import com.sckw.core.model.constant.NumberConstant;
|
|
|
import com.sckw.core.model.enums.CarWaybillEnum;
|
|
import com.sckw.core.model.enums.CarWaybillEnum;
|
|
|
|
|
+import com.sckw.core.model.enums.CarWaybillV1Enum;
|
|
|
import com.sckw.core.model.enums.LogisticsOrderEnum;
|
|
import com.sckw.core.model.enums.LogisticsOrderEnum;
|
|
|
import com.sckw.transport.api.dubbo.TransportRemoteStatisticsService;
|
|
import com.sckw.transport.api.dubbo.TransportRemoteStatisticsService;
|
|
|
import com.sckw.transport.dao.KwtLogisticsOrderMapper;
|
|
import com.sckw.transport.dao.KwtLogisticsOrderMapper;
|
|
|
import com.sckw.transport.dao.KwtWaybillOrderMapper;
|
|
import com.sckw.transport.dao.KwtWaybillOrderMapper;
|
|
|
|
|
+import com.sckw.transport.dao.KwtWaybillOrderSubtaskMapper;
|
|
|
|
|
+import com.sckw.transport.model.KwtLogisticsOrder;
|
|
|
|
|
+import com.sckw.transport.model.KwtWaybillOrder;
|
|
|
|
|
+import com.sckw.transport.model.KwtWaybillOrderSubtask;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboService;
|
|
import org.apache.dubbo.config.annotation.DubboService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -15,7 +22,10 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.ZoneId;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
|
+import java.util.Collections;
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
import java.util.Optional;
|
|
import java.util.Optional;
|
|
@@ -37,6 +47,9 @@ public class TransportStatisticsServiceImpl implements TransportRemoteStatistics
|
|
|
@Autowired
|
|
@Autowired
|
|
|
KwtLogisticsOrderMapper logisticsOrderMapper;
|
|
KwtLogisticsOrderMapper logisticsOrderMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ KwtWaybillOrderSubtaskMapper waybillOrderSubtaskMapper;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 统计调度派车次数
|
|
* 统计调度派车次数
|
|
|
*
|
|
*
|
|
@@ -142,7 +155,14 @@ public class TransportStatisticsServiceImpl implements TransportRemoteStatistics
|
|
|
if (Objects.isNull(tradeOrderId)) {
|
|
if (Objects.isNull(tradeOrderId)) {
|
|
|
throw new BusinessException("贸易订单ID不能为空");
|
|
throw new BusinessException("贸易订单ID不能为空");
|
|
|
}
|
|
}
|
|
|
- return Optional.ofNullable(logisticsOrderMapper.countDispatchedWaybillsByTradeOrderId(tradeOrderId))
|
|
|
|
|
|
|
+ List<Long> logisticsOrderIds = listLogisticsOrderIdsByTradeOrderId(tradeOrderId);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(logisticsOrderIds)) {
|
|
|
|
|
+ return 0L;
|
|
|
|
|
+ }
|
|
|
|
|
+ return Optional.ofNullable(waybillOrderMapper.selectCount(new QueryWrapper<KwtWaybillOrder>()
|
|
|
|
|
+ .eq("del_flag", Global.NO)
|
|
|
|
|
+ .in("l_order_id", logisticsOrderIds)
|
|
|
|
|
+ .ne("status", CarWaybillV1Enum.CANCELLED.getCode())))
|
|
|
.orElse(0L);
|
|
.orElse(0L);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -164,8 +184,79 @@ public class TransportStatisticsServiceImpl implements TransportRemoteStatistics
|
|
|
if (Objects.isNull(chargeType)) {
|
|
if (Objects.isNull(chargeType)) {
|
|
|
throw new BusinessException("计费方式不能为空");
|
|
throw new BusinessException("计费方式不能为空");
|
|
|
}
|
|
}
|
|
|
- return Optional.ofNullable(logisticsOrderMapper.sumCompletedWaybillVolumeByTimeRange(
|
|
|
|
|
- tradeOrderId, chargeType, startTime, endTime))
|
|
|
|
|
- .orElse(BigDecimal.ZERO);
|
|
|
|
|
|
|
+ if (!Objects.equals(chargeType, NumberConstant.ONE) && !Objects.equals(chargeType, NumberConstant.TWO)) {
|
|
|
|
|
+ return BigDecimal.ZERO;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Long> logisticsOrderIds = listLogisticsOrderIdsByTradeOrderId(tradeOrderId);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(logisticsOrderIds)) {
|
|
|
|
|
+ return BigDecimal.ZERO;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ QueryWrapper<KwtWaybillOrder> waybillWrapper = new QueryWrapper<KwtWaybillOrder>()
|
|
|
|
|
+ .select("id")
|
|
|
|
|
+ .eq("del_flag", Global.NO)
|
|
|
|
|
+ .in("l_order_id", logisticsOrderIds)
|
|
|
|
|
+ .eq("status", CarWaybillV1Enum.COMPLETED.getCode());
|
|
|
|
|
+ if (Objects.nonNull(startTime) && Objects.nonNull(endTime)) {
|
|
|
|
|
+ waybillWrapper.ge("update_time", toDate(startTime))
|
|
|
|
|
+ .lt("update_time", toDate(endTime));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<Long> waybillOrderIds = Optional.ofNullable(waybillOrderMapper.selectList(waybillWrapper))
|
|
|
|
|
+ .orElse(Collections.emptyList())
|
|
|
|
|
+ .stream()
|
|
|
|
|
+ .map(KwtWaybillOrder::getId)
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .distinct()
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ if (CollectionUtils.isEmpty(waybillOrderIds)) {
|
|
|
|
|
+ return BigDecimal.ZERO;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ QueryWrapper<KwtWaybillOrderSubtask> subtaskWrapper = new QueryWrapper<KwtWaybillOrderSubtask>()
|
|
|
|
|
+ .eq("del_flag", Global.NO)
|
|
|
|
|
+ .in("w_order_id", waybillOrderIds);
|
|
|
|
|
+ if (Objects.equals(chargeType, NumberConstant.ONE)) {
|
|
|
|
|
+ subtaskWrapper.select("load_amount")
|
|
|
|
|
+ .isNotNull("load_amount");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ subtaskWrapper.select("unload_amount")
|
|
|
|
|
+ .isNotNull("unload_amount");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return Optional.ofNullable(waybillOrderSubtaskMapper.selectList(subtaskWrapper))
|
|
|
|
|
+ .orElse(Collections.emptyList())
|
|
|
|
|
+ .stream()
|
|
|
|
|
+ .map(item -> Objects.equals(chargeType, NumberConstant.ONE) ? item.getLoadAmount() : item.getUnloadAmount())
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据贸易订单ID查询有效物流订单ID列表,统一复用 MyBatis-Plus 查询条件,避免手写SQL。
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param tradeOrderId 贸易订单ID
|
|
|
|
|
+ * @return 有效物流订单ID列表
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<Long> listLogisticsOrderIdsByTradeOrderId(Long tradeOrderId) {
|
|
|
|
|
+ return Optional.ofNullable(logisticsOrderMapper.selectList(new QueryWrapper<KwtLogisticsOrder>()
|
|
|
|
|
+ .select("id")
|
|
|
|
|
+ .eq("del_flag", Global.NO)
|
|
|
|
|
+ .eq("t_order_id", tradeOrderId)))
|
|
|
|
|
+ .orElse(Collections.emptyList())
|
|
|
|
|
+ .stream()
|
|
|
|
|
+ .map(KwtLogisticsOrder::getId)
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .distinct()
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * LocalDateTime 转 Date,保持与数据库时间字段类型一致。
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param dateTime 本地日期时间
|
|
|
|
|
+ * @return Date时间
|
|
|
|
|
+ */
|
|
|
|
|
+ private Date toDate(LocalDateTime dateTime) {
|
|
|
|
|
+ return Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|