|  | @@ -1,12 +1,16 @@
 | 
	
		
			
				|  |  |  package com.yonge.cooleshow.portal.controller;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.common.entity.HttpResponseResult;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.common.enums.CacheNameEnum;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.mall.common.api.CommonResult;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.mall.common.enums.OrderCacheEnum;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.mbg.model.OmsCartItem;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.portal.domain.CartProduct;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.portal.domain.CartPromotionItem;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.portal.dto.OrderPayRes;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.portal.service.OmsCartItemService;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.portal.service.UmsMemberService;
 | 
	
		
			
				|  |  | +import com.yonge.toolset.base.exception.BizException;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.base.util.StringUtil;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.payment.util.DistributedLock;
 | 
	
		
			
				|  |  |  import io.swagger.annotations.Api;
 | 
	
	
		
			
				|  | @@ -20,6 +24,7 @@ import org.springframework.web.bind.annotation.*;
 | 
	
		
			
				|  |  |  import java.util.List;
 | 
	
		
			
				|  |  |  import java.util.concurrent.TimeUnit;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import static com.yonge.cooleshow.mall.common.api.CommonResult.failed;
 | 
	
		
			
				|  |  |  import static com.yonge.cooleshow.mall.common.enums.OrderCacheEnum.LOCK_STOCK_MALL;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
	
		
			
				|  | @@ -44,11 +49,24 @@ public class OmsCartItemController {
 | 
	
		
			
				|  |  |      @ResponseBody
 | 
	
		
			
				|  |  |      public CommonResult<OmsCartItem> add(@RequestBody OmsCartItem cartItem) {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        OmsCartItem omsCartItem = DistributedLock.of(redissonClient)
 | 
	
		
			
				|  |  | -                                                 .runIfLockWaitGet(
 | 
	
		
			
				|  |  | -                                                         LOCK_STOCK_MALL.getRedisKey(cartItem.getProductSkuId()),
 | 
	
		
			
				|  |  | -                                                         () -> cartItemService.add(cartItem), 10, TimeUnit.SECONDS);
 | 
	
		
			
				|  |  | -        return CommonResult.success(omsCartItem);
 | 
	
		
			
				|  |  | +        RLock lock = redissonClient.getLock(OrderCacheEnum.LOCK_STOCK_MALL.getRedisKey(cartItem.getProductSkuId()));
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            boolean b = lock.tryLock(60, TimeUnit.SECONDS);
 | 
	
		
			
				|  |  | +            if (b) {
 | 
	
		
			
				|  |  | +                OmsCartItem omsCartItem = cartItemService.add(cartItem);
 | 
	
		
			
				|  |  | +                return CommonResult.success(omsCartItem);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            return failed("请求超时");
 | 
	
		
			
				|  |  | +        } catch (BizException e) {
 | 
	
		
			
				|  |  | +            return failed(e.getMessage());
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            e.printStackTrace();
 | 
	
		
			
				|  |  | +            return failed("请求超时");
 | 
	
		
			
				|  |  | +        } finally {
 | 
	
		
			
				|  |  | +            if (lock.getHoldCount()>0) {
 | 
	
		
			
				|  |  | +                lock.unlock();
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -77,10 +95,25 @@ public class OmsCartItemController {
 | 
	
		
			
				|  |  |                                         @RequestParam Integer quantity) {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          OmsCartItem omsCartItem = cartItemService.get(id);
 | 
	
		
			
				|  |  | -        DistributedLock.of(redissonClient)
 | 
	
		
			
				|  |  | -                       .runIfLockWaitGet(LOCK_STOCK_MALL.getRedisKey(omsCartItem.getProductSkuId())
 | 
	
		
			
				|  |  | -                               , () -> cartItemService.updateQuantity(id, memberService.getCurrentMember().getId(), quantity), 10, TimeUnit.SECONDS);
 | 
	
		
			
				|  |  | -        return CommonResult.success(1);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        RLock lock = redissonClient.getLock(OrderCacheEnum.LOCK_STOCK_MALL.getRedisKey(omsCartItem.getProductSkuId()));
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            boolean b = lock.tryLock(60, TimeUnit.SECONDS);
 | 
	
		
			
				|  |  | +            if (b) {
 | 
	
		
			
				|  |  | +                int i = cartItemService.updateQuantity(id, memberService.getCurrentMember().getId(), quantity);
 | 
	
		
			
				|  |  | +                return CommonResult.success(i);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            return failed("请求超时");
 | 
	
		
			
				|  |  | +        } catch (BizException e) {
 | 
	
		
			
				|  |  | +            return failed(e.getMessage());
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            e.printStackTrace();
 | 
	
		
			
				|  |  | +            return failed("请求超时");
 | 
	
		
			
				|  |  | +        } finally {
 | 
	
		
			
				|  |  | +            if (lock.getHoldCount()>0) {
 | 
	
		
			
				|  |  | +                lock.unlock();
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -100,7 +133,7 @@ public class OmsCartItemController {
 | 
	
		
			
				|  |  |          if (count > 0) {
 | 
	
		
			
				|  |  |              return CommonResult.success(count);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        return CommonResult.failed();
 | 
	
		
			
				|  |  | +        return failed();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @ApiOperation("删除购物车中的指定商品")
 | 
	
	
		
			
				|  | @@ -112,7 +145,7 @@ public class OmsCartItemController {
 | 
	
		
			
				|  |  |          if (count > 0) {
 | 
	
		
			
				|  |  |              return CommonResult.success(count);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        return CommonResult.failed();
 | 
	
		
			
				|  |  | +        return failed();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @ApiOperation("清空当前会员的购物车")
 | 
	
	
		
			
				|  | @@ -123,6 +156,6 @@ public class OmsCartItemController {
 | 
	
		
			
				|  |  |          if (count > 0) {
 | 
	
		
			
				|  |  |              return CommonResult.success(count);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        return CommonResult.failed();
 | 
	
		
			
				|  |  | +        return failed();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 |