gongchunyi
15 小时以前 6b4cfc6f9d660b92be99ba4e3411a3267bc57155
src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
@@ -2,13 +2,17 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.procurementrecord.mapper.ProcurementRecordMapper;
import com.ruoyi.procurementrecord.mapper.ProcurementRecordOutMapper;
import com.ruoyi.stock.dto.StockInRecordDto;
import com.ruoyi.stock.dto.StockInventoryDto;
import com.ruoyi.stock.dto.StockUninventoryDto;
import com.ruoyi.stock.pojo.StockInRecord;
import com.ruoyi.stock.pojo.StockInventory;
import com.ruoyi.stock.pojo.StockOutRecord;
import com.ruoyi.stock.pojo.StockUninventory;
import com.ruoyi.stock.service.StockInRecordService;
import com.ruoyi.stock.service.StockInventoryService;
import com.ruoyi.stock.service.StockOutRecordService;
@@ -34,66 +38,163 @@
    private final StockOutRecordService stockOutRecordService;
    /**
     * 合格库存出库前校验:按 stock_inventory 可用数量(数量 − 冻结)
     */
    public void assertQualifiedAvailable(Long productModelId, BigDecimal outboundQty) {
        if (productModelId == null) {
            throw new ServiceException("出库失败,产品规格未维护");
        }
        if (outboundQty == null || outboundQty.compareTo(BigDecimal.ZERO) <= 0) {
            return;
        }
        StockInventory inv = stockInventoryService.getOne(
                Wrappers.<StockInventory>lambdaQuery().eq(StockInventory::getProductModelId, productModelId));
        if (inv == null) {
            throw new ServiceException("出库失败,合格库中无该产品库存");
        }
        BigDecimal locked = inv.getLockedQuantity() == null ? BigDecimal.ZERO : inv.getLockedQuantity();
        BigDecimal qty = inv.getQualitity() == null ? BigDecimal.ZERO : inv.getQualitity();
        BigDecimal available = qty.subtract(locked);
        if (outboundQty.compareTo(available) > 0) {
            throw new ServiceException("出库失败,出库数量不能大于当前合格库存可用数量");
        }
    }
    /**
     * 不合格库存出库前校验:按 stock_uninventory 可用数量(数量 − 冻结)
     */
    public void assertUnqualifiedAvailable(Long productModelId, BigDecimal outboundQty) {
        if (productModelId == null) {
            throw new ServiceException("出库失败,产品规格未维护");
        }
        if (outboundQty == null || outboundQty.compareTo(BigDecimal.ZERO) <= 0) {
            return;
        }
        StockUninventory inv = stockUninventoryService.getOne(
                Wrappers.<StockUninventory>lambdaQuery().eq(StockUninventory::getProductModelId, productModelId));
        if (inv == null) {
            throw new ServiceException("出库失败,不合格库中无该产品库存");
        }
        BigDecimal locked = inv.getLockedQuantity() == null ? BigDecimal.ZERO : inv.getLockedQuantity();
        BigDecimal qty = inv.getQualitity() == null ? BigDecimal.ZERO : inv.getQualitity();
        BigDecimal available = qty.subtract(locked);
        if (outboundQty.compareTo(available) > 0) {
            throw new ServiceException("出库失败,出库数量不能大于当前不合格库存可用数量");
        }
    }
    /**
     * 不合格入库
     *
     * @param productModelId
     * @param quantity
     * @param recordType
     * @param recordId
     */
    public void addUnStock(Long productModelId, BigDecimal quantity, String recordType,Long recordId) {
    public void addUnStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
        addUnStock(null, null, productModelId, quantity, recordType, recordId);
    }
    /**
     * 不合格入库(带销售订单关联,写入入库记录)
     */
    public void addUnStock(Long salesLedgerId, Long salesLedgerProductId, Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
        StockUninventoryDto stockUninventoryDto = new StockUninventoryDto();
        stockUninventoryDto.setRecordId(recordId);
        stockUninventoryDto.setRecordType(String.valueOf(recordType));
        stockUninventoryDto.setQualitity(quantity);
        stockUninventoryDto.setProductModelId(productModelId);
        stockUninventoryDto.setSalesLedgerId(salesLedgerId);
        stockUninventoryDto.setSalesLedgerProductId(salesLedgerProductId);
        stockUninventoryService.addStockUninventory(stockUninventoryDto);
    }
    /**
     * 不合格出库
     * @param productModelId
     * @param quantity
     * @param recordType
     * @param recordId
     */
    public void subtractUnStock(Long productModelId, BigDecimal quantity, Integer recordType,Long recordId) {
    public void subtractUnStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
        subtractUnStock(null, null, productModelId, quantity, recordType, recordId);
    }
    /**
     * 不合格出库(可带销售订单关联写入出库记录)
     */
    public void subtractUnStock(Long salesLedgerId, Long salesLedgerProductId, Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
        StockUninventoryDto stockUninventoryDto = new StockUninventoryDto();
        stockUninventoryDto.setRecordId(recordId);
        stockUninventoryDto.setRecordType(String.valueOf(recordType));
        stockUninventoryDto.setRecordType(recordType);
        stockUninventoryDto.setQualitity(quantity);
        stockUninventoryDto.setProductModelId(productModelId);
        stockUninventoryDto.setSalesLedgerId(salesLedgerId);
        stockUninventoryDto.setSalesLedgerProductId(salesLedgerProductId);
        stockUninventoryService.subtractStockUninventory(stockUninventoryDto);
    }
    /**
     * 合格入库
     *
     * @param productModelId
     * @param quantity
     * @param recordType
     * @param recordId
     */
    public void addStock(Long productModelId, BigDecimal quantity, String recordType,Long recordId) {
    public void addStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
        addStock(null, null, productModelId, quantity, recordType, recordId);
    }
    /**
     * 合格入库
     *
     * @param productModelId
     * @param quantity
     * @param recordType
     * @param recordId
     */
    public void addStock(Long salesLedgerId, Long salesLedgerProductId, Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
        StockInventoryDto stockInventoryDto = new StockInventoryDto();
        stockInventoryDto.setRecordId(recordId);
        stockInventoryDto.setRecordType(String.valueOf(recordType));
        stockInventoryDto.setQualitity(quantity);
        stockInventoryDto.setProductModelId(productModelId);
        stockInventoryDto.setSalesLedgerId(salesLedgerId);
        stockInventoryDto.setSalesLedgerProductId(salesLedgerProductId);
        stockInventoryService.addstockInventory(stockInventoryDto);
    }
    /**
     * 合格出库
     *
     * @param productModelId
     * @param quantity
     * @param recordType
     * @param recordId
     */
    public void substractStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
        StockInventoryDto stockInventoryDto = new StockInventoryDto();
        stockInventoryDto.setRecordId(recordId);
        stockInventoryDto.setRecordType(String.valueOf(recordType));
        stockInventoryDto.setQualitity(quantity);
        stockInventoryDto.setProductModelId(productModelId);
        stockInventoryService.subtractStockInventory(stockInventoryDto);
    }
    /**
     * 合格出库
     *
     * @param productModelId
     * @param quantity
     * @param recordType
     * @param recordId
     */
    public void substractStock(Long productModelId, BigDecimal quantity, String recordType,Long recordId) {
    public void substractStock(Long salesId, Long salseProductId, Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
        StockInventoryDto stockInventoryDto = new StockInventoryDto();
        stockInventoryDto.setRecordId(recordId);
        stockInventoryDto.setRecordType(String.valueOf(recordType));
        stockInventoryDto.setQualitity(quantity);
        stockInventoryDto.setProductModelId(productModelId);
        stockInventoryDto.setSalesLedgerId(salesId);
        stockInventoryDto.setSalesLedgerProductId(salseProductId);
        stockInventoryService.subtractStockInventory(stockInventoryDto);
    }
@@ -106,6 +207,7 @@
            stockInRecordService.batchDelete(Collections.singletonList(one.getId()));
        }
    }
    public void deleteStockOutRecord(Long recordId, String recordType) {
        StockOutRecord one = stockOutRecordService.getOne(new QueryWrapper<StockOutRecord>()
                .lambda().eq(StockOutRecord::getRecordId, recordId)