| | |
| | | stockOutRecordService.add(stockOutRecordDto); |
| | | StockInventory oldStockInventory = stockInventoryMapper.selectOne(new QueryWrapper<StockInventory>().lambda().eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId())); |
| | | if (ObjectUtils.isEmpty(oldStockInventory)) { |
| | | throw new RuntimeException("产品库存不存在"); |
| | | throw new RuntimeException("该产品没有库存数量"); |
| | | } |
| | | BigDecimal lockedQty = oldStockInventory.getLockedQuantity(); |
| | | if (lockedQty == null) { |
| | | lockedQty = BigDecimal.ZERO; |
| | | } |
| | | if (stockInventoryDto.getQualitity().compareTo(oldStockInventory.getQualitity().subtract(lockedQty)) > 0) { |
| | | throw new RuntimeException("库存不足无法出库"); |
| | | } |
| | | |
| | | // 移除库存数量限制,允许库存不足时发货,库存可以为负数 |
| | | stockInventoryMapper.updateSubtractStockInventory(stockInventoryDto); |
| | | return true; |
| | | } |
| | |
| | | stockInventory.setLockedQuantity(stockInventory.getLockedQuantity().subtract(stockInventoryDto.getLockedQuantity())); |
| | | return this.updateById(stockInventory); |
| | | } |
| | | } |
| | | } |