buhuazhen
17 小时以前 956481188a15a01b6c4372a47e95a6aca3100956
refactor(production): 优化采购入库记录查询逻辑

- 使用 LambdaQueryWrapper 构建查询条件,避免空集合导致异常
- 添加判断以确保只有在 salesLedgerProducts 非空时才调用 in 查询
- 保持按入库数量降序排序逻辑
- 提升代码健壮性和可读性
已修改1个文件
14 ■■■■■ 文件已修改
src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
@@ -221,11 +221,15 @@
            ProcurementRecordOut procurementRecordOut1 = procurementRecordOutMapper.selectCode(dateFormat.format(now));
            Long aLong = procurementRecordOut1 == null ? 1L : Long.valueOf(procurementRecordOut1.getCode().split("LS" + dateFormat.format(now))[1]);
            // 查询采购入库记录
            List<ProcurementRecordStorage> procurementRecordStorages = procurementRecordMapper.selectList(new LambdaQueryWrapper<ProcurementRecordStorage>()
                    .in(ProcurementRecordStorage::getSalesLedgerProductId, salesLedgerProducts.stream()
                            .map(SalesLedgerProduct::getId)
                            .collect(Collectors.toList()))
                    .orderByDesc(ProcurementRecordStorage::getInboundNum));
            LambdaQueryWrapper<ProcurementRecordStorage> procurementRecordStorageLambdaQueryWrapper = new LambdaQueryWrapper<>();
            if (!org.springframework.util.CollectionUtils.isEmpty(salesLedgerProducts)) {
                procurementRecordStorageLambdaQueryWrapper.in(ProcurementRecordStorage::getSalesLedgerProductId, salesLedgerProducts.stream()
                        .map(SalesLedgerProduct::getId)
                        .collect(Collectors.toList()));
            }
            procurementRecordStorageLambdaQueryWrapper.orderByDesc(ProcurementRecordStorage::getInboundNum);
            List<ProcurementRecordStorage> procurementRecordStorages = procurementRecordMapper.selectList(procurementRecordStorageLambdaQueryWrapper);
            if(CollectionUtils.isNotEmpty(procurementRecordStorages)) {
                // 生产扣除采购库存原料
                BigDecimal quantity = productionProductInput.getQuantity();