From 6fc1c0449cc95ff3c316f025b0d38a6776775ca9 Mon Sep 17 00:00:00 2001 From: HuangHai <10402852@qq.com> Date: Mon, 17 Mar 2025 08:16:27 +0800 Subject: [PATCH] 'commit' --- AI/Text2Sql/Model/biModel.py | 23 ++++++++++++++++++++--- AI/Text2Sql/app.py | 20 ++++++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/AI/Text2Sql/Model/biModel.py b/AI/Text2Sql/Model/biModel.py index 2b326ff8..6c514cc4 100644 --- a/AI/Text2Sql/Model/biModel.py +++ b/AI/Text2Sql/Model/biModel.py @@ -80,7 +80,7 @@ def get_question_by_id(db, question_id: str): # 保存系统推荐 -def model_set_system_recommend(db, question_id: str, flag: str): +def set_system_recommend_questions(db, question_id: str, flag: str): sql = f""" UPDATE t_bi_question SET is_system =%s WHERE id = %s @@ -94,7 +94,7 @@ def model_set_system_recommend(db, question_id: str, flag: str): return False # 设置用户收藏 -def model_set_user_collect(db, question_id: str, flag: str): +def set_user_collect_questions(db, question_id: str, flag: str): sql = f""" UPDATE t_bi_question SET is_collect =%s WHERE id = %s @@ -105,4 +105,21 @@ def model_set_user_collect(db, question_id: str, flag: str): return True except Exception as e: print(f"更新失败: {e}") - return False \ No newline at end of file + return False + +# 查询有哪些系统推荐问题 +def get_system_recommend_questions(db): + sql = """ + SELECT * FROM t_bi_question WHERE is_system = 1 + """ + _data = db.execute_query(sql) + return _data + +# 查询有哪些用户收藏问题 +def get_user_collect_questions(db): + # 从t_bi_question表中获取所有is_collect=1的数据 + sql=""" + SELECT * FROM t_bi_question WHERE is_collect = 1 + """ + _data = db.execute_query(sql) + return _data \ No newline at end of file diff --git a/AI/Text2Sql/app.py b/AI/Text2Sql/app.py index 81dc3718..07066c4d 100644 --- a/AI/Text2Sql/app.py +++ b/AI/Text2Sql/app.py @@ -188,17 +188,33 @@ async def get_docx_file( # 设置问题为系统推荐问题 ,0:取消,1:设置 @app.post("/questions/set_system_recommend") def set_system_recommend(question_id: str = Form(...), flag: str = Form(...), db: PostgreSQLUtil = Depends(get_db)): - model_set_system_recommend(db, question_id, flag) + set_system_recommend_questions(db, question_id, flag) # 提示保存成功 return {"success": True, "message": "保存成功"} # 设置问题为用户收藏问题 ,0:取消,1:设置 @app.post("/questions/set_user_collect") def set_user_collect(question_id: str = Form(...), flag: str = Form(...), db: PostgreSQLUtil = Depends(get_db)): - model_set_user_collect(db, question_id, flag) + set_user_collect_questions(db, question_id, flag) # 提示保存成功 return {"success": True, "message": "保存成功"} +# 查询有哪些系统推荐问题 +@app.get("/questions/get_system_recommend") +def get_system_recommend(db: PostgreSQLUtil = Depends(get_db)): + # 查询所有系统推荐问题 + system_recommend_questions = get_system_recommend_questions(db) + # 返回查询结果 + return {"success": True, "data": system_recommend_questions} + +# 查询有哪些用户收藏问题 +@app.get("/questions/get_user_collect") +def get_user_collect(db: PostgreSQLUtil = Depends(get_db)): + # 查询所有用户收藏问题 + user_collect_questions = get_user_collect_questions(db) + # 返回查询结果 + return {"success": True, "data": user_collect_questions} + # 确保直接运行脚本时启动 FastAPI 应用 if __name__ == "__main__":