src/main/java/com/ruoyi/consumables/service/impl/ConsumablesInventoryServiceImpl.java
@@ -43,14 +43,15 @@
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ConsumablesInventoryServiceImpl extends ServiceImpl<ConsumablesInventoryMapper, ConsumablesInventory> implements ConsumablesInventoryService {
    private final ConsumablesInventoryMapper ConsumablesInventoryMapper;
    private final ConsumablesInRecordService ConsumablesInRecordService;
    private final ConsumablesOutRecordService ConsumablesOutRecordService;
    private final ConsumablesInventoryMapper consumablesInventoryMapper;
    private final ConsumablesInRecordService consumablesInRecordService;
    private final ConsumablesOutRecordService consumablesOutRecordService;
    private final SalesLedgerProductMapper salesLedgerProductMapper;
    private final WeighbridgeDocGenerator weighbridgeDocGenerator;
    @Override
    public IPage<ConsumablesInventoryDto> pageConsumablesInventory(Page page, ConsumablesInventoryDto ConsumablesInventoryDto) {
        return ConsumablesInventoryMapper.pageConsumablesInventory(page, ConsumablesInventoryDto);
    public IPage<ConsumablesInventoryDto> pageConsumablesInventory(Page page, ConsumablesInventoryDto consumablesInventoryDto) {
        return consumablesInventoryMapper.pageConsumablesInventory(page, consumablesInventoryDto);
    }
    //入库调用
@@ -61,32 +62,30 @@
        ConsumablesInRecordDto consumablesInRecordDto = new ConsumablesInRecordDto();
        consumablesInRecordDto.setRecordId(consumablesInventoryDto.getRecordId());
        consumablesInRecordDto.setRecordType(consumablesInventoryDto.getRecordType());
        consumablesInRecordDto.setConsumablesInNum(consumablesInventoryDto.getNetWeight());
        consumablesInRecordDto.setStockInNum(consumablesInventoryDto.getQualitity());
        consumablesInRecordDto.setWeighingDate(consumablesInventoryDto.getWeighingDate());
        consumablesInRecordDto.setNetWeight(consumablesInventoryDto.getNetWeight());
        consumablesInRecordDto.setGrossWeight(consumablesInventoryDto.getGrossWeight());
        consumablesInRecordDto.setTareWeight(consumablesInventoryDto.getTareWeight());
        consumablesInRecordDto.setLicensePlateNo(consumablesInventoryDto.getLicensePlateNo());
        consumablesInRecordDto.setWeighingOperator(consumablesInventoryDto.getWeighingOperator());
        consumablesInRecordDto.setProductModelId(consumablesInventoryDto.getProductModelId());
        consumablesInRecordDto.setProductId(consumablesInventoryDto.getProductId());
        consumablesInRecordDto.setPurchaser(consumablesInventoryDto.getPurchaser());
        consumablesInRecordDto.setType("0");
        ConsumablesInRecordService.add(consumablesInRecordDto);
        consumablesInRecordService.add(consumablesInRecordDto);
        //再进行新增库存数量库存
        //先查询库存表中的产品是否存在,不存在新增,存在更新
        ConsumablesInventory oldConsumablesInventory = ConsumablesInventoryMapper.selectOne(new QueryWrapper<ConsumablesInventory>().lambda().eq(ConsumablesInventory::getProductModelId, consumablesInventoryDto.getProductModelId()));
        ConsumablesInventory oldConsumablesInventory = consumablesInventoryMapper.selectOne(new QueryWrapper<ConsumablesInventory>().lambda().eq(ConsumablesInventory::getProductModelId, consumablesInventoryDto.getProductModelId()));
        if (ObjectUtils.isEmpty(oldConsumablesInventory)) {
            ConsumablesInventory newConsumablesInventory = new ConsumablesInventory();
            newConsumablesInventory.setProductModelId(consumablesInventoryDto.getProductModelId());
            newConsumablesInventory.setQualitity(consumablesInventoryDto.getNetWeight());
            newConsumablesInventory.setQualitity(consumablesInventoryDto.getQualitity());
            newConsumablesInventory.setVersion(1);
            newConsumablesInventory.setRemark(consumablesInventoryDto.getRemark());
            newConsumablesInventory.setLockedQuantity(consumablesInventoryDto.getLockedQuantity());
            newConsumablesInventory.setWarnNum(consumablesInventoryDto.getWarnNum());
            ConsumablesInventoryMapper.insert(newConsumablesInventory);
            newConsumablesInventory.setProductId(consumablesInventoryDto.getProductId());
            newConsumablesInventory.setPurchaser(consumablesInventoryDto.getPurchaser());
            consumablesInventoryMapper.insert(newConsumablesInventory);
        } else {
            consumablesInventoryDto.setQualitity(consumablesInventoryDto.getNetWeight());
            ConsumablesInventoryMapper.updateAddConsumablesInventory(consumablesInventoryDto);
            consumablesInventoryDto.setQualitity(consumablesInventoryDto.getQualitity());
            consumablesInventoryMapper.updateAddConsumablesInventory(consumablesInventoryDto);
        }
        return true;
    }
@@ -100,17 +99,15 @@
        consumablesOutRecordDto.setRecordId(consumablesInventoryDto.getRecordId());
        consumablesOutRecordDto.setRecordType(consumablesInventoryDto.getRecordType());
        consumablesOutRecordDto.setWeighingDate(consumablesInventoryDto.getWeighingDate());
        consumablesOutRecordDto.setConsumablesOutNum(consumablesInventoryDto.getNetWeight());
        consumablesOutRecordDto.setNetWeight(consumablesInventoryDto.getNetWeight());
        consumablesOutRecordDto.setGrossWeight(consumablesInventoryDto.getGrossWeight());
        consumablesOutRecordDto.setTareWeight(consumablesInventoryDto.getTareWeight());
        consumablesOutRecordDto.setStockOutNum(consumablesInventoryDto.getQualitity());
        consumablesOutRecordDto.setWeighingOperator(consumablesInventoryDto.getWeighingOperator());
        consumablesOutRecordDto.setProductModelId(consumablesInventoryDto.getProductModelId());
        consumablesOutRecordDto.setLicensePlateNo(consumablesInventoryDto.getLicensePlateNo());
        consumablesOutRecordDto.setProductId(consumablesInventoryDto.getProductId());
        consumablesOutRecordDto.setPurchaser(consumablesInventoryDto.getPurchaser());
        consumablesOutRecordDto.setType("0");
        ConsumablesOutRecordService.add(consumablesOutRecordDto);
        ConsumablesInventory oldConsumablesInventory = ConsumablesInventoryMapper.selectOne(new QueryWrapper<ConsumablesInventory>().lambda().eq(ConsumablesInventory::getProductModelId, consumablesInventoryDto.getProductModelId()));
        consumablesOutRecordService.add(consumablesOutRecordDto);
        ConsumablesInventory oldConsumablesInventory = consumablesInventoryMapper.selectOne(new QueryWrapper<ConsumablesInventory>().lambda().eq(ConsumablesInventory::getProductModelId, consumablesInventoryDto.getProductModelId()));
        if (ObjectUtils.isEmpty(oldConsumablesInventory)) {
            throw new RuntimeException("产品库存不存在");
        }
@@ -122,7 +119,7 @@
            throw new RuntimeException("库存不足无法出库");
        }
        ConsumablesInventoryMapper.updateSubtractConsumablesInventory(consumablesInventoryDto);
        consumablesInventoryMapper.updateSubtractConsumablesInventory(consumablesInventoryDto);
        return true;
    }
