招聘公告按原网页顺序展示导出

This commit is contained in:
2026-12-04 15:11:09 +08:00
parent ccb05fd17e
commit 5ad49852b3
4 changed files with 25 additions and 2 deletions
+3
View File
@@ -592,6 +592,9 @@ async def lifespan(_app: FastAPI):
columns = await conn.run_sync(lambda c: {col['name'] for col in inspect(c).get_columns('center_activity_meta')})
if 'material_id' not in columns:
await conn.execute(text('ALTER TABLE center_activity_meta ADD COLUMN material_id VARCHAR(32)'))
recruit_columns = await conn.run_sync(lambda c: {col['name'] for col in inspect(c).get_columns('recruit_announcements')})
if 'source_order' not in recruit_columns:
await conn.execute(text('ALTER TABLE recruit_announcements ADD COLUMN source_order INTEGER NOT NULL DEFAULT 0'))
await _migrate_legacy(conn)
# 一楼历史活动统一作为公开记录,历史参加数据保留存档但不再参与统计。
center_ids = select(center_activity_meta.c.activity_id)
+1
View File
@@ -199,6 +199,7 @@ recruit_announcements = Table('recruit_announcements', metadata,
Column('iswailian', Integer, nullable=False, default=0),
Column('wailian', String(500), nullable=False, default=''),
Column('url', String(500), nullable=False, default=''),
Column('source_order', Integer, nullable=False, default=0),
Column('synced_at', Integer, nullable=False))
Index('ix_recruit_announcements_check_time', recruit_announcements.c.check_time.desc())
+4 -2
View File
@@ -295,6 +295,7 @@ async def sync_all(db, client: httpx.AsyncClient | None = None) -> dict:
if owns_client:
await client.aclose()
now = int(datetime.now(BEIJING).timestamp() * 1000)
source_order = {int(raw["gonggaoId"]): order for order, raw in enumerate(rows) if str(raw.get("gonggaoId") or "").isdigit()}
for raw in rows:
try:
gonggao_id = int(raw["gonggaoId"])
@@ -312,6 +313,7 @@ async def sync_all(db, client: httpx.AsyncClient | None = None) -> dict:
"iswailian": int(raw.get("iswailian") or 0),
"wailian": str(raw.get("wailian") or ""),
"url": str(raw.get("url") or ""),
"source_order": source_order.get(gonggao_id, 0),
"synced_at": now,
}
existing = (await db.execute(select(recruit_announcements.c.gonggao_id).where(recruit_announcements.c.gonggao_id == gonggao_id))).scalar()
@@ -414,7 +416,7 @@ def install(app, get_db, current_user, cache_dir: Path | None = None):
keyword = f"%{q.strip()}%"
statement = statement.where(recruit_announcements.c.title.like(keyword) | recruit_announcements.c.companyname.like(keyword))
total = (await db.execute(select(func.count()).select_from(statement.subquery()))).scalar()
statement = statement.order_by(recruit_announcements.c.check_time.desc(), recruit_announcements.c.gonggao_id.desc()).limit(500)
statement = statement.order_by(recruit_announcements.c.source_order.asc(), recruit_announcements.c.gonggao_id.desc()).limit(500)
rows = [public_row(row) for row in (await db.execute(statement)).mappings()]
return {"items": rows, "total": total}
@@ -448,7 +450,7 @@ def install(app, get_db, current_user, cache_dir: Path | None = None):
elif q.strip():
keyword = f"%{q.strip()}%"
statement = statement.where(recruit_announcements.c.title.like(keyword) | recruit_announcements.c.companyname.like(keyword))
statement = statement.order_by(recruit_announcements.c.check_time.desc(), recruit_announcements.c.gonggao_id.desc())
statement = statement.order_by(recruit_announcements.c.source_order.asc(), recruit_announcements.c.gonggao_id.desc())
rows = [dict(row) for row in (await db.execute(statement)).mappings()]
if not rows:
raise HTTPException(404, "没有匹配的公告")