liding
2 天以前 181b6290310424dfbf873a1177ad25d08417d4b3
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;
@@ -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 + "行退料失败:更新领料主记录失败");
@@ -1121,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() + "|"