| | |
| | | throw new BaseException("该入库记录不存在,无法更新!!!"); |
| | | } |
| | | |
| | | // 记录修改前的 batch_no |
| | | String oldBatchNo = stockInRecord.getBatchNo(); |
| | | String newBatchNo = stockInRecordDto.getBatchNo(); |
| | | |
| | | String[] ignoreProperties = {"id", "inbound_batches"};//排除id属性 |
| | | BeanUtils.copyProperties(stockInRecordDto, stockInRecord, ignoreProperties); |
| | | return stockInRecordMapper.updateById(stockInRecord); |
| | | int result = stockInRecordMapper.updateById(stockInRecord); |
| | | |
| | | // 如果 batch_no 发生变化,需要同步更新关联表 |
| | | if (newBatchNo != null && !newBatchNo.equals(oldBatchNo)) { |
| | | updateRelatedBatchNo(stockInRecord, oldBatchNo, newBatchNo); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 同步更新关联表的 batch_no |
| | | * @param stockInRecord 入库记录 |
| | | * @param oldBatchNo 修改前的批号 |
| | | * @param newBatchNo 修改后的批号 |
| | | */ |
| | | private void updateRelatedBatchNo(StockInRecord stockInRecord, String oldBatchNo, String newBatchNo) { |
| | | // 1. 更新 stock_inventory 表(合格库存) |
| | | LambdaQueryWrapper<StockInventory> inventoryEq = new LambdaQueryWrapper<StockInventory>() |
| | | .eq(StockInventory::getProductModelId, stockInRecord.getProductModelId()); |
| | | if (StringUtils.isEmpty(oldBatchNo)) { |
| | | inventoryEq.isNull(StockInventory::getBatchNo); |
| | | } else { |
| | | inventoryEq.eq(StockInventory::getBatchNo, oldBatchNo); |
| | | } |
| | | StockInventory stockInventory = stockInventoryMapper.selectOne(inventoryEq); |
| | | if (stockInventory != null) { |
| | | stockInventory.setBatchNo(newBatchNo); |
| | | stockInventoryMapper.updateById(stockInventory); |
| | | } |
| | | |
| | | // 2. 更新 stock_uninventory 表(不合格库存) |
| | | LambdaQueryWrapper<StockUninventory> uninventoryEq = new LambdaQueryWrapper<StockUninventory>() |
| | | .eq(StockUninventory::getProductModelId, stockInRecord.getProductModelId()); |
| | | if (StringUtils.isEmpty(oldBatchNo)) { |
| | | uninventoryEq.isNull(StockUninventory::getBatchNo); |
| | | } else { |
| | | uninventoryEq.eq(StockUninventory::getBatchNo, oldBatchNo); |
| | | } |
| | | StockUninventory stockUninventory = stockUninventoryMapper.selectOne(uninventoryEq); |
| | | if (stockUninventory != null) { |
| | | stockUninventory.setBatchNo(newBatchNo); |
| | | stockUninventoryMapper.updateById(stockUninventory); |
| | | } |
| | | } |
| | | |
| | | @Override |