huminmin
昨天 802796c22d7d21a6d572cd4c11844e6865521666
src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
@@ -105,12 +105,7 @@
        eq.eq(StockInventory::getBatchNo, stockInventoryDto.getBatchNo());
        //新增入库记录再添加库存
        StockInRecordDto stockInRecordDto = new StockInRecordDto();
        stockInRecordDto.setRecordId(stockInventoryDto.getRecordId());
        stockInRecordDto.setRecordType(stockInventoryDto.getRecordType());
        stockInRecordDto.setStockInNum(stockInventoryDto.getQualitity());
        stockInRecordDto.setBatchNo(stockInventoryDto.getBatchNo());
        stockInRecordDto.setProductModelId(stockInventoryDto.getProductModelId());
        stockInRecordDto.setType("0");
        populateStockInRecord(stockInventoryDto, stockInRecordDto);
        stockInRecordService.add(stockInRecordDto);
        //再进行新增库存数量库存
        //先查询库存表中的产品是否存在,不存在新增,存在更新
@@ -124,8 +119,10 @@
            newStockInventory.setBatchNo(stockInventoryDto.getBatchNo());
            newStockInventory.setLockedQuantity(stockInventoryDto.getLockedQuantity());
            newStockInventory.setWarnNum(stockInventoryDto.getWarnNum());
            applySourceBindingFields(newStockInventory, stockInventoryDto);
            stockInventoryMapper.insert(newStockInventory);
        } else {
            applySourceBindingFields(stockInventoryDto, stockInventoryDto);
            stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
        }
        return true;
@@ -180,23 +177,50 @@
        stockInventoryDto.setBatchNo(batchNo);
        StockInRecordDto stockInRecordDto = new StockInRecordDto();
        populateStockInRecord(stockInventoryDto, stockInRecordDto);
        stockInRecordService.add(stockInRecordDto);
        return true;
    }
    private void applySourceBindingFields(StockInventory target, StockInventoryDto source) {
        if (target == null || source == null) {
            return;
        }
        target.setSource(source.getSource());
        if (StockInventorySourceEnum.PURCHASE_RECEIPT.getCode().equals(source.getSource())) {
            target.setSupplierId(source.getSupplierId());
            target.setManufacturerId(null);
            return;
        }
        if (StockInventorySourceEnum.OUTSOURCED_RECEIPT.getCode().equals(source.getSource())) {
            target.setManufacturerId(source.getManufacturerId());
            target.setSupplierId(null);
            return;
        }
        target.setManufacturerId(null);
        target.setSupplierId(null);
    }
    private void populateStockInRecord(StockInventoryDto stockInventoryDto, StockInRecordDto stockInRecordDto) {
        stockInRecordDto.setRecordId(stockInventoryDto.getRecordId());
        stockInRecordDto.setRecordType(stockInventoryDto.getRecordType());
        stockInRecordDto.setStockInNum(stockInventoryDto.getQualitity());
        stockInRecordDto.setBatchNo(batchNo);
        stockInRecordDto.setBatchNo(stockInventoryDto.getBatchNo());
        stockInRecordDto.setProductModelId(stockInventoryDto.getProductModelId());
        stockInRecordDto.setType("0");
        stockInRecordDto.setRemark(stockInventoryDto.getRemark());
        stockInRecordDto.setWarnNum(stockInventoryDto.getWarnNum());
        stockInRecordDto.setManufacturerId(stockInventoryDto.getManufacturerId());
        stockInRecordDto.setSource(stockInventoryDto.getSource());
        if (StockInventorySourceEnum.PURCHASE_RECEIPT.getCode().equals(stockInventoryDto.getSource())) {
            stockInRecordDto.setSupplierId(stockInventoryDto.getSupplierId());
        } else if (StockInventorySourceEnum.OUTSOURCED_RECEIPT.getCode().equals(stockInventoryDto.getSource())) {
            stockInRecordDto.setManufacturerId(stockInventoryDto.getManufacturerId());
        }
        // 设置含水量相关信息
        stockInRecordDto.setIsContainsWater(stockInventoryDto.getIsContainsWater());
        stockInRecordDto.setWaterContent(stockInventoryDto.getWaterContent());
        stockInRecordDto.setTheoryStockInNum(stockInventoryDto.getTheoryStockInNum());
        stockInRecordDto.setDifferenceNum(stockInventoryDto.getDifferenceNum());
        stockInRecordService.add(stockInRecordDto);
        return true;
    }
    //规则生成:20260424-产品编号-001