gongchunyi
2026-06-24 96a6f204fadc4c2516f7ca00c6f1f3874279b32b
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -274,8 +274,12 @@
            if (!bindList.isEmpty()) {
                List<Integer> processIds = bindList.stream().map(SalesLedgerProductProcessBind::getSalesLedgerProductProcessId).collect(Collectors.toList());
                Map<Integer, Integer> processQuantityMap = bindList.stream().collect(Collectors.toMap(SalesLedgerProductProcessBind::getSalesLedgerProductProcessId, SalesLedgerProductProcessBind::getQuantity, (a, b) -> a));
                Map<Integer, BigDecimal> processAmountMap = bindList.stream().collect(Collectors.toMap(SalesLedgerProductProcessBind::getSalesLedgerProductProcessId, SalesLedgerProductProcessBind::getAmount, (a, b) -> a));
                List<SalesLedgerProductProcess> processList = salesLedgerProductProcessService.listByIds(processIds);
                processList.forEach(p -> p.setQuantity(processQuantityMap.get(p.getId())));
                processList.forEach(p -> {
                    p.setQuantity(processQuantityMap.get(p.getId()));
                    if (processAmountMap.get(p.getId()) != null) p.setUnitPrice(processAmountMap.get(p.getId()));
                });
                product.setSalesProductProcessList(processList);
            }
            ProductModel productModel = productModelMap.get(product.getProductModelId());
@@ -652,6 +656,7 @@
                                        SalesLedgerProductProcess p = new SalesLedgerProductProcess();
                                        p.setId(process.getId());
                                        p.setQuantity(processQty.intValue());
                                        p.setUnitPrice(process.getUnitPrice());
                                        processList.add(p);
                                        extraProcessAmountPerPiece = extraProcessAmountPerPiece.add(defaultDecimal(process.getUnitPrice()).multiply(processQty));
                                    }
@@ -1910,11 +1915,7 @@
            BigDecimal stockedQty = item.getStockedQuantity() == null ? BigDecimal.ZERO : item.getStockedQuantity();
            return orderQty.compareTo(BigDecimal.ZERO) <= 0 || stockedQty.compareTo(orderQty) >= 0;
        });
        int newStockStatus = allStocked ? 2 : (hasStocked ? 1 : 0);
        if (newStockStatus > 0 && ledger.getDeliveryDate() == null) {
            ledger.setDeliveryDate(LocalDate.now().plusDays(7));
        }
        ledger.setStockStatus(newStockStatus);
        ledger.setStockStatus(allStocked ? 2 : (hasStocked ? 1 : 0));
        baseMapper.updateById(ledger);
    }
@@ -2079,11 +2080,7 @@
            return sq != null && sq.compareTo(BigDecimal.ZERO) > 0;
        });
        boolean allLinesFull = ledgerAllProducts.stream().allMatch(p -> Objects.equals(p.getProductStockStatus(), 2));
        int newStockStatus = allLinesFull ? 2 : (anyInbound ? 1 : 0);
        if (newStockStatus > 0 && salesLedger.getDeliveryDate() == null) {
            salesLedger.setDeliveryDate(LocalDate.now().plusDays(7));
        }
        salesLedger.setStockStatus(newStockStatus);
        salesLedger.setStockStatus(allLinesFull ? 2 : (anyInbound ? 1 : 0));
        baseMapper.updateById(salesLedger);
    }
@@ -3090,6 +3087,7 @@
            SalesLedgerProductProcess bind = new SalesLedgerProductProcess();
            bind.setId(process.getId());
            bind.setQuantity(entry.getValue());
            bind.setUnitPrice(process.getUnitPrice());
            result.add(bind);
        }
        return result;
@@ -3463,7 +3461,7 @@
        QualityTestStandard selectedStandard = null;
        if (dbProduct.getProductId() != null) {
            List<QualityTestStandard> standards = qualityTestStandardMapper.getQualityTestStandardByProductId(dbProduct.getProductId(), 2, null);
            List<QualityTestStandard> standards = qualityTestStandardMapper.getQualityTestStandardByProductId(dbProduct.getProductId(), 2);
            if (CollectionUtils.isNotEmpty(standards)) {
                selectedStandard = standards.get(0);
                qualityInspect.setTestStandardId(selectedStandard.getId());
@@ -3525,7 +3523,7 @@
        QualityTestStandard selectedStandard = null;
        if (dbProduct.getProductId() != null) {
            List<QualityTestStandard> standards = qualityTestStandardMapper.getQualityTestStandardByProductId(dbProduct.getProductId(), 2, null);
            List<QualityTestStandard> standards = qualityTestStandardMapper.getQualityTestStandardByProductId(dbProduct.getProductId(), 2);
            if (CollectionUtils.isNotEmpty(standards)) {
                selectedStandard = standards.get(0);
                qualityInspect.setTestStandardId(selectedStandard.getId());
@@ -3930,43 +3928,10 @@
            // 5. 取消审批流程
            cancelApproveProcesses(id, originalLedger.getSalesContractNo());
            // 6. 重新生成:创建新台账副本
            // 6. 重新生成:此处不直接在后端入库,而是返回原单据ID给前端
            // 前端拿到ID后会获取原单据详情并跳转到新增页面(带入预填数据),由用户在页面上编辑后统一新增,以避免数据重复生成
            if (dto.getCounterReviewType() == 2) {
                SalesLedger newLedger = new SalesLedger();
                BeanUtils.copyProperties(originalLedger, newLedger);
                newLedger.setId(null);
                newLedger.setSalesContractNo(generateSalesContractNo());
                newLedger.setDeliveryStatus(1);
                newLedger.setStockStatus(0);
                newLedger.setReviewStatus(0);
                newLedger.setCounterReviewTime(null);
                newLedger.setCounterReviewPerson(null);
                newLedger.setCounterReviewPersonId(null);
                newLedger.setCounterReviewType(null);
                newLedger.setCounterReviewDesc(null);
                salesLedgerMapper.insert(newLedger);
                // 复制产品到新台账
                List<SalesLedgerProduct> originalProducts = salesLedgerProductMapper.selectList(
                        Wrappers.<SalesLedgerProduct>lambdaQuery()
                                .eq(SalesLedgerProduct::getSalesLedgerId, id)
                );
                for (SalesLedgerProduct originalProduct : originalProducts) {
                    SalesLedgerProduct newProduct = new SalesLedgerProduct();
                    BeanUtils.copyProperties(originalProduct, newProduct);
                    newProduct.setId(null);
                    newProduct.setSalesLedgerId(newLedger.getId());
                    newProduct.setStockedQuantity(BigDecimal.ZERO);
                    newProduct.setShippedQuantity(BigDecimal.ZERO);
                    newProduct.setUnqualifiedStockedQuantity(BigDecimal.ZERO);
                    newProduct.setUnqualifiedShippedQuantity(BigDecimal.ZERO);
                    newProduct.setReturnQuality(BigDecimal.ZERO);
                    newProduct.setAvailableQuality(newProduct.getQuantity().subtract(newProduct.getReturnQuality()));
                    newProduct.setProductStockStatus(0);
                    newProduct.fillRemainingQuantity();
                    salesLedgerProductMapper.insert(newProduct);
                }
                newLedgerIds.add(newLedger.getId());
                newLedgerIds.add(id);
            }
        }
        return newLedgerIds;
@@ -4675,3 +4640,4 @@
    }
}