From daa6b2957949c84fec81564e2bac69c685f74aa8 Mon Sep 17 00:00:00 2001 From: zayac Date: Sat, 8 Jun 2024 16:14:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AD=98=E6=AC=BE=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=94=A8=E6=88=B7=E4=B8=8D=E8=83=BD=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/zayac/admin/schedule/DailyReport.java | 344 +++++++++--------- .../webapi/system/UserCenterController.java | 2 - 2 files changed, 172 insertions(+), 174 deletions(-) diff --git a/zayac-admin-agent/src/main/java/com/zayac/admin/schedule/DailyReport.java b/zayac-admin-agent/src/main/java/com/zayac/admin/schedule/DailyReport.java index 009c7ecb..4db9f935 100644 --- a/zayac-admin-agent/src/main/java/com/zayac/admin/schedule/DailyReport.java +++ b/zayac-admin-agent/src/main/java/com/zayac/admin/schedule/DailyReport.java @@ -89,12 +89,12 @@ public class DailyReport { deptWithUsersAndAccounts.forEach(dept -> { //根据用户角色对部门用户进行分组 Map> usersByRole = dept.getUsers() + .stream() + .flatMap(user -> user.getRoles() .stream() - .flatMap(user -> user.getRoles() - .stream() - .map(role -> new AbstractMap.SimpleEntry<>(role.getCode(), user))) - .collect(Collectors.groupingByConcurrent(Map.Entry::getKey, Collectors - .mapping(Map.Entry::getValue, Collectors.toList()))); + .map(role -> new AbstractMap.SimpleEntry<>(role.getCode(), user))) + .collect(Collectors.groupingByConcurrent(Map.Entry::getKey, Collectors + .mapping(Map.Entry::getValue, Collectors.toList()))); var ministerUser = usersByRole.get(MINISTER_ROLE_CODE).get(0); //获取账号不为空的用户 @@ -114,19 +114,19 @@ public class DailyReport { deptWithUsersAndAccounts.forEach(dept -> { //根据用户角色对部门用户进行分组 Map> usersByRole = dept.getUsers() + .stream() + .flatMap(user -> user.getRoles() .stream() - .flatMap(user -> user.getRoles() - .stream() - .map(role -> new AbstractMap.SimpleEntry<>(role.getCode(), user))) - .collect(Collectors.groupingByConcurrent(Map.Entry::getKey, Collectors - .mapping(Map.Entry::getValue, Collectors.toList()))); + .map(role -> new AbstractMap.SimpleEntry<>(role.getCode(), user))) + .collect(Collectors.groupingByConcurrent(Map.Entry::getKey, Collectors + .mapping(Map.Entry::getValue, Collectors.toList()))); // 获取所有账号的username与用户的映射 Map accountUsernameToUserMap = dept.getUsers() + .stream() + .flatMap(user -> user.getAccounts() .stream() - .flatMap(user -> user.getAccounts() - .stream() - .map(account -> new AbstractMap.SimpleEntry<>(account.getUsername(), user))) - .collect(Collectors.toConcurrentMap(Map.Entry::getKey, Map.Entry::getValue)); + .map(account -> new AbstractMap.SimpleEntry<>(account.getUsername(), user))) + .collect(Collectors.toConcurrentMap(Map.Entry::getKey, Map.Entry::getValue)); var ministerUser = usersByRole.get(MINISTER_ROLE_CODE).get(0); //获取账号不为空的用户 @@ -151,16 +151,16 @@ public class DailyReport { deptWithUsersAndAccounts.forEach(dept -> { //根据用户角色对部门用户进行分组 Map> usersByRole = dept.getUsers() + .stream() + .flatMap(user -> user.getRoles() .stream() - .flatMap(user -> user.getRoles() - .stream() - .map(role -> new AbstractMap.SimpleEntry<>(role.getCode(), user))) - .collect(Collectors.groupingByConcurrent(Map.Entry::getKey, Collectors - .mapping(Map.Entry::getValue, Collectors.toList()))); + .map(role -> new AbstractMap.SimpleEntry<>(role.getCode(), user))) + .collect(Collectors.groupingByConcurrent(Map.Entry::getKey, Collectors + .mapping(Map.Entry::getValue, Collectors.toList()))); var userWithRolesAndAccountsResps = usersByRole.get(MINISTER_ROLE_CODE); userWithRolesAndAccountsResps.forEach(ministerUser -> generateAndSendTeamReport(ministerUser, nowDate - .atStartOfDay(), nowDateTime, null)); + .atStartOfDay(), nowDateTime, null)); }); } @@ -174,76 +174,76 @@ public class DailyReport { LocalDate date) { TeamMemberReq memberListReq = TeamMemberReq.builder() - .registerStartDate(date) - .registerEndDate(date) - .startDate(date) - .endDate(date) - .registerSort(1) - .status(1) - .pageSize(100) - .build(); + .registerStartDate(date) + .registerEndDate(date) + .startDate(date) + .endDate(date) + .registerSort(1) + .status(1) + .pageSize(100) + .build(); List>> futureList = new ArrayList<>(); ministerUser.getAccounts().forEach(account -> { CompletableFuture>> memberPaginationCompletableFuture = completableFutureWebClientService - .fetchDataForAccount(account, ApiPathConstants.MEMBER_TEAM_LIST_URL, memberListReq, new ParameterizedTypeReference<>() { - }); + .fetchDataForAccount(account, ApiPathConstants.MEMBER_TEAM_LIST_URL, memberListReq, new ParameterizedTypeReference<>() { + }); CompletableFuture> teamMembersFuture = memberPaginationCompletableFuture - .thenApply(MemberPagination::getList) - .thenApplyAsync(members -> members.stream() - .filter(member -> member.getDeposit() != null && member.getDeposit() - .compareTo(BigDecimal.ZERO) == 0) - .collect(Collectors.toList()), asyncTaskExecutor) - .thenComposeAsync(membersWithoutDep -> { - List> memberFutures = membersWithoutDep.stream() - .map(memberWithoutDep -> { - PayRecordListReq req = PayRecordListReq.builder() - .startDate(date) - .endDate(date) - .pageSize(100) - .id(memberWithoutDep.getId()) - .build(); - CompletableFuture>> completableFuture = completableFutureWebClientService - .fetchDataForAccount(account, ApiPathConstants.PAY_RECORD_LIST_URL, req, new ParameterizedTypeReference<>() { - }); - return completableFuture.thenApplyAsync(pagination -> { - if (pagination.getOrderAmountTotal().compareTo(BigDecimal.ZERO) > 0 && pagination - .getScoreAmountTotal() - .compareTo(BigDecimal.ZERO) == 0) { - return memberWithoutDep; - } else { - return null; - } - }, asyncTaskExecutor); - }) - .toList(); - - return CompletableFuture.allOf(memberFutures.toArray(new CompletableFuture[0])) - .thenApply(v -> memberFutures.stream() - .map(CompletableFuture::join) - .filter(Objects::nonNull) - .collect(Collectors.toList())); - }, asyncTaskExecutor) - .thenApplyAsync(membersWithoutDep -> { - // 发送给每个account关联的user用户 - if (!membersWithoutDep.isEmpty()) { - Map> groupByTopAgentName = membersWithoutDep.stream() - .collect(Collectors.groupingBy(TeamMember::getTopAgentName)); - groupByTopAgentName.forEach((accountName, accountMembers) -> { - String notification = telegramMessageService - .buildFailedPayMessage(accountName, accountMembers); - UserWithRolesAndAccountsResp currUser = accountUsernameToUserMap.get(accountName); - if (currUser != null && DisEnableStatusEnum.ENABLE.equals(currUser.getNeedNotify())) { - String botToken = StrUtil.isEmpty(currUser.getBotToken()) - ? ministerUser.getBotToken() - : currUser.getBotToken(); - telegramMessageService.sendMessage(botToken, currUser.getRegAndDepIds(), notification); + .thenApply(MemberPagination::getList) + .thenApplyAsync(members -> members.stream() + .filter(member -> member.getDeposit() != null && member.getDeposit() + .compareTo(BigDecimal.ZERO) == 0) + .collect(Collectors.toList()), asyncTaskExecutor) + .thenComposeAsync(membersWithoutDep -> { + List> memberFutures = membersWithoutDep.stream() + .map(memberWithoutDep -> { + PayRecordListReq req = PayRecordListReq.builder() + .startDate(date) + .endDate(date) + .pageSize(100) + .id(memberWithoutDep.getId()) + .build(); + CompletableFuture>> completableFuture = completableFutureWebClientService + .fetchDataForAccount(account, ApiPathConstants.PAY_RECORD_LIST_URL, req, new ParameterizedTypeReference<>() { + }); + return completableFuture.thenApplyAsync(pagination -> { + if (pagination.getOrderAmountTotal().compareTo(BigDecimal.ZERO) > 0 && pagination + .getScoreAmountTotal() + .compareTo(BigDecimal.ZERO) == 0) { + return memberWithoutDep; + } else { + return null; } - }); - } - return membersWithoutDep; - }, asyncTaskExecutor); + }, asyncTaskExecutor); + }) + .toList(); + + return CompletableFuture.allOf(memberFutures.toArray(new CompletableFuture[0])) + .thenApply(v -> memberFutures.stream() + .map(CompletableFuture::join) + .filter(Objects::nonNull) + .collect(Collectors.toList())); + }, asyncTaskExecutor) + .thenApplyAsync(membersWithoutDep -> { + // 发送给每个account关联的user用户 + if (!membersWithoutDep.isEmpty()) { + Map> groupByTopAgentName = membersWithoutDep.stream() + .collect(Collectors.groupingBy(TeamMember::getTopAgentName)); + groupByTopAgentName.forEach((accountName, accountMembers) -> { + String notification = telegramMessageService + .buildFailedPayMessage(accountName, accountMembers); + UserWithRolesAndAccountsResp currUser = accountUsernameToUserMap.get(accountName); + if (currUser != null && DisEnableStatusEnum.ENABLE.equals(currUser.getNeedNotify())) { + String botToken = StrUtil.isEmpty(currUser.getBotToken()) + ? ministerUser.getBotToken() + : currUser.getBotToken(); + telegramMessageService.sendMessage(botToken, currUser.getRegAndDepIds(), notification); + } + }); + } + return membersWithoutDep; + }, asyncTaskExecutor); futureList.add(teamMembersFuture); }); @@ -252,22 +252,22 @@ public class DailyReport { allFutures.thenRunAsync(() -> { // 主线下的所有的存款失败用户 List allTeamMembers = futureList.stream() - .map(CompletableFuture::join) - .flatMap(List::stream) - .toList(); + .map(CompletableFuture::join) + .flatMap(List::stream) + .toList(); Map> groupByTopAgentName = new TreeMap<>(allTeamMembers.stream() - .collect(Collectors.groupingBy(TeamMember::getTopAgentName))); + .collect(Collectors.groupingBy(TeamMember::getTopAgentName))); StringBuilder combinedNotification = new StringBuilder(); groupByTopAgentName.forEach((accountName, accountMembers) -> { String notification = telegramMessageService.buildFailedPayMessage(accountName, accountMembers); combinedNotification.append(notification).append("\n"); }); telegramMessageService - .sendMessage("6013830443:AAHUOS4v6Ln19ziZkH-L28-HZQLJrGcvhto", 6054562838L, combinedNotification - .toString()); + .sendMessage("6013830443:AAHUOS4v6Ln19ziZkH-L28-HZQLJrGcvhto", 6054562838L, combinedNotification + .toString()); if (DisEnableStatusEnum.ENABLE.equals(ministerUser.getNeedNotify())) { telegramMessageService.sendMessage(ministerUser.getBotToken(), ministerUser - .getReportIds(), combinedNotification.toString()); + .getReportIds(), combinedNotification.toString()); } }, asyncTaskExecutor).exceptionally(ex -> { @@ -290,7 +290,7 @@ public class DailyReport { AgentDataVisualListReq agentDataVisualListReq = AgentDataVisualListReq.builder().monthDate(reportDate).build(); deptUsers.forEach(deptUser -> tasks - .add(processDeptUser(deptUser, ministerUser, agentDataVisualListReq, reportDate))); + .add(processDeptUser(deptUser, ministerUser, agentDataVisualListReq, reportDate))); CompletableFuture allTasks = CompletableFuture.allOf(tasks.toArray(new CompletableFuture[0])); allTasks.join(); @@ -317,32 +317,32 @@ public class DailyReport { TeamInfoReq teamInfoReq = TeamInfoReq.builder().startDate(startDateTime).endDate(endDateTime).build(); List> futures = accounts.stream() - .map(accountResp -> teamService.getLatestTeamInfoAsync(accountResp, teamInfoReq) - .thenAcceptAsync(team -> { - int totalNewMember = team.getList().stream().mapToInt(TeamAccount::getSubMemberNum).sum(); - int totalNewFirstDeposit = team.getList() - .stream() - .mapToInt(TeamAccount::getFirstDepositNum) - .sum(); - synchronized (totals) { - totals[0] += totalNewMember; - totals[1] += totalNewFirstDeposit; - } - String percent = getPercent(totalNewFirstDeposit, totalNewMember); - synchronized (rows) { - rows.add(new String[]{accountResp.getPlatformName(), String.valueOf(totalNewMember), String - .valueOf(totalNewFirstDeposit), percent}); - } - }, asyncTaskExecutor)) - .toList(); + .map(accountResp -> teamService.getLatestTeamInfoAsync(accountResp, teamInfoReq) + .thenAcceptAsync(team -> { + int totalNewMember = team.getList().stream().mapToInt(TeamAccount::getSubMemberNum).sum(); + int totalNewFirstDeposit = team.getList() + .stream() + .mapToInt(TeamAccount::getFirstDepositNum) + .sum(); + synchronized (totals) { + totals[0] += totalNewMember; + totals[1] += totalNewFirstDeposit; + } + String percent = getPercent(totalNewFirstDeposit, totalNewMember); + synchronized (rows) { + rows.add(new String[] {accountResp.getPlatformName(), String.valueOf(totalNewMember), String + .valueOf(totalNewFirstDeposit), percent}); + } + }, asyncTaskExecutor)) + .toList(); CompletableFuture allFutures = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); allFutures.join(); // 对 rows 列表进行排序 rows.sort(Comparator.comparing((String[] row) -> row[0].length()).thenComparing(row -> row[0])); - rows.add(new String[]{"总计", String.valueOf(totals[0]), String.valueOf(totals[1]), - getPercent(totals[1], totals[0])}); + rows.add(new String[] {"总计", String.valueOf(totals[0]), String.valueOf(totals[1]), + getPercent(totals[1], totals[0])}); String message = TableFormatter.formatTableAsHtml(rows); if (ministerUser.getNeedNotify() == DisEnableStatusEnum.ENABLE) { telegramMessageService.sendMessage(ministerUser.getBotToken(), ministerUser.getReportIds(), message); @@ -379,21 +379,21 @@ public class DailyReport { List currUserAccounts = deptUser.getAccounts(); List> futures = currUserAccounts.stream() - .map(currAccount -> agentDataVisualListService - .getAgentDataVisualList(currAccount, agentDataVisualListReq) - .thenApplyAsync(agentData -> agentData.getCurData() - .stream() - .filter(data -> data.getStaticsDate().equals(reportDate)) - .findFirst() - .orElseThrow(() -> new BusinessException("No data found for report date"))) - .exceptionally(ex -> { - log.error("Error fetching data for account {}: {}", currAccount.getId(), ex.getMessage()); - return null; - })) - .toList(); + .map(currAccount -> agentDataVisualListService + .getAgentDataVisualList(currAccount, agentDataVisualListReq) + .thenApplyAsync(agentData -> agentData.getCurData() + .stream() + .filter(data -> data.getStaticsDate().equals(reportDate)) + .findFirst() + .orElseThrow(() -> new BusinessException("No data found for report date"))) + .exceptionally(ex -> { + log.error("Error fetching data for account {}: {}", currAccount.getId(), ex.getMessage()); + return null; + })) + .toList(); CompletableFuture userStaticsFuture = CompletableFuture.allOf(futures - .toArray(new CompletableFuture[0])); + .toArray(new CompletableFuture[0])); userStaticsFuture.thenRunAsync(() -> { List agentDataList = futures.stream().map(future -> { try { @@ -409,8 +409,8 @@ public class DailyReport { if (StrUtil.isNotBlank(message) && deptUser.getNeedNotify() == DisEnableStatusEnum.ENABLE) { String botToken = StrUtil.isEmpty(deptUser.getBotToken()) - ? ministerUser.getBotToken() - : deptUser.getBotToken(); + ? ministerUser.getBotToken() + : deptUser.getBotToken(); telegramMessageService.sendMessage(botToken, deptUser.getReportIds(), message); } }, asyncTaskExecutor).exceptionally(ex -> { @@ -437,33 +437,33 @@ public class DailyReport { List> tasks = new ArrayList<>(); TeamFinanceReq teamFinanceReq = TeamFinanceReq.builder() - .pageNum(1) - .pageSize(999) - .commissionDate(reportDate) - .build(); + .pageNum(1) + .pageSize(999) + .commissionDate(reportDate) + .build(); // 异步处理 ministerUserAccounts CompletableFuture ministerAccountsFuture = CompletableFuture.runAsync(() -> { List> accountFutures = ministerUser.getAccounts() - .stream() - .map(accountResp -> completableFutureFinanceService.getTeamFinance(accountResp, teamFinanceReq) - .thenAcceptAsync(financePagination -> { - List financeReqList = financePagination.getList().stream().map(finance -> { - FinanceDO financeDO = new FinanceDO(); - BeanUtil.copyProperties(finance, financeDO); - return financeDO; - }).toList(); - financeService.addAll(financeReqList); - FinanceSumReq financeSumReq = new FinanceSumReq(); - BeanUtil.copyProperties(financePagination.getTotalSumVo(), financeSumReq); - financeSumService.add(financeSumReq); - }, asyncTaskExecutor) - .exceptionally(ex -> { - log.error("Error processing minister accounts for account {}", accountResp - .getUsername(), ex); - return null; - })) - .toList(); + .stream() + .map(accountResp -> completableFutureFinanceService.getTeamFinance(accountResp, teamFinanceReq) + .thenAcceptAsync(financePagination -> { + List financeReqList = financePagination.getList().stream().map(finance -> { + FinanceDO financeDO = new FinanceDO(); + BeanUtil.copyProperties(finance, financeDO); + return financeDO; + }).toList(); + financeService.addAll(financeReqList); + FinanceSumReq financeSumReq = new FinanceSumReq(); + BeanUtil.copyProperties(financePagination.getTotalSumVo(), financeSumReq); + financeSumService.add(financeSumReq); + }, asyncTaskExecutor) + .exceptionally(ex -> { + log.error("Error processing minister accounts for account {}", accountResp + .getUsername(), ex); + return null; + })) + .toList(); CompletableFuture.allOf(accountFutures.toArray(new CompletableFuture[0])).join(); }, asyncTaskExecutor).exceptionally(ex -> { log.error("Error processing minister accounts", ex); @@ -473,36 +473,36 @@ public class DailyReport { // 异步处理 deptUsers AgentDataVisualListReq agentDataVisualListReq = AgentDataVisualListReq.builder() - .monthDate(reportDate) - .build(); + .monthDate(reportDate) + .build(); deptUsers.forEach(deptUser -> { CompletableFuture deptUserFuture = CompletableFuture.runAsync(() -> { List currUserAccounts = deptUser.getAccounts(); List> futures = currUserAccounts.stream() - .map(currAccount -> agentDataVisualListService - .getAgentDataVisualList(currAccount, agentDataVisualListReq) - .thenApplyAsync(agentData -> { - Statics statics = agentData.getCurData() - .stream() - .filter(data -> data.getStaticsDate().equals(reportDate)) - .findFirst() - .orElseThrow(() -> new BusinessException("No data found for report date")); - StatsDO statsDO = new StatsDO(); - BeanUtil.copyProperties(statics, statsDO); - return statsDO; - }, asyncTaskExecutor) - .exceptionally(ex -> { - log.error("Error fetching data for account {}: {}", currAccount.getId(), ex - .getMessage()); - return null; - })) - .toList(); + .map(currAccount -> agentDataVisualListService + .getAgentDataVisualList(currAccount, agentDataVisualListReq) + .thenApplyAsync(agentData -> { + Statics statics = agentData.getCurData() + .stream() + .filter(data -> data.getStaticsDate().equals(reportDate)) + .findFirst() + .orElseThrow(() -> new BusinessException("No data found for report date")); + StatsDO statsDO = new StatsDO(); + BeanUtil.copyProperties(statics, statsDO); + return statsDO; + }, asyncTaskExecutor) + .exceptionally(ex -> { + log.error("Error fetching data for account {}: {}", currAccount.getId(), ex + .getMessage()); + return null; + })) + .toList(); List list = futures.stream() - .map(CompletableFuture::join) - .filter(Objects::nonNull) - .collect(Collectors.toList()); + .map(CompletableFuture::join) + .filter(Objects::nonNull) + .collect(Collectors.toList()); statsService.addAll(list); }, asyncTaskExecutor).exceptionally(ex -> { diff --git a/zayac-admin-webapi/src/main/java/com/zayac/admin/webapi/system/UserCenterController.java b/zayac-admin-webapi/src/main/java/com/zayac/admin/webapi/system/UserCenterController.java index eefe595b..b9748ccc 100644 --- a/zayac-admin-webapi/src/main/java/com/zayac/admin/webapi/system/UserCenterController.java +++ b/zayac-admin-webapi/src/main/java/com/zayac/admin/webapi/system/UserCenterController.java @@ -16,7 +16,6 @@ package com.zayac.admin.webapi.system; -import cn.hutool.core.util.ReUtil; import com.xkcoding.justauth.AuthRequestFactory; import com.zayac.admin.system.model.entity.UserSocialDO; import com.zayac.admin.system.model.req.UserBasicInfoUpdateReq; @@ -41,7 +40,6 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import com.zayac.admin.common.constant.CacheConstants; -import com.zayac.admin.common.constant.RegexConstants; import com.zayac.admin.common.enums.SocialSourceEnum; import com.zayac.admin.common.util.SecureUtils; import com.zayac.admin.common.util.helper.LoginHelper;