|  |  | 
 |  |  |             // 获取锁,最多等待 10 秒,锁自动释放时间 30 秒 | 
 |  |  |             if (lock.tryLock(10, 30, TimeUnit.SECONDS)) { | 
 |  |  |                 try { | 
 |  |  |                     // 活动优惠券和积分优惠券需要根据库存来控制- 根据优惠券的发放数量来控制有没有超发 | 
 |  |  |                     if(StringUtils.isNotBlank(couponTemplateDO.getCategory()) && ( | 
 |  |  |                             couponTemplateDO.getCategory().equals(CouponCategoryEnum.ACTIVITY.getStatus()) || couponTemplateDO.getCategory().equals(CouponCategoryEnum.POINT.getStatus()) | 
 |  |  |                     )){ | 
 |  |  |                     // 活动优惠券 根据优惠券的发放数量来控制有没有超发 | 
 |  |  |                     if(StringUtils.isNotBlank(couponTemplateDO.getCategory()) && | 
 |  |  |                             couponTemplateDO.getCategory().equals(CouponCategoryEnum.ACTIVITY.getStatus()) | 
 |  |  |                     ){ | 
 |  |  |                         // 获取当前优惠券已经领取的数量 | 
 |  |  |                         final Integer gainTotal = getExistGainCouponRecordAmountById(couponTemplateDO.getId()); | 
 |  |  |                         if(couponTemplateDO.getCouponAmount().compareTo(gainTotal)<=0){ | 
 |  |  |                             throw new ValidationException("当前优惠券已经领完!"); | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                     if(StringUtils.isNotBlank(couponTemplateDO.getCategory()) | 
 |  |  |                             && couponTemplateDO.getCategory().equals(CouponCategoryEnum.POINT.getStatus() | 
 |  |  |                     )){ | 
 |  |  |                         // 获取当前优惠券已经领取的数量 | 
 |  |  |  | 
 |  |  |                         if(couponTemplateDO.getCouponAmount()<=0){ | 
 |  |  |                             throw new ValidationException("当前优惠券已经领完!"); | 
 |  |  |                         }else{ | 
 |  |  |                             couponTemplateDO.setCouponAmount(couponTemplateDO.getCouponAmount()-1); | 
 |  |  |                             // 更新库存 | 
 |  |  |                             couponTemplateService.updateById(couponTemplateDO); | 
 |  |  |                         } | 
 |  |  |  | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  |                     // 根据用户领取设置的getLimit 查看当前用户是否已经超领优惠券 | 
 |  |  |                     if(StringUtils.isNotBlank(couponTemplateDO.getCategory()) && couponTemplateDO.getCategory().equals(CouponCategoryEnum.ACTIVITY.getStatus()) ){ |