gongchunyi
2026-06-23 23b349e9e8ac448b507c3f286483ac06a47e5ea4
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -27,6 +27,7 @@
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.*;
import com.ruoyi.common.utils.excel.ExcelUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.other.mapper.TempFileMapper;
@@ -273,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());
@@ -651,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));
                                    }
@@ -822,7 +828,11 @@
            record.setSalesLedgerProcessRouteId(route.getId());
            Integer isCompleted = inputRecord != null && inputRecord.getIsCompleted() != null ? inputRecord.getIsCompleted() : 0;
            record.setIsCompleted(isCompleted);
            record.setCompletedTime(Objects.equals(isCompleted, 1) ? LocalDateTime.now() : null);
            if (Objects.equals(isCompleted, 1)) {
                record.setCompletedTime(inputRecord != null && inputRecord.getCompletedTime() != null ? inputRecord.getCompletedTime() : LocalDateTime.now());
            } else {
                record.setCompletedTime(null);
            }
            routeRecordList.add(record);
        }
        salesLedgerProcessRouteRecordService.saveBatch(routeRecordList);
@@ -1905,7 +1915,11 @@
            BigDecimal stockedQty = item.getStockedQuantity() == null ? BigDecimal.ZERO : item.getStockedQuantity();
            return orderQty.compareTo(BigDecimal.ZERO) <= 0 || stockedQty.compareTo(orderQty) >= 0;
        });
        ledger.setStockStatus(allStocked ? 2 : (hasStocked ? 1 : 0));
        int newStockStatus = allStocked ? 2 : (hasStocked ? 1 : 0);
        if (newStockStatus > 0 && ledger.getDeliveryDate() == null) {
            ledger.setDeliveryDate(LocalDate.now().plusDays(7));
        }
        ledger.setStockStatus(newStockStatus);
        baseMapper.updateById(ledger);
    }
@@ -2070,7 +2084,11 @@
            return sq != null && sq.compareTo(BigDecimal.ZERO) > 0;
        });
        boolean allLinesFull = ledgerAllProducts.stream().allMatch(p -> Objects.equals(p.getProductStockStatus(), 2));
        salesLedger.setStockStatus(allLinesFull ? 2 : (anyInbound ? 1 : 0));
        int newStockStatus = allLinesFull ? 2 : (anyInbound ? 1 : 0);
        if (newStockStatus > 0 && salesLedger.getDeliveryDate() == null) {
            salesLedger.setDeliveryDate(LocalDate.now().plusDays(7));
        }
        salesLedger.setStockStatus(newStockStatus);
        baseMapper.updateById(salesLedger);
    }
@@ -3077,6 +3095,7 @@
            SalesLedgerProductProcess bind = new SalesLedgerProductProcess();
            bind.setId(process.getId());
            bind.setQuantity(entry.getValue());
            bind.setUnitPrice(process.getUnitPrice());
            result.add(bind);
        }
        return result;
@@ -4441,7 +4460,7 @@
                sheetMap.put("工艺路线", sheetData);
            }
            com.ruoyi.common.utils.excel.ExcelUtils.exportManySheet(response, "销售台账工艺路线导出", sheetMap);
            ExcelUtils.exportManySheet(response, "销售台账工艺路线导出", sheetMap);
        } catch (Exception e) {
            log.error("导出售后台账工艺路线失败", e);
            throw new ServiceException("导出售后台账工艺路线失败:" + e.getMessage());
@@ -4487,7 +4506,7 @@
    private List<Object> buildProcessRouteRow(SalesLedger salesLedger, SalesLedgerProduct product, SalesLedgerProcessRouteRecord route) {
        List<Object> row = new ArrayList<>();
        row.add(salesLedger.getEntryDate() == null ? "" : DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, salesLedger.getEntryDate()));
        row.add(route.getCompletedTime() == null ? "" : route.getCompletedTime().format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd")));
        row.add(salesLedger.getSalesContractNo());
        row.add(salesLedger.getCustomerName());
        row.add(product == null ? "" : product.getSpecificationModel());
@@ -4662,3 +4681,4 @@
    }
}