src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
@@ -1,6 +1,8 @@
package com.ruoyi.procurementrecord.utils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.ruoyi.procurementrecord.mapper.ProcurementRecordMapper;
import com.ruoyi.procurementrecord.mapper.ProcurementRecordOutMapper;
import com.ruoyi.stock.dto.StockInRecordDto;
@@ -20,7 +22,9 @@
import java.math.BigDecimal;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component
@RequiredArgsConstructor
@@ -45,6 +49,7 @@
        stockUninventoryDto.setRecordType(String.valueOf(recordType));
        stockUninventoryDto.setQualitity(quantity);
        stockUninventoryDto.setProductModelId(productModelId);
        stockUninventoryDto.setStockLocation("不合格库位");
        stockUninventoryService.addStockUninventory(stockUninventoryDto);
    }
@@ -61,6 +66,7 @@
        stockUninventoryDto.setRecordType(String.valueOf(recordType));
        stockUninventoryDto.setQualitity(quantity);
        stockUninventoryDto.setProductModelId(productModelId);
        stockUninventoryDto.setStockLocation("不合格库位");
        stockUninventoryService.subtractStockUninventory(stockUninventoryDto);
    }
@@ -71,13 +77,19 @@
     * @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,
                         String stockLocation,
                         Integer isProduction) {
        StockInventoryDto stockInventoryDto = new StockInventoryDto();
        stockInventoryDto.setRecordId(recordId);
        stockInventoryDto.setRecordType(String.valueOf(recordType));
        stockInventoryDto.setQualitity(quantity);
        stockInventoryDto.setProductModelId(productModelId);
        stockInventoryService.addstockInventory(stockInventoryDto);
        stockInventoryDto.setStockLocation(stockLocation);
        stockInventoryService.addstockInventory(stockInventoryDto,isProduction);
    }
    /**
@@ -87,28 +99,31 @@
     * @param recordType
     * @param recordId
     */
    public void substractStock(Long productModelId, BigDecimal quantity, String recordType,Long recordId) {
    public void substractStock(Long productModelId, BigDecimal quantity, String recordType,Long recordId,String stockLocation) {
        StockInventoryDto stockInventoryDto = new StockInventoryDto();
        stockInventoryDto.setRecordId(recordId);
        stockInventoryDto.setRecordType(String.valueOf(recordType));
        stockInventoryDto.setQualitity(quantity);
        stockInventoryDto.setProductModelId(productModelId);
        stockInventoryDto.setStockLocation(stockLocation);
        stockInventoryService.subtractStockInventory(stockInventoryDto);
    }
    //不合格库存删除
    public void deleteStockInRecord(Long recordId, String recordType) {
        StockInRecord one = stockInRecordService.getOne(new QueryWrapper<StockInRecord>()
        List<StockInRecord> one = stockInRecordService.getBaseMapper().selectList(new QueryWrapper<StockInRecord>()
                .lambda().eq(StockInRecord::getRecordId, recordId)
                .eq(StockInRecord::getRecordType, recordType));
        stockInRecordService.batchDelete(Collections.singletonList(one.getId()));
        if (CollectionUtils.isNotEmpty(one)) {
            stockInRecordService.batchDelete(one.stream().map(StockInRecord::getId).collect(Collectors.toList()));
        }
    }
    public void deleteStockOutRecord(Long recordId, String recordType) {
        StockOutRecord one = stockOutRecordService.getOne(new QueryWrapper<StockOutRecord>()
        List<StockOutRecord> one = stockOutRecordService.getBaseMapper().selectList(new QueryWrapper<StockOutRecord>()
                .lambda().eq(StockOutRecord::getRecordId, recordId)
                .eq(StockOutRecord::getRecordType, recordType));
        stockOutRecordService.batchDelete(Collections.singletonList(one.getId()));
        if (CollectionUtils.isNotEmpty(one)) {
            stockOutRecordService.batchDelete(one.stream().map(StockOutRecord::getId).collect(Collectors.toList()));
        }
    }
}