feat:增加导出到excel功能_api
This commit is contained in:
9
main.py
9
main.py
@@ -3,6 +3,7 @@ import uvicorn
|
||||
from fastapi import FastAPI, File, UploadFile, HTTPException
|
||||
from typing import List
|
||||
from service.file_service import check_and_create_directory, upload_and_save_file
|
||||
from service import excel_service
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@@ -20,10 +21,16 @@ async def create_upload_files(files: List[UploadFile] = File(...)):
|
||||
return {"result": False, "code": 500, "message": "create directory failed"}
|
||||
flag, message = await upload_and_save_file(dir_id, files)
|
||||
if flag:
|
||||
#触发异步任务,解析文件 TODO
|
||||
# 触发异步任务,解析文件 TODO
|
||||
pass
|
||||
return {"result": flag, "message": message}
|
||||
|
||||
|
||||
@app.get("/export_task_data_to_excel")
|
||||
def export_task_data_to_excel(task_id: str):
|
||||
message = excel_service.export_task_data_to_excel(task_id)
|
||||
return {"message": message}
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
uvicorn.run(app, host="127.0.0.1", port=3006)
|
||||
|
||||
@@ -6,7 +6,8 @@ from decouple import config
|
||||
|
||||
BASE_PATH = config('BASE_PATH', default='E://pyptoject//yj_resume//')
|
||||
|
||||
#导出数据到excel
|
||||
|
||||
# 导出数据到excel
|
||||
def export_to_excel(task_id):
|
||||
# 获取所有成功的信息
|
||||
list_data = SqliteSqlalchemy().session.query(DBRESUME).filter_by(task_id=task_id, status=1).all()
|
||||
@@ -17,4 +18,13 @@ def export_to_excel(task_id):
|
||||
# 导出到excel
|
||||
pathxx = pathlib.Path(BASE_PATH).joinpath(task_id)
|
||||
pathxx = pathxx.joinpath(f"{task_id}.xlsx")
|
||||
data_frame.to_excel(pathxx, encoding='utf-8', index=False)
|
||||
data_frame.to_excel(pathxx, index=False)
|
||||
|
||||
|
||||
def export_task_data_to_excel(task_id):
|
||||
session = SqliteSqlalchemy().session
|
||||
task = session.query(DBTASK).filter_by(id=task_id).first()
|
||||
if not task or task.status == 0 or task.status == 2:
|
||||
return "任务未完成或者失败"
|
||||
export_to_excel(task_id)
|
||||
return "导出成功"
|
||||
|
||||
Reference in New Issue
Block a user