Forráskód Böngészése

商品库存加锁

LuoDLeo 1 hónapja
szülő
commit
4f1e38c82c

+ 5 - 2
src/main/java/org/springblade/modules/finance/service/impl/OrderGoodsServiceImpl.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.redisson.api.RLock;
 import org.redisson.api.RedissonClient;
 import org.springblade.common.enums.YesOrNoEnum;
@@ -43,6 +44,7 @@ import java.util.concurrent.TimeUnit;
  * @author BladeX
  * @since 2024-07-17
  */
+@Slf4j
 @AllArgsConstructor
 @Service("orderGoodsServiceImpl")
 public class OrderGoodsServiceImpl extends ServiceImpl<OrderGoodsMapper, OrderGoods> implements IOrderGoodsService, SubmitOrderService {
@@ -94,7 +96,7 @@ public class OrderGoodsServiceImpl extends ServiceImpl<OrderGoodsMapper, OrderGo
             Assert.notNull(goods, "商品信息不存在");
             FacilityCargoWay cargoWay = iFacilityCargoWayService.getById(request.getCargoWayId());
             //库存校验
-            Assert.isTrue(cargoWay.getGoodsStore() < 1 || cargoWay.getGoodsStore() < request.getGoodsNum(), "商品库存不足");
+            Assert.isFalse(cargoWay.getGoodsStore() < 1 || cargoWay.getGoodsStore() < request.getGoodsNum(), "商品库存不足");
             Assert.notNull(cargoWay, "货道信息不存在");
             Shop shop = iShopService.getById(request.getShopId());
             Assert.notNull(shop, "门店信息不存在");
@@ -141,7 +143,8 @@ public class OrderGoodsServiceImpl extends ServiceImpl<OrderGoodsMapper, OrderGo
             return order.getOrderNo();
         } catch (Exception e) {
             log.error("下单失败", e);
-            throw new ServiceException("下单失败");
+            e.printStackTrace();
+            throw new ServiceException("下单失败:" + e.getMessage());
         } finally {
             lock.unlock();
         }