From b572e82dcafea0fd893d908c7bb0e048483a1dd3 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期三, 01 四月 2026 13:38:54 +0800
Subject: [PATCH] fix: 生产计划下发时产品类型ID未保存
---
src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java | 64 +++++++++++++++++++++++++------
1 files changed, 51 insertions(+), 13 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 1444f36..f71f3db 100644
--- a/src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
+++ b/src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
@@ -17,6 +17,7 @@
import com.ruoyi.production.enums.ProductOrderStatusEnum;
import com.ruoyi.production.pojo.ProductMaterialSku;
import com.ruoyi.production.pojo.ProductOrder;
+import com.ruoyi.production.service.IProductionOrderAppendixService;
import com.ruoyi.production.service.ProductMaterialService;
import com.ruoyi.production.service.ProductMaterialSkuService;
import com.ruoyi.production.service.ProductOrderService;
@@ -77,6 +78,9 @@
@Autowired
private ProductMaterialService productMaterialService;
+ @Autowired
+ private IProductionOrderAppendixService productionOrderAppendixService;
+
/**
* 鍚屾閿侊紝纭繚鎵嬪姩鍜屽畾鏃朵换鍔′笉鍚屾椂鎵ц
*/
@@ -116,6 +120,10 @@
// 鏌ヨ涓荤敓浜ц鍒�
List<ProductionPlanDto> plans = productionPlanMapper.selectWithMaterialByIds(productionPlanDto.getIds());
+ if (plans == null || plans.isEmpty()) {
+ throw new ServiceException("涓嬪彂澶辫触,鐢熶骇璁″垝涓嶅瓨鍦�");
+ }
+
// 鏍¢獙鏄惁瀛樺湪涓嶅悓鐨勪骇鍝佸悕绉�
String firstProductName = plans.get(0).getProductName();
if (plans.stream().anyMatch(p -> p.getProductName() == null || !p.getProductName().equals(firstProductName))) {
@@ -143,7 +151,20 @@
productOrder.setQuantity(productionPlanDto.getTotalAssignedQuantity());
productOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime());
productOrder.setStatus(ProductOrderStatusEnum.WAIT.getCode());
- productOrderService.addProductOrder(productOrder);
+ productOrder.setStrength(productionPlanDto.getStrength());
+ productOrder.setProductMaterialSkuId(plans.get(0).getProductMaterialSkuId());
+
+ Long orderId = productOrderService.insertProductOrder(productOrder);
+
+ // 褰撲笅鍙戠殑浜у搧涓虹爩鍧楁垨鏉挎潗锛屽氨鎷夊彇BOM瀛愰泦涓庡伐鑹鸿矾绾垮瓙闆嗘暟鎹瓨鍏ュ埌闄勮〃涓�
+ if ("鐮屽潡".equals(productionPlanDto.getProductName())) {
+ productOrder.setRouteId(productionOrderAppendixService.populateBlocks(orderId, productionPlanDto));
+ }
+ if ("鏉挎潗".equals(productionPlanDto.getProductName())) {
+ productOrder.setRouteId(productionOrderAppendixService.populatePlates(orderId, productionPlanDto));
+ }
+ // 鏇存柊缁戝畾鐨勫伐鑹鸿矾绾�
+ productOrderService.updateById(productOrder);
// 鏍规嵁涓嬪彂鏁伴噺锛屼粠绗竴涓敓浜ц鍒掑紑濮嬪垎閰嶆柟鏁�
BigDecimal assignedVolume = BigDecimal.ZERO;
@@ -165,11 +186,9 @@
if (assignedVolume.add(remainingVolume).compareTo(productionPlanDto.getTotalAssignedQuantity()) >= 0) {
// 鏈�鍚庝竴涓鍒掞紝鍒嗛厤鍓╀綑鏂规暟
BigDecimal lastRemainingVolume = productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume);
- plan.setStatus(1);
- plan.setAssignedQuantity(plan.getAssignedQuantity().add(lastRemainingVolume));
- if (plan.getAssignedQuantity().compareTo(plan.getVolume()) >= 0) {
- plan.setStatus(2);
- }
+ BigDecimal assignedQuantity = Optional.ofNullable(plan.getAssignedQuantity()).orElse(BigDecimal.ZERO).add(lastRemainingVolume);
+ plan.setAssignedQuantity(assignedQuantity);
+ plan.setStatus(assignedQuantity.compareTo(plan.getVolume()) >= 0 ? 2 : 1);
productOrderPlan.setAssignedQuantity(lastRemainingVolume);
productionPlanMapper.updateById(plan);
productOrderPlanMapper.insert(productOrderPlan);
@@ -177,17 +196,28 @@
}
// 鍒嗛厤褰撳墠璁″垝鏂规暟
- plan.setStatus(1);
- if (remainingVolume.compareTo(BigDecimal.ZERO) <= 0) {
- plan.setStatus(2);
- }
- plan.setAssignedQuantity(plan.getAssignedQuantity().add(remainingVolume));
+ BigDecimal assignedQuantity = Optional.ofNullable(plan.getAssignedQuantity()).orElse(BigDecimal.ZERO).add(remainingVolume);
+ plan.setAssignedQuantity(assignedQuantity);
+ plan.setStatus(assignedQuantity.compareTo(plan.getVolume()) >= 0 ? 2 : 1);
productOrderPlan.setAssignedQuantity(remainingVolume);
// 鏇存柊鐢熶骇璁″垝
productionPlanMapper.updateById(plan);
// 鍒涘缓鍏宠仈鍏崇郴
productOrderPlanMapper.insert(productOrderPlan);
assignedVolume = assignedVolume.add(remainingVolume);
+ }
+
+ for (ProductionPlan plan : plans) {
+ BigDecimal assignedQuantity = Optional.ofNullable(plan.getAssignedQuantity()).orElse(BigDecimal.ZERO);
+ BigDecimal volume = Optional.ofNullable(plan.getVolume()).orElse(BigDecimal.ZERO);
+ if (assignedQuantity.compareTo(BigDecimal.ZERO) <= 0) {
+ plan.setStatus(0);
+ } else if (assignedQuantity.compareTo(volume) >= 0) {
+ plan.setStatus(2);
+ } else {
+ plan.setStatus(1);
+ }
+ productionPlanMapper.updateById(plan);
}
return true;
}
@@ -204,9 +234,17 @@
@Override
@Transactional(rollbackFor = Exception.class)
public boolean update(ProductionPlanDto productionPlanDto) {
+ if (productionPlanDto == null) {
+ throw new ServiceException("缂栬緫澶辫触,鏁版嵁涓嶈兘涓虹┖");
+ }
+ ProductionPlan productionPlan = getById(productionPlanDto.getId());
+ if (productionPlan == null) {
+ throw new ServiceException("缂栬緫澶辫触,涓荤敓浜ц鍒掍笉瀛樺湪");
+ }
+
// 宸蹭笅鍙戠姸鎬侊紝涓嶈兘缂栬緫
- if (productionPlanDto.getStatus() != 0) {
- throw new BaseException("宸蹭笅鍙戞垨閮ㄥ垎涓嬪彂鐘舵�侊紝涓嶈兘缂栬緫");
+ if (productionPlan.getStatus() != 0) {
+ throw new BaseException("缂栬緫澶辫触,璇ョ敓浜ц鍒掑凡涓嬪彂鎴栭儴鍒嗕笅鍙戠姸鎬�,绂佹缂栬緫");
}
// 鏌ヨ鏄惁鏈夊叧鑱旇鍗�
boolean hasProductOrderPlan = productOrderPlanMapper.selectList(Wrappers.<ProductOrderPlan>lambdaQuery().eq(ProductOrderPlan::getProductionPlanId, productionPlanDto.getId())).stream().anyMatch(p -> p.getProductOrderId() != null);
--
Gitblit v1.9.3