From 9a6f134f562bd831acecd5ae11a5b0837c5c1f17 Mon Sep 17 00:00:00 2001 From: Nixevol Date: Sun, 15 Nov 2026 00:48:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=87=AD=E6=8D=AE=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E6=97=B6=E8=AE=B0=E5=BD=95=E6=9C=AC=E6=9C=88=E5=AD=A6=E6=97=B6?= =?UTF-8?q?=E5=92=8C=E6=9C=89=E6=95=88=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/admin/users.py | 24 +++++++------------ backend/alembic/versions/0006_month_hours.py | 19 +++++++++++++++ backend/euniv/models.py | 25 ++++++++++++++++++++ web/src/features/admin/UsersView.vue | 8 +++++-- 4 files changed, 58 insertions(+), 18 deletions(-) create mode 100644 backend/alembic/versions/0006_month_hours.py diff --git a/backend/admin/users.py b/backend/admin/users.py index e5ec54d..0bc68f2 100644 --- a/backend/admin/users.py +++ b/backend/admin/users.py @@ -48,25 +48,17 @@ def _iso_time(value: datetime | None) -> str | None: def list_users(db: Session) -> list[dict]: - has_credential = (Account.credential_cipher != "").label("has_credential") - rows = db.execute( - select( - Account.employee_id, - has_credential, - Account.refresh_paused, - Account.last_refresh_at, - Account.credential_valid, - ).order_by(Account.employee_id) - ).all() + accounts = db.scalars(select(Account).order_by(Account.employee_id)).all() return [ { - "employee_id": row.employee_id, - "has_credential": bool(row.has_credential), - "refresh_paused": bool(row.refresh_paused), - "last_refresh_at": _iso_time(row.last_refresh_at), - "credential_valid": _optional_bool(row.credential_valid), + "employee_id": account.employee_id, + "has_credential": bool(account.credential_cipher), + "refresh_paused": bool(account.refresh_paused), + "last_refresh_at": _iso_time(account.last_refresh_at), + "credential_valid": _optional_bool(account.credential_valid), + "month_hours": account.month_hours or "", } - for row in rows + for account in accounts ] diff --git a/backend/alembic/versions/0006_month_hours.py b/backend/alembic/versions/0006_month_hours.py new file mode 100644 index 0000000..a9b403e --- /dev/null +++ b/backend/alembic/versions/0006_month_hours.py @@ -0,0 +1,19 @@ +"""用户表保存刷新时写入的本月学时。""" + +from alembic import op +import sqlalchemy as sa + +revision = "0006_month_hours" +down_revision = "0005_courses" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + with op.batch_alter_table("accounts") as batch: + batch.add_column(sa.Column("month_hours", sa.String(length=32), nullable=False, server_default="")) + + +def downgrade() -> None: + with op.batch_alter_table("accounts") as batch: + batch.drop_column("month_hours") diff --git a/backend/euniv/models.py b/backend/euniv/models.py index 63e1e84..a19cfcb 100644 --- a/backend/euniv/models.py +++ b/backend/euniv/models.py @@ -12,6 +12,30 @@ class Base(DeclarativeBase): pass +class Course(Base): + __tablename__ = "courses" + + path: Mapped[str] = mapped_column(String(160), primary_key=True) + title: Mapped[str] = mapped_column(String(300), nullable=False, default="") + kind: Mapped[str] = mapped_column(String(32), nullable=False, default="") + contributor: Mapped[str] = mapped_column(String(64), nullable=False, default="") + recommend: Mapped[str] = mapped_column(String(16), nullable=False, default="") + learners: Mapped[str] = mapped_column(String(16), nullable=False, default="") + released_on: Mapped[str] = mapped_column(String(16), nullable=False, default="") + updated_on: Mapped[str] = mapped_column(String(16), nullable=False, default="") + comments: Mapped[str] = mapped_column(String(16), nullable=False, default="") + + +class CourseSync(Base): + __tablename__ = "course_sync" + + id: Mapped[int] = mapped_column(primary_key=True) + last_employee_id: Mapped[str] = mapped_column(String(32), nullable=False, default="") + finished_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True) + next_allowed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True) + course_count: Mapped[int] = mapped_column(nullable=False, default=0) + + class Account(Base): __tablename__ = "accounts" @@ -21,3 +45,4 @@ class Account(Base): refresh_paused: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, server_default=sql_false()) last_refresh_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True) credential_valid: Mapped[bool | None] = mapped_column(Boolean, nullable=True) + month_hours: Mapped[str] = mapped_column(String(32), nullable=False, default="", server_default="") diff --git a/web/src/features/admin/UsersView.vue b/web/src/features/admin/UsersView.vue index 7db9ec0..04f11d0 100644 --- a/web/src/features/admin/UsersView.vue +++ b/web/src/features/admin/UsersView.vue @@ -9,6 +9,7 @@ interface UserRow { refresh_paused: boolean; last_refresh_at: string | null; credential_valid: boolean | null; + month_hours: string; } interface SecretField { @@ -66,6 +67,7 @@ function asUser(value: unknown): UserRow | null { refresh_paused: value.refresh_paused === true, last_refresh_at: typeof value.last_refresh_at === "string" && value.last_refresh_at ? value.last_refresh_at : null, credential_valid: readValid(value.credential_valid), + month_hours: textOf(value.month_hours), }; } @@ -86,8 +88,8 @@ function checkLabel(payload: Record) { function validityText(row: UserRow) { const live = liveResults.value[row.employee_id]; - if (live) return live; - if (row.refresh_paused) return "未检查"; + if (live === "检查失败") return live; + if (!row.has_credential) return "未保存凭证"; if (row.credential_valid === true) return "有效"; if (row.credential_valid === false) return "已失效"; return "未检查"; @@ -325,6 +327,7 @@ onMounted(() => { 工号 凭证 凭据是否有效 + 本月学时 上次刷新时间 自动刷新 操作 @@ -335,6 +338,7 @@ onMounted(() => { {{ row.employee_id }} {{ row.has_credential ? "已保存凭证" : "未保存凭证" }} {{ validityText(row) }} + {{ row.month_hours || "—" }} {{ formatRefreshTime(row.last_refresh_at) }} {{ row.refresh_paused ? "已停止" : "开启" }}