招聘公告按原网页顺序展示导出
This commit is contained in:
@@ -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')})
|
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:
|
if 'material_id' not in columns:
|
||||||
await conn.execute(text('ALTER TABLE center_activity_meta ADD COLUMN material_id VARCHAR(32)'))
|
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)
|
await _migrate_legacy(conn)
|
||||||
# 一楼历史活动统一作为公开记录,历史参加数据保留存档但不再参与统计。
|
# 一楼历史活动统一作为公开记录,历史参加数据保留存档但不再参与统计。
|
||||||
center_ids = select(center_activity_meta.c.activity_id)
|
center_ids = select(center_activity_meta.c.activity_id)
|
||||||
|
|||||||
@@ -199,6 +199,7 @@ recruit_announcements = Table('recruit_announcements', metadata,
|
|||||||
Column('iswailian', Integer, nullable=False, default=0),
|
Column('iswailian', Integer, nullable=False, default=0),
|
||||||
Column('wailian', String(500), nullable=False, default=''),
|
Column('wailian', String(500), nullable=False, default=''),
|
||||||
Column('url', 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))
|
Column('synced_at', Integer, nullable=False))
|
||||||
Index('ix_recruit_announcements_check_time', recruit_announcements.c.check_time.desc())
|
Index('ix_recruit_announcements_check_time', recruit_announcements.c.check_time.desc())
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -295,6 +295,7 @@ async def sync_all(db, client: httpx.AsyncClient | None = None) -> dict:
|
|||||||
if owns_client:
|
if owns_client:
|
||||||
await client.aclose()
|
await client.aclose()
|
||||||
now = int(datetime.now(BEIJING).timestamp() * 1000)
|
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:
|
for raw in rows:
|
||||||
try:
|
try:
|
||||||
gonggao_id = int(raw["gonggaoId"])
|
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),
|
"iswailian": int(raw.get("iswailian") or 0),
|
||||||
"wailian": str(raw.get("wailian") or ""),
|
"wailian": str(raw.get("wailian") or ""),
|
||||||
"url": str(raw.get("url") or ""),
|
"url": str(raw.get("url") or ""),
|
||||||
|
"source_order": source_order.get(gonggao_id, 0),
|
||||||
"synced_at": now,
|
"synced_at": now,
|
||||||
}
|
}
|
||||||
existing = (await db.execute(select(recruit_announcements.c.gonggao_id).where(recruit_announcements.c.gonggao_id == gonggao_id))).scalar()
|
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()}%"
|
keyword = f"%{q.strip()}%"
|
||||||
statement = statement.where(recruit_announcements.c.title.like(keyword) | recruit_announcements.c.companyname.like(keyword))
|
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()
|
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()]
|
rows = [public_row(row) for row in (await db.execute(statement)).mappings()]
|
||||||
return {"items": rows, "total": total}
|
return {"items": rows, "total": total}
|
||||||
|
|
||||||
@@ -448,7 +450,7 @@ def install(app, get_db, current_user, cache_dir: Path | None = None):
|
|||||||
elif q.strip():
|
elif q.strip():
|
||||||
keyword = f"%{q.strip()}%"
|
keyword = f"%{q.strip()}%"
|
||||||
statement = statement.where(recruit_announcements.c.title.like(keyword) | recruit_announcements.c.companyname.like(keyword))
|
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()]
|
rows = [dict(row) for row in (await db.execute(statement)).mappings()]
|
||||||
if not rows:
|
if not rows:
|
||||||
raise HTTPException(404, "没有匹配的公告")
|
raise HTTPException(404, "没有匹配的公告")
|
||||||
|
|||||||
@@ -76,3 +76,20 @@ class RecruitTests(ApiTestCase):
|
|||||||
fetch_detail.assert_awaited_once()
|
fetch_detail.assert_awaited_once()
|
||||||
detail = (await self.client.get('/api/recruit/announcements/2', headers=auth(owner['token']))).json()
|
detail = (await self.client.get('/api/recruit/announcements/2', headers=auth(owner['token']))).json()
|
||||||
self.assertIn('外贸业务员', detail['content_html'])
|
self.assertIn('外贸业务员', detail['content_html'])
|
||||||
|
|
||||||
|
async def test_list_and_export_follow_source_order(self):
|
||||||
|
owner = await register(self.client, 'recruit-order')
|
||||||
|
rows = [
|
||||||
|
dict(RAW, gonggaoId=21, checkTime='2020-01-01 00:00:00'),
|
||||||
|
dict(RAW, gonggaoId=22, checkTime='2020-01-02 00:00:00'),
|
||||||
|
dict(RAW, gonggaoId=23, checkTime='2020-01-03 00:00:00'),
|
||||||
|
]
|
||||||
|
fetch = AsyncMock(return_value={"code": 0, "rows": rows, "extra": {"pages": 1}})
|
||||||
|
with patch.object(recruit, 'fetch_page', new=fetch):
|
||||||
|
await self.client.post('/api/recruit/sync', headers=auth(owner['token']))
|
||||||
|
data = (await self.client.get('/api/recruit/announcements', headers=auth(owner['token']))).json()
|
||||||
|
self.assertEqual([item['gonggao_id'] for item in data['items']], [21, 22, 23])
|
||||||
|
response = await self.client.get('/api/recruit/export', params={'ids': '23,21,22', 'format': 'markdown'}, headers=auth(owner['token']))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertEqual(response.headers['X-Recruit-Export-Count'], '3')
|
||||||
|
self.assertLess(response.text.find('测试公告'), response.text.find('原文链接'))
|
||||||
|
|||||||
Reference in New Issue
Block a user