|
@@ -46,58 +46,9 @@ import java.util.stream.Collectors;
|
|
|
@RequiredArgsConstructor
|
|
@RequiredArgsConstructor
|
|
|
public class SalesWaybillOrderService {
|
|
public class SalesWaybillOrderService {
|
|
|
|
|
|
|
|
- private final KwtLogisticsOrderRepository logisticsOrderRepository;
|
|
|
|
|
- private final KwtLogisticsOrderCirculateRepository logisticsOrderCirculateRepository;
|
|
|
|
|
- private final KwtLogisticsOrderGoodsRepository logisticsOrderGoodsRepository;
|
|
|
|
|
- private final KwtLogisticsOrderAddressRepository logisticsOrderAddressRepository;
|
|
|
|
|
- private final KwtLogisticsOrderUnitRepository logisticsOrderUnitRepository;
|
|
|
|
|
-
|
|
|
|
|
private final KwtWaybillOrderSubtaskRepository waybillOrderSubtaskRepository;
|
|
private final KwtWaybillOrderSubtaskRepository waybillOrderSubtaskRepository;
|
|
|
- private final KwtWaybillOrderRepository waybillOrderRepository;
|
|
|
|
|
- private final KwtWaybillOrderAddressRepository waybillOrderAddressRepository;
|
|
|
|
|
- private final KwtWaybillOrderTicketRepository waybillOrderTicketRepository;
|
|
|
|
|
- private final KwtWaybillOrderNodeRepository waybillOrderNodeRepository;
|
|
|
|
|
-
|
|
|
|
|
- @DubboReference(version = "1.0.0", group = "design", check = false, timeout = 6000)
|
|
|
|
|
- RemoteSystemService remoteSystemService;
|
|
|
|
|
- @DubboReference(version = "1.0.0", group = "design", check = false, timeout = 80000)
|
|
|
|
|
- TradeOrderInfoService tradeOrderInfoService;
|
|
|
|
|
- @DubboReference(version = "1.0.0", group = "design", check = false, timeout = 6000)
|
|
|
|
|
- RemoteFleetService remoteFleetService;
|
|
|
|
|
- @DubboReference(version = "1.0.0", group = "design", check = false, timeout = 6000)
|
|
|
|
|
- GoodsInfoService goodsInfoService;
|
|
|
|
|
-
|
|
|
|
|
- private final TakingOrderHandler takingOrderHandler;
|
|
|
|
|
- private final CancelHandler cancelHandler;
|
|
|
|
|
- private final ComeIntoHandler comeIntoHandler;
|
|
|
|
|
- private final LoadingHandler loadingHandler;
|
|
|
|
|
- private final LeaveMockHandler leaveMockHandler;
|
|
|
|
|
- private final LeaveHandler leaveHandler;
|
|
|
|
|
- private final EmptyLoadLeaveHandler emptyLoadLeaveHandler;
|
|
|
|
|
- private final ReplenishHandler replenishHandler;
|
|
|
|
|
- private final LiftRodReleaseHandler liftRodReleaseHandler;
|
|
|
|
|
-
|
|
|
|
|
- private final UnloadingHandler unloadingHandler;
|
|
|
|
|
-
|
|
|
|
|
private final KwtWaybillOrderV1Service waybillOrderV1Service;
|
|
private final KwtWaybillOrderV1Service waybillOrderV1Service;
|
|
|
-
|
|
|
|
|
- // 注入RedisTemplate用于分布式锁
|
|
|
|
|
- @Resource
|
|
|
|
|
- private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
-
|
|
|
|
|
- // 分布式锁相关常量
|
|
|
|
|
- private static final String TAKING_ORDER_LOCK_PREFIX = "transport:taking_order:lock:";
|
|
|
|
|
- // 锁超时时间30秒
|
|
|
|
|
- private static final long LOCK_EXPIRE_SECONDS = 30;
|
|
|
|
|
- // 锁等待时间500毫秒
|
|
|
|
|
- private static final long LOCK_WAIT_MILLIS = 500;
|
|
|
|
|
- // 锁重试间隔100毫秒
|
|
|
|
|
- private static final long LOCK_RETRY_INTERVAL = 100;
|
|
|
|
|
-
|
|
|
|
|
- //载重任务量浮动吨数
|
|
|
|
|
- private static final BigDecimal TWO_TONS = new BigDecimal("2");
|
|
|
|
|
- //载重任务量计算比例
|
|
|
|
|
- private static final BigDecimal EIGHTY_PERCENT = new BigDecimal("0.8");
|
|
|
|
|
|
|
+ private final KwtGatekeeperWaybillOrderRepository gatekeeperWaybillOrderRepository;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 查询销售数据
|
|
* 查询销售数据
|
|
@@ -108,7 +59,7 @@ public class SalesWaybillOrderService {
|
|
|
log.info("查询销售数据:{}", JSON.toJSONString(param));
|
|
log.info("查询销售数据:{}", JSON.toJSONString(param));
|
|
|
SalesWaybillOrderResp salesResp = new SalesWaybillOrderResp();
|
|
SalesWaybillOrderResp salesResp = new SalesWaybillOrderResp();
|
|
|
// 1. 计算执行中订单(物流订单)
|
|
// 1. 计算执行中订单(物流订单)
|
|
|
- calOngoingLogOrder(param, salesResp);
|
|
|
|
|
|
|
+ calOngoingLogOrderCount(param, salesResp);
|
|
|
|
|
|
|
|
// 2.计算今日车次
|
|
// 2.计算今日车次
|
|
|
calTodayTruckCount(param, salesResp);
|
|
calTodayTruckCount(param, salesResp);
|
|
@@ -127,12 +78,12 @@ public class SalesWaybillOrderService {
|
|
|
* @param param
|
|
* @param param
|
|
|
* @param salesResp
|
|
* @param salesResp
|
|
|
*/
|
|
*/
|
|
|
- private void calOngoingLogOrder(SalesWaybillOrderQueryParam param, SalesWaybillOrderResp salesResp) {
|
|
|
|
|
|
|
+ private void calOngoingLogOrderCount(SalesWaybillOrderQueryParam param, SalesWaybillOrderResp salesResp) {
|
|
|
WaybillOrderReq req = new WaybillOrderReq();
|
|
WaybillOrderReq req = new WaybillOrderReq();
|
|
|
req.setEntId(String.valueOf(param.getEntId()));
|
|
req.setEntId(String.valueOf(param.getEntId()));
|
|
|
StatisticsWaybillResp statisticsWaybillResp = waybillOrderV1Service.statisticsWaybillOrder(req);
|
|
StatisticsWaybillResp statisticsWaybillResp = waybillOrderV1Service.statisticsWaybillOrder(req);
|
|
|
if (statisticsWaybillResp == null) {
|
|
if (statisticsWaybillResp == null) {
|
|
|
- salesResp.setOngoingLogOrder(Global.NUMERICAL_ZERO);
|
|
|
|
|
|
|
+ salesResp.setOngoingLogOrderCount(Global.NUMERICAL_ZERO);
|
|
|
}
|
|
}
|
|
|
List<String> targetStatus = List.of("5", "10", "15");
|
|
List<String> targetStatus = List.of("5", "10", "15");
|
|
|
List<StatisticsWaybillResp.OrderBillStatusStatistics> orderStatusStatistics = statisticsWaybillResp.getOrderStatusStatistics();
|
|
List<StatisticsWaybillResp.OrderBillStatusStatistics> orderStatusStatistics = statisticsWaybillResp.getOrderStatusStatistics();
|
|
@@ -146,7 +97,7 @@ public class SalesWaybillOrderService {
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
.sum();
|
|
.sum();
|
|
|
- salesResp.setOngoingLogOrder(ongoingLogOrder);
|
|
|
|
|
|
|
+ salesResp.setOngoingLogOrderCount(ongoingLogOrder);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -155,79 +106,102 @@ public class SalesWaybillOrderService {
|
|
|
* @param salesResp
|
|
* @param salesResp
|
|
|
*/
|
|
*/
|
|
|
private void calTodayTruckCount(SalesWaybillOrderQueryParam param, SalesWaybillOrderResp salesResp) {
|
|
private void calTodayTruckCount(SalesWaybillOrderQueryParam param, SalesWaybillOrderResp salesResp) {
|
|
|
- //今日车次
|
|
|
|
|
- LocalDateTime todayStart = LocalDate.now().atStartOfDay(); // 今天 00:00:00
|
|
|
|
|
|
|
+ //今日车次/出货量
|
|
|
|
|
+ todayTruckCount(param, salesResp);
|
|
|
|
|
+ //本月出货量
|
|
|
|
|
+ monthShipmentWeightCount(param, salesResp);
|
|
|
|
|
+ //近7天出货量
|
|
|
|
|
+ recentSevenDayShipmentCount(param, salesResp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 今日车次/出货量
|
|
|
|
|
+ * @param param
|
|
|
|
|
+ * @param salesResp
|
|
|
|
|
+ */
|
|
|
|
|
+ private void todayTruckCount(SalesWaybillOrderQueryParam param, SalesWaybillOrderResp salesResp) {
|
|
|
|
|
+ // 今天 00:00:00
|
|
|
|
|
+ LocalDateTime todayStart = LocalDate.now().atStartOfDay();
|
|
|
|
|
+ // 今天 23:59:59
|
|
|
LocalDateTime todayEnd = LocalDate.now().atTime(23, 59, 59);
|
|
LocalDateTime todayEnd = LocalDate.now().atTime(23, 59, 59);
|
|
|
- List<KwtWaybillOrderSubtask> todayTruckCount = waybillOrderSubtaskRepository
|
|
|
|
|
|
|
+ List<KwtWaybillOrderSubtask> todayWaybillOrderSub = waybillOrderSubtaskRepository
|
|
|
.queryWaybillOrderSubByEntIdAndStatus(param.getEntId(), CarWaybillV1Enum.COMPLETED.getCode(), todayStart, todayEnd);
|
|
.queryWaybillOrderSubByEntIdAndStatus(param.getEntId(), CarWaybillV1Enum.COMPLETED.getCode(), todayStart, todayEnd);
|
|
|
- if (CollectionUtils.isEmpty(todayTruckCount)) {
|
|
|
|
|
|
|
+ if (CollectionUtils.isEmpty(todayWaybillOrderSub)) {
|
|
|
salesResp.setTodayTruckCount(Global.NUMERICAL_ZERO);
|
|
salesResp.setTodayTruckCount(Global.NUMERICAL_ZERO);
|
|
|
- salesResp.setTodayShipmentWeight(BigDecimal.ZERO);
|
|
|
|
|
|
|
+ salesResp.setTodayShipmentWeightCount(BigDecimal.ZERO);
|
|
|
}
|
|
}
|
|
|
//今日车次
|
|
//今日车次
|
|
|
- salesResp.setTodayTruckCount(todayTruckCount.size());
|
|
|
|
|
|
|
+ salesResp.setTodayTruckCount(todayWaybillOrderSub.size());
|
|
|
//今日出货量
|
|
//今日出货量
|
|
|
- BigDecimal todayLoadAmount = todayTruckCount.stream()
|
|
|
|
|
|
|
+ BigDecimal todayLoadAmount = todayWaybillOrderSub.stream()
|
|
|
.filter(sub -> sub.getLoadAmount() != null)
|
|
.filter(sub -> sub.getLoadAmount() != null)
|
|
|
.map(KwtWaybillOrderSubtask::getLoadAmount)
|
|
.map(KwtWaybillOrderSubtask::getLoadAmount)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- salesResp.setTodayShipmentWeight(todayLoadAmount);
|
|
|
|
|
|
|
+ salesResp.setTodayShipmentWeightCount(todayLoadAmount);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- //本月出货量
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 本月出货量
|
|
|
|
|
+ * @param param
|
|
|
|
|
+ * @param salesResp
|
|
|
|
|
+ */
|
|
|
|
|
+ private void monthShipmentWeightCount(SalesWaybillOrderQueryParam param, SalesWaybillOrderResp salesResp) {
|
|
|
|
|
+ // 本月第一天 00:00:00
|
|
|
LocalDateTime monthStart = LocalDate.now().withDayOfMonth(1).atStartOfDay();
|
|
LocalDateTime monthStart = LocalDate.now().withDayOfMonth(1).atStartOfDay();
|
|
|
|
|
+ // 本月最后一天 23:59:59
|
|
|
LocalDateTime monthEnd = LocalDate.now().withDayOfMonth(LocalDate.now().lengthOfMonth()).atTime(23, 59, 59);
|
|
LocalDateTime monthEnd = LocalDate.now().withDayOfMonth(LocalDate.now().lengthOfMonth()).atTime(23, 59, 59);
|
|
|
- List<KwtWaybillOrderSubtask> monthShipmentWeight = waybillOrderSubtaskRepository
|
|
|
|
|
|
|
+ List<KwtWaybillOrderSubtask> monthWaybillOrderSub = waybillOrderSubtaskRepository
|
|
|
.queryWaybillOrderSubByEntIdAndStatus(param.getEntId(), CarWaybillV1Enum.COMPLETED.getCode(), monthStart, monthEnd);
|
|
.queryWaybillOrderSubByEntIdAndStatus(param.getEntId(), CarWaybillV1Enum.COMPLETED.getCode(), monthStart, monthEnd);
|
|
|
- if (CollectionUtils.isEmpty(todayTruckCount)) {
|
|
|
|
|
- salesResp.setMonthShipmentWeight(BigDecimal.ZERO);
|
|
|
|
|
|
|
+ if (CollectionUtils.isEmpty(monthWaybillOrderSub)) {
|
|
|
|
|
+ salesResp.setMonthShipmentWeightCount(BigDecimal.ZERO);
|
|
|
}
|
|
}
|
|
|
//本月出货量
|
|
//本月出货量
|
|
|
- BigDecimal monthLoadAmount = todayTruckCount.stream()
|
|
|
|
|
|
|
+ BigDecimal monthLoadAmount = monthWaybillOrderSub.stream()
|
|
|
.filter(sub -> sub.getLoadAmount() != null)
|
|
.filter(sub -> sub.getLoadAmount() != null)
|
|
|
.map(KwtWaybillOrderSubtask::getLoadAmount)
|
|
.map(KwtWaybillOrderSubtask::getLoadAmount)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- salesResp.setTodayShipmentWeight(monthLoadAmount);
|
|
|
|
|
|
|
+ salesResp.setMonthShipmentWeightCount(monthLoadAmount);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 1. 定义时间范围:近7天(包含今天)
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 近7天出货量
|
|
|
|
|
+ * @param param
|
|
|
|
|
+ * @param salesResp
|
|
|
|
|
+ */
|
|
|
|
|
+ private void recentSevenDayShipmentCount(SalesWaybillOrderQueryParam param, SalesWaybillOrderResp salesResp) {
|
|
|
|
|
+ // 7天前 00:00:00
|
|
|
LocalDate today = LocalDate.now();
|
|
LocalDate today = LocalDate.now();
|
|
|
- LocalDateTime sevenDaysStartTime = today.minusDays(6).atStartOfDay(); // 7天前 00:00:00
|
|
|
|
|
- LocalDateTime sevenDaysEndTime = today.atTime(23, 59, 59); // 今天 23:59:59
|
|
|
|
|
|
|
+ LocalDateTime sevenDaysStartTime = today.minusDays(6).atStartOfDay();
|
|
|
|
|
+ // 今天 23:59:59
|
|
|
|
|
+ LocalDateTime sevenDaysEndTime = today.atTime(23, 59, 59);
|
|
|
|
|
|
|
|
- // 2. 查询数据库:获取近7天的所有已完成子运单数据
|
|
|
|
|
- List<KwtWaybillOrderSubtask> subtaskList = waybillOrderSubtaskRepository
|
|
|
|
|
|
|
+ // 查询数据库,获取近7天的所有已完成子运单数据
|
|
|
|
|
+ List<KwtWaybillOrderSubtask> sevenDayWaybillOrderSubtask = waybillOrderSubtaskRepository
|
|
|
.queryWaybillOrderSubByEntIdAndStatus(param.getEntId(), CarWaybillV1Enum.COMPLETED.getCode(), sevenDaysStartTime, sevenDaysEndTime);
|
|
.queryWaybillOrderSubByEntIdAndStatus(param.getEntId(), CarWaybillV1Enum.COMPLETED.getCode(), sevenDaysStartTime, sevenDaysEndTime);
|
|
|
|
|
|
|
|
- // 3. 内存分组统计:按“日期”聚合求和
|
|
|
|
|
- // 结果格式:Map<"2026-04-23", 100.5>
|
|
|
|
|
- Map<String, BigDecimal> dailyWeightMap = subtaskList.stream()
|
|
|
|
|
- .filter(task -> task.getLoadAmount() != null) // 过滤空值
|
|
|
|
|
|
|
+ // 分组统计,按日期聚合求和
|
|
|
|
|
+ Map<String, BigDecimal> dailyWeightMap = sevenDayWaybillOrderSubtask.stream()
|
|
|
|
|
+ .filter(task -> task.getLoadAmount() != null)
|
|
|
.collect(Collectors.groupingBy(
|
|
.collect(Collectors.groupingBy(
|
|
|
- // 关键:按创建时间的日期部分分组 (yyyy-MM-dd)
|
|
|
|
|
- task -> java.time.LocalDateTime.ofInstant(task.getCreateTime().toInstant(),
|
|
|
|
|
|
|
+ task -> LocalDateTime.ofInstant(task.getCreateTime().toInstant(),
|
|
|
java.time.ZoneId.systemDefault()).toLocalDate().toString(),
|
|
java.time.ZoneId.systemDefault()).toLocalDate().toString(),
|
|
|
- // 求和
|
|
|
|
|
Collectors.mapping(KwtWaybillOrderSubtask::getLoadAmount, Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))
|
|
Collectors.mapping(KwtWaybillOrderSubtask::getLoadAmount, Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))
|
|
|
));
|
|
));
|
|
|
|
|
|
|
|
- // 4. 构建前端需要的 VO 列表(按时间顺序,并补全缺失日期的0值)
|
|
|
|
|
- List<SalesWaybillOrderResp.RecentSevenDaysShipmentVO> resultVOs = new ArrayList<>();
|
|
|
|
|
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
|
-
|
|
|
|
|
|
|
+ // 构建VO列表,按时间顺序,并补全缺失日期
|
|
|
|
|
+ List<SalesWaybillOrderResp.RecentSevenDayShipmentVO> resultVOs = new ArrayList<>();
|
|
|
for (int i = 6; i >= 0; i--) {
|
|
for (int i = 6; i >= 0; i--) {
|
|
|
- // 倒序循环:从6天前遍历到今天,保证列表是按时间正序排列
|
|
|
|
|
|
|
+ // 时间正序排列
|
|
|
LocalDate date = today.minusDays(i);
|
|
LocalDate date = today.minusDays(i);
|
|
|
- String dateStr = date.format(formatter);
|
|
|
|
|
-
|
|
|
|
|
- // 从 Map 中获取当天的重量,如果没有数据则默认为 0
|
|
|
|
|
|
|
+ String dateStr = date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
BigDecimal weight = dailyWeightMap.getOrDefault(dateStr, BigDecimal.ZERO);
|
|
BigDecimal weight = dailyWeightMap.getOrDefault(dateStr, BigDecimal.ZERO);
|
|
|
|
|
|
|
|
- SalesWaybillOrderResp.RecentSevenDaysShipmentVO vo = new SalesWaybillOrderResp.RecentSevenDaysShipmentVO();
|
|
|
|
|
|
|
+ SalesWaybillOrderResp.RecentSevenDayShipmentVO vo = new SalesWaybillOrderResp.RecentSevenDayShipmentVO();
|
|
|
vo.setDate(dateStr);
|
|
vo.setDate(dateStr);
|
|
|
vo.setShipmentWeight(weight);
|
|
vo.setShipmentWeight(weight);
|
|
|
-
|
|
|
|
|
resultVOs.add(vo);
|
|
resultVOs.add(vo);
|
|
|
}
|
|
}
|
|
|
- salesResp.setRecentSevenDaysShipmentVOs(resultVOs);
|
|
|
|
|
|
|
+ salesResp.setRecentSevenDayShipmentCountVOs(resultVOs);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|