liyong
8 天以前 9d4cf882be7a2ad8d3cc422bcd0dbc461f626f58
src/main/java/com/ruoyi/procurementrecord/service/impl/ProcurementRecordServiceImpl.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.mapper.ProductModelMapper;
@@ -291,7 +292,6 @@
        LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
        procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect);
        procurementRecordLambdaQueryWrapper.eq(ProcurementRecordOut::getType, type);
        procurementRecordLambdaQueryWrapper.eq(ProcurementRecordOut::getType, type);
        List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper);
        if(CollectionUtils.isEmpty( procurementRecords)){
            ExcelUtil<CustomStorage> util = new ExcelUtil<CustomStorage>(CustomStorage.class);
@@ -482,6 +482,7 @@
        inventoryInformationDto.setInventoryChangeValue(inventoryChangeValue.subtract(totalInventoryValue));
        return inventoryInformationDto;
    }
    @Override
    public IPage<ProcurementPageDto> listPageByProduction(Page page, ProcurementPageDto procurementDto) {
        IPage<ProcurementPageDto> procurementPageDtoIPage = procurementRecordMapper.listPageByProduction(page, procurementDto);
@@ -612,7 +613,7 @@
        List<ProcurementRecordOut> recordOutList = procurementRecordOutMapper.selectList(queryWrapper);
        // 2. 按SalesLedgerProductId分组,统计每个id对应的已出库数量总和-已出库数量
        Map<Integer, BigDecimal> storageIdToTotalOutNumMap = recordOutList.stream()
        Map<Long, BigDecimal> storageIdToTotalOutNumMap = recordOutList.stream()
                .collect(Collectors.groupingBy(
                        ProcurementRecordOut::getSalesLedgerProductId,
                        Collectors.reducing(
@@ -764,7 +765,10 @@
            procurementRecordLambdaQueryWrapper.eq(ProcurementRecordStorage::getSalesLedgerProductId, detail.getId())
                    .eq(ProcurementRecordStorage::getType, procurementDto.getType());
            Long aLong = procurementRecordMapper.selectCount(procurementRecordLambdaQueryWrapper);
            SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(detail.getId());
            if (ObjectUtils.isNull(detail.getProductModelId())) {
                detail.setProductModelId(salesLedgerProduct.getProductModelId());
            }
            ProcurementRecordStorage.ProcurementRecordStorageBuilder procurementRecordBuilder = ProcurementRecordStorage.builder()
                    .salesLedgerProductId(detail.getId())
                    .inboundBatches(aLong.equals(0L) ? "第1批次("+ procurementDto.getTypeName() +")" : "第"+ (aLong + 1) + "批次(" + procurementDto.getTypeName() + ")" )
@@ -776,12 +780,10 @@
                    .createTime(LocalDateTime.now())
                    .createUser(loginUser.getUserId())
                    .updateTime(LocalDateTime.now())
                    .boxNum(detail.getBoxNum())
                    .cartonSpecifications(detail.getCartonSpecifications())
                    .dollarPrice(detail.getDollarPrice())
                    .updateUser(loginUser.getUserId())
                    .createBy(procurementDto.getNickName())
                    .productModelId(detail.getProductModelId());
                    .productModelId(detail.getProductModelId())
                    .qualityInspectId(ObjectUtils.isNotNull(procurementDto.getQualityInspectId()) ? procurementDto.getQualityInspectId() : 0L);
            this.save(procurementRecordBuilder.build());
            // 入库成功减掉采购数量
//            LambdaQueryWrapper<SalesLedgerProduct> salesLedgerProductLambdaQueryWrapper = new LambdaQueryWrapper<>();
@@ -836,15 +838,6 @@
        return procurementPageDtoIPage;
    }
    public List<Long> listCopyIds(String ids) {
        List<Long> idsSet = new ArrayList<>();
        String[] split = ids.split(",");
        for (String s : split) {
            idsSet.add(Long.valueOf(s));
        }
        return idsSet;
    }
    @Override
    public IPage<ProcurementPageDtoCopy> listPageCopy(Page page, ProcurementPageDto procurementDto) {
        IPage<ProcurementPageDtoCopy> procurementPageDtoCopyIPage = procurementRecordMapper.listPageCopy(page, procurementDto);
@@ -874,8 +867,9 @@
                dto.setTotalInboundNum(BigDecimal.ZERO);
                continue;
            }
            // 计算已出库数量总和,并设置待出库数量
            BigDecimal totalInboundNum = procurementRecords.stream()
            BigDecimal totalInboundNum = collect1.stream()
                    .map(ProcurementRecordOut::getInboundNum)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);
            // 出库数量 = 总数量 - 待出库数量
@@ -889,6 +883,7 @@
        }
        return procurementPageDtoCopyIPage;
    }
    @Override
    public IPage<ProductModel> listPageProductionStock(Page page) {
        ProductModel productModel = new ProductModel();
@@ -901,9 +896,46 @@
        return iPage;
    }
    @Override
    public IPage<ProcurementPageDto> listPageByProductProduction(Page page, ProcurementPageDto procurementDto) {
        IPage<ProcurementPageDto> procurementPageDtoIPage = procurementRecordMapper.listPageByProductProduction(page, procurementDto);
        List<ProcurementPageDto> procurementPageDtos = procurementPageDtoIPage.getRecords();
        // 计算待入库数量
        // 查询采购记录已入库数量
        List<Integer> collect = procurementPageDtos.stream().map(ProcurementPageDto::getId).collect(Collectors.toList());
        if (CollectionUtils.isEmpty(collect)) {
            return procurementPageDtoIPage;
        }
        LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
        procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect)
                .eq(ProcurementRecordOut::getType, 4);
        List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper);
        if (CollectionUtils.isEmpty(procurementRecords)) {
            return procurementPageDtoIPage;
        }
        for (ProcurementPageDto dto : procurementPageDtos) {
            // 根据采购台账ID筛选对应的出库记录
            List<ProcurementRecordOut> collect1 = procurementRecords.stream()
                    .filter(ProcurementRecordOut -> ProcurementRecordOut.getProcurementRecordStorageId().equals(dto.getId()))
                    .collect(Collectors.toList());
            // 如果没有相关的出库记录,跳过该条数据
            if (CollectionUtils.isEmpty(collect1)) {
                dto.setInboundNum0(dto.getInboundNum());
                continue;
            }
            // 计算已出库数量总和,并设置待出库数量
            BigDecimal totalInboundNum = collect1.stream()
                    .map(ProcurementRecordOut::getInboundNum)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);
            // 待出库数量 = 总数量 - 已出库数量
            dto.setInboundNum0(dto.getInboundNum().subtract(totalInboundNum));
        }
        return procurementPageDtoIPage;
    }