From a27bcd2f9cba539ba9ffb7cfa949dc102d7446ff Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期一, 30 三月 2026 09:36:35 +0800
Subject: [PATCH] fix(production): 修复单位数量为零时的计算错误
---
src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java | 37 ++++++++++++++++++++++++++-----------
1 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
index 15f2596..4e3fcf2 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
@@ -44,6 +44,7 @@
import oshi.driver.mac.net.NetStat;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@@ -164,15 +165,23 @@
List<ProductStructureDto> productStructureDtos = productStructureMapper.listBybomAndProcess(productProcessRoute.getBomId(), productProcess.getId());
List<Long> lastProcessIds = new ArrayList<>();
+ List<Long> firstProcessIds = new ArrayList<>();
if (!allProcess.isEmpty()) {
String lastProcessName = allProcess.get(allProcess.size() - 1).getProcessName();
+ String firstProcessName = allProcess.get(0).getProcessName();
for (int i = allProcess.size() - 1; i >= 0; i--) {
ProductStructureDto d = allProcess.get(i);
-
if (lastProcessName.equals(d.getProcessName())) {
lastProcessIds.add(d.getId());
+ } else {
+ break;
+ }
+ }
+ for (ProductStructureDto d : allProcess) {
+ if (firstProcessName.equals(d.getProcessName())) {
+ firstProcessIds.add(d.getId());
} else {
break;
}
@@ -190,13 +199,15 @@
ProductModel productModel1 = productModelMapper.selectById(productStructureDto.getProductModelId());
Product product = productMapper.selectById(productModel1.getProductId());
- // 鍒ゆ柇鏄惁涓烘渶鍚庝竴閬撳伐搴�
- BigDecimal needQuantity = dto.getQuantity().divide(productStructureDto.getUnitQuantity(), 2, BigDecimal.ROUND_HALF_UP);
- if (lastProcessIds.contains(productStructureDto.getId())) {
+ // 鍒ゆ柇鏄惁涓烘渶鍚庝竴閬撳伐搴� 鎴栬�呬负绗竴閬撳伐搴�
+ BigDecimal needQuantity = BigDecimal.ZERO;
+
+ if(BigDecimal.ZERO.equals(productStructureDto.getUnitQuantity())){
+ needQuantity = dto.getQuantity().divide(productStructureDto.getUnitQuantity(), 2, RoundingMode.HALF_UP);
+ }
+ if (lastProcessIds.contains(productStructureDto.getId()) || firstProcessIds.contains(productStructureDto.getId())) {
needQuantity = dto.getQuantity().multiply(productStructureDto.getUnitQuantity());
}
-
-
// 鏌ヨ浜у搧搴撳瓨
BigDecimal stockQuantity = stockUtils.getStockQuantity(productModel1.getId()).get("stockQuantity");
if (!(stockQuantity.compareTo(BigDecimal.ZERO) > 0)) {
@@ -221,11 +232,15 @@
ProcurementRecordOut procurementRecordOut1 = procurementRecordOutMapper.selectCode(dateFormat.format(now));
Long aLong = procurementRecordOut1 == null ? 1L : Long.valueOf(procurementRecordOut1.getCode().split("LS" + dateFormat.format(now))[1]);
// 鏌ヨ閲囪喘鍏ュ簱璁板綍
- List<ProcurementRecordStorage> procurementRecordStorages = procurementRecordMapper.selectList(new LambdaQueryWrapper<ProcurementRecordStorage>()
- .in(ProcurementRecordStorage::getSalesLedgerProductId, salesLedgerProducts.stream()
- .map(SalesLedgerProduct::getId)
- .collect(Collectors.toList()))
- .orderByDesc(ProcurementRecordStorage::getInboundNum));
+ LambdaQueryWrapper<ProcurementRecordStorage> procurementRecordStorageLambdaQueryWrapper = new LambdaQueryWrapper<>();
+ if (!org.springframework.util.CollectionUtils.isEmpty(salesLedgerProducts)) {
+ procurementRecordStorageLambdaQueryWrapper.in(ProcurementRecordStorage::getSalesLedgerProductId, salesLedgerProducts.stream()
+ .map(SalesLedgerProduct::getId)
+ .collect(Collectors.toList()));
+ }
+
+ procurementRecordStorageLambdaQueryWrapper.orderByDesc(ProcurementRecordStorage::getInboundNum);
+ List<ProcurementRecordStorage> procurementRecordStorages = procurementRecordMapper.selectList(procurementRecordStorageLambdaQueryWrapper);
if(CollectionUtils.isNotEmpty(procurementRecordStorages)) {
// 鐢熶骇鎵i櫎閲囪喘搴撳瓨鍘熸枡
BigDecimal quantity = productionProductInput.getQuantity();
--
Gitblit v1.9.3