| | |
| | | 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; |
| | |
| | | |
| | | @Autowired |
| | | private RedisDistributedLock redisDistributedLock; |
| | | |
| | | @Autowired |
| | | InsuranceProductService insuranceProductService; |
| | | |
| | | /** |
| | | * 保险购买申请 |
| | |
| | | */ |
| | | @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(); |
| | | |
| | |
| | | |
| | | // 产品名称模糊查询 |
| | | if (org.apache.commons.lang3.StringUtils.isNotBlank(account)) { |
| | | wrapper.like(UserPolicy::getUserId, account); |
| | | wrapper.like(UserPolicy::getAccount, account); |
| | | } |
| | | |
| | | // 产品代码模糊查询 |
| | |
| | | } |
| | | |
| | | // 审批状态 |
| | | if (status != null && status != 3) { |
| | | if (state != null && state == 3) { |
| | | wrapper.ne(UserPolicy::getApprovalStatus, 0); |
| | | }else{ |
| | | wrapper.eq(UserPolicy::getApprovalStatus, 0); |
| | |
| | | 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()); |
| | |
| | | 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("审批成功"); |