feat: 历史统计时对照显示官方本月学时

This commit is contained in:
Nixevol
2026-11-19 02:54:32 +08:00
parent ba787a513b
commit a0ceb51348
12 changed files with 156 additions and 13 deletions
+22 -4
View File
@@ -62,8 +62,10 @@ def _iso_time(value: datetime | None) -> str | None:
def list_users(db: Session) -> list[dict]:
from admin.settings import hours_source_of
from euniv.autostudy import autostudy_status, work_running
source = hours_source_of()
accounts = db.scalars(select(Account).order_by(Account.employee_id)).all()
live_users = autostudy_status().get("users") or {}
rows = []
@@ -82,6 +84,8 @@ def list_users(db: Session) -> list[dict]:
"last_refresh_at": _iso_time(account.last_refresh_at),
"credential_valid": _optional_bool(account.credential_valid),
"month_hours": account.month_hours or "",
"official_month_hours": account.official_month_hours or "",
"hours_source": source,
"monthly_target": account.monthly_target if account.monthly_target is not None else 600,
"has_proxy": enabled(account),
"proxy": summary_of(account),
@@ -111,13 +115,23 @@ def _require(db: Session, employee_id: str) -> Account:
return account
def _checked_hours(client) -> str:
def _checked_hours(client) -> tuple[str, str]:
from admin.settings import hours_source_of
from euniv.service import _month_hours
try:
return _month_hours(client)
hours = _month_hours(client)
except Exception:
return ""
hours = ""
official = ""
if hours and hours_source_of() == "history":
reader = getattr(client, "month_hours", None)
if callable(reader):
try:
official = str(reader() or "").strip()
except Exception:
official = ""
return hours, official
def _checked_profile(client) -> dict:
@@ -146,6 +160,7 @@ def check_employee(db: Session, employee_id: str) -> dict:
valid: bool | None = None
profile: dict = {}
hours = ""
official_hours = ""
try:
for _ in range(MAX_SWITCHES + 1):
proxy = bind_url(account) if pooled else url_of(account)
@@ -157,11 +172,12 @@ def check_employee(db: Session, employee_id: str) -> dict:
valid = alive
profile = _checked_profile(client) if alive else {}
if alive:
hours = _checked_hours(client)
hours, official_hours = _checked_hours(client)
break
except Exception as exc:
profile = {}
hours = ""
official_hours = ""
if pooled and proxy and is_proxy_failure(exc):
retire_if_dead(employee_id, proxy, str(exc)[:200])
client.close()
@@ -190,6 +206,8 @@ def check_employee(db: Session, employee_id: str) -> dict:
from euniv.study_control import stamp_hours
stamp_hours(account, hours)
if official_hours:
account.official_month_hours = official_hours[:32]
db.commit()
payload = {"employee_id": employee_id, "result": result}
if result == "检查失败":