Commit daf6bdcccdbcad3f2c853f247385ca428a7ca4ce

Authored by 房远帅
1 parent 60729944

发货计划:后日预发是的时候默认填写发货时点(10:00),在第二天创建明日预发数据时自动带入发货时点

... ... @@ -336,9 +336,9 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP
336 336 List<PurchaseOrderLine> orderLineList = purchaseOrderLineService.listByShipmentDate(dateList, false);
337 337 // 获取订货单数据
338 338 Map<String, PurchaseOrderInfo> orderInfoMap = new HashMap<>();
  339 + List<String> orderIds = new ArrayList<>();
  340 + List<String> orderSpecIds = new ArrayList<>();
339 341 if (CollectionUtils.isNotEmpty(orderLineList)) {
340   - List<String> orderIds = new ArrayList<>();
341   - List<String> orderSpecIds = new ArrayList<>();
342 342 // 获取发货明细
343 343 for (PurchaseOrderLine orderLine : orderLineList) {
344 344 orderSpecIds.add(orderLine.getId());
... ... @@ -376,6 +376,30 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP
376 376 shipmentsPlanService.getBaseMapper().insert(plan);
377 377 // 生成发货计划明细
378 378 if (CollectionUtils.isNotEmpty(orderLineList)) {
  379 + // 不考虑分厂:昨天(D-1)的定时任务里写入的后日预发(preShipments=true),其 shipmentsDate = 昨天后日 = (D-1)+2 = D+1 = tomorrow
  380 + // 因此今天生成明日预发明细(shipmentsDate=tomorrow)时,按同一 orderSpecId 在 shipmentsDate=tomorrow + preShipments=true + canShipments=YES 的记录里取 shipmentsTime
  381 + Map<String, LocalTime> shipmentsTimeMap = new HashMap<>();
  382 + if (CollectionUtils.isNotEmpty(orderSpecIds)) {
  383 + LambdaQueryWrapper<ShipmentsPlanDetail> preQueryWrapper = Wrappers.lambdaQuery(ShipmentsPlanDetail.class);
  384 + preQueryWrapper.in(ShipmentsPlanDetail::getOrderSpecId, orderSpecIds)
  385 + .eq(ShipmentsPlanDetail::getDelFlag, Boolean.FALSE)
  386 + .eq(ShipmentsPlanDetail::getPreShipments, Boolean.TRUE)
  387 + .eq(ShipmentsPlanDetail::getCanShipments, Boolean.TRUE)
  388 + .eq(ShipmentsPlanDetail::getShipmentsDate, tomorrow)
  389 + .isNotNull(ShipmentsPlanDetail::getShipmentsTime);
  390 + List<ShipmentsPlanDetail> preDetailList = getBaseMapper().selectList(preQueryWrapper);
  391 + if (CollectionUtils.isNotEmpty(preDetailList)) {
  392 + // 同一 orderSpecId 取创建时间最新的一条发货时点
  393 + preDetailList.sort(Comparator.comparing(ShipmentsPlanDetail::getUpdateTime,
  394 + Comparator.nullsLast(Comparator.naturalOrder())).reversed());
  395 + for (ShipmentsPlanDetail preDetail : preDetailList) {
  396 + if (StringUtils.isBlank(preDetail.getOrderSpecId()) || preDetail.getShipmentsTime() == null) {
  397 + continue;
  398 + }
  399 + shipmentsTimeMap.putIfAbsent(preDetail.getOrderSpecId(), preDetail.getShipmentsTime());
  400 + }
  401 + }
  402 + }
379 403 List<ShipmentsPlanDetail> planDetails = new ArrayList<>();
380 404 for (PurchaseOrderLine line : orderLineList) {
381 405 ShipmentsPlanDetail detail = new ShipmentsPlanDetail();
... ... @@ -408,7 +432,13 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP
408 432 detail.setDelFlag(Boolean.FALSE);
409 433 detail.setCreateById("1");
410 434 detail.setUpdateById("1");
411   -
  435 + // 新建「明日预发」明细时:前一天的后日预发里若 canShipments=YES,自动带入原发货时点
  436 + if (Boolean.FALSE.equals(detail.getPreShipments())) {
  437 + LocalTime shipmentsTime = shipmentsTimeMap.get(line.getId());
  438 + if (shipmentsTime != null) {
  439 + detail.setShipmentsTime(shipmentsTime);
  440 + }
  441 + }
412 442 planDetails.add(detail);
413 443 }
414 444 if (CollectionUtils.isNotEmpty(planDetails)) {
... ... @@ -489,6 +519,30 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP
489 519 }
490 520
491 521 // 6. 生成发货计划明细,加入明日预发
  522 + // 不考虑分厂:昨天(D-1)的定时任务里写入的后日预发(preShipments=true),其 shipmentsDate = 昨天后日 = (D-1)+2 = D+1 = tomorrow
  523 + // 因此今天生成明日预发明细(shipmentsDate=tomorrow)时,按同一 orderSpecId 在 shipmentsDate=tomorrow + preShipments=true + canShipments=YES 的记录里取 shipmentsTime
  524 + Map<String, LocalTime> shipmentsTimeMap = new HashMap<>();
  525 + if (CollectionUtils.isNotEmpty(specIds)) {
  526 + LambdaQueryWrapper<ShipmentsPlanDetail> preQueryWrapper = Wrappers.lambdaQuery(ShipmentsPlanDetail.class);
  527 + preQueryWrapper.in(ShipmentsPlanDetail::getOrderSpecId, specIds)
  528 + .eq(ShipmentsPlanDetail::getDelFlag, Boolean.FALSE)
  529 + .eq(ShipmentsPlanDetail::getPreShipments, Boolean.TRUE)
  530 + .eq(ShipmentsPlanDetail::getCanShipments, Boolean.TRUE)
  531 + .eq(ShipmentsPlanDetail::getShipmentsDate, tomorrow)
  532 + .isNotNull(ShipmentsPlanDetail::getShipmentsTime);
  533 + List<ShipmentsPlanDetail> preDetailList = getBaseMapper().selectList(preQueryWrapper);
  534 + if (CollectionUtils.isNotEmpty(preDetailList)) {
  535 + preDetailList.sort(Comparator.comparing(ShipmentsPlanDetail::getUpdateTime,
  536 + Comparator.nullsLast(Comparator.naturalOrder())).reversed());
  537 + for (ShipmentsPlanDetail preDetail : preDetailList) {
  538 + if (StringUtils.isBlank(preDetail.getOrderSpecId()) || preDetail.getShipmentsTime() == null) {
  539 + continue;
  540 + }
  541 + shipmentsTimeMap.putIfAbsent(preDetail.getOrderSpecId(), preDetail.getShipmentsTime());
  542 + }
  543 + }
  544 + }
  545 + // 6. 生成发货计划明细,加入明日预发
492 546 List<ShipmentsPlanDetail> planDetails = new ArrayList<>();
493 547 for (PurchaseOrderLine line : orderLines) {
494 548 ShipmentsPlanDetail detail = new ShipmentsPlanDetail();
... ... @@ -501,7 +555,10 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP
501 555 detail.setDelFlag(Boolean.FALSE);
502 556 detail.setCreateById("1");
503 557 detail.setUpdateById("1");
504   -
  558 + LocalTime shipmentsTime = shipmentsTimeMap.get(line.getId());
  559 + if (shipmentsTime != null) {
  560 + detail.setShipmentsTime(shipmentsTime);
  561 + }
505 562 planDetails.add(detail);
506 563 }
507 564 if (CollectionUtils.isNotEmpty(planDetails)) {
... ...