|
@@ -11,6 +11,7 @@ import com.gree.mall.contest.constant.Constant;
|
|
import com.gree.mall.contest.exception.RemoteServiceException;
|
|
import com.gree.mall.contest.exception.RemoteServiceException;
|
|
import com.gree.mall.contest.helper.ResponseHelper;
|
|
import com.gree.mall.contest.helper.ResponseHelper;
|
|
import com.gree.mall.contest.logic.coupon.CouponLogic;
|
|
import com.gree.mall.contest.logic.coupon.CouponLogic;
|
|
|
|
+import com.gree.mall.contest.logic.user.UserLogic;
|
|
import com.gree.mall.contest.plus.entity.UserCoupon;
|
|
import com.gree.mall.contest.plus.entity.UserCoupon;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
@@ -37,6 +38,7 @@ import java.util.concurrent.locks.Lock;
|
|
public class MiniCouponController {
|
|
public class MiniCouponController {
|
|
|
|
|
|
private final CouponLogic couponLogic;
|
|
private final CouponLogic couponLogic;
|
|
|
|
+ private final UserLogic userLogic;
|
|
private final RedisLockRegistry redisLockRegistry;
|
|
private final RedisLockRegistry redisLockRegistry;
|
|
|
|
|
|
|
|
|
|
@@ -87,7 +89,7 @@ public class MiniCouponController {
|
|
@Parameter(description = "用户id") @RequestParam(required = false) String userId,
|
|
@Parameter(description = "用户id") @RequestParam(required = false) String userId,
|
|
HttpServletRequest request
|
|
HttpServletRequest request
|
|
) throws RemoteServiceException {
|
|
) throws RemoteServiceException {
|
|
- List<CouponObtainBean> coupons = couponLogic.allObtainCoupou(userId,request);
|
|
|
|
|
|
+ List<CouponObtainBean> coupons = couponLogic.allObtainCoupou(userId, request);
|
|
return ResponseHelper.success(coupons);
|
|
return ResponseHelper.success(coupons);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -95,19 +97,19 @@ public class MiniCouponController {
|
|
@GetMapping("/obtain")
|
|
@GetMapping("/obtain")
|
|
@Operation(summary = "领券")
|
|
@Operation(summary = "领券")
|
|
public ResponseHelper obtain(HttpServletRequest request,
|
|
public ResponseHelper obtain(HttpServletRequest request,
|
|
- @Parameter(description = "用户id") @RequestParam(required = false) String userId,
|
|
|
|
- @Parameter(description = "优惠券id") @RequestParam(required = false) List<String> couponIds
|
|
|
|
|
|
+ @Parameter(description = "用户id") @RequestParam(required = false) String userId,
|
|
|
|
+ @Parameter(description = "优惠券id") @RequestParam(required = false) List<String> couponIds
|
|
|
|
|
|
) throws RemoteServiceException, InterruptedException {
|
|
) throws RemoteServiceException, InterruptedException {
|
|
- for(String couponId : couponIds) {
|
|
|
|
|
|
+ for (String couponId : couponIds) {
|
|
Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_COUPON + couponId);
|
|
Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_COUPON + couponId);
|
|
- if(!obtain.tryLock(10,TimeUnit.SECONDS)){
|
|
|
|
- log.error("系统繁忙,领券失败,userId:{},couponId:{}",userId,couponId);
|
|
|
|
|
|
+ if (!obtain.tryLock(10, TimeUnit.SECONDS)) {
|
|
|
|
+ log.error("系统繁忙,领券失败,userId:{},couponId:{}", userId, couponId);
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
couponLogic.obtainCoupou(request, userId, couponId);
|
|
couponLogic.obtainCoupou(request, userId, couponId);
|
|
- }finally {
|
|
|
|
|
|
+ } finally {
|
|
obtain.unlock();
|
|
obtain.unlock();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -145,10 +147,10 @@ public class MiniCouponController {
|
|
|
|
|
|
@GetMapping("/transfer/coupon")
|
|
@GetMapping("/transfer/coupon")
|
|
@Operation(summary = "转赠优惠券")
|
|
@Operation(summary = "转赠优惠券")
|
|
- public ResponseHelper<String> transferCoupon(HttpServletRequest request,@Parameter(description = "id", required = true) @RequestParam String userCouponId)
|
|
|
|
|
|
+ public ResponseHelper<String> transferCoupon(HttpServletRequest request, @Parameter(description = "id", required = true) @RequestParam String userCouponId)
|
|
throws RemoteServiceException {
|
|
throws RemoteServiceException {
|
|
|
|
|
|
- return ResponseHelper.success(couponLogic.transferCoupon(request,userCouponId));
|
|
|
|
|
|
+ return ResponseHelper.success(couponLogic.transferCoupon(request, userCouponId, userLogic));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|