招聘公告按原网页顺序展示导出
This commit is contained in:
+4
-2
@@ -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, "没有匹配的公告")
|
||||
|
||||
Reference in New Issue
Block a user