@@ -143,18 +140,18 @@
                for (SalesLedgerProduct item : salesLedgerProducts) {
                    if (item.getProductCategory().equals(dto.getProductName()) &&
                            item.getSpecificationModel().equals(dto.getModel())) {
                        ConsumablesInventoryDto ConsumablesInventoryDto = new ConsumablesInventoryDto();
                        ConsumablesInventoryDto.setRecordId(0L);
                        ConsumablesInventoryDto.setRecordType(StockInQualifiedRecordTypeEnum.CUSTOMIZATION_STOCK_IN.getCode());
                        ConsumablesInventoryDto.setQualitity(dto.getQualitity());
                        ConsumablesInventoryDto.setRemark(dto.getRemark());
                        ConsumablesInventoryDto.setWarnNum(dto.getWarnNum());
                        ConsumablesInventoryDto consumablesInventoryDto = new ConsumablesInventoryDto();
                        consumablesInventoryDto.setRecordId(0L);
                        consumablesInventoryDto.setRecordType(StockInQualifiedRecordTypeEnum.CUSTOMIZATION_STOCK_IN.getCode());
                        consumablesInventoryDto.setQualitity(dto.getQualitity());
                        consumablesInventoryDto.setRemark(dto.getRemark());
                        consumablesInventoryDto.setNetWeight(dto.getNetWeight());
                        if (ObjectUtils.isNotEmpty(dto.getLockedQuantity()) && dto.getLockedQuantity().compareTo(dto.getQualitity()) > 0) {
                            throw new RuntimeException("冻结数量不能超过本次导入的库存数量");
                        }
                        ConsumablesInventoryDto.setLockedQuantity(dto.getLockedQuantity());
                        ConsumablesInventoryDto.setProductModelId(item.getProductModelId());
                        this.addConsumablesInventory(ConsumablesInventoryDto);
                        consumablesInventoryDto.setLockedQuantity(dto.getLockedQuantity());
                        consumablesInventoryDto.setProductModelId(item.getProductModelId());
                        this.addConsumablesInventory(consumablesInventoryDto);
                        matched = true;
                        break; // 找到匹配项后跳出循环
                    }
@@ -184,44 +181,44 @@
    @Override
    public void exportConsumablesInventory(HttpServletResponse response, ConsumablesInventoryDto ConsumablesInventoryDto) {
    public void exportConsumablesInventory(HttpServletResponse response, ConsumablesInventoryDto consumablesInventoryDto) {
        List<ConsumablesInventoryExportData> list = ConsumablesInventoryMapper.listConsumablesInventoryExportData(ConsumablesInventoryDto);
        List<ConsumablesInventoryExportData> list = consumablesInventoryMapper.listConsumablesInventoryExportData(consumablesInventoryDto);
        ExcelUtil<ConsumablesInventoryExportData> util = new ExcelUtil<>(ConsumablesInventoryExportData.class);
        util.exportExcel(response, list, "库存信息");
    }
    @Override
    public IPage<ConsumablesInRecordDto> consumablesInventoryPage(ConsumablesInventoryDto consumablesInventoryDto, Page page) {
        return ConsumablesInventoryMapper.ConsumablesInventoryPage(consumablesInventoryDto, page);
        return consumablesInventoryMapper.consumablesInventoryPage(consumablesInventoryDto, page);
    }
    @Override
    public IPage<ConsumablesInventoryDto> consumablesInAndOutRecord(ConsumablesInventoryDto consumablesInventoryDto, Page page) {
        return ConsumablesInventoryMapper.ConsumablesInAndOutRecord(consumablesInventoryDto, page);
        return consumablesInventoryMapper.consumablesInAndOutRecord(consumablesInventoryDto, page);
    }
    @Override
    public Boolean frozenConsumables(ConsumablesInventoryDto ConsumablesInventoryDto) {
        ConsumablesInventory ConsumablesInventory = ConsumablesInventoryMapper.selectById(ConsumablesInventoryDto.getId());
        if (ConsumablesInventory.getQualitity().compareTo(ConsumablesInventoryDto.getLockedQuantity()) < 0) {
    public Boolean frozenConsumables(ConsumablesInventoryDto consumablesInventoryDto) {
        ConsumablesInventory consumablesInventory = consumablesInventoryMapper.selectById(consumablesInventoryDto.getId());
        if (consumablesInventory.getQualitity().compareTo(consumablesInventoryDto.getLockedQuantity()) < 0) {
            throw new RuntimeException("冻结数量不能超过库存数量");
        }
        if (ObjectUtils.isEmpty(ConsumablesInventory.getLockedQuantity())) {
            ConsumablesInventory.setLockedQuantity(ConsumablesInventoryDto.getLockedQuantity());
        if (ObjectUtils.isEmpty(consumablesInventory.getLockedQuantity())) {
            consumablesInventory.setLockedQuantity(consumablesInventoryDto.getLockedQuantity());
        } else {
            ConsumablesInventory.setLockedQuantity(ConsumablesInventory.getLockedQuantity().add(ConsumablesInventoryDto.getLockedQuantity()));
            consumablesInventory.setLockedQuantity(consumablesInventory.getLockedQuantity().add(consumablesInventoryDto.getLockedQuantity()));
        }
        return this.updateById(ConsumablesInventory);
        return this.updateById(consumablesInventory);
    }
    @Override
    public Boolean thawConsumables(ConsumablesInventoryDto ConsumablesInventoryDto) {
        ConsumablesInventory ConsumablesInventory = ConsumablesInventoryMapper.selectById(ConsumablesInventoryDto.getId());
        if (ConsumablesInventory.getLockedQuantity().compareTo(ConsumablesInventoryDto.getLockedQuantity()) < 0) {
    public Boolean thawConsumables(ConsumablesInventoryDto consumablesInventoryDto) {
        ConsumablesInventory consumablesInventory = consumablesInventoryMapper.selectById(consumablesInventoryDto.getId());
        if (consumablesInventory.getLockedQuantity().compareTo(consumablesInventoryDto.getLockedQuantity()) < 0) {
            throw new RuntimeException("解冻数量不能超过冻结数量");
        }
        ConsumablesInventory.setLockedQuantity(ConsumablesInventory.getLockedQuantity().subtract(ConsumablesInventoryDto.getLockedQuantity()));
        return this.updateById(ConsumablesInventory);
        consumablesInventory.setLockedQuantity(consumablesInventory.getLockedQuantity().subtract(consumablesInventoryDto.getLockedQuantity()));
        return this.updateById(consumablesInventory);
    }
}