| | |
| | | import com.ruoyi.im.util.UserPolicyUtils; |
| | | import com.ruoyi.system.domain.*; |
| | | import com.ruoyi.system.domain.dto.PayCallbackDTO; |
| | | import com.ruoyi.system.domain.dto.SubordinateInformationDto; |
| | | import com.ruoyi.system.domain.dto.UserPolicyDto; |
| | | import com.ruoyi.im.service.UserPolicyService; |
| | | import com.ruoyi.system.domain.out.UserTeamAndPositionOut; |
| | | import com.ruoyi.system.service.PaymentRecordService; |
| | | import com.ruoyi.system.service.UserAccountService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | */ |
| | | @PostMapping("/purchaseApplication") |
| | | public Result purchaseApplication(UserPolicyDto dto) { |
| | | // 生成锁的key:基于用户ID和产品ID,防止同一用户同时购买同一产品 |
| | | String lockKey = redisDistributedLock.generateLockKey(dto.getAccount(), dto.getProductId()); |
| | | synchronized (dto.getAccount()) { |
| | | // 生成锁的key:基于用户ID和产品ID,防止同一用户同时购买同一产品 |
| | | String lockKey = redisDistributedLock.generateLockKey(dto.getAccount(), dto.getProductId()); |
| | | |
| | | boolean lockAcquired = false; |
| | | try { |
| | | // 尝试获取分布式锁:等待10秒,锁过期30秒 |
| | | lockAcquired = redisDistributedLock.tryLock(lockKey, 30L, 10L); |
| | | boolean lockAcquired = false; |
| | | try { |
| | | // 尝试获取分布式锁:等待10秒,锁过期30秒 |
| | | lockAcquired = redisDistributedLock.tryLock(lockKey, 30L, 10L); |
| | | |
| | | if (!lockAcquired) { |
| | | return Result.error("操作过于频繁,请稍后重试"); |
| | | } |
| | | if (!lockAcquired) { |
| | | return Result.error("操作过于频繁,请稍后重试"); |
| | | } |
| | | |
| | | // 执行购买逻辑 |
| | | return userPolicyService.purchaseApplication(dto); |
| | | // 执行购买逻辑 |
| | | return userPolicyService.purchaseApplication(dto); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return Result.error("购买失败"); |
| | | } finally { |
| | | // 释放锁 |
| | | if (lockAcquired) { |
| | | redisDistributedLock.releaseLock(lockKey); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return Result.error("购买失败"); |
| | | } finally { |
| | | // 释放锁 |
| | | if (lockAcquired) { |
| | | redisDistributedLock.releaseLock(lockKey); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | /** |
| | | * 根据用户id查询保单 |
| | | */ |
| | | @GetMapping("/updateGender") |
| | | public AjaxResult updateGender(@RequestParam(value = "id") Integer id,@RequestParam(value = "gender") UserPolicy.Gender gender) { |
| | | try { |
| | | UserPolicy userPolicy = userPolicyService.getById(id); |
| | | if(ObjectUtil.isEmpty(userPolicy)){ |
| | | AjaxResult.error("保单不存在!"); |
| | | } |
| | | userPolicy.setGender(gender); |
| | | userPolicyService.updateById(userPolicy); |
| | | return AjaxResult.success("修改成功"); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return AjaxResult.error("修改失败!"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据用户id查询保单 |
| | | */ |
| | | @GetMapping("/getPolicyById") |
| | | public Result getPolicyById(@RequestParam(value = "account") String account) { |
| | | try { |