feat: 学习进度轮询、学时依据与首页代理弹窗
This commit is contained in:
@@ -22,3 +22,4 @@ class SystemConfig(Base):
|
||||
heartbeat_video_seconds: Mapped[int] = mapped_column(Integer, nullable=False, default=30, server_default="30")
|
||||
heartbeat_document_seconds: Mapped[int] = mapped_column(Integer, nullable=False, default=120, server_default="120")
|
||||
heartbeat_scorm_seconds: Mapped[int] = mapped_column(Integer, nullable=False, default=120, server_default="120")
|
||||
hours_source: Mapped[str] = mapped_column(String(16), nullable=False, default="api", server_default="api")
|
||||
|
||||
@@ -49,6 +49,7 @@ class SettingsBody(BaseModel):
|
||||
heartbeat_video_seconds: int = 30
|
||||
heartbeat_document_seconds: int = 120
|
||||
heartbeat_scorm_seconds: int = 120
|
||||
hours_source: str = "api"
|
||||
|
||||
|
||||
class PauseBody(BaseModel):
|
||||
|
||||
@@ -85,6 +85,17 @@ def heartbeat_intervals(db: Session | None = None) -> dict:
|
||||
}
|
||||
|
||||
|
||||
def hours_source_of(row: SystemConfig | None = None) -> str:
|
||||
"""api:接口本月学时;history:学时历史本月分钟合计。"""
|
||||
if row is None:
|
||||
from euniv.db import SessionLocal
|
||||
|
||||
with SessionLocal() as owned:
|
||||
return hours_source_of(load_config(owned))
|
||||
value = str(row.hours_source or "api").strip().lower()
|
||||
return value if value in ("api", "history") else "api"
|
||||
|
||||
|
||||
def settings_view(row: SystemConfig) -> dict:
|
||||
return {
|
||||
"refresh_interval_minutes": int(row.refresh_interval_minutes),
|
||||
@@ -96,6 +107,7 @@ def settings_view(row: SystemConfig) -> dict:
|
||||
"heartbeat_video_seconds": int(row.heartbeat_video_seconds),
|
||||
"heartbeat_document_seconds": int(row.heartbeat_document_seconds),
|
||||
"heartbeat_scorm_seconds": int(row.heartbeat_scorm_seconds),
|
||||
"hours_source": hours_source_of(row),
|
||||
}
|
||||
|
||||
|
||||
@@ -150,6 +162,9 @@ def save_settings(db: Session, payload: dict) -> SystemConfig:
|
||||
raise SettingsError("文档心跳间隔须为 30 到 600 的整数")
|
||||
if hb_scorm is None or not 30 <= hb_scorm <= 600:
|
||||
raise SettingsError("Scorm 心跳间隔须为 30 到 600 的整数")
|
||||
source = str(payload.get("hours_source") or "api").strip().lower()
|
||||
if source not in ("api", "history"):
|
||||
raise SettingsError("学时达标依据须为 api 或 history")
|
||||
|
||||
row = load_config(db)
|
||||
previous_interval = int(row.refresh_interval_minutes)
|
||||
@@ -162,6 +177,7 @@ def save_settings(db: Session, payload: dict) -> SystemConfig:
|
||||
row.heartbeat_video_seconds = hb_video
|
||||
row.heartbeat_document_seconds = hb_doc
|
||||
row.heartbeat_scorm_seconds = hb_scorm
|
||||
row.hours_source = source
|
||||
if password is not None and password != "":
|
||||
row.admin_password_cipher = encrypt_secret(str(password))
|
||||
db.commit()
|
||||
|
||||
Reference in New Issue
Block a user