| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean addstockInventory(StockInventoryDto stockInventoryDto) { |
| | | //新增入库记录再添加库存 |
| | | // 更新产品入库状态 |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(stockInventoryDto.getSalesLedgerProductId()); |
| | | if (salesLedgerProduct == null) { |
| | | throw new ServiceException("入库失败,销售产品不存在"); |
| | | // 更新订单产品入库状态(仅当传入了产品行ID时) |
| | | if (stockInventoryDto.getSalesLedgerProductId() != null) { |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(stockInventoryDto.getSalesLedgerProductId()); |
| | | if (salesLedgerProduct == null) { |
| | | throw new ServiceException("入库失败,销售产品不存在"); |
| | | } |
| | | salesLedgerProduct.setProductStockStatus(1); |
| | | salesLedgerProductMapper.updateById(salesLedgerProduct); |
| | | } |
| | | salesLedgerProduct.setProductStockStatus(1); |
| | | salesLedgerProductMapper.updateById(salesLedgerProduct); |
| | | |
| | | StockInRecordDto stockInRecordDto = new StockInRecordDto(); |
| | | stockInRecordDto.setRecordId(stockInventoryDto.getRecordId()); |
| | |
| | | stockInRecordService.add(stockInRecordDto); |
| | | //再进行新增库存数量库存 |
| | | //先查询库存表中的产品是否存在,不存在新增,存在更新 |
| | | StockInventory oldStockInventory = stockInventoryMapper.selectOne(new QueryWrapper<StockInventory>().lambda().eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId())); |
| | | List<StockInventory> stockInventories = stockInventoryMapper.selectList(new QueryWrapper<StockInventory>().lambda() |
| | | .eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId()) |
| | | .orderByDesc(StockInventory::getId)); |
| | | StockInventory oldStockInventory = (stockInventories == null || stockInventories.isEmpty()) ? null : stockInventories.get(0); |
| | | if (ObjectUtils.isEmpty(oldStockInventory)) { |
| | | StockInventory newStockInventory = new StockInventory(); |
| | | newStockInventory.setProductModelId(stockInventoryDto.getProductModelId()); |
| | |
| | | stockOutRecordDto.setSalesLedgerId(stockInventoryDto.getSalesLedgerId()); |
| | | stockOutRecordDto.setSalesLedgerProductId(stockInventoryDto.getSalesLedgerProductId()); |
| | | stockOutRecordService.add(stockOutRecordDto); |
| | | StockInventory oldStockInventory = stockInventoryMapper.selectOne(new QueryWrapper<StockInventory>().lambda().eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId())); |
| | | List<StockInventory> stockInventories = stockInventoryMapper.selectList(new QueryWrapper<StockInventory>().lambda() |
| | | .eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId()) |
| | | .orderByDesc(StockInventory::getId)); |
| | | StockInventory oldStockInventory = (stockInventories == null || stockInventories.isEmpty()) ? null : stockInventories.get(0); |
| | | if (ObjectUtils.isEmpty(oldStockInventory)) { |
| | | throw new RuntimeException("产品库存不存在"); |
| | | } |