zss
2 天以前 ba0dd873d9843fd219cf3776e7eaff33b6bb98dd
库存调整增加手动入库
已修改4个文件
153 ■■■■■ 文件已修改
src/main/java/com/ruoyi/procurementrecord/controller/ProcurementRecordController.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/procurementrecord/service/ProcurementRecordService.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/procurementrecord/service/impl/ProcurementRecordServiceImpl.java 101 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/procurementrecord/ProcurementRecordMapper.xml 44 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/procurementrecord/controller/ProcurementRecordController.java
@@ -44,6 +44,13 @@
        return AjaxResult.success(procurementRecordService.add(procurementDto));
    }
    @PostMapping("/addProduct")
    @Log(title = "入库管理-产品入库", businessType = BusinessType.INSERT)
    @Transactional
    public AjaxResult addProduct(@RequestBody Details detail) {
        return AjaxResult.success(procurementRecordService.addProduct(detail));
    }
    @PostMapping("/update")
    @Log(title = "采购入库-入库管理-修改入库", businessType = BusinessType.UPDATE)
    @Transactional
src/main/java/com/ruoyi/procurementrecord/service/ProcurementRecordService.java
@@ -18,6 +18,7 @@
    List<ProcurementDto> listProcurementBySalesLedgerId(ProcurementDto procurementDto);
    int add(ProcurementAddDto procurementDto);
    int addProduct(Details detail);
    IPage<ProcurementPageDto> listPage(Page page, ProcurementPageDto procurementDto);
