| | |
| | | } |
| | | |
| | | /** |
| | | * 增量更新库存占用量 |
| | | * |
| | | * @param id 库存记录编号 |
| | | * @param count 变动数量(正数=增加占用,负数=减少占用) |
| | | * @param checkFlag 是否校验可用量充足(为 true 时占用不允许超过可用量) |
| | | * @return 影响行数 |
| | | */ |
| | | default int updateReservedQuantity(Long id, BigDecimal count, boolean checkFlag) { |
| | | LambdaUpdateWrapper<MesWmMaterialStockDO> updateWrapper = new LambdaUpdateWrapper<MesWmMaterialStockDO>() |
| | | .eq(MesWmMaterialStockDO::getId, id) |
| | | .setSql("reserved_quantity = reserved_quantity + " + count); |
| | | if (checkFlag && count.compareTo(BigDecimal.ZERO) > 0) { |
| | | // 校验可用量充足:quantity - frozen_quantity - reserved_quantity >= count |
| | | updateWrapper.setSql("reserved_quantity = reserved_quantity + " + count + |
| | | " WHERE quantity - IFNULL(frozen_quantity, 0) - IFNULL(reserved_quantity, 0) >= " + count); |
| | | } |
| | | return update(null, updateWrapper); |
| | | } |
| | | |
| | | /** |
| | | * 增量更新库存在途量 |
| | | * |
| | | * @param id 库存记录编号 |
| | | * @param count 变动数量(正数=增加在途,负数=减少在途) |
| | | * @return 影响行数 |
| | | */ |
| | | default int updateInTransitQuantity(Long id, BigDecimal count) { |
| | | LambdaUpdateWrapper<MesWmMaterialStockDO> updateWrapper = new LambdaUpdateWrapper<MesWmMaterialStockDO>() |
| | | .eq(MesWmMaterialStockDO::getId, id) |
| | | .setSql("in_transit_quantity = in_transit_quantity + " + count); |
| | | return update(null, updateWrapper); |
| | | } |
| | | |
| | | /** |
| | | * 按组合键查询库存记录 |
| | | * |
| | | * 唯一键:(itemId, warehouseId, locationId, areaId, batchId, vendorId) |