diff --git a/src/main/java/io/github/talelin/latticy/common/configuration/WmsCommonConfiguration.java b/src/main/java/io/github/talelin/latticy/common/configuration/WmsCommonConfiguration.java index 913ed4a1b10cdbba47cee368a49284efe66e6006..6a834f71e3ac5b8e889fadd1cb53b69867d722d6 100644 --- a/src/main/java/io/github/talelin/latticy/common/configuration/WmsCommonConfiguration.java +++ b/src/main/java/io/github/talelin/latticy/common/configuration/WmsCommonConfiguration.java @@ -3,6 +3,7 @@ package io.github.talelin.latticy.common.configuration; import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import io.github.talelin.autoconfigure.bean.PermissionMetaCollector; @@ -34,6 +35,8 @@ public class WmsCommonConfiguration { @Bean public MybatisPlusInterceptor mybatisPlusInterceptor() { MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + // 乐观锁 + interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor()); interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); return interceptor; } diff --git a/src/main/java/io/github/talelin/latticy/service/StockService.java b/src/main/java/io/github/talelin/latticy/service/StockService.java index c8d326658206d58436a74d58237118b279e2c369..b6c8f157f35b8277ddfcdc56e0e056e22fac7b68 100644 --- a/src/main/java/io/github/talelin/latticy/service/StockService.java +++ b/src/main/java/io/github/talelin/latticy/service/StockService.java @@ -33,4 +33,13 @@ public interface StockService extends IService { * @return */ Boolean insertOrUpStock(StockDTO stockDTO); + + + /** + * 使用乐观锁修改库存信息 + * + * @param stockDO + * @return + */ + Boolean updateByIdAndVersion(StockDO stockDO); } diff --git a/src/main/java/io/github/talelin/latticy/service/impl/BatchStockServiceImpl.java b/src/main/java/io/github/talelin/latticy/service/impl/BatchStockServiceImpl.java index baf372f12228f436b8d2e7a7076abd79d10720c2..53e2fa7a4680e8f816c999cd1d654191949b47a4 100644 --- a/src/main/java/io/github/talelin/latticy/service/impl/BatchStockServiceImpl.java +++ b/src/main/java/io/github/talelin/latticy/service/impl/BatchStockServiceImpl.java @@ -87,7 +87,8 @@ public class BatchStockServiceImpl extends ServiceImpl implemen .eq(StockDO::getSku, sku)); } + @Override + public Boolean updateByIdAndVersion(StockDO stockDO) { + return baseMapper.updateById(stockDO) > 0; + } @Override public Boolean insertOrUpStock(StockDTO stockDTO) { @@ -47,6 +51,7 @@ public class StockServiceImpl extends ServiceImpl implemen StockDO stockDO = new StockDO(); stockDO.setId(stock.getId()); stockDO.setDelivered(stockDTO.getQuantity() + stock.getDelivered()); - return updateById(stockDO); + stockDO.setVersion(stock.getVersion()); + return updateByIdAndVersion(stockDO); } }