修复存款不提示的问题
This commit is contained in:
parent
ec44c11024
commit
668e274ab2
@ -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.account import Account
|
||||||
from src.entity.member import (MemberList, async_get_member_detail_by_name,
|
from src.entity.member import (MemberList, async_get_member_detail_by_name,
|
||||||
get_member_by_name, get_member_list)
|
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
|
@dataclass
|
||||||
@ -51,37 +51,53 @@ def get_pay_record(account: Account):
|
|||||||
return [PayRecord(**item) for item in api_response.data['list']]
|
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):
|
def get_latest_deposit_user(account: Account, count: int):
|
||||||
logger.info(f'Getting latest deposit user for account: {account.name} and count: {count}')
|
logger.info(f'Getting latest deposit user for account: {account.name} and count: {count}')
|
||||||
pay_record_list = get_pay_record(account)
|
pay_record_list = get_pay_record(account)
|
||||||
# 提取所有用户名
|
|
||||||
names = []
|
# 提取所有用户名,并确保在指定时间内
|
||||||
seen = set()
|
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
for item in pay_record_list:
|
unique_names_within_time = {
|
||||||
name = item.name
|
item.name for item in pay_record_list if util.get_difference(item.createdAt, now) < 7200
|
||||||
if name not in seen and util.get_difference(item.createdAt, now) < 7200:
|
}
|
||||||
names.append(name)
|
|
||||||
seen.add(name)
|
logger.debug(f"获取到{len(unique_names_within_time)}个成功存款人数")
|
||||||
logger.debug(f"获取到{len(names)}个成功存款人数")
|
|
||||||
# 开启多线程 根据用户名查询所有数据
|
# 开启多线程根据用户名查询所有数据
|
||||||
with ThreadPoolExecutor(max_workers=len(names)) as executor:
|
results = []
|
||||||
futures = [executor.submit(get_member_by_name, account, name) for name in names]
|
with ThreadPoolExecutor(max_workers=min(len(unique_names_within_time), 20)) as executor: # 限制最大工作线程数
|
||||||
try:
|
futures = [executor.submit(get_member_by_name, account, name) for name in unique_names_within_time]
|
||||||
results = [future.result() for future in futures]
|
for future in as_completed(futures):
|
||||||
except Exception as e:
|
try:
|
||||||
logger.debug(f'查询失败:{e}')
|
result = future.result()
|
||||||
sorted_members = sorted(results, key=lambda member_detail: member_detail.get_first_pay_datetime(), reverse=True)
|
results.append(result)
|
||||||
# 截取前n个
|
except Exception as e:
|
||||||
details = sorted_members[:count]
|
logger.debug(f'查询失败:{e}')
|
||||||
record_dict = {record.createdAt: record.scoreAmount for record in pay_record_list}
|
|
||||||
member_details = []
|
# 筛选出有有效结果的成员,并按首次付款时间降序排序
|
||||||
for detail in details:
|
valid_results = [result for result in results if result is not None]
|
||||||
if detail.firstPayAt in record_dict:
|
sorted_members = sorted(valid_results, key=lambda member_detail: member_detail.get_first_pay_datetime(),
|
||||||
detail.deposit = record_dict[detail.firstPayAt]
|
reverse=True)
|
||||||
member_details.append(detail)
|
|
||||||
logger.info(f'Finished getting latest deposit user for account: {account.name} and count: {count}')
|
# 截取前n个
|
||||||
return member_details
|
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)
|
logger.info(text)
|
||||||
return 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)
|
||||||
|
@ -549,3 +549,4 @@ class Application(QMainWindow):
|
|||||||
def copy_to_clipboard(text):
|
def copy_to_clipboard(text):
|
||||||
clipboard = QApplication.clipboard()
|
clipboard = QApplication.clipboard()
|
||||||
clipboard.setText(text)
|
clipboard.setText(text)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user