feat:更新方法名称
This commit is contained in:
@@ -16,5 +16,5 @@ public interface InventoryRepository extends IService<InventoryDO> {
|
|||||||
/**
|
/**
|
||||||
* 更新库存(乐观锁)
|
* 更新库存(乐观锁)
|
||||||
*/
|
*/
|
||||||
boolean updateWithVersion(InventoryDO inventoryDO);
|
boolean update(InventoryDO inventoryDO);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class InventoryRepositoryImpl extends ServiceImpl<InventoryMapper, Invent
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateWithVersion(InventoryDO inventoryDO) {
|
public boolean update(InventoryDO inventoryDO) {
|
||||||
if (inventoryDO.getRemainingStock() < 0) {
|
if (inventoryDO.getRemainingStock() < 0) {
|
||||||
LogUtil.warn("库存更新失败(剩余库存为负), inventoryCode={}, remainingStock={}",
|
LogUtil.warn("库存更新失败(剩余库存为负), inventoryCode={}, remainingStock={}",
|
||||||
inventoryDO.getInventoryCode(), inventoryDO.getRemainingStock());
|
inventoryDO.getInventoryCode(), inventoryDO.getRemainingStock());
|
||||||
|
|||||||
@@ -123,11 +123,11 @@ public class RouteServiceImpl implements RouteService {
|
|||||||
|
|
||||||
Integer beforeQty = inventory.getRemainingStock();
|
Integer beforeQty = inventory.getRemainingStock();
|
||||||
|
|
||||||
// 扣减剩余库存(使用乐观锁)
|
// 扣减剩余库存
|
||||||
inventory.setRemainingStock(inventory.getRemainingStock() - dto.getQuantity());
|
inventory.setRemainingStock(inventory.getRemainingStock() - dto.getQuantity());
|
||||||
inventory.setUpdateTime(LocalDateTime.now());
|
inventory.setUpdateTime(LocalDateTime.now());
|
||||||
|
|
||||||
boolean success = inventoryRepository.updateWithVersion(inventory);
|
boolean success = inventoryRepository.update(inventory);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
return Result.fail("INVENTORY_LOCK_FAILED", "库存锁定失败,可能库存不足或并发冲突");
|
return Result.fail("INVENTORY_LOCK_FAILED", "库存锁定失败,可能库存不足或并发冲突");
|
||||||
@@ -297,7 +297,7 @@ public class RouteServiceImpl implements RouteService {
|
|||||||
inventory.setRemainingStock(inventory.getRemainingStock() - dto.getQuantity());
|
inventory.setRemainingStock(inventory.getRemainingStock() - dto.getQuantity());
|
||||||
inventory.setUpdateTime(LocalDateTime.now());
|
inventory.setUpdateTime(LocalDateTime.now());
|
||||||
|
|
||||||
boolean success = inventoryRepository.updateWithVersion(inventory);
|
boolean success = inventoryRepository.update(inventory);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
return Result.fail("INVENTORY_LOCK_FAILED", "库存锁定失败,可能库存不足或并发冲突");
|
return Result.fail("INVENTORY_LOCK_FAILED", "库存锁定失败,可能库存不足或并发冲突");
|
||||||
|
|||||||
Reference in New Issue
Block a user