| | |
| | | public Result<String> subscribe(@Valid UserSubscription model) { |
| | | String partyId = SecurityUtils.getUser().getUserId(); |
| | | if (StringUtils.isEmpty(partyId)) { |
| | | throw new YamiShopBindException("请重新登录"); |
| | | throw new YamiShopBindException("Please log in again"); |
| | | } |
| | | RLock rLock = redissonClient.getLock("subscribe" + partyId); |
| | | boolean lockAcquired = false; |
| | |
| | | lockAcquired = rLock.tryLock(5, TimeUnit.SECONDS); |
| | | if (!lockAcquired) { |
| | | log.warn("无法获取锁: subscribe{}", partyId); |
| | | throw new YamiShopBindException("请稍后再试"); |
| | | throw new YamiShopBindException("Please try again later"); |
| | | } |
| | | model.setUserId(partyId); |
| | | return icoService.subscribe(model); |
| | |
| | | throw e; // 重新抛出自定义异常 |
| | | } catch (Exception e) { |
| | | log.error("系统异常: {}", e.getMessage(), e); |
| | | throw new YamiShopBindException("操作失败,请稍后再试"); |
| | | throw new YamiShopBindException("Operation failed, please try again later"); |
| | | } finally { |
| | | // 确保释放锁 |
| | | if (lockAcquired && rLock.isHeldByCurrentThread()) { |
| | |
| | | QueryWrapper queryWrapper = QueryWrapperGenerator.buildQueryCondition (icoQuery, IcoQuery.class); |
| | | String partyId = SecurityUtils.getUser().getUserId(); |
| | | if (StringUtils.isEmpty(partyId)) { |
| | | throw new YamiShopBindException("请重新登录"); |
| | | throw new YamiShopBindException("Please log in again"); |
| | | } |
| | | queryWrapper.eq("u.user_id", partyId); |
| | | queryWrapper.orderByDesc("created_at"); |