From a76e1d17d67641993dea6335cb8e1465a94df58d Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 21 五月 2026 15:39:05 +0800
Subject: [PATCH] feat(stock): 优化库存管理和成品树结构功能 1- 为ApproveProcessMapper.xml和ProductBomMapper.xml添加排序功能 2- 在ProductionProductMainDto中新增bomInputQty字段用于产品结构投入数量 3- 修改ProductionProductMainServiceImpl中投入数量计算逻辑,使用前端传入的bomInputQty值 4- 在ProductWorkOrderDto中添加bomInputQty字段并在服务实现中计算标准投入数量 5- 更新SalesLedgerMapper.xml查询逻辑,从product_summary获取电压信息 6- 为SalesLedgerProduct添加stockId字段并修改库存扣减逻辑使用具体库存ID 7- 重构StockInventoryController中的成品库存树查询接口和导入导出功能 8- 新增成品和非成品库存导入导出的数据模型和Excel工具类 9- 优化StockInventoryServiceImpl中的库存扣减逻辑,支持按特定库存ID操作 10- 更新库存导入导出功能,区分成品和非成品类型并提供相应模板
---
src/main/java/com/ruoyi/production/service/impl/ProductWorkOrderServiceImpl.java | 212 +++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 182 insertions(+), 30 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductWorkOrderServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductWorkOrderServiceImpl.java
index 6bbb940..b73d629 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductWorkOrderServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductWorkOrderServiceImpl.java
@@ -7,23 +7,18 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deepoove.poi.XWPFTemplate;
-import com.deepoove.poi.config.Configure;
import com.deepoove.poi.data.PictureRenderData;
import com.deepoove.poi.data.Pictures;
-import com.ruoyi.common.utils.HackLoopTableRenderPolicy;
import com.ruoyi.common.utils.MatrixToImageWriter;
import com.ruoyi.production.dto.ProductWorkOrderDto;
-import com.ruoyi.production.mapper.ProductProcessRouteItemMapper;
-import com.ruoyi.production.mapper.ProductWorkOrderFileMapper;
-import com.ruoyi.production.mapper.ProductWorkOrderMapper;
-import com.ruoyi.production.mapper.ProductionProductMainMapper;
-import com.ruoyi.production.pojo.ProductProcessRouteItem;
-import com.ruoyi.production.pojo.ProductWorkOrder;
-import com.ruoyi.production.pojo.ProductWorkOrderFile;
-import com.ruoyi.production.pojo.ProductionProductMain;
+import com.ruoyi.production.dto.ProductStructureDto;
+import com.ruoyi.production.mapper.*;
+import com.ruoyi.production.pojo.*;
import com.ruoyi.production.service.ProductWorkOrderService;
-import com.ruoyi.quality.pojo.QualityInspectParam;
-import lombok.AllArgsConstructor;
+import com.ruoyi.quality.mapper.QualityInspectMapper;
+import com.ruoyi.quality.mapper.QualityUnqualifiedMapper;
+import com.ruoyi.quality.pojo.QualityInspect;
+import com.ruoyi.quality.pojo.QualityUnqualified;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@@ -33,11 +28,11 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
@Service
@Transactional(rollbackFor = Exception.class)
@@ -50,7 +45,21 @@
@Autowired
private ProductProcessRouteItemMapper productProcessRouteItemMapper;
@Autowired
+ private ProductProcessMapper productProcessMapper;
+ @Autowired
+ private ProductProcessRouteMapper productProcessRouteMapper;
+ @Autowired
+ private ProductStructureMapper productStructureMapper;
+ @Autowired
private ProductionProductMainMapper productionProductMainMapper;
+ @Autowired
+ private ProductionProductOutputMapper productionProductOutputMapper;
+ @Autowired
+ private ProductionProductInputMapper productionProductInputMapper;
+ @Autowired
+ private QualityUnqualifiedMapper qualityUnqualifiedMapper;
+ @Autowired
+ private QualityInspectMapper qualityInspectMapper;
@Value("${file.temp-dir}")
private String tempDir;
@@ -58,30 +67,128 @@
@Override
public IPage<ProductWorkOrderDto> listPage(Page<ProductWorkOrderDto> page, ProductWorkOrderDto productWorkOrder) {
IPage<ProductWorkOrderDto> productWorkOrderDtoIPage = productWorkOrdermapper.pageProductWorkOrder(page, productWorkOrder);
+ Map<String, BigDecimal> bomInputQtyCache = new HashMap<>();
productWorkOrderDtoIPage.getRecords().forEach(record -> {
- //妫�鏌ヤ笂涓�涓伐搴忔槸鍚﹀凡鎶ュ伐
+ // 鏄惁鑳芥姤宸ワ細 1. 绗竴涓伐搴忚兘鎶ュ伐 2. 涓婁竴涓伐搴忓凡鎶ュ伐 3. 涔嬪墠鐨勫伐搴忔湭琚殧绂�
Integer currentDragSort = record.getDragSort();
if (currentDragSort == null || currentDragSort == 1) {
record.setIsCanReport(true);
} else {
- //鏌ユ壘涓婁竴涓伐搴�
- ProductProcessRouteItem previousItem = productProcessRouteItemMapper.selectOne(
- Wrappers.<ProductProcessRouteItem>lambdaQuery()
- .eq(ProductProcessRouteItem::getProductRouteId, record.getProductRouteId())
- .eq(ProductProcessRouteItem::getDragSort, currentDragSort - 1)
+ // 涓婁竴涓伐搴忔槸鍚﹀凡鎶ュ伐
+ boolean isPreviousReported = productionProductMainMapper.checkPreviousProcessReported(
+ record.getId(),
+ currentDragSort
);
+ record.setIsCanReport(isPreviousReported);
- if (previousItem != null) {
- //妫�鏌ヤ笂涓�涓伐搴忔槸鍚︽湁鎶ュ伐璁板綍
- Long count = productionProductMainMapper.selectCount(
- Wrappers.<ProductionProductMain>lambdaQuery()
- .eq(ProductionProductMain::getProductProcessRouteItemId, previousItem.getId())
+ // 涔嬪墠鐨勫伐搴忔槸鍚﹁闅旂
+ if (record.getIsCanReport()) {
+ // 鏌ヨ鎵�鏈変箣鍓嶇殑宸ュ簭锛堟帓搴忓彿灏忎簬褰撳墠宸ュ簭锛�
+ List<ProductProcessRouteItem> previousItems = productProcessRouteItemMapper.selectList(
+ Wrappers.<ProductProcessRouteItem>lambdaQuery()
+ .eq(ProductProcessRouteItem::getProductRouteId, record.getProductRouteId())
+ .lt(ProductProcessRouteItem::getDragSort, currentDragSort)
);
- record.setIsCanReport(count > 0);
- } else {
- record.setIsCanReport(true);
+
+ if (CollectionUtils.isNotEmpty(previousItems)) {
+ // 鎻愬彇涔嬪墠宸ュ簭鐨勫悕绉板垪琛�
+ List<String> previousProcessNames = new ArrayList<>();
+ for (ProductProcessRouteItem item : previousItems) {
+ ProductProcess process = productProcessMapper.selectById(item.getProcessId());
+ if (process != null) {
+ previousProcessNames.add(process.getName());
+ }
+ }
+
+ // 妫�鏌ヤ箣鍓嶇殑宸ュ簭鏄惁鏈夎闅旂鐨勪笉鍚堟牸璁板綍
+ List<QualityUnqualified> unqualifiedList = Collections.emptyList();
+ if (CollectionUtils.isNotEmpty(previousProcessNames)) {
+ unqualifiedList = qualityUnqualifiedMapper.selectUnqualifiedByProductOrderAndProcessNames(
+ record.getProductOrderId(),
+ previousProcessNames
+ );
+ }
+ if (CollectionUtils.isNotEmpty(unqualifiedList)) {
+ record.setIsCanReport(false);
+ }
+ }
}
}
+
+ // 鏌ヨ褰撳墠瀹為檯鐨勫悎鏍肩巼
+ // 鏌ヨ鍏宠仈浜у嚭琛ㄦ暟鎹�
+ List<ProductionProductMain> productionProductMains = productionProductMainMapper.selectList(Wrappers.<ProductionProductMain>lambdaQuery().eq(ProductionProductMain::getWorkOrderId, record.getId()));
+ BigDecimal totalScrapQty = BigDecimal.ZERO;
+ if (CollectionUtils.isNotEmpty(productionProductMains)) {
+ // 璁$畻鎶ュ簾鏁伴噺
+ List<Long> mainIds = productionProductMains.stream().map(ProductionProductMain::getId).collect(Collectors.toList());
+ List<ProductionProductOutput> productionProductOutputs = productionProductOutputMapper.selectList(Wrappers.<ProductionProductOutput>lambdaQuery().in(ProductionProductOutput::getProductMainId, mainIds));
+ totalScrapQty = productionProductOutputs.stream().map(ProductionProductOutput::getScrapQty).reduce(BigDecimal.ZERO, BigDecimal::add);
+ }
+ if (record.getCompleteQuantity().compareTo(BigDecimal.ZERO) > 0) {
+ record.setActualQualifiedRate((record.getCompleteQuantity().subtract(totalScrapQty))
+ .divide(record.getCompleteQuantity(), 2, RoundingMode.HALF_UP)
+ .multiply(new BigDecimal("100"))
+ );
+ } else {
+ record.setActualQualifiedRate((record.getCompleteQuantity().subtract(totalScrapQty)).multiply(BigDecimal.valueOf(100)));
+ }
+
+ // 鏌ヨ褰撳墠宸ュ崟瀵瑰簲浜у搧缁撴瀯涓殑鏍囧噯鎶曞叆鏁伴噺
+ String bomInputQtyCacheKey = record.getProductRouteId() + "_" + record.getProcessId() + "_" + record.getPlanQuantity();
+ BigDecimal bomInputQty = bomInputQtyCache.get(bomInputQtyCacheKey);
+ if (bomInputQty == null) {
+ bomInputQty = BigDecimal.ZERO;
+ ProductProcessRoute productProcessRoute = productProcessRouteMapper.selectById(record.getProductRouteId());
+ if (productProcessRoute != null && productProcessRoute.getBomId() != null && record.getProcessId() != null) {
+ List<ProductStructureDto> productStructureDtos = productStructureMapper.listBybomAndProcess(
+ productProcessRoute.getBomId(),
+ record.getProcessId()
+ );
+
+ if (CollectionUtils.isEmpty(productStructureDtos)) {
+ bomInputQty = record.getPlanQuantity() == null ? BigDecimal.ZERO : record.getPlanQuantity();
+ } else {
+ Set<Long> parentIds = productStructureDtos.stream()
+ .map(ProductStructureDto::getParentId)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toSet());
+
+ Map<Long, ProductStructureDto> parentMap = new HashMap<>();
+ if (CollectionUtils.isNotEmpty(parentIds)) {
+ parentMap = productStructureMapper.selectByIds(parentIds)
+ .stream()
+ .collect(Collectors.toMap(ProductStructureDto::getId, Function.identity(), (a, b) -> a));
+ }
+
+ BigDecimal planQty = record.getPlanQuantity() == null ? BigDecimal.ZERO : record.getPlanQuantity();
+ for (ProductStructureDto productStructureDto : productStructureDtos) {
+ BigDecimal childQty = productStructureDto.getUnitQuantity();
+ if (childQty == null || childQty.compareTo(BigDecimal.ZERO) <= 0) {
+ continue;
+ }
+
+ BigDecimal parentQty = BigDecimal.ONE;
+ if (productStructureDto.getParentId() != null) {
+ ProductStructureDto parent = parentMap.get(productStructureDto.getParentId());
+ if (parent != null && parent.getUnitQuantity() != null && parent.getUnitQuantity().compareTo(BigDecimal.ZERO) > 0) {
+ parentQty = parent.getUnitQuantity();
+ }
+ }
+
+ if (parentQty.compareTo(BigDecimal.ZERO) <= 0) {
+ continue;
+ }
+
+ bomInputQty = bomInputQty.add(
+ childQty.divide(parentQty, 6, RoundingMode.HALF_UP).multiply(planQty)
+ );
+ }
+ }
+ }
+ bomInputQtyCache.put(bomInputQtyCacheKey, bomInputQty);
+ }
+ record.setBomInputQty(bomInputQty);
});
return productWorkOrderDtoIPage;
}
@@ -120,6 +227,7 @@
put("productName", productWorkOrderDto.getProductName());
put("planQuantity", productWorkOrderDto.getPlanQuantity());
put("model", productWorkOrderDto.getModel());
+ put("unit", productWorkOrderDto.getUnit());
put("completeQuantity", productWorkOrderDto.getCompleteQuantity());
put("scrapQty", productWorkOrderDto.getScrapQty());
put("planStartTime", productWorkOrderDto.getPlanStartTime());
@@ -148,4 +256,48 @@
}
}
+ @Override
+ public List<ProductWorkOrderDto> getByProductOrderId(Long productOrderId) {
+ List<ProductWorkOrderDto> productWorkOrderDtos = productWorkOrdermapper.getByProductOrderId(productOrderId);
+ if (CollectionUtils.isNotEmpty(productWorkOrderDtos)) {
+ productWorkOrderDtos.forEach(productWorkOrderDto -> {
+ // 鏌ヨ鍏宠仈浜у嚭琛ㄦ暟鎹�
+ List<ProductionProductMain> productionProductMains = productionProductMainMapper.selectList(Wrappers.<ProductionProductMain>lambdaQuery().eq(ProductionProductMain::getWorkOrderId, productWorkOrderDto.getId()));
+ // 鏌ヨ鎶ュ簾鏁伴噺
+ BigDecimal scrapQty = BigDecimal.ZERO;
+ // 鏌ヨ涓嶈壇鏁伴噺
+ BigDecimal defectiveQuantity = BigDecimal.ZERO;
+ // 鏌ヨ鎶曞叆鏁伴噺
+ BigDecimal inputQty = BigDecimal.ZERO;
+ if (CollectionUtils.isNotEmpty(productionProductMains)) {
+ // 璁$畻鎶ュ簾鏁伴噺
+ List<Long> mainIds = productionProductMains.stream().map(ProductionProductMain::getId).collect(Collectors.toList());
+ List<ProductionProductOutput> productionProductOutputs = productionProductOutputMapper.selectList(Wrappers.<ProductionProductOutput>lambdaQuery().in(ProductionProductOutput::getProductMainId, mainIds));
+ List<QualityInspect> qualityInspects = qualityInspectMapper.selectList(Wrappers.<QualityInspect>lambdaQuery().in(QualityInspect::getProductMainId, mainIds));
+ if (CollectionUtils.isNotEmpty(productionProductOutputs)) {
+ scrapQty = productionProductOutputs.stream().map(ProductionProductOutput::getScrapQty).reduce(BigDecimal.ZERO, BigDecimal::add);
+ }
+ List<ProductionProductInput> productionProductInputs = productionProductInputMapper.selectList(Wrappers.<ProductionProductInput>lambdaQuery().in(ProductionProductInput::getProductMainId, mainIds));
+ if (CollectionUtils.isNotEmpty(productionProductInputs)) {
+ inputQty = productionProductInputs.stream().map(ProductionProductInput::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);
+ }
+ if (CollectionUtils.isNotEmpty(qualityInspects)) {
+ defectiveQuantity = qualityInspects.stream().map(QualityInspect::getDefectiveQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);
+ }
+ }
+ BigDecimal totalQuantity = productWorkOrderDto.getCompleteQuantity().add(scrapQty);
+ if (totalQuantity.compareTo(BigDecimal.ZERO) > 0) {
+ productWorkOrderDto.setDefectiveRate(defectiveQuantity.divide(productWorkOrderDto.getCompleteQuantity(), 4, RoundingMode.HALF_UP));
+ } else {
+ productWorkOrderDto.setDefectiveRate(defectiveQuantity.multiply(BigDecimal.valueOf(100)));
+ }
+ productWorkOrderDto.setInputQty(inputQty);
+ productWorkOrderDto.setScrapQty(scrapQty);
+ productWorkOrderDto.setTotalQty(totalQuantity);
+ productWorkOrderDto.setDefectiveQuantity(defectiveQuantity);
+ productWorkOrderDto.setCompleteQty(productWorkOrderDto.getCompleteQuantity().subtract(defectiveQuantity));
+ });
+ }
+ return productWorkOrderDtos;
+ }
}
--
Gitblit v1.9.3