修复存款失败用户不能正常发送消息的问题

This commit is contained in:
zayac 2024-06-08 16:12:29 +08:00
parent 616d55d1a7
commit 8326e316fb
4 changed files with 173 additions and 178 deletions

View File

@ -62,7 +62,7 @@ import java.util.stream.Collectors;
@Component @Component
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j @Slf4j
@Profile("prod") @Profile("dev")
public class DailyReport { public class DailyReport {
private final TeamService teamService; private final TeamService teamService;
private final DeptService deptService; private final DeptService deptService;
@ -89,12 +89,12 @@ public class DailyReport {
deptWithUsersAndAccounts.forEach(dept -> { deptWithUsersAndAccounts.forEach(dept -> {
//根据用户角色对部门用户进行分组 //根据用户角色对部门用户进行分组
Map<String, List<UserWithRolesAndAccountsResp>> usersByRole = dept.getUsers() Map<String, List<UserWithRolesAndAccountsResp>> usersByRole = dept.getUsers()
.stream()
.flatMap(user -> user.getRoles()
.stream() .stream()
.map(role -> new AbstractMap.SimpleEntry<>(role.getCode(), user))) .flatMap(user -> user.getRoles()
.collect(Collectors.groupingByConcurrent(Map.Entry::getKey, Collectors .stream()
.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); var ministerUser = usersByRole.get(MINISTER_ROLE_CODE).get(0);
//获取账号不为空的用户 //获取账号不为空的用户
@ -114,19 +114,19 @@ public class DailyReport {
deptWithUsersAndAccounts.forEach(dept -> { deptWithUsersAndAccounts.forEach(dept -> {
//根据用户角色对部门用户进行分组 //根据用户角色对部门用户进行分组
Map<String, List<UserWithRolesAndAccountsResp>> usersByRole = dept.getUsers() Map<String, List<UserWithRolesAndAccountsResp>> usersByRole = dept.getUsers()
.stream()
.flatMap(user -> user.getRoles()
.stream() .stream()
.map(role -> new AbstractMap.SimpleEntry<>(role.getCode(), user))) .flatMap(user -> user.getRoles()
.collect(Collectors.groupingByConcurrent(Map.Entry::getKey, Collectors .stream()
.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与用户的映射 // 获取所有账号的username与用户的映射
Map<String, UserWithRolesAndAccountsResp> accountUsernameToUserMap = dept.getUsers() Map<String, UserWithRolesAndAccountsResp> accountUsernameToUserMap = dept.getUsers()
.stream()
.flatMap(user -> user.getAccounts()
.stream() .stream()
.map(account -> new AbstractMap.SimpleEntry<>(account.getUsername(), user))) .flatMap(user -> user.getAccounts()
.collect(Collectors.toConcurrentMap(Map.Entry::getKey, Map.Entry::getValue)); .stream()
.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); var ministerUser = usersByRole.get(MINISTER_ROLE_CODE).get(0);
//获取账号不为空的用户 //获取账号不为空的用户
@ -142,7 +142,6 @@ public class DailyReport {
// 一小时发送一次 // 一小时发送一次
@Scheduled(cron = "0 0 * * * ?") @Scheduled(cron = "0 0 * * * ?")
//@Scheduled(fixedDelay = 6000L)
public void generateTeamReportTask() { public void generateTeamReportTask() {
LocalDateTime nowDateTime = LocalDateTime.now(); LocalDateTime nowDateTime = LocalDateTime.now();
LocalDate nowDate = LocalDate.now(); LocalDate nowDate = LocalDate.now();
@ -152,16 +151,16 @@ public class DailyReport {
deptWithUsersAndAccounts.forEach(dept -> { deptWithUsersAndAccounts.forEach(dept -> {
//根据用户角色对部门用户进行分组 //根据用户角色对部门用户进行分组
Map<String, List<UserWithRolesAndAccountsResp>> usersByRole = dept.getUsers() Map<String, List<UserWithRolesAndAccountsResp>> usersByRole = dept.getUsers()
.stream()
.flatMap(user -> user.getRoles()
.stream() .stream()
.map(role -> new AbstractMap.SimpleEntry<>(role.getCode(), user))) .flatMap(user -> user.getRoles()
.collect(Collectors.groupingByConcurrent(Map.Entry::getKey, Collectors .stream()
.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); var userWithRolesAndAccountsResps = usersByRole.get(MINISTER_ROLE_CODE);
userWithRolesAndAccountsResps.forEach(ministerUser -> generateAndSendTeamReport(ministerUser, nowDate userWithRolesAndAccountsResps.forEach(ministerUser -> generateAndSendTeamReport(ministerUser, nowDate
.atStartOfDay(), nowDateTime, null)); .atStartOfDay(), nowDateTime, null));
}); });
} }
@ -175,76 +174,76 @@ public class DailyReport {
LocalDate date) { LocalDate date) {
TeamMemberReq memberListReq = TeamMemberReq.builder() TeamMemberReq memberListReq = TeamMemberReq.builder()
.registerStartDate(date) .registerStartDate(date)
.registerEndDate(date) .registerEndDate(date)
.startDate(date) .startDate(date)
.endDate(date) .endDate(date)
.registerSort(1) .registerSort(1)
.status(1) .status(1)
.pageSize(100) .pageSize(100)
.build(); .build();
List<CompletableFuture<List<TeamMember>>> futureList = new ArrayList<>(); List<CompletableFuture<List<TeamMember>>> futureList = new ArrayList<>();
ministerUser.getAccounts().forEach(account -> { ministerUser.getAccounts().forEach(account -> {
CompletableFuture<MemberPagination<List<TeamMember>>> memberPaginationCompletableFuture = completableFutureWebClientService CompletableFuture<MemberPagination<List<TeamMember>>> memberPaginationCompletableFuture = completableFutureWebClientService
.fetchDataForAccount(account, ApiPathConstants.MEMBER_TEAM_LIST_URL, memberListReq, new ParameterizedTypeReference<>() { .fetchDataForAccount(account, ApiPathConstants.MEMBER_TEAM_LIST_URL, memberListReq, new ParameterizedTypeReference<>() {
}); });
CompletableFuture<List<TeamMember>> teamMembersFuture = memberPaginationCompletableFuture CompletableFuture<List<TeamMember>> teamMembersFuture = memberPaginationCompletableFuture
.thenApply(MemberPagination::getList) .thenApply(MemberPagination::getList)
.thenApplyAsync(members -> members.stream() .thenApplyAsync(members -> members.stream()
.filter(member -> member.getDeposit() != null && member.getDeposit() .filter(member -> member.getDeposit() != null && member.getDeposit()
.compareTo(BigDecimal.ZERO) == 0) .compareTo(BigDecimal.ZERO) == 0)
.collect(Collectors.toList()), asyncTaskExecutor) .collect(Collectors.toList()), asyncTaskExecutor)
.thenComposeAsync(membersWithoutDep -> { .thenComposeAsync(membersWithoutDep -> {
List<CompletableFuture<TeamMember>> memberFutures = membersWithoutDep.stream() List<CompletableFuture<TeamMember>> memberFutures = membersWithoutDep.stream()
.map(memberWithoutDep -> { .map(memberWithoutDep -> {
PayRecordListReq req = PayRecordListReq.builder() PayRecordListReq req = PayRecordListReq.builder()
.startDate(date) .startDate(date)
.endDate(date) .endDate(date)
.pageSize(100) .pageSize(100)
.id(memberWithoutDep.getId()) .id(memberWithoutDep.getId())
.build(); .build();
CompletableFuture<PayRecordList<List<PayRecord>>> completableFuture = completableFutureWebClientService CompletableFuture<PayRecordList<List<PayRecord>>> completableFuture = completableFutureWebClientService
.fetchDataForAccount(account, ApiPathConstants.PAY_RECORD_LIST_URL, req, new ParameterizedTypeReference<>() { .fetchDataForAccount(account, ApiPathConstants.PAY_RECORD_LIST_URL, req, new ParameterizedTypeReference<>() {
}); });
return completableFuture.thenApplyAsync(pagination -> { return completableFuture.thenApplyAsync(pagination -> {
if (pagination.getOrderAmountTotal().compareTo(BigDecimal.ZERO) > 0 && pagination if (pagination.getOrderAmountTotal().compareTo(BigDecimal.ZERO) > 0 && pagination
.getScoreAmountTotal() .getScoreAmountTotal()
.compareTo(BigDecimal.ZERO) == 0) { .compareTo(BigDecimal.ZERO) == 0) {
return memberWithoutDep; return memberWithoutDep;
} else { } else {
return null; return null;
} }
}, asyncTaskExecutor); }, asyncTaskExecutor);
}) })
.toList(); .toList();
return CompletableFuture.allOf(memberFutures.toArray(new CompletableFuture[0])) return CompletableFuture.allOf(memberFutures.toArray(new CompletableFuture[0]))
.thenApply(v -> memberFutures.stream() .thenApply(v -> memberFutures.stream()
.map(CompletableFuture::join) .map(CompletableFuture::join)
.filter(Objects::nonNull) .filter(Objects::nonNull)
.collect(Collectors.toList())); .collect(Collectors.toList()));
}, asyncTaskExecutor) }, asyncTaskExecutor)
.thenApplyAsync(membersWithoutDep -> { .thenApplyAsync(membersWithoutDep -> {
// 发送给每个account关联的user用户 // 发送给每个account关联的user用户
if (!membersWithoutDep.isEmpty()) { if (!membersWithoutDep.isEmpty()) {
Map<String, List<TeamMember>> groupByTopAgentName = membersWithoutDep.stream() Map<String, List<TeamMember>> groupByTopAgentName = membersWithoutDep.stream()
.collect(Collectors.groupingBy(TeamMember::getTopAgentName)); .collect(Collectors.groupingBy(TeamMember::getTopAgentName));
groupByTopAgentName.forEach((accountName, accountMembers) -> { groupByTopAgentName.forEach((accountName, accountMembers) -> {
String notification = telegramMessageService String notification = telegramMessageService
.buildFailedPayMessage(accountName, accountMembers); .buildFailedPayMessage(accountName, accountMembers);
UserWithRolesAndAccountsResp currUser = accountUsernameToUserMap.get(accountName); UserWithRolesAndAccountsResp currUser = accountUsernameToUserMap.get(accountName);
if (DisEnableStatusEnum.ENABLE.equals(currUser.getNeedNotify())) { if (currUser != null && DisEnableStatusEnum.ENABLE.equals(currUser.getNeedNotify())) {
String botToken = StrUtil.isEmpty(currUser.getBotToken()) String botToken = StrUtil.isEmpty(currUser.getBotToken())
? ministerUser.getBotToken() ? ministerUser.getBotToken()
: currUser.getBotToken(); : currUser.getBotToken();
telegramMessageService.sendMessage(botToken, currUser.getRegAndDepIds(), notification); telegramMessageService.sendMessage(botToken, currUser.getRegAndDepIds(), notification);
} }
}); });
} }
return membersWithoutDep; return membersWithoutDep;
}, asyncTaskExecutor); }, asyncTaskExecutor);
futureList.add(teamMembersFuture); futureList.add(teamMembersFuture);
}); });
@ -253,22 +252,22 @@ public class DailyReport {
allFutures.thenRunAsync(() -> { allFutures.thenRunAsync(() -> {
// 主线下的所有的存款失败用户 // 主线下的所有的存款失败用户
List<TeamMember> allTeamMembers = futureList.stream() List<TeamMember> allTeamMembers = futureList.stream()
.map(CompletableFuture::join) .map(CompletableFuture::join)
.flatMap(List::stream) .flatMap(List::stream)
.toList(); .toList();
Map<String, List<TeamMember>> groupByTopAgentName = new TreeMap<>(allTeamMembers.stream() Map<String, List<TeamMember>> groupByTopAgentName = new TreeMap<>(allTeamMembers.stream()
.collect(Collectors.groupingBy(TeamMember::getTopAgentName))); .collect(Collectors.groupingBy(TeamMember::getTopAgentName)));
StringBuilder combinedNotification = new StringBuilder(); StringBuilder combinedNotification = new StringBuilder();
groupByTopAgentName.forEach((accountName, accountMembers) -> { groupByTopAgentName.forEach((accountName, accountMembers) -> {
String notification = telegramMessageService.buildFailedPayMessage(accountName, accountMembers); String notification = telegramMessageService.buildFailedPayMessage(accountName, accountMembers);
combinedNotification.append(notification).append("\n"); combinedNotification.append(notification).append("\n");
}); });
telegramMessageService telegramMessageService
.sendMessage("6013830443:AAHUOS4v6Ln19ziZkH-L28-HZQLJrGcvhto", 6054562838L, combinedNotification .sendMessage("6013830443:AAHUOS4v6Ln19ziZkH-L28-HZQLJrGcvhto", 6054562838L, combinedNotification
.toString()); .toString());
if (DisEnableStatusEnum.ENABLE.equals(ministerUser.getNeedNotify())) { if (DisEnableStatusEnum.ENABLE.equals(ministerUser.getNeedNotify())) {
telegramMessageService.sendMessage(ministerUser.getBotToken(), ministerUser telegramMessageService.sendMessage(ministerUser.getBotToken(), ministerUser
.getReportIds(), combinedNotification.toString()); .getReportIds(), combinedNotification.toString());
} }
}, asyncTaskExecutor).exceptionally(ex -> { }, asyncTaskExecutor).exceptionally(ex -> {
@ -291,7 +290,7 @@ public class DailyReport {
AgentDataVisualListReq agentDataVisualListReq = AgentDataVisualListReq.builder().monthDate(reportDate).build(); AgentDataVisualListReq agentDataVisualListReq = AgentDataVisualListReq.builder().monthDate(reportDate).build();
deptUsers.forEach(deptUser -> tasks deptUsers.forEach(deptUser -> tasks
.add(processDeptUser(deptUser, ministerUser, agentDataVisualListReq, reportDate))); .add(processDeptUser(deptUser, ministerUser, agentDataVisualListReq, reportDate)));
CompletableFuture<Void> allTasks = CompletableFuture.allOf(tasks.toArray(new CompletableFuture[0])); CompletableFuture<Void> allTasks = CompletableFuture.allOf(tasks.toArray(new CompletableFuture[0]));
allTasks.join(); allTasks.join();
@ -318,32 +317,32 @@ public class DailyReport {
TeamInfoReq teamInfoReq = TeamInfoReq.builder().startDate(startDateTime).endDate(endDateTime).build(); TeamInfoReq teamInfoReq = TeamInfoReq.builder().startDate(startDateTime).endDate(endDateTime).build();
List<CompletableFuture<Void>> futures = accounts.stream() List<CompletableFuture<Void>> futures = accounts.stream()
.map(accountResp -> teamService.getLatestTeamInfoAsync(accountResp, teamInfoReq) .map(accountResp -> teamService.getLatestTeamInfoAsync(accountResp, teamInfoReq)
.thenAcceptAsync(team -> { .thenAcceptAsync(team -> {
int totalNewMember = team.getList().stream().mapToInt(TeamAccount::getSubMemberNum).sum(); int totalNewMember = team.getList().stream().mapToInt(TeamAccount::getSubMemberNum).sum();
int totalNewFirstDeposit = team.getList() int totalNewFirstDeposit = team.getList()
.stream() .stream()
.mapToInt(TeamAccount::getFirstDepositNum) .mapToInt(TeamAccount::getFirstDepositNum)
.sum(); .sum();
synchronized (totals) { synchronized (totals) {
totals[0] += totalNewMember; totals[0] += totalNewMember;
totals[1] += totalNewFirstDeposit; totals[1] += totalNewFirstDeposit;
} }
String percent = getPercent(totalNewFirstDeposit, totalNewMember); String percent = getPercent(totalNewFirstDeposit, totalNewMember);
synchronized (rows) { synchronized (rows) {
rows.add(new String[] {accountResp.getPlatformName(), String.valueOf(totalNewMember), String rows.add(new String[]{accountResp.getPlatformName(), String.valueOf(totalNewMember), String
.valueOf(totalNewFirstDeposit), percent}); .valueOf(totalNewFirstDeposit), percent});
} }
}, asyncTaskExecutor)) }, asyncTaskExecutor))
.toList(); .toList();
CompletableFuture<Void> allFutures = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); CompletableFuture<Void> allFutures = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
allFutures.join(); allFutures.join();
// rows 列表进行排序 // rows 列表进行排序
rows.sort(Comparator.comparing((String[] row) -> row[0].length()).thenComparing(row -> row[0])); 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]), rows.add(new String[]{"总计", String.valueOf(totals[0]), String.valueOf(totals[1]),
getPercent(totals[1], totals[0])}); getPercent(totals[1], totals[0])});
String message = TableFormatter.formatTableAsHtml(rows); String message = TableFormatter.formatTableAsHtml(rows);
if (ministerUser.getNeedNotify() == DisEnableStatusEnum.ENABLE) { if (ministerUser.getNeedNotify() == DisEnableStatusEnum.ENABLE) {
telegramMessageService.sendMessage(ministerUser.getBotToken(), ministerUser.getReportIds(), message); telegramMessageService.sendMessage(ministerUser.getBotToken(), ministerUser.getReportIds(), message);
@ -380,21 +379,21 @@ public class DailyReport {
List<AccountResp> currUserAccounts = deptUser.getAccounts(); List<AccountResp> currUserAccounts = deptUser.getAccounts();
List<CompletableFuture<Statics>> futures = currUserAccounts.stream() List<CompletableFuture<Statics>> futures = currUserAccounts.stream()
.map(currAccount -> agentDataVisualListService .map(currAccount -> agentDataVisualListService
.getAgentDataVisualList(currAccount, agentDataVisualListReq) .getAgentDataVisualList(currAccount, agentDataVisualListReq)
.thenApplyAsync(agentData -> agentData.getCurData() .thenApplyAsync(agentData -> agentData.getCurData()
.stream() .stream()
.filter(data -> data.getStaticsDate().equals(reportDate)) .filter(data -> data.getStaticsDate().equals(reportDate))
.findFirst() .findFirst()
.orElseThrow(() -> new BusinessException("No data found for report date"))) .orElseThrow(() -> new BusinessException("No data found for report date")))
.exceptionally(ex -> { .exceptionally(ex -> {
log.error("Error fetching data for account {}: {}", currAccount.getId(), ex.getMessage()); log.error("Error fetching data for account {}: {}", currAccount.getId(), ex.getMessage());
return null; return null;
})) }))
.toList(); .toList();
CompletableFuture<Void> userStaticsFuture = CompletableFuture.allOf(futures CompletableFuture<Void> userStaticsFuture = CompletableFuture.allOf(futures
.toArray(new CompletableFuture[0])); .toArray(new CompletableFuture[0]));
userStaticsFuture.thenRunAsync(() -> { userStaticsFuture.thenRunAsync(() -> {
List<Statics> agentDataList = futures.stream().map(future -> { List<Statics> agentDataList = futures.stream().map(future -> {
try { try {
@ -410,8 +409,8 @@ public class DailyReport {
if (StrUtil.isNotBlank(message) && deptUser.getNeedNotify() == DisEnableStatusEnum.ENABLE) { if (StrUtil.isNotBlank(message) && deptUser.getNeedNotify() == DisEnableStatusEnum.ENABLE) {
String botToken = StrUtil.isEmpty(deptUser.getBotToken()) String botToken = StrUtil.isEmpty(deptUser.getBotToken())
? ministerUser.getBotToken() ? ministerUser.getBotToken()
: deptUser.getBotToken(); : deptUser.getBotToken();
telegramMessageService.sendMessage(botToken, deptUser.getReportIds(), message); telegramMessageService.sendMessage(botToken, deptUser.getReportIds(), message);
} }
}, asyncTaskExecutor).exceptionally(ex -> { }, asyncTaskExecutor).exceptionally(ex -> {
@ -438,33 +437,33 @@ public class DailyReport {
List<CompletableFuture<Void>> tasks = new ArrayList<>(); List<CompletableFuture<Void>> tasks = new ArrayList<>();
TeamFinanceReq teamFinanceReq = TeamFinanceReq.builder() TeamFinanceReq teamFinanceReq = TeamFinanceReq.builder()
.pageNum(1) .pageNum(1)
.pageSize(999) .pageSize(999)
.commissionDate(reportDate) .commissionDate(reportDate)
.build(); .build();
// 异步处理 ministerUserAccounts // 异步处理 ministerUserAccounts
CompletableFuture<Void> ministerAccountsFuture = CompletableFuture.runAsync(() -> { CompletableFuture<Void> ministerAccountsFuture = CompletableFuture.runAsync(() -> {
List<CompletableFuture<Void>> accountFutures = ministerUser.getAccounts() List<CompletableFuture<Void>> accountFutures = ministerUser.getAccounts()
.stream() .stream()
.map(accountResp -> completableFutureFinanceService.getTeamFinance(accountResp, teamFinanceReq) .map(accountResp -> completableFutureFinanceService.getTeamFinance(accountResp, teamFinanceReq)
.thenAcceptAsync(financePagination -> { .thenAcceptAsync(financePagination -> {
List<FinanceDO> financeReqList = financePagination.getList().stream().map(finance -> { List<FinanceDO> financeReqList = financePagination.getList().stream().map(finance -> {
FinanceDO financeDO = new FinanceDO(); FinanceDO financeDO = new FinanceDO();
BeanUtil.copyProperties(finance, financeDO); BeanUtil.copyProperties(finance, financeDO);
return financeDO; return financeDO;
}).toList(); }).toList();
financeService.addAll(financeReqList); financeService.addAll(financeReqList);
FinanceSumReq financeSumReq = new FinanceSumReq(); FinanceSumReq financeSumReq = new FinanceSumReq();
BeanUtil.copyProperties(financePagination.getTotalSumVo(), financeSumReq); BeanUtil.copyProperties(financePagination.getTotalSumVo(), financeSumReq);
financeSumService.add(financeSumReq); financeSumService.add(financeSumReq);
}, asyncTaskExecutor) }, asyncTaskExecutor)
.exceptionally(ex -> { .exceptionally(ex -> {
log.error("Error processing minister accounts for account {}", accountResp log.error("Error processing minister accounts for account {}", accountResp
.getUsername(), ex); .getUsername(), ex);
return null; return null;
})) }))
.toList(); .toList();
CompletableFuture.allOf(accountFutures.toArray(new CompletableFuture[0])).join(); CompletableFuture.allOf(accountFutures.toArray(new CompletableFuture[0])).join();
}, asyncTaskExecutor).exceptionally(ex -> { }, asyncTaskExecutor).exceptionally(ex -> {
log.error("Error processing minister accounts", ex); log.error("Error processing minister accounts", ex);
@ -474,36 +473,36 @@ public class DailyReport {
// 异步处理 deptUsers // 异步处理 deptUsers
AgentDataVisualListReq agentDataVisualListReq = AgentDataVisualListReq.builder() AgentDataVisualListReq agentDataVisualListReq = AgentDataVisualListReq.builder()
.monthDate(reportDate) .monthDate(reportDate)
.build(); .build();
deptUsers.forEach(deptUser -> { deptUsers.forEach(deptUser -> {
CompletableFuture<Void> deptUserFuture = CompletableFuture.runAsync(() -> { CompletableFuture<Void> deptUserFuture = CompletableFuture.runAsync(() -> {
List<AccountResp> currUserAccounts = deptUser.getAccounts(); List<AccountResp> currUserAccounts = deptUser.getAccounts();
List<CompletableFuture<StatsDO>> futures = currUserAccounts.stream() List<CompletableFuture<StatsDO>> futures = currUserAccounts.stream()
.map(currAccount -> agentDataVisualListService .map(currAccount -> agentDataVisualListService
.getAgentDataVisualList(currAccount, agentDataVisualListReq) .getAgentDataVisualList(currAccount, agentDataVisualListReq)
.thenApplyAsync(agentData -> { .thenApplyAsync(agentData -> {
Statics statics = agentData.getCurData() Statics statics = agentData.getCurData()
.stream() .stream()
.filter(data -> data.getStaticsDate().equals(reportDate)) .filter(data -> data.getStaticsDate().equals(reportDate))
.findFirst() .findFirst()
.orElseThrow(() -> new BusinessException("No data found for report date")); .orElseThrow(() -> new BusinessException("No data found for report date"));
StatsDO statsDO = new StatsDO(); StatsDO statsDO = new StatsDO();
BeanUtil.copyProperties(statics, statsDO); BeanUtil.copyProperties(statics, statsDO);
return statsDO; return statsDO;
}, asyncTaskExecutor) }, asyncTaskExecutor)
.exceptionally(ex -> { .exceptionally(ex -> {
log.error("Error fetching data for account {}: {}", currAccount.getId(), ex log.error("Error fetching data for account {}: {}", currAccount.getId(), ex
.getMessage()); .getMessage());
return null; return null;
})) }))
.toList(); .toList();
List<StatsDO> list = futures.stream() List<StatsDO> list = futures.stream()
.map(CompletableFuture::join) .map(CompletableFuture::join)
.filter(Objects::nonNull) .filter(Objects::nonNull)
.collect(Collectors.toList()); .collect(Collectors.toList());
statsService.addAll(list); statsService.addAll(list);
}, asyncTaskExecutor).exceptionally(ex -> { }, asyncTaskExecutor).exceptionally(ex -> {

View File

@ -80,7 +80,6 @@ public class LoginServiceImpl implements LoginService {
private final PasswordEncoder passwordEncoder; private final PasswordEncoder passwordEncoder;
private final OptionService optionService; private final OptionService optionService;
@Override
public String accountLogin(String username, String password) { public String accountLogin(String username, String password) {
UserDO user = userService.getByUsername(username); UserDO user = userService.getByUsername(username);
boolean isError = ObjectUtil.isNull(user) || !passwordEncoder.matches(password, user.getPassword()); boolean isError = ObjectUtil.isNull(user) || !passwordEncoder.matches(password, user.getPassword());

View File

@ -90,5 +90,4 @@ public class OptionServiceImpl implements OptionService {
RedisUtils.set(CacheConstants.OPTION_KEY_PREFIX + code.getValue(), value); RedisUtils.set(CacheConstants.OPTION_KEY_PREFIX + code.getValue(), value);
return mapper.apply(value); return mapper.apply(value);
} }
} }

View File

@ -95,8 +95,6 @@ public class UserCenterController {
String rawNewPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq String rawNewPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq
.getNewPassword())); .getNewPassword()));
ValidationUtils.throwIfNull(rawNewPassword, "新密码解密失败"); ValidationUtils.throwIfNull(rawNewPassword, "新密码解密失败");
ValidationUtils.throwIf(!ReUtil
.isMatch(RegexConstants.PASSWORD, rawNewPassword), "密码长度为 6 到 32 位,可以包含字母、数字、下划线,特殊字符,同时包含字母和数字");
userService.updatePassword(rawOldPassword, rawNewPassword, LoginHelper.getUserId()); userService.updatePassword(rawOldPassword, rawNewPassword, LoginHelper.getUserId());
return R.ok("修改成功,请牢记你的新密码"); return R.ok("修改成功,请牢记你的新密码");
} }