From 831163b8a651e5b4e752581d48762f4f7db4ed80 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期三, 11 三月 2026 17:43:05 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_宁夏_中盛建材' into dev_宁夏_中盛建材
---
src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java | 70 +++++++++++++++++++---------------
1 files changed, 39 insertions(+), 31 deletions(-)
diff --git a/src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java b/src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
index f0584d7..1b21552 100644
--- a/src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
+++ b/src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
@@ -107,6 +107,7 @@
// 鏌ヨ涓荤敓浜ц鍒�
List<ProductionPlan> plans = productionPlanMapper.selectBatchIds(productionPlanDto.getIds());
+ plans.sort(Comparator.comparingLong(ProductionPlan::getId));
// 鏍¢獙鏄惁瀛樺湪涓嶅悓鐨勪骇鍝佸悕绉�
String firstProductName = plans.get(0).getProductName();
@@ -121,37 +122,14 @@
}
- // 鍙犲姞鏂规暟
- BigDecimal totalVolume = plans.stream()
- .map(ProductionPlan::getVolume)
+ // 鍙犲姞鍓╀綑鏂规暟
+ BigDecimal totalRemainingVolume = plans.stream()
+ .map(ProductionPlan::getRemainingVolume)
.filter(v -> v != null)
.reduce(BigDecimal.ZERO, BigDecimal::add);
- // 鍒ゆ柇涓嬪彂鏁伴噺鏄惁澶т簬绛変簬鏂规暟
- if (productionPlanDto.getTotalAssignedQuantity().compareTo(totalVolume) > 0) {
-
- log.warn("鎿嶄綔澶辫触锛屼笅鍙戞暟閲忎笉鑳藉ぇ浜庢柟鏁�");
- return false;
- }
-
- // 鏍规嵁涓嬪彂鏁伴噺锛屼粠绗竴涓敓浜ц鍒掑紑濮嬪垎閰嶆柟鏁�
- BigDecimal assignedVolume = BigDecimal.ZERO;
- for (ProductionPlan plan : plans) {
- BigDecimal volume = plan.getVolume();
- if (volume == null) {
- continue;
- }
-
- if (assignedVolume.add(volume).compareTo(productionPlanDto.getTotalAssignedQuantity()) >= 0) {
- // 鏈�鍚庝竴涓鍒掞紝鍒嗛厤鍓╀綑鏂规暟
- plan.setAssignedQuantity(productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume));
- productionPlanMapper.updateById(plan);
- break;
- }
-
- // 鍒嗛厤褰撳墠璁″垝鏂规暟
- plan.setAssignedQuantity(volume);
- productionPlanMapper.updateById(plan);
- assignedVolume = assignedVolume.add(volume);
+ // 鍒ゆ柇涓嬪彂鏁伴噺鏄惁澶т簬绛変簬鍓╀綑鏂规暟
+ if (productionPlanDto.getTotalAssignedQuantity().compareTo(totalRemainingVolume) > 0) {
+ throw new BaseException("鎿嶄綔澶辫触锛屼笅鍙戞暟閲忎笉鑳藉ぇ浜庡墿浣欐柟鏁�");
}
// 鍒涘缓鐢熶骇璁㈠崟
@@ -160,11 +138,41 @@
productOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime());
productOrderService.addProductOrder(productOrder);
- for (Long planId : productionPlanDto.getIds()) {
+ // 鏍规嵁涓嬪彂鏁伴噺锛屼粠绗竴涓敓浜ц鍒掑紑濮嬪垎閰嶆柟鏁�
+ BigDecimal assignedVolume = BigDecimal.ZERO;
+ for (ProductionPlan plan : plans) {
+ BigDecimal volume = plan.getVolume();
+ if (volume == null) {
+ continue;
+ }
+ // 璁$畻鍓╀綑鏂规暟
+ BigDecimal remainingVolume = plan.getRemainingVolume();
+ if (remainingVolume.compareTo(BigDecimal.ZERO) <= 0) {
+ continue;
+ }
+
ProductOrderPlan productOrderPlan = new ProductOrderPlan();
productOrderPlan.setProductOrderId(productOrder.getId());
- productOrderPlan.setProductionPlanId(planId);
+ productOrderPlan.setProductionPlanId(plan.getId());
+
+ if (assignedVolume.add(remainingVolume).compareTo(productionPlanDto.getTotalAssignedQuantity()) >= 0) {
+ // 鏈�鍚庝竴涓鍒掞紝鍒嗛厤鍓╀綑鏂规暟
+ BigDecimal lastRemainingVolume = productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume);
+ plan.setAssignedQuantity(plan.getAssignedQuantity().add(lastRemainingVolume));
+ productOrderPlan.setAssignedQuantity(lastRemainingVolume);
+ productionPlanMapper.updateById(plan);
+ productOrderPlanMapper.insert(productOrderPlan);
+ break;
+ }
+
+ // 鍒嗛厤褰撳墠璁″垝鏂规暟
+ plan.setAssignedQuantity(plan.getAssignedQuantity().add(remainingVolume));
+ productOrderPlan.setAssignedQuantity(remainingVolume);
+ // 鏇存柊鐢熶骇璁″垝
+ productionPlanMapper.updateById(plan);
+ // 鍒涘缓鍏宠仈鍏崇郴
productOrderPlanMapper.insert(productOrderPlan);
+ assignedVolume = assignedVolume.add(remainingVolume);
}
return true;
}
--
Gitblit v1.9.3