From 6287f5366df7a0f13fef767ce7d6505979a13b22 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Thu, 25 Sep 2025 23:53:56 +0800
Subject: [PATCH] 1
---
ruoyi-admin/src/main/java/com/ruoyi/web/controller/product/UserPolicyController.java | 94 ++++++++++++++++++++++++++--------------------
1 files changed, 53 insertions(+), 41 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 d01cdb1..4e471e8 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
@@ -9,6 +9,7 @@
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.im.comm.Result;
+import com.ruoyi.im.service.InsuranceProductService;
import com.ruoyi.im.service.MedicalInsuranceAccountService;
import com.ruoyi.im.service.impl.InsurancePositionServiceImpl;
import com.ruoyi.im.util.RedisDistributedLock;
@@ -51,6 +52,9 @@
@Autowired
private RedisDistributedLock redisDistributedLock;
+
+ @Autowired
+ InsuranceProductService insuranceProductService;
/**
* 保险购买申请
@@ -106,7 +110,7 @@
*/
@GetMapping("/list")
public TableDataInfo list(@RequestParam(value = "account",required = false) String account,
- @RequestParam(value = "status",defaultValue = "0") Integer status,
+ @RequestParam(value = "state",defaultValue = "0") Integer state,
@RequestParam(value = "productName",required = false) String productName) {
startPage();
@@ -114,7 +118,7 @@
// 产品名称模糊查询
if (org.apache.commons.lang3.StringUtils.isNotBlank(account)) {
- wrapper.like(UserPolicy::getUserId, account);
+ wrapper.like(UserPolicy::getAccount, account);
}
// 产品代码模糊查询
@@ -123,7 +127,7 @@
}
// 审批状态
- if (status != null && status != 3) {
+ if (state != null && state == 3) {
wrapper.ne(UserPolicy::getApprovalStatus, 0);
}else{
wrapper.eq(UserPolicy::getApprovalStatus, 0);
@@ -156,6 +160,17 @@
if(approvalStatus == 2 && StringUtils.isEmpty(message)){
return AjaxResult.error("驳回理由不能为空!");
}
+ UserAccount userAccount = userAccountService.getById(userPolicy.getUserId());
+ if(approvalStatus == 2){
+ userPolicy.setApprovalStatus(approvalStatus);
+ userPolicy.setMessage(message);
+ userPolicy.setUpdatedAt(new Date());
+ userPolicyService.updateById(userPolicy);
+
+ userAccount.setBalance(userAccount.getBalance().add(userPolicy.getPremium()));
+ userAccountService.updateById(userAccount);
+ return AjaxResult.success("审批成功");
+ }
//计算到期时间
LocalDate expirationTime = calculateInsuranceEndDateToDay(LocalDate.now(), userPolicy.getTerm());
@@ -184,47 +199,44 @@
medicalInsuranceAccount.setUpdatedAt(new Date());
medicalInsuranceAccountService.save(medicalInsuranceAccount);
-
//判断上级用户职位达成
if(approvalStatus == 1){
- //查询当前用户
- UserAccount userAccount = userAccountService.getOne(new LambdaQueryWrapper<UserAccount>()
- .eq(UserAccount::getId, userPolicy.getUserId())
- );
- //上级
- UserAccount superiorUser = userAccountService.getOne(new LambdaQueryWrapper<UserAccount>()
- .eq(UserAccount::getAccount, userAccount.getInvitationAccount())
- );
- //查询上级的所有下级
- List<UserAccount> userAccountList = userAccountService.list(new LambdaQueryWrapper<UserAccount>()
- .eq(UserAccount::getInvitationAccount, superiorUser.getAccount())
- );
- if(userAccountList.size() == 0){
- return AjaxResult.success("审批成功");
- }
- List<Integer> idList = userAccountList.stream()
- .map(UserAccount::getId)
- .collect(Collectors.toList());
- //查询下级的保单
- List<UserPolicy> userPolicyList = userPolicyService.list(new LambdaQueryWrapper<>(UserPolicy.class)
- .in(UserPolicy::getUserId, idList)
- );
- // 手动将当前审批的保单加入到列表中(因为事务隔离可能查不到)
- userPolicyList.add(userPolicy);
- if(userPolicyList.size() == 0){
- return AjaxResult.success("审批成功");
- }
- //生效保单数量
- long activePolicies = UserPolicyUtils.countActivePolicies(userPolicyList);
- //查询所有职位
- List<InsurancePosition> positions = insurancePositionService.list();
- positions.forEach(f->{
- if(activePolicies >= f.getNumberPeople()){
- superiorUser.setPosition(f.getPosition());
- superiorUser.setAgreedTime(LocalDate.now());
+ if(StringUtils.isNotEmpty(userAccount.getInvitationAccount())){
+ //上级
+ UserAccount superiorUser = userAccountService.getOne(new LambdaQueryWrapper<UserAccount>()
+ .eq(UserAccount::getAccount, userAccount.getInvitationAccount())
+ );
+ //查询上级的所有下级
+ List<UserAccount> userAccountList = userAccountService.list(new LambdaQueryWrapper<UserAccount>()
+ .eq(UserAccount::getInvitationAccount, superiorUser.getAccount())
+ );
+ if(userAccountList.size() == 0){
+ return AjaxResult.success("审批成功");
}
- });
- userAccountService.updateById(superiorUser);
+ List<Integer> idList = userAccountList.stream()
+ .map(UserAccount::getId)
+ .collect(Collectors.toList());
+ //查询下级的保单
+ List<UserPolicy> userPolicyList = userPolicyService.list(new LambdaQueryWrapper<>(UserPolicy.class)
+ .in(UserPolicy::getUserId, idList)
+ );
+ // 手动将当前审批的保单加入到列表中(因为事务隔离可能查不到)
+ userPolicyList.add(userPolicy);
+ if(userPolicyList.size() == 0){
+ return AjaxResult.success("审批成功");
+ }
+ //生效保单数量
+ long activePolicies = UserPolicyUtils.countActivePolicies(userPolicyList);
+ //查询所有职位
+ List<InsurancePosition> positions = insurancePositionService.list();
+ positions.forEach(f->{
+ if(activePolicies >= f.getNumberPeople()){
+ superiorUser.setPosition(f.getPosition());
+ superiorUser.setAgreedTime(LocalDate.now());
+ }
+ });
+ userAccountService.updateById(superiorUser);
+ }
return AjaxResult.success("审批成功");
}
return AjaxResult.success("审批成功");
--
Gitblit v1.9.3