| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean addstockInventory(StockInventoryDto stockInventoryDto) { |
| | | //新增入库记录再添加库存 |
| | | // 1. 创建入库记录 |
| | | StockInRecordDto stockInRecordDto = new StockInRecordDto(); |
| | | stockInRecordDto.setRecordId(stockInventoryDto.getRecordId()); |
| | | stockInRecordDto.setRecordType(stockInventoryDto.getRecordType()); |
| | | stockInRecordDto.setWeighingOperator(stockInventoryDto.getWeighingOperator()); |
| | | stockInRecordDto.setProductModelId(stockInventoryDto.getProductModelId()); |
| | | stockInRecordDto.setProductId(stockInventoryDto.getProductId()); |
| | | stockInRecordDto.setRemark(stockInventoryDto.getRemark()); |
| | | stockInRecordDto.setType("0"); |
| | | |
| | | // 根据产品类型设置不同的重量字段 |
| | | if (stockInventoryDto.getProductType() != null && stockInventoryDto.getProductType() == 0) { |
| | | stockInRecordDto.setStockInNum(stockInventoryDto.getNetWeight()); |
| | | stockInRecordDto.setWeighingDate(stockInventoryDto.getWeighingDate()); |
| | | stockInRecordDto.setNetWeight(stockInventoryDto.getNetWeight()); |
| | | stockInRecordDto.setGrossWeight(stockInventoryDto.getGrossWeight()); |
| | | stockInRecordDto.setTareWeight(stockInventoryDto.getTareWeight()); |
| | | stockInRecordDto.setLicensePlateNo(stockInventoryDto.getLicensePlateNo()); |
| | | stockInRecordDto.setWeighingOperator(stockInventoryDto.getWeighingOperator()); |
| | | stockInRecordDto.setProductModelId(stockInventoryDto.getProductModelId()); |
| | | stockInRecordDto.setProductId(stockInventoryDto.getProductId()); |
| | | stockInRecordDto.setRemark(stockInventoryDto.getRemark()); |
| | | stockInRecordDto.setType("0"); |
| | | //生成磅单 |
| | | String absoluteDocPath = weighbridgeDocGenerator.generateWeighbridgeDoc(stockInRecordDto); |
| | | stockInRecordDto.setWeighbridgeDocPath(absoluteDocPath); |
| | | } else { |
| | | stockInRecordDto.setStockInNum(stockInventoryDto.getQualitity()); |
| | | stockInRecordDto.setNetWeight(stockInventoryDto.getQualitity()); |
| | | } |
| | | |
| | | // 保存入库记录 |
| | | stockInRecordService.add(stockInRecordDto); |
| | | //再进行新增库存数量库存 |
| | | //先查询库存表中的产品是否存在,不存在新增,存在更新 |
| | | StockInventory oldStockInventory = stockInventoryMapper.selectOne(new QueryWrapper<StockInventory>().lambda().eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId())); |
| | | |
| | | // 2. 更新库存 |
| | | StockInventory oldStockInventory = stockInventoryMapper.selectOne( |
| | | new QueryWrapper<StockInventory>().lambda() |
| | | .eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId()) |
| | | ); |
| | | if (ObjectUtils.isEmpty(oldStockInventory)) { |
| | | // 新增库存 |
| | | StockInventory newStockInventory = new StockInventory(); |
| | | newStockInventory.setProductModelId(stockInventoryDto.getProductModelId()); |
| | | newStockInventory.setQualitity(stockInventoryDto.getNetWeight()); |
| | | newStockInventory.setQualitity(stockInventoryDto.getProductType() == 0 ? |
| | | stockInventoryDto.getNetWeight() : stockInventoryDto.getQualitity()); |
| | | newStockInventory.setVersion(1); |
| | | newStockInventory.setRemark(stockInventoryDto.getRemark()); |
| | | newStockInventory.setLockedQuantity(stockInventoryDto.getLockedQuantity()); |
| | |
| | | newStockInventory.setProductId(stockInventoryDto.getProductId()); |
| | | stockInventoryMapper.insert(newStockInventory); |
| | | } else { |
| | | stockInventoryDto.setQualitity(stockInventoryDto.getNetWeight()); |
| | | // 更新库存 |
| | | stockInventoryDto.setQualitity(stockInventoryDto.getProductType() != null && stockInventoryDto.getProductType() == 0 ? |
| | | stockInventoryDto.getNetWeight() : stockInventoryDto.getQualitity()); |
| | | stockInventoryMapper.updateAddStockInventory(stockInventoryDto); |
| | | } |
| | | return true; |