From 4fadacc0638d051189ffaebb25d0747380d6b02c Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期四, 23 四月 2026 16:50:18 +0800
Subject: [PATCH] fix(production): 修改生产数量计算逻辑
---
src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java | 34 ++++++++++++++++++++++++++++++----
src/main/resources/mapper/production/ProductStructureMapper.xml | 8 ++++++++
src/main/java/com/ruoyi/production/mapper/ProductStructureMapper.java | 4 ++++
3 files changed, 42 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/mapper/ProductStructureMapper.java b/src/main/java/com/ruoyi/production/mapper/ProductStructureMapper.java
index bd59242..c264bc3 100644
--- a/src/main/java/com/ruoyi/production/mapper/ProductStructureMapper.java
+++ b/src/main/java/com/ruoyi/production/mapper/ProductStructureMapper.java
@@ -8,7 +8,9 @@
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
+import java.util.Collection;
import java.util.List;
+import java.util.Set;
@Mapper
public interface ProductStructureMapper extends BaseMapper<ProductStructure> {
@@ -16,4 +18,6 @@
List<ProductStructureDto> listBybomId(@Param("bomId") Integer bomId);
List<ProductStructureDto> listBybomAndProcess(@Param("bomId") Integer bomId, @Param("processId") Long processId);
+
+ List<ProductStructureDto> selectByIds(@Param("parentIds") Set<Long> parentIds);
}
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 b2ab1ce..d22f0f4 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
@@ -34,12 +34,12 @@
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.function.Function;
import java.util.stream.Collectors;
@Service
@@ -184,10 +184,36 @@
productStructureDto.setUnitQuantity(BigDecimal.ONE);
productStructureDtos.add(productStructureDto);
}
+ Set<Long> parentIds = productStructureDtos.stream()
+ .map(ProductStructureDto::getParentId)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toSet());
+ Map<Long, ProductStructureDto> parentMap =
+ productStructureMapper.selectByIds(parentIds)
+ .stream()
+ .collect(Collectors.toMap(
+ ProductStructureDto::getId,
+ Function.identity()
+ ));
for (ProductStructureDto productStructureDto : productStructureDtos) {
ProductionProductInput productionProductInput = new ProductionProductInput();
productionProductInput.setProductModelId(productStructureDto.getProductModelId());
- productionProductInput.setQuantity(productStructureDto.getUnitQuantity().multiply(dto.getQuantity()));
+// productionProductInput.setQuantity(productStructureDto.getUnitQuantity().multiply(dto.getQuantity()));
+ BigDecimal childQty = productStructureDto.getUnitQuantity();
+ BigDecimal parentQty = BigDecimal.ONE;
+ if (productStructureDto.getParentId() != null) {
+ ProductStructureDto parent = parentMap.get(productStructureDto.getParentId());
+ if (parent != null) {
+ parentQty = parent.getUnitQuantity();
+ }
+ }
+
+ // 鏍稿績璁$畻
+ BigDecimal needQty = childQty.divide(parentQty, 6, RoundingMode.HALF_UP).multiply(dto.getQuantity());
+
+
+ productionProductInput.setQuantity(needQty);
+
productionProductInput.setProductMainId(productionProductMain.getId());
productionProductInputMapper.insert(productionProductInput);
stockUtils.substractStock(productStructureDto.getProductModelId(), productionProductInput.getQuantity(), StockOutQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_OUT.getCode(), productionProductMain.getId(), null);
diff --git a/src/main/resources/mapper/production/ProductStructureMapper.xml b/src/main/resources/mapper/production/ProductStructureMapper.xml
index 61177af..31ad32f 100644
--- a/src/main/resources/mapper/production/ProductStructureMapper.xml
+++ b/src/main/resources/mapper/production/ProductStructureMapper.xml
@@ -41,4 +41,12 @@
and ps.process_id=#{processId}
order by ps.id
</select>
+ <select id="selectByIds" resultType="com.ruoyi.production.dto.ProductStructureDto">
+ select *
+ from product_structure
+ where id in
+ <foreach item="item" collection="parentIds" separator="," open="(" close=")" index="">
+ #{item}
+ </foreach>
+ </select>
</mapper>
--
Gitblit v1.9.3