| | |
| | | } |
| | | |
| | | @Override |
| | | public InventoryInformationDto getReportList() { |
| | | InventoryInformationDto inventoryInformationDto = new InventoryInformationDto(); |
| | | IPage<ProcurementPageDto> procurementPageDtoIPage = this.listPage(new Page<>(1, -1), new ProcurementPageDto()); |
| | | if(CollectionUtils.isEmpty(procurementPageDtoIPage.getRecords())){ |
| | | return inventoryInformationDto; |
| | | } |
| | | // 计算总库存数量 |
| | | inventoryInformationDto.setTotalInventoryCount(procurementPageDtoIPage.getRecords().stream() |
| | | .map(ProcurementPageDto::getInboundNum0) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add) |
| | | .intValue()); |
| | | // 计算总库存金额-ProcurementPageDto里每个对象的inboundNum0值和taxInclusiveUnitPrice的乘积,之后相加得到总库存金额 |
| | | BigDecimal totalInventoryValue = procurementPageDtoIPage.getRecords().stream() |
| | | // 过滤空对象,避免NPE |
| | | .filter(Objects::nonNull) |
| | | // 处理每个对象的空值:null转为0 |
| | | .map(dto -> { |
| | | // 入库数量:null → 0 |
| | | BigDecimal inboundNum0 = Optional.ofNullable(dto.getInboundNum0()).orElse(BigDecimal.ZERO); |
| | | // 含税单价:null → 0 |
| | | BigDecimal taxInclusiveUnitPrice = Optional.ofNullable(dto.getTaxInclusiveUnitPrice()).orElse(BigDecimal.ZERO); |
| | | // 计算单个对象的库存金额:数量 × 含税单价 |
| | | return inboundNum0.multiply(taxInclusiveUnitPrice); |
| | | }) |
| | | // 所有单个金额求和,初始值为0 |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // 设置总库存金额 |
| | | inventoryInformationDto.setTotalInventoryValue(totalInventoryValue); |
| | | // 计算库存变动数量-ProcurementPageDto里每个对象的inboundNum值和inboundNum0值的差值,之后相加得到库存变动数量 |
| | | inventoryInformationDto.setInventoryChangeCount(procurementPageDtoIPage.getRecords().stream() |
| | | // 过滤空对象,避免NPE |
| | | .filter(Objects::nonNull) |
| | | // 处理每个对象的空值:null转为0 |
| | | .map(dto -> { |
| | | // 入库数量:null → 0 |
| | | BigDecimal inboundNum = Optional.ofNullable(dto.getInboundNum()).orElse(BigDecimal.ZERO); |
| | | // 待出库数量:null → 0 |
| | | BigDecimal inboundNum0 = Optional.ofNullable(dto.getInboundNum0()).orElse(BigDecimal.ZERO); |
| | | // 计算单个对象的库存变动数量:数量 - 待出库数量 |
| | | return inboundNum.subtract(inboundNum0); |
| | | }) |
| | | // 所有单个变动数量求和,初始值为0 |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add) |
| | | .intValue()); |
| | | // 计算库存变动金额ProcurementPageDto里每个对象的taxInclusiveTotalPrice值的和 |
| | | BigDecimal inventoryChangeValue = procurementPageDtoIPage.getRecords().stream() |
| | | // 过滤空对象,避免NPE |
| | | .filter(Objects::nonNull) |
| | | // 处理每个对象的空值:null转为0 |
| | | .map(dto -> { |
| | | // 含税总价:null → 0 |
| | | BigDecimal taxInclusiveTotalPrice = Optional.ofNullable(dto.getTaxInclusiveTotalPrice()).orElse(BigDecimal.ZERO); |
| | | // 计算单个对象的入库库存金额:含税总价 |
| | | return taxInclusiveTotalPrice; |
| | | }) |
| | | // 所有单个变动金额求和,初始值为0 |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // 设置库存变动金额 |
| | | inventoryInformationDto.setInventoryChangeValue(inventoryChangeValue.subtract(totalInventoryValue)); |
| | | return inventoryInformationDto; |
| | | } |
| | | @Override |
| | | public IPage<ProcurementPageDto> listPageByProduction(Page page, ProcurementPageDto procurementDto) { |
| | | IPage<ProcurementPageDto> procurementPageDtoIPage = procurementRecordMapper.listPageByProduction(page, procurementDto); |
| | | List<ProcurementPageDto> procurementPageDtos = procurementPageDtoIPage.getRecords(); |