feat: 凭据刷新时记录本月学时和有效状态

This commit is contained in:
2026-11-15 00:48:18 +08:00
parent 98c11f42d8
commit 9a6f134f56
4 changed files with 58 additions and 18 deletions
+8 -16
View File
@@ -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
]
@@ -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")
+25
View File
@@ -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="")