yaowanxin
9 天以前 fd7446cbdb4f852cd0d9098aa3f103fd15edbfbe
src/main/java/com/ruoyi/procurementrecord/service/impl/ProcurementRecordServiceImpl.java
@@ -16,6 +16,7 @@
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.SysUserMapper;
import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -102,6 +103,7 @@
    public int updatePro(ProcurementUpdateDto procurementDto) {
        ProcurementRecordStorage procurementRecordStorageById = getProcurementRecordById(procurementDto.getId());
        procurementRecordStorageById.setInboundNum(procurementDto.getQuantityStock());
        procurementRecordStorageById.setWarnNum(procurementDto.getWarnNum());
        procurementRecordStorageById.setUpdateUser(SecurityUtils.getLoginUser().getUserId());
        procurementRecordStorageById.setUpdateTime(LocalDateTime.now());
        return procurementRecordMapper.updateById(procurementRecordStorageById);
@@ -176,6 +178,12 @@
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String entryDateStr = procurementDto.getEntryDate() + " 00:00:00";
        String createTimeStr = procurementDto.getCreateTime() + " 00:00:00";
        SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(procurementDto.getSalesLedgerProductId());
        if(salesLedgerProduct == null){
            throw new RuntimeException("销售台账产品不存在");
        }
        salesLedgerProduct.setMinStock(procurementDto.getMinStock());
        salesLedgerProductMapper.updateById(salesLedgerProduct);
        ProcurementRecordStorage procurementRecordStorageById = getProcurementRecordById(procurementDto.getId());
        procurementRecordStorageById.setCreateBy(sysUser.getNickName());
        procurementRecordStorageById.setCreateUser(sysUser.getUserId());
@@ -328,6 +336,69 @@
    }
    @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 int add(ProcurementAddDto procurementDto) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        // 批量新增
@@ -341,6 +412,7 @@
                    .salesLedgerProductId(detail.getId())
                    .inboundBatches(aLong.equals(0L) ? "第1批次" : "第"+ (aLong + 1) + "批次")
                    .inboundNum(detail.getInboundQuantity())
                    .warnNum(detail.getWarnNum())
                    .createTime(LocalDateTime.now())
                    .createUser(loginUser.getUserId())
                    .updateTime(LocalDateTime.now())