src/main/java/com/ruoyi/procurementrecord/service/impl/ProcurementRecordServiceImpl.java
@@ -51,13 +51,13 @@
        // 计算待入库数量
        // 查询采购记录已入库数量
        List<Integer> collect = procurementDtos.stream().map(ProcurementDto::getId).collect(Collectors.toList());
        if(CollectionUtils.isEmpty( collect)){
        if (CollectionUtils.isEmpty(collect)) {
            return procurementDtos;
        }
        LambdaQueryWrapper<ProcurementRecordStorage> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
        procurementRecordLambdaQueryWrapper.in(ProcurementRecordStorage::getSalesLedgerProductId, collect);
        List<ProcurementRecordStorage> procurementRecordStorages = procurementRecordMapper.selectList(procurementRecordLambdaQueryWrapper);
        if(CollectionUtils.isEmpty(procurementRecordStorages)){
        if (CollectionUtils.isEmpty(procurementRecordStorages)) {
            return procurementDtos;
        }
        for (ProcurementDto dto : procurementDtos) {
@@ -65,35 +65,35 @@
            List<ProcurementRecordStorage> collect1 = procurementRecordStorages.stream()
                    .filter(procurementRecordStorage -> procurementRecordStorage.getSalesLedgerProductId().equals(dto.getId()))
                    .collect(Collectors.toList());
            // 如果没有相关的入库记录,跳过该条数据
            if(CollectionUtils.isEmpty(collect1)){
            if (CollectionUtils.isEmpty(collect1)) {
                dto.setQuantity0(dto.getQuantity());
                continue;
            }
            // 计算已入库数量总和,并设置待入库数量
            BigDecimal totalInboundNum = collect1.stream()
                    .map(ProcurementRecordStorage::getInboundNum)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);
            // 待入库数量 = 总数量 - 已入库数量
            dto.setQuantity0(dto.getQuantity().subtract(totalInboundNum));
        }
        return procurementDtos;
    }
    public ProcurementRecordStorage getProcurementRecordById(Integer id){
    public ProcurementRecordStorage getProcurementRecordById(Integer id) {
        ProcurementRecordStorage procurementRecordStorage = procurementRecordMapper.selectById(id);
        if(procurementRecordStorage == null) {
        if (procurementRecordStorage == null) {
            throw new RuntimeException("未找到该采购入库记录");
        }
        return procurementRecordStorage;
    }
    public List<ProcurementRecordStorage> getProcurementRecordByIds(List<Integer> id){
    public List<ProcurementRecordStorage> getProcurementRecordByIds(List<Integer> id) {
        List<ProcurementRecordStorage> procurementRecordStorage = procurementRecordMapper.selectBatchIds(id);
        if(procurementRecordStorage == null) {
        if (procurementRecordStorage == null) {
            throw new RuntimeException("未找到该采购入库记录");
        }
        return procurementRecordStorage;
@@ -119,7 +119,7 @@
        LambdaQueryWrapper<ProcurementRecordOut> procurementRecordOutLambdaQueryWrapper = new LambdaQueryWrapper<>();
        procurementRecordOutLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, procurementDto.getIds());
        List<ProcurementRecordOut> procurementRecordOuts = procurementRecordOutMapper.selectList(procurementRecordOutLambdaQueryWrapper);
        if(!CollectionUtils.isEmpty(procurementRecordOuts)){
        if (!CollectionUtils.isEmpty(procurementRecordOuts)) {
            procurementRecordOutMapper.deleteBatchIds(procurementRecordOuts.stream().map(ProcurementRecordOut::getId).collect(Collectors.toList()));
        }
        return 0;
@@ -127,11 +127,11 @@
    @Override
    public void export(HttpServletResponse response) {
        List<ProcurementPageDto> list =procurementRecordMapper.list();
        List<ProcurementPageDto> list = procurementRecordMapper.list();
        // 计算待入库数量
        // 查询采购记录已入库数量
        List<Integer> collect = list.stream().map(ProcurementPageDto::getId).collect(Collectors.toList());
        if(CollectionUtils.isEmpty( collect)){
        if (CollectionUtils.isEmpty(collect)) {
            ExcelUtil<ProcurementPageDto> util = new ExcelUtil<ProcurementPageDto>(ProcurementPageDto.class);
            util.exportExcel(response, list, "入库台账");
            return;
@@ -139,7 +139,7 @@
        LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
        procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect);
        List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper);
        if(CollectionUtils.isEmpty( procurementRecords)){
        if (CollectionUtils.isEmpty(procurementRecords)) {
            ExcelUtil<ProcurementPageDto> util = new ExcelUtil<ProcurementPageDto>(ProcurementPageDto.class);
            util.exportExcel(response, list, "入库台账");
            return;
@@ -151,7 +151,7 @@
                    .collect(Collectors.toList());
            // 如果没有相关的出库记录,跳过该条数据
            if(CollectionUtils.isEmpty(collect1)){
            if (CollectionUtils.isEmpty(collect1)) {
                dto.setInboundNum0(dto.getInboundNum());
                continue;
            }
@@ -174,14 +174,14 @@
    public int updateManagement(ProcurementManagementUpdateDto procurementDto) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser sysUser = sysUserMapper.selectUserById(procurementDto.getCreateUser());
        if(sysUser == null){
        if (sysUser == null) {
            throw new RuntimeException("入库人不存在");
        }
        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){
        if (salesLedgerProduct == null) {
            throw new RuntimeException("销售台账产品不存在");
        }
        salesLedgerProduct.setMinStock(procurementDto.getMinStock());
@@ -189,20 +189,20 @@
        ProcurementRecordStorage procurementRecordStorageById = getProcurementRecordById(procurementDto.getId());
        procurementRecordStorageById.setCreateBy(sysUser.getNickName());
        procurementRecordStorageById.setCreateUser(sysUser.getUserId());
        procurementRecordStorageById.setUpdateTime(LocalDateTime.parse(entryDateStr,df));
        procurementRecordStorageById.setUpdateTime(LocalDateTime.parse(entryDateStr, df));
        procurementRecordStorageById.setUpdateUser(loginUser.getUserId());
        procurementRecordStorageById.setCreateTime(LocalDateTime.parse(createTimeStr,df));
        procurementRecordStorageById.setCreateTime(LocalDateTime.parse(createTimeStr, df));
        procurementRecordMapper.updateById(procurementRecordStorageById);
        return 0;
    }
    @Override
    public void exportCopy(HttpServletResponse response) {
        List<ProcurementPageDtoCopy> list =procurementRecordMapper.listCopy();
        List<ProcurementPageDtoCopy> list = procurementRecordMapper.listCopy();
        // 计算待入库数量
        // 查询采购记录已入库数量
        List<Integer> collect = list.stream().map(ProcurementPageDtoCopy::getId).collect(Collectors.toList());
        if(CollectionUtils.isEmpty( collect)){
        if (CollectionUtils.isEmpty(collect)) {
            ExcelUtil<ProcurementPageDtoCopy> util = new ExcelUtil<ProcurementPageDtoCopy>(ProcurementPageDtoCopy.class);
            util.exportExcel(response, list, "库存管理");
            return;
@@ -210,7 +210,7 @@
        LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
        procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect);
        List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper);
        if(CollectionUtils.isEmpty( procurementRecords)){
        if (CollectionUtils.isEmpty(procurementRecords)) {
            ExcelUtil<ProcurementPageDtoCopy> util = new ExcelUtil<ProcurementPageDtoCopy>(ProcurementPageDtoCopy.class);
            util.exportExcel(response, list, "库存管理");
            return;
@@ -222,7 +222,7 @@
                    .collect(Collectors.toList());
            // 如果没有相关的出库记录,跳过该条数据
            if(CollectionUtils.isEmpty(collect1)){
            if (CollectionUtils.isEmpty(collect1)) {
                dto.setInboundNum0(dto.getInboundNum());
                continue;
            }
@@ -252,19 +252,19 @@
        reportData.put("tableData", procurementPageDtoCopyList);
        // 查询采购记录已入库数量
        List<Integer> collect = procurementPageDtoCopyList.stream().map(ProcurementPageDtoCopy::getId).collect(Collectors.toList());
        if(CollectionUtils.isEmpty(collect)){
             return reportData;
        if (CollectionUtils.isEmpty(collect)) {
            return reportData;
        }
        LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
        procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect);
        List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper);
        if(CollectionUtils.isEmpty( procurementRecords)){
             return reportData;
        if (CollectionUtils.isEmpty(procurementRecords)) {
            return reportData;
        }
        int totalIn =0;
        int totalOut =0;
        int currentStock =0;
        int turnoverRate =0;
        int totalIn = 0;
        int totalOut = 0;
        int currentStock = 0;
        int turnoverRate = 0;
        List<String> dates = new ArrayList<>();
        List<Integer> values = new ArrayList<>();
        List<String> comparisonDates = new ArrayList<>();
@@ -282,7 +282,7 @@
                    .collect(Collectors.toList());
            // 如果没有相关的出库记录,跳过该条数据
            if(CollectionUtils.isEmpty(collect1)){
            if (CollectionUtils.isEmpty(collect1)) {
                dto.setInboundNum0(dto.getInboundNum());
                continue;
            }
@@ -305,7 +305,7 @@
            currentStock += dto.getInboundNum().intValue() - totalInboundNum.intValue();
            values.add(currentStock);
            // 计算周转率
            if(totalIn > 0){
            if (totalIn > 0) {
                turnoverRate = totalOut * 100 / totalIn;
            }
        }
@@ -341,7 +341,7 @@
    public InventoryInformationDto getReportList() {
        InventoryInformationDto inventoryInformationDto = new InventoryInformationDto();
        IPage<ProcurementPageDto> procurementPageDtoIPage = this.listPage(new Page<>(1, -1), new ProcurementPageDto());
        if(CollectionUtils.isEmpty(procurementPageDtoIPage.getRecords())){
        if (CollectionUtils.isEmpty(procurementPageDtoIPage.getRecords())) {
            return inventoryInformationDto;
        }
        // 计算总库存数量
@@ -412,7 +412,7 @@
            ProcurementRecordStorage.ProcurementRecordStorageBuilder procurementRecordBuilder = ProcurementRecordStorage.builder()
                    .salesLedgerProductId(detail.getId())
                    .inboundBatches(aLong.equals(0L) ? "第1批次" : "第"+ (aLong + 1) + "批次")
                    .inboundBatches(aLong.equals(0L) ? "第1批次" : "第" + (aLong + 1) + "批次")
                    .inboundNum(detail.getInboundQuantity())
                    .warnNum(detail.getWarnNum())
                    .outStockQuantity(detail.getOutStockQuantity())
@@ -438,19 +438,38 @@
    }
    @Override
    public int addProduct(Details detail) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        ProcurementRecordStorage.ProcurementRecordStorageBuilder procurementRecordBuilder = ProcurementRecordStorage.builder()
                .inboundBatches("第1批次")
                .inboundNum(detail.getInboundQuantity())
                .warnNum(detail.getWarnNum())
                .outStockQuantity(detail.getOutStockQuantity())
                .shortageDescription(detail.getShortageDescription())
                .createTime(LocalDateTime.now())
                .createUser(loginUser.getUserId())
                .updateTime(LocalDateTime.now())
                .updateUser(loginUser.getUserId())
                .createBy(loginUser.getNickName())
                .productModelId(detail.getProductModelId());
        this.save(procurementRecordBuilder.build());
        return 1;
    }
    @Override
    public IPage<ProcurementPageDto> listPage(Page page, ProcurementPageDto procurementDto) {
        IPage<ProcurementPageDto> procurementPageDtoIPage = procurementRecordMapper.listPage(page, procurementDto);
        List<ProcurementPageDto> procurementPageDtos = procurementPageDtoIPage.getRecords();
        // 计算待入库数量
        // 查询采购记录已入库数量
        List<Integer> collect = procurementPageDtos.stream().map(ProcurementPageDto::getId).collect(Collectors.toList());
        if(CollectionUtils.isEmpty( collect)){
        if (CollectionUtils.isEmpty(collect)) {
            return procurementPageDtoIPage;
        }
        LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
        procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect);
        List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper);
        if(CollectionUtils.isEmpty( procurementRecords)){
        if (CollectionUtils.isEmpty(procurementRecords)) {
            return procurementPageDtoIPage;
        }
        for (ProcurementPageDto dto : procurementPageDtos) {
@@ -460,7 +479,7 @@
                    .collect(Collectors.toList());
            // 如果没有相关的出库记录,跳过该条数据
            if(CollectionUtils.isEmpty(collect1)){
            if (CollectionUtils.isEmpty(collect1)) {
                dto.setInboundNum0(dto.getInboundNum());
                continue;
            }
@@ -483,13 +502,13 @@
        // 计算待入库数量
        // 查询采购记录已入库数量
        List<Integer> collect = procurementPageDtoCopyList.stream().map(ProcurementPageDtoCopy::getId).collect(Collectors.toList());
        if(CollectionUtils.isEmpty( collect)){
        if (CollectionUtils.isEmpty(collect)) {
            return procurementPageDtoCopyIPage;
        }
        LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
        procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect);
        List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper);
        if(CollectionUtils.isEmpty( procurementRecords)){
        if (CollectionUtils.isEmpty(procurementRecords)) {
            return procurementPageDtoCopyIPage;
        }
        for (ProcurementPageDtoCopy dto : procurementPageDtoCopyList) {
@@ -499,7 +518,7 @@
                    .collect(Collectors.toList());
            // 如果没有相关的出库记录,跳过该条数据
            if(CollectionUtils.isEmpty(collect1)){
            if (CollectionUtils.isEmpty(collect1)) {
                dto.setInboundNum0(dto.getInboundNum());
                continue;
            }
src/main/resources/mapper/procurementrecord/ProcurementRecordMapper.xml
@@ -33,13 +33,16 @@
        select
        t3.supplier_name,
        t3.purchase_contract_number,
        t2.product_category,
        case when t2.product_category is null then t5.product_name
            else t2.product_category end as productCategory,
        t1.id,
        t1.sales_ledger_product_id,
        t1.product_model_id,
        t1.create_user,
        t2.specification_model,
        t2.unit,
        case when t2.specification_model is null then t4.model
            else t2.specification_model end as specificationModel,
        case when t2.unit is null then t4.unit
            else t2.unit end as unit,
        t2.tax_rate,
        t2.tax_inclusive_unit_price,
        (t1.inbound_num * t2.tax_inclusive_unit_price) as taxInclusiveTotalPrice,
@@ -56,6 +59,8 @@
        from  procurement_record_storage t1
                  left join sales_ledger_product t2 on t2.id = t1.sales_ledger_product_id
                  left join purchase_ledger t3 on t3.id = t2.sales_ledger_id
                  left join product_model t4 on t4.id = t1.product_model_id
                  left join product t5 on t5.id = t4.product_id
        <where>
            1 = 1
            <if test="req.supplierName != null and req.supplierName != ''">
@@ -70,10 +75,13 @@
        select
            t3.supplier_name,
            t3.purchase_contract_number,
            t2.product_category,
            case when t2.product_category is null then t5.product_name
                 else t2.product_category end as productCategory,
            t1.id,
            t2.specification_model,
            t2.unit,
            case when t2.specification_model is null then t4.model
                 else t2.specification_model end as specificationModel,
            case when t2.unit is null then t4.unit
                 else t2.unit end as unit,
            t2.quantity,
            t2.quantity as quantity0,
            t2.tax_rate,
@@ -88,17 +96,22 @@
        from  procurement_record_storage t1
                  left join sales_ledger_product t2 on t2.id = t1.sales_ledger_product_id
                  left join purchase_ledger t3 on t3.id = t2.sales_ledger_id
                  left join product_model t4 on t4.id = t1.product_model_id
                  left join product t5 on t5.id = t4.product_id
    </select>
    <select id="listPageCopy" resultType="com.ruoyi.procurementrecord.dto.ProcurementPageDtoCopy">
        select
        t3.supplier_name,
        t3.purchase_contract_number,
        t2.product_category,
        case when t2.product_category is null then t5.product_name
                 else t2.product_category end as productCategory,
        t1.id,
        t1.sales_ledger_product_id,
        t1.create_user,
        t2.specification_model,
        t2.unit,
        case when t2.specification_model is null then t4.model
                 else t2.specification_model end as specificationModel,
            case when t2.unit is null then t4.unit
                 else t2.unit end as unit,
        t2.min_stock,
        t2.tax_rate,
        t2.tax_inclusive_unit_price,
@@ -115,6 +128,8 @@
        from  procurement_record_storage t1
        left join sales_ledger_product t2 on t2.id = t1.sales_ledger_product_id
        left join purchase_ledger t3 on t3.id = t2.sales_ledger_id
        left join product_model t4 on t4.id = t1.product_model_id
        left join product t5 on t5.id = t4.product_id
        <where>
            1 = 1
            <if test="req.supplierName != null and req.supplierName != ''">
@@ -145,12 +160,15 @@
        select
            t3.supplier_name,
            t3.purchase_contract_number,
            t2.product_category,
            case when t2.product_category is null then t5.product_name
                 else t2.product_category end as productCategory,
            t1.id,
            t1.sales_ledger_product_id,
            t1.create_user,
            t2.specification_model,
            t2.unit,
            case when t2.specification_model is null then t4.model
                 else t2.specification_model end as specificationModel,
            case when t2.unit is null then t4.unit
                 else t2.unit end as unit,
            t2.tax_rate,
            t2.tax_inclusive_unit_price,
            t2.tax_inclusive_total_price,
@@ -166,6 +184,8 @@
        from  procurement_record_storage t1
                  left join sales_ledger_product t2 on t2.id = t1.sales_ledger_product_id
                  left join purchase_ledger t3 on t3.id = t2.sales_ledger_id
                  left join product_model t4 on t4.id = t1.product_model_id
                  left join product t5 on t5.id = t4.product_id
    </select>
    <select id="getSumQuantity" resultType="BigDecimal">
        select COALESCE(sum(inbound_num), 0)