From 054da4899184dfe5fd2f8e1f6dc5ab694239b3c9 Mon Sep 17 00:00:00 2001 From: HuangHai <10402852@qq.com> Date: Tue, 15 Jul 2025 13:45:03 +0800 Subject: [PATCH] 'commit' --- dsLightRag/Start.py | 86 +++++++++++++++++++++++++ dsLightRag/static/ChangChun.html | 2 +- dsLightRag/static/ChangChunManager.html | 8 +-- 3 files changed, 91 insertions(+), 5 deletions(-) diff --git a/dsLightRag/Start.py b/dsLightRag/Start.py index a6b09126..4c60c69f 100644 --- a/dsLightRag/Start.py +++ b/dsLightRag/Start.py @@ -295,5 +295,91 @@ async def render_html(request: fastapi.Request): } +@app.get("/api/sources") +async def get_sources(page: int = 1, limit: int = 10): + try: + pg_pool = await init_postgres_pool() + async with pg_pool.acquire() as conn: + # 获取总数 + total = await conn.fetchval("SELECT COUNT(*) FROM t_wechat_source") + # 获取分页数据 + offset = (page - 1) * limit + rows = await conn.fetch( + """ + SELECT id, account_id,account_name, created_at + FROM t_wechat_source + ORDER BY created_at DESC + LIMIT $1 OFFSET $2 + """, + limit, offset + ) + + sources = [ + { + "id": row[0], + "name": row[1], + "type": row[2], + "update_time": row[3].strftime("%Y-%m-%d %H:%M:%S") if row[3] else None + } + for row in rows + ] + + return { + "code": 0, + "data": { + "list": sources, + "total": total, + "page": page, + "limit": limit + } + } + except Exception as e: + return {"code": 1, "msg": str(e)} + + +@app.get("/api/articles") +async def get_articles(page: int = 1, limit: int = 10): + try: + pg_pool = await init_postgres_pool() + async with pg_pool.acquire() as conn: + # 获取总数 + total = await conn.fetchval("SELECT COUNT(*) FROM t_wechat_articles") + # 获取分页数据 + offset = (page - 1) * limit + rows = await conn.fetch( + """ + SELECT a.id, a.title, a.source as source as name, + a.publish_time, a.collection_time + FROM t_wechat_articles a + ORDER BY a.collection_time DESC + LIMIT $1 OFFSET $2 + """, + limit, offset + ) + + articles = [ + { + "id": row[0], + "title": row[1], + "source": row[2], + "publish_date": row[3].strftime("%Y-%m-%d") if row[3] else None, + "collect_time": row[4].strftime("%Y-%m-%d %H:%M:%S") if row[4] else None + } + for row in rows + ] + + return { + "code": 0, + "data": { + "list": articles, + "total": total, + "page": page, + "limit": limit + } + } + except Exception as e: + return {"code": 1, "msg": str(e)} + + if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=8000) diff --git a/dsLightRag/static/ChangChun.html b/dsLightRag/static/ChangChun.html index 146411a3..a4105b5f 100644 --- a/dsLightRag/static/ChangChun.html +++ b/dsLightRag/static/ChangChun.html @@ -177,7 +177,7 @@

【长春市教育信息资讯库】

-

资讯库维护

+

资讯库维护

请在下方输入您的问题,答案将在此处显示

diff --git a/dsLightRag/static/ChangChunManager.html b/dsLightRag/static/ChangChunManager.html index ade4b8dd..b29c1cfe 100644 --- a/dsLightRag/static/ChangChunManager.html +++ b/dsLightRag/static/ChangChunManager.html @@ -3,14 +3,14 @@ - 长春市信息资讯库管理系统 + 长春市教育信息资讯库维护
-

长春市信息资讯库管理系统

+

长春市教育信息资讯库维护

@@ -43,8 +43,8 @@ page: true, cols: [[ {field: 'id', title: 'ID', width:80}, - {field: 'name', title: '来源名称'}, - {field: 'type', title: '类型'}, + {field: 'name', title: '简称'}, + {field: 'type', title: '名称'}, {field: 'update_time', title: '更新时间'} ]] });