feat:增加导出到excel功能
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
from sqlalchemy import Column, DateTime, Integer, BigInteger, String, create_engine, Boolean, Text
|
||||
from sqlalchemy.orm import declarative_base, sessionmaker
|
||||
|
||||
# 申明基类对象
|
||||
Base = declarative_base()
|
||||
from decouple import config
|
||||
|
||||
DB_PATH = config('DB_PATH', default='E://pyptoject//yj_resume//main.sqlite3')
|
||||
|
||||
|
||||
@@ -42,3 +40,7 @@ class SqliteSqlalchemy(object):
|
||||
Base.metadata.create_all(engine, checkfirst=True)
|
||||
# 创建sqlite的session连接对象
|
||||
self.session = sessionmaker(bind=engine)()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,4 +4,6 @@ uvicorn
|
||||
docxtpl
|
||||
SQLAlchemy
|
||||
python-decouple
|
||||
python-multipart
|
||||
python-multipart
|
||||
pandas
|
||||
openpyxl
|
||||
|
||||
20
service/excel_service.py
Normal file
20
service/excel_service.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from db.sql_db import DBTASK, DBRESUME, SqliteSqlalchemy
|
||||
import json
|
||||
import pandas as pd
|
||||
import pathlib
|
||||
from decouple import config
|
||||
|
||||
BASE_PATH = config('BASE_PATH', default='E://pyptoject//yj_resume//')
|
||||
|
||||
#导出数据到excel
|
||||
def export_to_excel(task_id):
|
||||
# 获取所有成功的信息
|
||||
list_data = SqliteSqlalchemy().session.query(DBRESUME).filter_by(task_id=task_id, status=1).all()
|
||||
pd_data = []
|
||||
for data in list_data:
|
||||
pd_data.append(json.loads(data.data_info))
|
||||
data_frame = pd.DataFrame(pd_data)
|
||||
# 导出到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)
|
||||
@@ -56,3 +56,4 @@ async def upload_and_save_file(dir_id, files: List[UploadFile]) -> (bool, str):
|
||||
finally:
|
||||
session.close()
|
||||
return True, "success"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user