From 181b6290310424dfbf873a1177ad25d08417d4b3 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期五, 12 六月 2026 13:53:36 +0800
Subject: [PATCH] fix(production): 修复生产订单状态更新逻辑
---
src/main/java/com/ruoyi/production/service/impl/ProductionOrderPickServiceImpl.java | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductionOrderPickServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductionOrderPickServiceImpl.java
index 598ae6b..285c652 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionOrderPickServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionOrderPickServiceImpl.java
@@ -189,6 +189,7 @@
return Collections.emptyList();
}
List<ProductionOrderPickVo> detailList = baseMapper.listPickedDetailByOrderId(productionOrderId);
+ fillStockQuantity(detailList);
fillBatchNoList(detailList);
fillSelectableBatchNoList(detailList);
return detailList;
@@ -430,7 +431,7 @@
BigDecimal totalReturnQty = oldReturnQty.add(currentReturnQty);
if (currentReturnQty.compareTo(BigDecimal.ZERO) > 0) {
String returnBatchNo = resolveInventoryBatchNoFromStored(oldPick.getBatchNo());
- addInventory(oldPick.getId(), oldPick.getProductModelId(), returnBatchNo, currentReturnQty, FEED_RETURN_IN_RECORD_TYPE);
+ addInventoryRecordOnly(oldPick.getId(), oldPick.getProductModelId(), returnBatchNo, currentReturnQty, FEED_RETURN_IN_RECORD_TYPE);
}
BigDecimal actualQty = defaultDecimal(oldPick.getQuantity())
@@ -443,7 +444,8 @@
updatePick.setId(oldPick.getId());
updatePick.setReturnQty(totalReturnQty);
updatePick.setActualQty(actualQty);
- updatePick.setReturned(totalReturnQty.compareTo(BigDecimal.ZERO) > 0);
+ // 瀹為檯鐢ㄩ噺褰掗浂鏃舵墠鏍囪閫�鏂欏畬鎴愶紝鍚﹀垯鍏佽缁х画閫�鏂欍��
+ updatePick.setReturned(actualQty.compareTo(BigDecimal.ZERO) == 0);
int affected = baseMapper.updateById(updatePick);
if (affected <= 0) {
throw new ServiceException("绗�" + rowNo + "琛岄��鏂欏け璐ワ細鏇存柊棰嗘枡涓昏褰曞け璐�");
@@ -734,6 +736,31 @@
throw ex;
} catch (Exception ex) {
throw new ServiceException("鍥炶ˉ搴撳瓨澶辫触锛�" + ex.getMessage());
+ }
+ }
+
+ private void addInventoryRecordOnly(Long recordId,
+ Long productModelId,
+ String batchNo,
+ BigDecimal quantity,
+ String stockInRecordType) {
+ // 浠呰褰曞叆搴撶敵璇凤紝涓嶅仛瀹℃牳閫氳繃銆�
+ BigDecimal addQuantity = defaultDecimal(quantity);
+ if (addQuantity.compareTo(BigDecimal.ZERO) <= 0) {
+ return;
+ }
+ try {
+ StockInventoryDto stockInventoryDto = new StockInventoryDto();
+ stockInventoryDto.setProductModelId(productModelId);
+ stockInventoryDto.setBatchNo(batchNo);
+ stockInventoryDto.setQualitity(addQuantity);
+ stockInventoryDto.setRecordType(stockInRecordType);
+ stockInventoryDto.setRecordId(recordId == null ? 0L : recordId);
+ stockInventoryService.addStockInRecordOnly(stockInventoryDto);
+ } catch (ServiceException ex) {
+ throw ex;
+ } catch (Exception ex) {
+ throw new ServiceException("閫�鏂欏叆搴撹褰曚繚瀛樺け璐ワ細" + ex.getMessage());
}
}
@@ -1096,6 +1123,34 @@
}
}
+ private void fillStockQuantity(List<ProductionOrderPickVo> detailList) {
+ if (detailList == null || detailList.isEmpty()) {
+ return;
+ }
+ Set<Long> productModelIdSet = detailList.stream()
+ .map(ProductionOrderPickVo::getProductModelId)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toSet());
+ if (productModelIdSet.isEmpty()) {
+ return;
+ }
+ List<StockInventory> stockList = stockInventoryMapper.selectList(
+ Wrappers.<StockInventory>lambdaQuery()
+ .in(StockInventory::getProductModelId, productModelIdSet));
+ Map<Long, BigDecimal> stockQuantityMap = new HashMap<>();
+ for (StockInventory stockInventory : stockList) {
+ if (stockInventory == null || stockInventory.getProductModelId() == null) {
+ continue;
+ }
+ stockQuantityMap.merge(stockInventory.getProductModelId(),
+ defaultDecimal(stockInventory.getQualitity()),
+ BigDecimal::add);
+ }
+ for (ProductionOrderPickVo detail : detailList) {
+ detail.setStockQuantity(stockQuantityMap.getOrDefault(detail.getProductModelId(), BigDecimal.ZERO));
+ }
+ }
+
private String buildBatchNoGroupKey(ProductionOrderPickVo detail) {
// 鏋勫缓鎵规鑱氬悎鍒嗙粍閿��
return detail.getProductionOrderId() + "|"
--
Gitblit v1.9.3