bug修改

This commit is contained in:
wcq 2023-04-04 17:08:38 +08:00
parent ca6f90a29b
commit fec659bdf4
5 changed files with 70 additions and 20 deletions

View File

@ -16,6 +16,7 @@ def add_file(db: Session, data: FileSechemas.UserFileCreate):
db.refresh(new_file) db.refresh(new_file)
return new_file return new_file
def file_query(db: Session, params: FileSechemas.UserFileQuery) -> (int, List[UserFile]): def file_query(db: Session, params: FileSechemas.UserFileQuery) -> (int, List[UserFile]):
query = db.query(UserFile) query = db.query(UserFile)
if params.md: if params.md:

View File

@ -1,8 +1,10 @@
import pandas as pd import pandas as pd
from sqlalchemy.orm import Session
from Utils.SqlAlchemyUtils import get_db_i from Utils.SqlAlchemyUtils import get_db_i
from Models.PostModel import Post from Models.PostModel import Post
from Models.DepartmentModel import Department from Models.DepartmentModel import Department
from Models.UserModel import UserInfo,User from Models.UserModel import UserInfo, User
from Models.DailyModel import Daily from Models.DailyModel import Daily
import json import json
@ -81,9 +83,9 @@ def user_table_to_db():
def load_daily(): def load_daily():
db=get_db_i() db = get_db_i()
data=pd.read_excel('动态类数据.xlsx') data = pd.read_excel('动态类数据.xlsx')
length=data.shape[0] length = data.shape[0]
d_name_dic = {item.name: item.id for item in db.query(Department).all()} d_name_dic = {item.name: item.id for item in db.query(Department).all()}
post_dic = {} post_dic = {}
for item in db.query(Post).all(): for item in db.query(Post).all():
@ -92,17 +94,65 @@ def load_daily():
if item.name not in post_dic[item.belong]: if item.name not in post_dic[item.belong]:
post_dic[item.belong][item.name] = item.id post_dic[item.belong][item.name] = item.id
for i in range(length): for i in range(length):
row=data.loc[i].to_dict() row = data.loc[i].to_dict()
报送类型=row['报送类型'] 报送类型 = row['报送类型']
报送人=row['报送人'] 报送人 = row['报送人']
报送时间=row['报送时间'] 报送时间 = row['报送时间']
标题=row['标题'] 标题 = row['标题']
标题="" if pd.isna(标题) else 标题 标题 = "" if pd.isna(标题) else 标题
正文=row['正文'] 正文 = row['正文']
部门=row['部门'] 部门 = row['部门']
职务=row['职务'] 职务 = row['职务']
email=db.query(User).filter_by(name=报送人).first().email email = db.query(User).filter_by(name=报送人).first().email
department_id=d_name_dic[部门] department_id = d_name_dic[部门]
post_id=post_dic[department_id][职务] post_id = post_dic[department_id][职务]
db.add(Daily(type=报送类型,fill_user=email,title=标题,content=正文,post=post_id,department=department_id,daily_time=报送时间)) db.add(Daily(type=报送类型, fill_user=email, title=标题, content=正文, post=post_id, department=department_id,
db.commit() daily_time=报送时间))
db.commit()
def load_user_data(db: Session):
dt = pd.read_excel("远东员工花名册(1).xlsx")
line_count = dt.shape[0]
user_list = []
post_list = []
dp_id_dic = {item.name: item.id for item in db.query(Department).all()}
dt = dt.fillna(value="")
for i in range(line_count):
row = dt.loc[i]
部门1 = row["部门"]
部门2 = row["部门2"]
职务1 = row["职务"]
职务2 = row["职务2"]
user_info = {
"email": row["邮箱"],
"name": row["姓名"],
"manage_departments": row["所看部门"].split(',') if row["所看部门"] else [],
"phone": row["移动电话"],
"department": [item for item in [部门1, 部门2] if item],
"post": [item for item in [[部门1, 职务1], [部门2, 职务2]] if item[0]]
}
post_list.extend(user_info["post"])
user_list.append(user_info)
# post_list.sort(key=lambda x: dp_id_dic[x[0]])
# db.query(Post).delete()
# for post in post_list:
# new_post = Post(name=post[1], belong=dp_id_dic[post[0]])
# db.add(new_post)
# db.commit()
dp_post_dic = {}
for item in db.query(Post).all():
if not dp_post_dic.get(item.belong):
dp_post_dic[item.belong] = {}
dp_post_dic[item.belong][item.name] = item.id
db.query(User).delete()
for user_info in user_list:
new_user = User()
new_user.email = user_info['email']
new_user.name = user_info['name']
new_user.manage_departments = ",".join([str(dp_id_dic[item]) for item in user_info['manage_departments']])
new_user.post = ",".join([str(dp_post_dic[dp_id_dic[item[0]]][item[1]]) for item in user_info['post']])
new_user.department = ",".join([str(dp_id_dic[item]) for item in user_info['department']])
new_user.phone = str(int(user_info['phone'])) if user_info['phone'] else None
db.add(new_user)
db.commit()

View File

@ -29,6 +29,5 @@ class RedisPool:
return conn return conn
redis_pool = RedisPool(host=REDIS_HOST, port=REDIS_PORT) redis_pool = RedisPool(host=REDIS_HOST, port=REDIS_PORT)
redis_pool.connect() redis_pool.connect()

View File

@ -7,7 +7,7 @@ from typing import Literal, List, Any, Optional
Base = declarative_base() Base = declarative_base()
user = "root" user = "root"
password = "123456" password = "12345"
host = "127.0.0.1" host = "127.0.0.1"
db = 'daily' db = 'daily'

Binary file not shown.