|
...
|
...
|
@@ -371,6 +371,7 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP |
|
371
|
371
|
plan.setWorkshopId(workshop.getId());
|
|
372
|
372
|
plan.setTomoPreShipDate(tomorrow);
|
|
373
|
373
|
plan.setAfTomoPreShipDate(afTomorrow);
|
|
|
374
|
+ plan.setAutoGenerate(Boolean.TRUE);
|
|
374
|
375
|
|
|
375
|
376
|
shipmentsPlanService.getBaseMapper().insert(plan);
|
|
376
|
377
|
// 生成发货计划明细
|
|
...
|
...
|
@@ -417,6 +418,97 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP |
|
417
|
418
|
}
|
|
418
|
419
|
}
|
|
419
|
420
|
|
|
|
421
|
+ @Override
|
|
|
422
|
+ public void autoCreateShipmentPlanFromApply(String purchaseOrderId, String workshopId) {
|
|
|
423
|
+ // 1. 获取订货单数据
|
|
|
424
|
+ PurchaseOrderInfo orderInfo = purchaseOrderInfoService.findById(purchaseOrderId);
|
|
|
425
|
+ if (orderInfo == null) {
|
|
|
426
|
+ return;
|
|
|
427
|
+ }
|
|
|
428
|
+
|
|
|
429
|
+ // 2. 过滤不需要发货的数据(参考autoCreateShipmentPlan逻辑)
|
|
|
430
|
+ String type = orderInfo.getType();
|
|
|
431
|
+ String examineStatus = orderInfo.getExamineStatus();
|
|
|
432
|
+ String status = orderInfo.getStatus();
|
|
|
433
|
+ String revokeStatus = orderInfo.getRevokeStatus();
|
|
|
434
|
+ String specChangeStatus = orderInfo.getSpecChangeStatus();
|
|
|
435
|
+ if (!"PRODUCTION".equals(type) || !"PASS".equals(examineStatus)
|
|
|
436
|
+ || "SHIPPED".equals(status) || "DELIVERED".equals(status) || "CANCEL".equals(status)
|
|
|
437
|
+ || "UNDOING".equals(revokeStatus) || "IN_PROGRESS".equals(specChangeStatus)) {
|
|
|
438
|
+ return;
|
|
|
439
|
+ }
|
|
|
440
|
+
|
|
|
441
|
+ // 3. 获取订货单规格
|
|
|
442
|
+ List<PurchaseOrderLine> orderLines = purchaseOrderLineService.listByOrderIds(Collections.singletonList(purchaseOrderId), false);
|
|
|
443
|
+ if (CollectionUtils.isEmpty(orderLines)) {
|
|
|
444
|
+ return;
|
|
|
445
|
+ }
|
|
|
446
|
+
|
|
|
447
|
+ // 4. 过滤已在发货计划中的数据(明日预发的数据)
|
|
|
448
|
+ List<String> specIds = orderLines.stream().map(PurchaseOrderLine::getId).collect(Collectors.toList());
|
|
|
449
|
+ LambdaQueryWrapper<ShipmentsPlanDetail> queryWrapper = Wrappers.lambdaQuery(ShipmentsPlanDetail.class);
|
|
|
450
|
+ queryWrapper.in(ShipmentsPlanDetail::getOrderSpecId, specIds)
|
|
|
451
|
+ .eq(ShipmentsPlanDetail::getDelFlag, Boolean.FALSE)
|
|
|
452
|
+ .eq(ShipmentsPlanDetail::getPreShipments, Boolean.FALSE);
|
|
|
453
|
+ List<ShipmentsPlanDetail> existingDetails = getBaseMapper().selectList(queryWrapper);
|
|
|
454
|
+ if (CollectionUtils.isNotEmpty(existingDetails)) {
|
|
|
455
|
+ // 过滤掉已在发货计划中的规格
|
|
|
456
|
+ List<String> existingSpecIds = existingDetails.stream()
|
|
|
457
|
+ .map(ShipmentsPlanDetail::getOrderSpecId).distinct().collect(Collectors.toList());
|
|
|
458
|
+ orderLines.removeIf(next -> existingSpecIds.contains(next.getId()));
|
|
|
459
|
+ }
|
|
|
460
|
+ if (CollectionUtils.isEmpty(orderLines)) {
|
|
|
461
|
+ return;
|
|
|
462
|
+ }
|
|
|
463
|
+
|
|
|
464
|
+ // 5. 查找30分钟内同分厂的申请发货计划
|
|
|
465
|
+ LocalDateTime thirtyMinutesAgo = LocalDateTime.now().minusMinutes(30);
|
|
|
466
|
+ LambdaQueryWrapper<ShipmentsPlan> planQueryWrapper = Wrappers.lambdaQuery(ShipmentsPlan.class);
|
|
|
467
|
+ planQueryWrapper.eq(ShipmentsPlan::getWorkshopId, workshopId)
|
|
|
468
|
+ .eq(ShipmentsPlan::getSource, "APPLY_SHIPMENT")
|
|
|
469
|
+ .eq(ShipmentsPlan::getStatus, "DRAFT")
|
|
|
470
|
+ .ge(ShipmentsPlan::getCreateTime, thirtyMinutesAgo);
|
|
|
471
|
+ List<ShipmentsPlan> existingPlans = shipmentsPlanService.getBaseMapper().selectList(planQueryWrapper);
|
|
|
472
|
+
|
|
|
473
|
+ ShipmentsPlan plan;
|
|
|
474
|
+ LocalDate tomorrow = LocalDate.now().plusDays(1);
|
|
|
475
|
+ if (CollectionUtils.isNotEmpty(existingPlans)) {
|
|
|
476
|
+ // 已存在30分钟内的计划,复用
|
|
|
477
|
+ plan = existingPlans.get(0);
|
|
|
478
|
+ } else {
|
|
|
479
|
+ // 新建发货计划
|
|
|
480
|
+ plan = new ShipmentsPlan();
|
|
|
481
|
+ plan.setId(IdUtil.getId());
|
|
|
482
|
+ plan.setStatus("DRAFT");
|
|
|
483
|
+ plan.setWorkshopId(workshopId);
|
|
|
484
|
+ plan.setTomoPreShipDate(tomorrow);
|
|
|
485
|
+ plan.setAfTomoPreShipDate(LocalDate.now().plusDays(2));
|
|
|
486
|
+ plan.setAutoGenerate(Boolean.TRUE);
|
|
|
487
|
+ plan.setSource("APPLY_SHIPMENT");
|
|
|
488
|
+ shipmentsPlanService.getBaseMapper().insert(plan);
|
|
|
489
|
+ }
|
|
|
490
|
+
|
|
|
491
|
+ // 6. 生成发货计划明细,加入明日预发
|
|
|
492
|
+ List<ShipmentsPlanDetail> planDetails = new ArrayList<>();
|
|
|
493
|
+ for (PurchaseOrderLine line : orderLines) {
|
|
|
494
|
+ ShipmentsPlanDetail detail = new ShipmentsPlanDetail();
|
|
|
495
|
+ detail.setId(IdUtil.getId());
|
|
|
496
|
+ detail.setPlanId(plan.getId());
|
|
|
497
|
+ detail.setOrderId(purchaseOrderId);
|
|
|
498
|
+ detail.setOrderSpecId(line.getId());
|
|
|
499
|
+ detail.setShipmentsDate(tomorrow);
|
|
|
500
|
+ detail.setPreShipments(Boolean.FALSE);
|
|
|
501
|
+ detail.setDelFlag(Boolean.FALSE);
|
|
|
502
|
+ detail.setCreateById("1");
|
|
|
503
|
+ detail.setUpdateById("1");
|
|
|
504
|
+
|
|
|
505
|
+ planDetails.add(detail);
|
|
|
506
|
+ }
|
|
|
507
|
+ if (CollectionUtils.isNotEmpty(planDetails)) {
|
|
|
508
|
+ getBaseMapper().batchAdd(planDetails);
|
|
|
509
|
+ }
|
|
|
510
|
+ }
|
|
|
511
|
+
|
|
420
|
512
|
/**
|
|
421
|
513
|
* 批量删除
|
|
422
|
514
|
*
|
...
|
...
|
|