修复存款不提示的问题

This commit is contained in:
zayac 2024-01-30 17:57:30 +08:00
parent ec44c11024
commit 668e274ab2
2 changed files with 52 additions and 28 deletions

View File

@ -11,7 +11,7 @@ from src.core.util import get_curr_day, get_first_day_month
from src.entity.account import Account
from src.entity.member import (MemberList, async_get_member_detail_by_name,
get_member_by_name, get_member_list)
from src.entity.user import User, get_user_by_telegram_id
from src.entity.user import User, get_user_by_telegram_id, get_user_by_username_and_password
@dataclass
@ -51,37 +51,53 @@ def get_pay_record(account: Account):
return [PayRecord(**item) for item in api_response.data['list']]
from concurrent.futures import ThreadPoolExecutor, as_completed
from datetime import datetime
def get_latest_deposit_user(account: Account, count: int):
logger.info(f'Getting latest deposit user for account: {account.name} and count: {count}')
pay_record_list = get_pay_record(account)
# 提取所有用户名
names = []
seen = set()
# 提取所有用户名,并确保在指定时间内
now = datetime.now()
for item in pay_record_list:
name = item.name
if name not in seen and util.get_difference(item.createdAt, now) < 7200:
names.append(name)
seen.add(name)
logger.debug(f"获取到{len(names)}个成功存款人数")
# 开启多线程 根据用户名查询所有数据
with ThreadPoolExecutor(max_workers=len(names)) as executor:
futures = [executor.submit(get_member_by_name, account, name) for name in names]
try:
results = [future.result() for future in futures]
except Exception as e:
logger.debug(f'查询失败:{e}')
sorted_members = sorted(results, key=lambda member_detail: member_detail.get_first_pay_datetime(), reverse=True)
# 截取前n个
details = sorted_members[:count]
record_dict = {record.createdAt: record.scoreAmount for record in pay_record_list}
member_details = []
for detail in details:
if detail.firstPayAt in record_dict:
detail.deposit = record_dict[detail.firstPayAt]
member_details.append(detail)
logger.info(f'Finished getting latest deposit user for account: {account.name} and count: {count}')
return member_details
unique_names_within_time = {
item.name for item in pay_record_list if util.get_difference(item.createdAt, now) < 7200
}
logger.debug(f"获取到{len(unique_names_within_time)}个成功存款人数")
# 开启多线程根据用户名查询所有数据
results = []
with ThreadPoolExecutor(max_workers=min(len(unique_names_within_time), 20)) as executor: # 限制最大工作线程数
futures = [executor.submit(get_member_by_name, account, name) for name in unique_names_within_time]
for future in as_completed(futures):
try:
result = future.result()
results.append(result)
except Exception as e:
logger.debug(f'查询失败:{e}')
# 筛选出有有效结果的成员,并按首次付款时间降序排序
valid_results = [result for result in results if result is not None]
sorted_members = sorted(valid_results, key=lambda member_detail: member_detail.get_first_pay_datetime(),
reverse=True)
# 截取前n个
selected_members = sorted_members[:count]
# 构建时间和金额的映射字典
record_dict = {record.createdAt: record.scoreAmount for record in pay_record_list}
member_details = []
for detail in selected_members:
# 检查 detail.firstPayAt 是否在 record_dict 中,避免 KeyError
if detail.firstPayAt in record_dict:
detail.deposit = record_dict[detail.firstPayAt]
member_details.append(detail)
logger.info(f'Finished getting latest deposit user for account: {account.name} and count: {count}')
return member_details
# 根据用户查询最新存款信息
@ -227,3 +243,10 @@ def get_pay_failed_by_telegram_id(telegram_id: int) -> Optional[str]:
logger.info(text)
return text
if __name__ == '__main__':
deposit_results = '\n'.join(
[f"用户: `{member.name}`, 首存金额: *{member.deposit}*" for member in
get_latest_deposit_user(get_user_by_username_and_password('zayac', 'password').accounts[0], 1)])
print(deposit_results)

View File

@ -549,3 +549,4 @@ class Application(QMainWindow):
def copy_to_clipboard(text):
clipboard = QApplication.clipboard()
clipboard.setText(text)