| | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.im.service.UserPolicyService; |
| | | import com.ruoyi.im.service.impl.InsurancePositionServiceImpl; |
| | | import com.ruoyi.im.util.UserPolicyUtils; |
| | | import com.ruoyi.system.domain.InsurancePosition; |
| | | import com.ruoyi.system.domain.UserAccount; |
| | | import com.ruoyi.system.domain.UserPolicy; |
| | | import com.ruoyi.system.domain.out.HomePageStatisticsOut; |
| | |
| | | public AjaxResult getUserTeamAndPosition(@RequestParam(value = "invitationCode", required = false) String invitationCode) { |
| | | HomePageStatisticsOut statisticsOut = new HomePageStatisticsOut(); |
| | | |
| | | // 标志是否统计所有用户 |
| | | boolean isStatisticsAll = StringUtils.isEmpty(invitationCode); |
| | | |
| | | // 所有需要统计的下级账号列表 |
| | | List<String> allSubordinateAccounts = new ArrayList<>(); |
| | | |
| | | if (StringUtils.isNotEmpty(invitationCode)) { |
| | | if (!isStatisticsAll) { |
| | | // 如果指定了邀请码,只统计该邀请码对应的用户及其下级 |
| | | UserAccount userAccount = userAccountService.getOne(new LambdaQueryWrapper<UserAccount>() |
| | | .eq(UserAccount::getInvitationCode, invitationCode) |
| | | .select(UserAccount::getAccount) // 只查询需要的字段 |
| | |
| | | allSubordinateAccounts = getCachedSubordinateAccounts(rootAccount); |
| | | } |
| | | } |
| | | |
| | | // 如果下级账号数量为0,直接返回空结果,避免不必要的查询 |
| | | if (allSubordinateAccounts.isEmpty()) { |
| | | return AjaxResult.success(statisticsOut); |
| | | } |
| | | // 如果 invitationCode 为 null,isStatisticsAll 为 true,将不设置 allSubordinateAccounts |
| | | // 在后续查询中,如果 allSubordinateAccounts 为空且 isStatisticsAll 为 true,则查询所有用户 |
| | | |
| | | // 并行执行统计查询 |
| | | try { |
| | | List<String> finalAllSubordinateAccounts = allSubordinateAccounts; |
| | | CompletableFuture<Long> todayRegisterFuture = CompletableFuture.supplyAsync(() -> getTodayRegister(finalAllSubordinateAccounts)); |
| | | List<String> finalAllSubordinateAccounts2 = allSubordinateAccounts; |
| | | CompletableFuture<Long> totalRegisterFuture = CompletableFuture.supplyAsync(() -> getTotalRegister(finalAllSubordinateAccounts2)); |
| | | CompletableFuture<Long> todayRegisterFuture = CompletableFuture.supplyAsync(() -> |
| | | getTodayRegister(finalAllSubordinateAccounts, isStatisticsAll)); |
| | | List<String> finalAllSubordinateAccounts1 = allSubordinateAccounts; |
| | | CompletableFuture<Long> todayActivateFuture = CompletableFuture.supplyAsync(() -> getTodayActivate(finalAllSubordinateAccounts1)); |
| | | CompletableFuture<Long> totalRegisterFuture = CompletableFuture.supplyAsync(() -> |
| | | getTotalRegister(finalAllSubordinateAccounts1, isStatisticsAll)); |
| | | List<String> finalAllSubordinateAccounts2 = allSubordinateAccounts; |
| | | CompletableFuture<Long> todayActivateFuture = CompletableFuture.supplyAsync(() -> |
| | | getTodayActivate(finalAllSubordinateAccounts2, isStatisticsAll)); |
| | | List<String> finalAllSubordinateAccounts3 = allSubordinateAccounts; |
| | | CompletableFuture<Long> totalActivateFuture = CompletableFuture.supplyAsync(() -> getTotalActivate(finalAllSubordinateAccounts3)); |
| | | CompletableFuture<Long> totalActivateFuture = CompletableFuture.supplyAsync(() -> |
| | | getTotalActivate(finalAllSubordinateAccounts3, isStatisticsAll)); |
| | | |
| | | // 等待所有查询完成 |
| | | statisticsOut.setTodayRegister(todayRegisterFuture.get()); |
| | |
| | | } |
| | | |
| | | // 分离的查询方法,便于并行执行 |
| | | private Long getTodayRegister(List<String> subordinateAccounts) { |
| | | private Long getTodayRegister(List<String> subordinateAccounts, boolean isStatisticsAll) { |
| | | LambdaQueryWrapper<UserAccount> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.apply("DATE(create_time) = CURDATE()") |
| | | .in(UserAccount::getAccount, subordinateAccounts); |
| | | return userAccountService.count(wrapper); |
| | | } |
| | | wrapper.apply("DATE(create_time) = CURDATE()"); |
| | | |
| | | private Long getTotalRegister(List<String> subordinateAccounts) { |
| | | LambdaQueryWrapper<UserAccount> wrapper = new LambdaQueryWrapper<>(); |
| | | // 如果指定了邀请码,按账号列表过滤;否则查询所有 |
| | | if (!isStatisticsAll && !subordinateAccounts.isEmpty()) { |
| | | wrapper.in(UserAccount::getAccount, subordinateAccounts); |
| | | } |
| | | // 如果 isStatisticsAll 为 true,不添加账号过滤条件,查询所有用户 |
| | | |
| | | return userAccountService.count(wrapper); |
| | | } |
| | | |
| | | private Long getTodayActivate(List<String> subordinateAccounts) { |
| | | private Long getTotalRegister(List<String> subordinateAccounts, boolean isStatisticsAll) { |
| | | LambdaQueryWrapper<UserAccount> wrapper = new LambdaQueryWrapper<>(); |
| | | |
| | | // 如果指定了邀请码,按账号列表过滤;否则查询所有 |
| | | if (!isStatisticsAll && !subordinateAccounts.isEmpty()) { |
| | | wrapper.in(UserAccount::getAccount, subordinateAccounts); |
| | | } |
| | | // 如果 isStatisticsAll 为 true,不添加账号过滤条件,查询所有用户 |
| | | |
| | | return userAccountService.count(wrapper); |
| | | } |
| | | |
| | | private Long getTodayActivate(List<String> subordinateAccounts, boolean isStatisticsAll) { |
| | | LambdaQueryWrapper<UserPolicy> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(UserPolicy::getApprovalStatus, 1) |
| | | .in(UserPolicy::getAccount, subordinateAccounts) |
| | | .apply("DATE(created_at) = CURDATE()"); |
| | | |
| | | // 如果指定了邀请码,按账号列表过滤;否则查询所有 |
| | | if (!isStatisticsAll && !subordinateAccounts.isEmpty()) { |
| | | wrapper.in(UserPolicy::getAccount, subordinateAccounts); |
| | | } |
| | | // 如果 isStatisticsAll 为 true,不添加账号过滤条件,查询所有用户 |
| | | |
| | | return userPolicyService.count(wrapper); |
| | | } |
| | | |
| | | private Long getTotalActivate(List<String> subordinateAccounts) { |
| | | private Long getTotalActivate(List<String> subordinateAccounts, boolean isStatisticsAll) { |
| | | LambdaQueryWrapper<UserPolicy> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(UserPolicy::getApprovalStatus, 1) |
| | | .in(UserPolicy::getAccount, subordinateAccounts); |
| | | wrapper.eq(UserPolicy::getApprovalStatus, 1); |
| | | |
| | | // 如果指定了邀请码,按账号列表过滤;否则查询所有 |
| | | if (!isStatisticsAll && !subordinateAccounts.isEmpty()) { |
| | | wrapper.in(UserPolicy::getAccount, subordinateAccounts); |
| | | } |
| | | // 如果 isStatisticsAll 为 true,不添加账号过滤条件,查询所有用户 |
| | | |
| | | return userPolicyService.count(wrapper); |
| | | } |
| | | |