From 11ffae1ecbe3d26863fd51262d7ffb043eb089da Mon Sep 17 00:00:00 2001
From: dd <gitluke@outlook.com>
Date: Mon, 27 Oct 2025 03:38:28 +0800
Subject: [PATCH] 1
---
ruoyi-admin/src/main/java/com/ruoyi/web/controller/product/UserPolicyController.java | 109 ++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 81 insertions(+), 28 deletions(-)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/product/UserPolicyController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/product/UserPolicyController.java
index c7e9d4a..8424adb 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/product/UserPolicyController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/product/UserPolicyController.java
@@ -18,8 +18,11 @@
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.FundsLogService;
import com.ruoyi.system.service.PaymentRecordService;
import com.ruoyi.system.service.UserAccountService;
import lombok.extern.slf4j.Slf4j;
@@ -68,6 +71,9 @@
@Autowired
PaymentRecordService paymentRecordService;
+ @Autowired
+ FundsLogService fundsLogService;
+
@Value("${pay.key}")
private String key;
@@ -76,33 +82,54 @@
*/
@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查询保单
@@ -220,6 +247,8 @@
userAccount.setBalance(userAccount.getBalance().add(userPolicy.getPremium()));
userAccountService.updateById(userAccount);
+ fundsLogService.addLog(userAccount.getId(), userAccount.getAccount(), userPolicy.getPremium(), OperationType.REFUND);
+
return AjaxResult.success("审批成功");
}
@@ -370,10 +399,16 @@
log.error("签名验证失败: {}", callbackDTO.getOrderId());
return "签名验证失败";
}
-
+ PaymentRecord paymentRecord = paymentRecordService.getOne(new LambdaQueryWrapper<PaymentRecord>()
+ .eq(PaymentRecord::getPayOrdeNo, callbackDTO.getOrderId())
+ );
+ if (paymentRecord == null) {
+ log.error("支付订单不存在: {}", paymentRecord.getPayOrdeNo());
+ return "支付订单不存在";
+ }
// 2. 根据订单号查询保单
UserPolicy userPolicy = userPolicyService.getOne(new LambdaQueryWrapper<UserPolicy>()
- .eq(UserPolicy::getOrderNo, callbackDTO.getOrderId()));
+ .eq(UserPolicy::getId, paymentRecord.getOrderId()));
if (userPolicy == null) {
log.error("订单不存在: {}", callbackDTO.getOrderId());
return "订单不存在";
@@ -532,18 +567,36 @@
}
if(byId.getPaymentStatus() == 2){
return AjaxResult.error("订单已支付,禁止删除");
+ }else{
+ paymentRecordService.removeById(byId);
}
UserPolicy userPolicy = userPolicyService.getById(byId.getOrderId());
- if(ObjectUtil.isEmpty(userPolicy)){
- return AjaxResult.error("保单不存在!");
- }
- if(userPolicy.getPayStatus() == 2){
- return AjaxResult.error("订单已支付,禁止删除");
- }
- paymentRecordService.removeById(byId);
- userPolicyService.removeById(userPolicy);
+ if(ObjectUtil.isNotEmpty(userPolicy) && userPolicy.getPayStatus() == 2){
+ return AjaxResult.error("订单已支付,禁止删除");
+ }else{
+ userPolicyService.removeById(userPolicy);
+ }
return AjaxResult.success("删除成功");
}
+ /**
+ * 保单列表
+ */
+ @GetMapping("/getFundsLogList")
+ public TableDataInfo getFundsLogList(@RequestParam(value = "account",required = false) String account,@RequestParam(value = "operationType",required = false) Integer operationType) {
+ startPage();
+
+ LambdaQueryWrapper<FundsLog> wrapper = new LambdaQueryWrapper<>();
+
+ if(StringUtils.isNotEmpty(account)){
+ wrapper.eq(FundsLog::getAccount,account);
+ }
+ if (ObjectUtil.isNotEmpty(operationType)){
+ wrapper.eq(FundsLog::getOperationType,operationType);
+ }
+ wrapper.orderByDesc(FundsLog::getCreateTime);
+ List<FundsLog> list = fundsLogService.list(wrapper);
+ return getDataTable(list);
+ }
}
--
Gitblit v1.9.3