liyong
2026-05-15 0578c6c76f13e367b5dc7d0882efe3c69ca4cb0e
src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
@@ -1,5 +1,6 @@
package com.ruoyi.procurementrecord.utils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.ruoyi.procurementrecord.mapper.ProcurementRecordMapper;
@@ -33,7 +34,7 @@
    private final StockInventoryMapper stockInventoryMapper;
    /**
     * 不合格入库
     * 涓嶅悎鏍煎叆搴?
     *
     * @param productModelId
     * @param quantity
@@ -46,11 +47,11 @@
        stockUninventoryDto.setRecordType(String.valueOf(recordType));
        stockUninventoryDto.setQualitity(quantity);
        stockUninventoryDto.setProductModelId(productModelId);
        stockUninventoryService.addStockInRecordOnly(stockUninventoryDto);
        stockUninventoryService.addStockUninventory(stockUninventoryDto);
    }
    /**
     * 不合格出库
     * 涓嶅悎鏍煎嚭搴?
     *
     * @param productModelId
     * @param quantity
@@ -67,40 +68,49 @@
    }
    /**
     * 合格入库
     * @param productModelId
     * @param quantity
     * 鍚堟牸鍏ュ簱
     * @param recordType
     * @param recordId
     */
    public void addStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
        addStock(productModelId, quantity, recordType, recordId, resolveWarehouseInfoId(null, productModelId, null));
    }
    public void addStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId, Long warehouseInfoId) {
        StockInventoryDto stockInventoryDto = new StockInventoryDto();
        stockInventoryDto.setRecordId(recordId);
        stockInventoryDto.setRecordType(String.valueOf(recordType));
        stockInventoryDto.setQualitity(quantity);
        stockInventoryDto.setProductModelId(productModelId);
        stockInventoryDto.setWarehouseInfoId(warehouseInfoId);
        stockInventoryService.addStockInRecordOnly(stockInventoryDto);
    }
    /**
     * 合格入库带批次号
     * 鍚堟牸鍏ュ簱甯︽壒娆″彿
     * @param productModelId
     * @param quantity
     * @param recordType
     * @param recordId
     */
    public StockInRecordDto addStockWithBatchNo(Long productModelId, BigDecimal quantity, String recordType, Long recordId, String batchNo) {
        return addStockWithBatchNo(productModelId, quantity, recordType, recordId, batchNo,
                resolveWarehouseInfoId(null, productModelId, batchNo));
    }
    public StockInRecordDto addStockWithBatchNo(Long productModelId, BigDecimal quantity, String recordType, Long recordId, String batchNo, Long warehouseInfoId) {
        StockInventoryDto stockInventoryDto = new StockInventoryDto();
        stockInventoryDto.setRecordId(recordId);
        stockInventoryDto.setRecordType(String.valueOf(recordType));
        stockInventoryDto.setQualitity(quantity);
        stockInventoryDto.setProductModelId(productModelId);
        stockInventoryDto.setBatchNo(batchNo);
       return stockInventoryService.addStockInRecordOnly(stockInventoryDto);
        stockInventoryDto.setWarehouseInfoId(warehouseInfoId);
        return stockInventoryService.addStockInRecordOnly(stockInventoryDto);
    }
    /**
     * 合格出库
     * 鍚堟牸鍑哄簱
     *
     * @param productModelId
     * @param quantity
@@ -108,36 +118,59 @@
     * @param recordId
     */
    public void substractStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
        substractStock(productModelId, quantity, recordType, recordId, resolveWarehouseInfoId(null, productModelId, null));
    }
    public void substractStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId, Long warehouseInfoId) {
        StockInventoryDto stockInventoryDto = new StockInventoryDto();
        stockInventoryDto.setRecordId(recordId);
        stockInventoryDto.setRecordType(String.valueOf(recordType));
        stockInventoryDto.setQualitity(quantity);
        stockInventoryDto.setProductModelId(productModelId);
        stockInventoryDto.setWarehouseInfoId(warehouseInfoId);
        stockInventoryService.subtractStockInventory(stockInventoryDto);
    }
    public StockOutRecordDto substractStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId, String batchNo) {
        return substractStock(productModelId, quantity, recordType, recordId, batchNo,
                resolveWarehouseInfoId(null, productModelId, batchNo));
    }
    public StockOutRecordDto substractStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId, String batchNo, Long warehouseInfoId) {
        StockInventoryDto stockInventoryDto = new StockInventoryDto();
        stockInventoryDto.setRecordId(recordId);
        stockInventoryDto.setRecordType(String.valueOf(recordType));
        stockInventoryDto.setQualitity(quantity);
        stockInventoryDto.setProductModelId(productModelId);
        stockInventoryDto.setBatchNo(batchNo);
       return stockInventoryService.subtractStockInventory(stockInventoryDto);
        stockInventoryDto.setWarehouseInfoId(warehouseInfoId);
        return stockInventoryService.addStockOutRecordOnly(stockInventoryDto);
    }
    //不合格库存删除
    /**
     * @param recordType
     * @param recordId
     */
    public void shipmentStatus(String recordType, Long recordId) {
        LambdaQueryWrapper<StockOutRecord> queryWrapper = new LambdaQueryWrapper<StockOutRecord>().eq(StockOutRecord::getRecordType, recordType)
                .eq(StockOutRecord::getRecordId, recordId);
        StockOutRecord stockOutRecord = stockOutRecordService.getOne(queryWrapper);
        stockOutRecord.setApprovalStatus(0);
        stockOutRecordService.updateById(stockOutRecord);
    }
    public void deleteStockInRecord(Long recordId, String recordType) {
        StockInRecord one = stockInRecordService.getOne(new QueryWrapper<StockInRecord>()
                .lambda().eq(StockInRecord::getRecordId, recordId)
                .eq(StockInRecord::getRecordType, recordType));
        if (ObjectUtils.isNotEmpty(one)) {
            stockInRecordService.batchDelete(Collections.singletonList(one.getId()));
            //将库存减回来
            StockInventoryDto stockInventoryDto = new StockInventoryDto();
            stockInventoryDto.setRecordId(recordId);
            stockInventoryDto.setRecordType(recordType);
            stockInventoryDto.setQualitity(one.getStockInNum());
            stockInventoryDto.setProductModelId(one.getProductModelId());
            stockInventoryDto.setBatchNo(one.getBatchNo());
            stockInventoryMapper.updateSubtractStockInventory((stockInventoryDto));
        }
@@ -149,13 +182,22 @@
                .eq(StockOutRecord::getRecordType, recordType));
        if (ObjectUtils.isNotEmpty(one)) {
            stockOutRecordService.batchDelete(Collections.singletonList(one.getId()));
            //将库存加回来
            StockInventoryDto stockInventoryDto = new StockInventoryDto();
            stockInventoryDto.setRecordId(recordId);
            stockInventoryDto.setRecordType(recordType);
            stockInventoryDto.setQualitity(one.getStockOutNum());
            stockInventoryDto.setProductModelId(one.getProductModelId());
            stockInventoryDto.setBatchNo(one.getBatchNo());
            stockInventoryDto.setWarehouseInfoId(one.getWarehouseInfoId());
            stockInventoryMapper.updateAddStockInventory((stockInventoryDto));
        }
    }
    private Long resolveWarehouseInfoId(Long warehouseInfoId, Long productModelId, String batchNo) {
        if (warehouseInfoId == null) {
            throw new IllegalArgumentException("warehouseInfoId不能为空");
        }
        return warehouseInfoId;
    }
}