feat: 凭据刷新时记录本月学时和有效状态
This commit is contained in:
+8
-16
@@ -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")
|
||||
@@ -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="")
|
||||
|
||||
@@ -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<string, unknown>) {
|
||||
|
||||
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(() => {
|
||||
<th>工号</th>
|
||||
<th>凭证</th>
|
||||
<th>凭据是否有效</th>
|
||||
<th>本月学时</th>
|
||||
<th>上次刷新时间</th>
|
||||
<th>自动刷新</th>
|
||||
<th>操作</th>
|
||||
@@ -335,6 +338,7 @@ onMounted(() => {
|
||||
<td class="employee">{{ row.employee_id }}</td>
|
||||
<td>{{ row.has_credential ? "已保存凭证" : "未保存凭证" }}</td>
|
||||
<td :class="validityClass(validityText(row))">{{ validityText(row) }}</td>
|
||||
<td class="when">{{ row.month_hours || "—" }}</td>
|
||||
<td class="when">{{ formatRefreshTime(row.last_refresh_at) }}</td>
|
||||
<td>{{ row.refresh_paused ? "已停止" : "开启" }}</td>
|
||||
<td>
|
||||
|
||||
Reference in New Issue
Block a user