From 21d7f957832e050fe2fe3a9e9f53cbd762ad4afb Mon Sep 17 00:00:00 2001 From: zcy9999 <1328476842@qq.com> Date: Thu, 30 Jun 2022 21:56:42 +0800 Subject: [PATCH] =?UTF-8?q?docs(=E5=BA=93=E5=AD=98=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BA=93=E5=AD=98=E4=BD=BF=E7=94=A8=E4=B9=90?= =?UTF-8?q?=E8=A7=82=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/configuration/WmsCommonConfiguration.java | 3 +++ .../io/github/talelin/latticy/service/StockService.java | 9 +++++++++ .../latticy/service/impl/BatchStockServiceImpl.java | 3 ++- .../talelin/latticy/service/impl/StockServiceImpl.java | 7 ++++++- 4 files changed, 20 insertions(+), 2 deletions(-) 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 913ed4a..6a834f7 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 c8d3266..b6c8f15 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 baf372f..53e2fa7 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); } } -- Gitee