feat: 按账号调度自动学习并让首页实时跟上状态
This commit is contained in:
+12
-2
@@ -86,6 +86,7 @@ def list_users(db: Session) -> list[dict]:
|
||||
"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),
|
||||
"study_schedule_enabled": control["schedule_enabled"],
|
||||
"course_workers": workers_of(account),
|
||||
"study_paused": control["paused"],
|
||||
"study_ignore_window": control["ignore_window"],
|
||||
@@ -284,7 +285,7 @@ def set_study_action(db: Session, employee_ids: list[str], action: str) -> dict:
|
||||
if kind not in {"start", "stop"}:
|
||||
raise HTTPException(status_code=400, detail="请选择开始或停止")
|
||||
accounts = _accounts_by_ids(db, employee_ids)
|
||||
from euniv.autostudy import request_stop, request_wake
|
||||
from euniv.autostudy import request_stop, sync_work
|
||||
|
||||
for account in accounts:
|
||||
if kind == "start":
|
||||
@@ -292,8 +293,10 @@ def set_study_action(db: Session, employee_ids: list[str], action: str) -> dict:
|
||||
else:
|
||||
stop_now(account)
|
||||
db.commit()
|
||||
|
||||
if kind == "start":
|
||||
request_wake()
|
||||
for account in accounts:
|
||||
sync_work(account.employee_id)
|
||||
else:
|
||||
for account in accounts:
|
||||
request_stop(account.employee_id)
|
||||
@@ -308,6 +311,7 @@ def set_study_settings(
|
||||
hour: int | None = None,
|
||||
minute: int | None = None,
|
||||
second: int | None = None,
|
||||
schedule_enabled: bool | None = None,
|
||||
workers: int | None = None,
|
||||
scheme: str | None = None,
|
||||
host: str = "",
|
||||
@@ -325,6 +329,8 @@ def set_study_settings(
|
||||
account.monthly_target = monthly_target
|
||||
if day is not None:
|
||||
apply_start(account, day, hour, minute, second)
|
||||
if schedule_enabled is not None:
|
||||
account.study_schedule_enabled = bool(schedule_enabled)
|
||||
if workers is not None:
|
||||
apply_workers(account, workers)
|
||||
if scheme is not None:
|
||||
@@ -333,6 +339,10 @@ def set_study_settings(
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
db.commit()
|
||||
from euniv.autostudy import sync_work
|
||||
|
||||
for account in accounts:
|
||||
sync_work(account.employee_id)
|
||||
return {"ok": True, "count": len(accounts)}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user