feat: 每月定时开始学习并改为本地计算心跳摘要

This commit is contained in:
2026-11-15 01:30:24 +08:00
parent e9a1e9b315
commit caa79d79b7
14 changed files with 510 additions and 35 deletions
+32
View File
@@ -12,6 +12,10 @@ from sqlalchemy.orm import Session
from euniv.crypto import decrypt_secret
from euniv.models import Account
from euniv.proxy import ProxyError, apply, clear, summary_of, url_of, view_of
from euniv.study_window import StudyWindowError
from euniv.study_window import apply as apply_start
from euniv.study_window import label_of as start_label
from euniv.study_window import view_of as start_view
_TOKEN_KEYS = (
"ucs_token",
@@ -67,6 +71,11 @@ def list_users(db: Session) -> list[dict]:
"month_hours": account.month_hours or "",
"has_proxy": bool(account.proxy_scheme and account.proxy_host and account.proxy_port),
"proxy": summary_of(account),
"study_start": start_label(account),
"study_start_day": int(account.study_start_day or 1),
"study_start_hour": int(account.study_start_hour or 0),
"study_start_minute": int(account.study_start_minute or 0),
"study_start_second": int(account.study_start_second or 0),
}
for account in accounts
]
@@ -217,6 +226,29 @@ def clear_proxy(db: Session, employee_ids: list[str]) -> dict:
return {"ok": True, "count": len(accounts)}
def read_study_start(db: Session, employee_id: str) -> dict:
return start_view(_require(db, employee_id))
def set_study_start(
db: Session,
employee_ids: list[str],
day: int,
hour: int,
minute: int,
second: int,
) -> dict:
accounts = _accounts_by_ids(db, employee_ids)
try:
for account in accounts:
apply_start(account, day, hour, minute, second)
except StudyWindowError as exc:
db.rollback()
raise HTTPException(status_code=400, detail=str(exc)) from exc
db.commit()
return {"ok": True, "count": len(accounts)}
def delete_user(db: Session, employee_id: str) -> dict:
account = _require(db, employee_id)
db.delete(account)