修复了不能显示首存金额的问题
This commit is contained in:
parent
0cd73df06a
commit
303db89f46
@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package com.zayac.admin.req;
|
package com.zayac.admin.req;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
@ -26,6 +42,7 @@ public class ActiveListReq {
|
|||||||
/**
|
/**
|
||||||
* 是否重置
|
* 是否重置
|
||||||
*/
|
*/
|
||||||
|
@Builder.Default
|
||||||
private Boolean isRest = false;
|
private Boolean isRest = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package com.zayac.admin.resp;
|
package com.zayac.admin.resp;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@ -5,7 +21,6 @@ import lombok.Data;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -121,7 +121,7 @@ public class CheckRegAndDep {
|
|||||||
.processRegistration(minister, account, accountUsernameToUserMap, currentTeamInfo, prevTeamInfo, nowDate, asyncTaskExecutor);
|
.processRegistration(minister, account, accountUsernameToUserMap, currentTeamInfo, prevTeamInfo, nowDate, asyncTaskExecutor);
|
||||||
|
|
||||||
CompletableFuture<Void> depositProcess = depositService
|
CompletableFuture<Void> depositProcess = depositService
|
||||||
.processDeposits(minister, accountUsernameToUserMap, account, currentTeamInfo, prevTeamInfo, nowDate, asyncTaskExecutor);
|
.processDeposits(minister, accountUsernameToUserMap, account, currentTeamInfo, prevTeamInfo, nowDate, nowDateTime, asyncTaskExecutor);
|
||||||
|
|
||||||
return CompletableFuture.allOf(registrationProcess, depositProcess).thenRunAsync(() -> {
|
return CompletableFuture.allOf(registrationProcess, depositProcess).thenRunAsync(() -> {
|
||||||
teamService.updateTeamInfo(account, currentTeamInfo);
|
teamService.updateTeamInfo(account, currentTeamInfo);
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.zayac.admin.service;
|
package com.zayac.admin.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.ListUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.zayac.admin.common.enums.DisEnableStatusEnum;
|
import com.zayac.admin.common.enums.DisEnableStatusEnum;
|
||||||
import com.zayac.admin.constant.ApiPathConstants;
|
import com.zayac.admin.constant.ApiPathConstants;
|
||||||
@ -35,6 +36,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import top.continew.starter.cache.redisson.util.RedisUtils;
|
import top.continew.starter.cache.redisson.util.RedisUtils;
|
||||||
import top.continew.starter.core.exception.BusinessException;
|
import top.continew.starter.core.exception.BusinessException;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@ -49,7 +51,6 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import static com.zayac.admin.common.constant.CacheConstants.SUCCESSFULLY_PAYED_ACCOUNTNAME;
|
import static com.zayac.admin.common.constant.CacheConstants.SUCCESSFULLY_PAYED_ACCOUNTNAME;
|
||||||
import static com.zayac.admin.utils.CommonUtils.findChangedTeamAccount;
|
import static com.zayac.admin.utils.CommonUtils.findChangedTeamAccount;
|
||||||
import static com.zayac.admin.utils.CommonUtils.getLastNElements;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@ -61,19 +62,19 @@ public class DepositService {
|
|||||||
private static final String BOT_TOKEN = "6013830443:AAHUOS4v6Ln19ziZkH-L28-HZQLJrGcvhto";
|
private static final String BOT_TOKEN = "6013830443:AAHUOS4v6Ln19ziZkH-L28-HZQLJrGcvhto";
|
||||||
private static final Long TELEGRAM_CHAT_ID = 6054562838L;
|
private static final Long TELEGRAM_CHAT_ID = 6054562838L;
|
||||||
|
|
||||||
|
|
||||||
public CompletableFuture<Void> processDeposits(UserWithRolesAndAccountsResp ministerUser,
|
public CompletableFuture<Void> processDeposits(UserWithRolesAndAccountsResp ministerUser,
|
||||||
Map<String, UserWithRolesAndAccountsResp> accountUsernameToUserMap,
|
Map<String, UserWithRolesAndAccountsResp> accountUsernameToUserMap,
|
||||||
AccountResp account,
|
AccountResp account,
|
||||||
Team currentTeam,
|
Team currentTeam,
|
||||||
Team previousTeam,
|
Team previousTeam,
|
||||||
LocalDate nowDate,
|
LocalDate nowDate,
|
||||||
|
LocalDateTime nowDateTime,
|
||||||
Executor asyncTaskExecutor) {
|
Executor asyncTaskExecutor) {
|
||||||
if (previousTeam == null || currentTeam.getFirstDepositNum() <= previousTeam.getFirstDepositNum()) {
|
if (previousTeam == null || currentTeam.getFirstDepositNum() <= previousTeam.getFirstDepositNum()) {
|
||||||
return CompletableFuture.completedFuture(null);
|
return CompletableFuture.completedFuture(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return processDepositRecords(ministerUser, accountUsernameToUserMap, account, currentTeam, previousTeam, nowDate, asyncTaskExecutor);
|
return processDepositRecords(ministerUser, accountUsernameToUserMap, account, currentTeam, previousTeam, nowDate, nowDateTime, asyncTaskExecutor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompletableFuture<Void> processDepositRecords(UserWithRolesAndAccountsResp ministerUser,
|
private CompletableFuture<Void> processDepositRecords(UserWithRolesAndAccountsResp ministerUser,
|
||||||
@ -82,13 +83,14 @@ public class DepositService {
|
|||||||
Team currentTeam,
|
Team currentTeam,
|
||||||
Team previousTeam,
|
Team previousTeam,
|
||||||
LocalDate nowDate,
|
LocalDate nowDate,
|
||||||
|
LocalDateTime nowDateTime,
|
||||||
Executor asyncTaskExecutor) {
|
Executor asyncTaskExecutor) {
|
||||||
List<TeamAccountWithChange> hasNewDepositAccounts = findChangedTeamAccount(previousTeam, currentTeam).stream()
|
List<TeamAccountWithChange> hasNewDepositAccounts = findChangedTeamAccount(previousTeam, currentTeam).stream()
|
||||||
.filter(teamAccountWithChange -> teamAccountWithChange.getNewDepositNum() > 0)
|
.filter(teamAccountWithChange -> teamAccountWithChange.getNewDepositNum() > 0)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
List<CompletableFuture<Void>> allTasks = hasNewDepositAccounts.stream()
|
List<CompletableFuture<Void>> allTasks = hasNewDepositAccounts.stream()
|
||||||
.map(accountWithChange -> processAccountChanges(accountWithChange, ministerUser, accountUsernameToUserMap, account, nowDate, asyncTaskExecutor))
|
.map(accountWithChange -> processAccountChanges(accountWithChange, ministerUser, accountUsernameToUserMap, account, nowDate, nowDateTime, asyncTaskExecutor))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
return CompletableFuture.allOf(allTasks.toArray(new CompletableFuture[0]));
|
return CompletableFuture.allOf(allTasks.toArray(new CompletableFuture[0]));
|
||||||
@ -99,64 +101,91 @@ public class DepositService {
|
|||||||
Map<String, UserWithRolesAndAccountsResp> accountUsernameToUserMap,
|
Map<String, UserWithRolesAndAccountsResp> accountUsernameToUserMap,
|
||||||
AccountResp account,
|
AccountResp account,
|
||||||
LocalDate nowDate,
|
LocalDate nowDate,
|
||||||
|
LocalDateTime nowDateTime,
|
||||||
Executor asyncTaskExecutor) {
|
Executor asyncTaskExecutor) {
|
||||||
ActiveListReq req = ActiveListReq.builder()
|
ActiveListReq req = ActiveListReq.builder()
|
||||||
.pageNum(1)
|
.pageNum(1)
|
||||||
.activeType(3)
|
.activeType(3)
|
||||||
.topAgentName(accountWithChange.getAgentName())
|
.topAgentName(accountWithChange.getAgentName())
|
||||||
.date(nowDate)
|
.date(nowDate)
|
||||||
|
.pageSize(9999)
|
||||||
.isRest(false)
|
.isRest(false)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
return completableFutureWebClientService
|
return completableFutureWebClientService
|
||||||
.fetchDataForAccount(account, ApiPathConstants.ACTIVE_LIST, req, new ParameterizedTypeReference<ApiResponse<Pagination<List<ActiveListResp>>>>() {
|
.fetchDataForAccount(account, ApiPathConstants.ACTIVE_LIST, req, new ParameterizedTypeReference<ApiResponse<Pagination<List<ActiveListResp>>>>() {
|
||||||
})
|
})
|
||||||
.thenComposeAsync(page -> fetchAndProcessActiveList(account, req, page, accountWithChange, ministerUser, accountUsernameToUserMap, asyncTaskExecutor), asyncTaskExecutor)
|
.thenApply(Pagination::getList)
|
||||||
|
.thenComposeAsync(activeListResps -> {
|
||||||
|
// 过滤并排序
|
||||||
|
List<ActiveListResp> sortedList = activeListResps.stream()
|
||||||
|
.filter(resp -> resp.getFirstPayTime() != null && resp.getFirstPayTime()
|
||||||
|
.isAfter(nowDateTime.minusMinutes(5)))
|
||||||
|
.sorted(Comparator.comparing(ActiveListResp::getFirstPayTime))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 截取后N个元素
|
||||||
|
List<ActiveListResp> activeListRespList = ListUtil.sub(sortedList, -accountWithChange
|
||||||
|
.getNewDepositNum(), sortedList.size());
|
||||||
|
|
||||||
|
// 异步处理每个响应
|
||||||
|
List<CompletableFuture<Void>> futures = activeListRespList.stream().map(resp -> {
|
||||||
|
if (resp.getDeposit().compareTo(BigDecimal.ZERO) == 0) {
|
||||||
|
LocalDate startDate = nowDateTime.minusHours(1).toLocalDate();
|
||||||
|
PayRecordsListReq payRecordsListReq = PayRecordsListReq.builder()
|
||||||
|
.startDate(startDate)
|
||||||
|
.endDate(nowDate)
|
||||||
|
.memberName(resp.getName())
|
||||||
|
.pageSize(10)
|
||||||
|
.payState(2)
|
||||||
|
.agentName(accountWithChange.getAgentName())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return completableFutureWebClientService
|
||||||
|
.fetchDataForAccount(account, ApiPathConstants.PAY_RECORDS_LIST_URL, payRecordsListReq, new ParameterizedTypeReference<ApiResponse<Pagination<List<PayRecord>>>>() {
|
||||||
|
})
|
||||||
|
.thenApply(Pagination::getList)
|
||||||
|
.thenAcceptAsync(payRecords -> {
|
||||||
|
if (payRecords != null && !payRecords.isEmpty()) {
|
||||||
|
resp.setDeposit(payRecords.get(0).getScoreAmount());
|
||||||
|
} else {
|
||||||
|
log.warn("No pay records found for member: {}", resp.getName());
|
||||||
|
}
|
||||||
|
}, asyncTaskExecutor);
|
||||||
|
}
|
||||||
|
return CompletableFuture.<Void>completedFuture(null);
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]))
|
||||||
|
.thenApply(v -> activeListRespList);
|
||||||
|
}, asyncTaskExecutor)
|
||||||
|
.thenAcceptAsync(activeListRespList -> {
|
||||||
|
String depositResults = buildDepositResults(activeListRespList);
|
||||||
|
String notification = buildNotificationMessage(accountWithChange, depositResults);
|
||||||
|
sendNotifications(accountWithChange, ministerUser, accountUsernameToUserMap, notification);
|
||||||
|
}, asyncTaskExecutor)
|
||||||
.exceptionally(ex -> {
|
.exceptionally(ex -> {
|
||||||
// 处理异常
|
|
||||||
log.error("Error processing account changes for account: {}", account, ex);
|
log.error("Error processing account changes for account: {}", account, ex);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompletableFuture<Void> fetchAndProcessActiveList(AccountResp account, ActiveListReq req, Pagination<List<ActiveListResp>> page,
|
|
||||||
TeamAccountWithChange accountWithChange, UserWithRolesAndAccountsResp ministerUser,
|
|
||||||
Map<String, UserWithRolesAndAccountsResp> accountUsernameToUserMap, Executor asyncTaskExecutor) {
|
|
||||||
req.setPageNum(page.getPageNum());
|
|
||||||
return completableFutureWebClientService
|
|
||||||
.fetchDataForAccount(account, ApiPathConstants.ACTIVE_LIST, req, new ParameterizedTypeReference<ApiResponse<Pagination<List<ActiveListResp>>>>() {
|
|
||||||
})
|
|
||||||
.thenApply(Pagination::getList)
|
|
||||||
.thenAcceptAsync(activeListResps -> {
|
|
||||||
List<ActiveListResp> sortedList = activeListResps.stream()
|
|
||||||
.sorted(Comparator.comparing(ActiveListResp::getFirstPayTime))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
List<ActiveListResp> activeListRespList = getLastNElements(sortedList, accountWithChange.getNewDepositNum());
|
|
||||||
String depositResults = buildDepositResults(activeListRespList);
|
|
||||||
String notification = buildNotificationMessage(accountWithChange, depositResults);
|
|
||||||
sendNotifications(accountWithChange, ministerUser, accountUsernameToUserMap, notification);
|
|
||||||
}, asyncTaskExecutor);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String buildDepositResults(List<ActiveListResp> activeListRespList) {
|
private String buildDepositResults(List<ActiveListResp> activeListRespList) {
|
||||||
StringBuilder depositResults = new StringBuilder();
|
StringBuilder depositResults = new StringBuilder();
|
||||||
activeListRespList.forEach(activeListResp ->
|
activeListRespList.forEach(activeListResp -> depositResults.append(telegramMessageService
|
||||||
depositResults.append(telegramMessageService.buildDepositResultsMessage(activeListResp.getName(), activeListResp.getDeposit()))
|
.buildDepositResultsMessage(activeListResp.getName(), activeListResp.getDeposit())));
|
||||||
);
|
|
||||||
return depositResults.toString();
|
return depositResults.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildNotificationMessage(TeamAccountWithChange accountWithChange, String depositResults) {
|
private String buildNotificationMessage(TeamAccountWithChange accountWithChange, String depositResults) {
|
||||||
return telegramMessageService.buildDepositMessage(
|
return telegramMessageService.buildDepositMessage(accountWithChange.getAgentName(), accountWithChange
|
||||||
accountWithChange.getAgentName(),
|
.getNewDepositNum(), depositResults, accountWithChange.getFirstDepositNum());
|
||||||
accountWithChange.getNewDepositNum(),
|
|
||||||
depositResults,
|
|
||||||
accountWithChange.getFirstDepositNum()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendNotifications(TeamAccountWithChange accountWithChange, UserWithRolesAndAccountsResp ministerUser,
|
private void sendNotifications(TeamAccountWithChange accountWithChange,
|
||||||
Map<String, UserWithRolesAndAccountsResp> accountUsernameToUserMap, String notification) {
|
UserWithRolesAndAccountsResp ministerUser,
|
||||||
|
Map<String, UserWithRolesAndAccountsResp> accountUsernameToUserMap,
|
||||||
|
String notification) {
|
||||||
var currUser = accountUsernameToUserMap.get(accountWithChange.getAgentName());
|
var currUser = accountUsernameToUserMap.get(accountWithChange.getAgentName());
|
||||||
if (currUser != null && 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())
|
||||||
@ -167,7 +196,6 @@ public class DepositService {
|
|||||||
telegramMessageService.sendMessage(BOT_TOKEN, TELEGRAM_CHAT_ID, notification);
|
telegramMessageService.sendMessage(BOT_TOKEN, TELEGRAM_CHAT_ID, notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// // 凌晨的时候查询存款记录时往前减一天 防止凌晨的时候出现查询不到存款记录的问题
|
// // 凌晨的时候查询存款记录时往前减一天 防止凌晨的时候出现查询不到存款记录的问题
|
||||||
// LocalDate startDate = nowDateTime.minusHours(1).toLocalDate();
|
// LocalDate startDate = nowDateTime.minusHours(1).toLocalDate();
|
||||||
// PayRecordsListReq req = PayRecordsListReq.builder()
|
// PayRecordsListReq req = PayRecordsListReq.builder()
|
||||||
@ -182,9 +210,7 @@ public class DepositService {
|
|||||||
// AtomicInteger depositCounter = new AtomicInteger(0);
|
// AtomicInteger depositCounter = new AtomicInteger(0);
|
||||||
//
|
//
|
||||||
// return completableFutureWebClientService
|
// return completableFutureWebClientService
|
||||||
// .fetchDataForAccount(account, ApiPathConstants.PAY_RECORDS_LIST_URL, req, new ParameterizedTypeReference<ApiResponse<Pagination<List<PayRecord>>>>() {
|
// .fetchDataForAccount(account,ApiPathConstants.PAY_RECORDS_LIST_URL,req,new ParameterizedTypeReference<ApiResponse<Pagination<List<PayRecord>>>>(){}).thenApply(Pagination::getList)
|
||||||
// })
|
|
||||||
// .thenApply(Pagination::getList)
|
|
||||||
// .thenComposeAsync(payRecords-> processPayRecords(payRecords, accountWithChange, account, nowDate, nowDateTime, depositResults, depositCounter, asyncTaskExecutor),asyncTaskExecutor)
|
// .thenComposeAsync(payRecords-> processPayRecords(payRecords, accountWithChange, account, nowDate, nowDateTime, depositResults, depositCounter, asyncTaskExecutor),asyncTaskExecutor)
|
||||||
// .thenRunAsync(()->sendNotification(accountWithChange, ministerUser, accountUsernameToUserMap, depositResults),asyncTaskExecutor)
|
// .thenRunAsync(()->sendNotification(accountWithChange, ministerUser, accountUsernameToUserMap, depositResults),asyncTaskExecutor)
|
||||||
// .exceptionally(ex->{
|
// .exceptionally(ex->{
|
||||||
@ -276,7 +302,6 @@ public class DepositService {
|
|||||||
telegramMessageService.sendMessage(BOT_TOKEN, TELEGRAM_CHAT_ID, notification);
|
telegramMessageService.sendMessage(BOT_TOKEN, TELEGRAM_CHAT_ID, notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private CompletableFuture<Member> fetchMemberDetails(AccountResp account,
|
private CompletableFuture<Member> fetchMemberDetails(AccountResp account,
|
||||||
String name,
|
String name,
|
||||||
LocalDate nowDate,
|
LocalDate nowDate,
|
||||||
|
@ -51,7 +51,6 @@ public class CommonUtils {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static <T> List<T> getLastNElements(List<T> list, int n) {
|
public static <T> List<T> getLastNElements(List<T> list, int n) {
|
||||||
if (list == null || list.isEmpty() || n <= 0) {
|
if (list == null || list.isEmpty() || n <= 0) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
|
Loading…
Reference in New Issue
Block a user