tools-pyqt/src/ui/data_query.py

68 lines
2.4 KiB
Python

import time
from PyQt6.QtCore import QObject, QRunnable, pyqtSignal
from src.entity.banner_info import get_banner_info, get_banner_info_by_user
from src.entity.finance import get_adjusted_salary, get_net_win_by_user
from src.entity.pay_record import get_pay_failed_by_user
from src.entity.visual_list import text_count_by_user
class TaskSignals(QObject):
query_completed = pyqtSignal(str, bool, bool)
table_updated = pyqtSignal(str, list)
class ReportTask(QRunnable):
def __init__(self, account):
super().__init__()
self.account = account
self.signals = TaskSignals()
def run(self):
data = self.query_data_for_account(self.account)
self.signals.table_updated.emit(self.account.username, data)
@staticmethod
def query_data_for_account(account):
time_str = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
banner_info = get_banner_info(account)
# 返回数据列表
return [time_str, banner_info.registerMembers, banner_info.firstDepositNum, banner_info.netWinLose,
banner_info.effectiveNew, banner_info.activeMembers]
@staticmethod
def query_data_for_user(user):
banner_info_res = get_banner_info_by_user(user)
return banner_info_res
class ButtonTask(QRunnable):
def __init__(self, query_type, selected_date_str, user):
super().__init__()
self.query_type = query_type
self.selected_date_str = selected_date_str
self.user = user
self.signals = TaskSignals()
def run(self):
result = ''
auto_clipboard = False
notify = False
if self.query_type == '报数':
result = text_count_by_user(self.user, self.selected_date_str)
auto_clipboard = True
notify = True
elif self.query_type == '存款失败用户':
result = get_pay_failed_by_user(self.user, self.selected_date_str)
if '' not in result:
auto_clipboard = True
notify = True
elif self.query_type == '负盈利':
result = get_net_win_by_user(self.user, self.selected_date_str)
elif self.query_type == '薪资':
result = get_adjusted_salary(self.user, self.selected_date_str)
# 数据查询完成,发出信号
self.signals.query_completed.emit(result, auto_clipboard, notify)