敏感词 部门排序
This commit is contained in:
parent
614b3c8e4a
commit
332cd569b9
File diff suppressed because one or more lines are too long
|
@ -50,7 +50,7 @@ def daily_query(db: Session, params: DailyQuery, token_data: TokenData) -> [int]
|
|||
# 筛选能有权限看的日报
|
||||
query = query.filter(
|
||||
or_(*[func.find_in_set(str(item), Daily.required_auth) for item in has_auth],
|
||||
Daily.required_auth == None, Daily.required_auth == '',
|
||||
Daily.required_auth == None, Daily.required_auth == '',Daily.required_auth == '-1',
|
||||
Daily.fill_user == token_data.email
|
||||
))
|
||||
if params.type == DailyTypeEnum.部门子公司日报:
|
||||
|
|
|
@ -109,7 +109,7 @@ def get_user_by_department_type(db: Session, department_type: str):
|
|||
|
||||
|
||||
def get_department_list(db: Session):
|
||||
return db.query(Department).all()
|
||||
return db.query(Department).order_by(Department.index).all()
|
||||
|
||||
|
||||
def get_department_config(db: Session):
|
||||
|
|
|
@ -12,6 +12,7 @@ class Department(Base):
|
|||
auth_data = Column(Text, comment="部门权限数据")
|
||||
type = Column(Enum(DepartmentTypeEnum, values_callable=lambda x: [e.value for e in x]), nullable=False)
|
||||
sub_type = Column(String(255), comment="二级分类")
|
||||
index = Column(Integer, comment="索引")
|
||||
|
||||
def to_dict(self):
|
||||
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
|
||||
|
|
|
@ -125,17 +125,17 @@ class DailyNotice:
|
|||
*[func.find_in_set(str(d_id), User.department) for d_id in
|
||||
can_watch_departments])):
|
||||
emails.append(user.email)
|
||||
数字化部emails = [item.email for item in db.query(User).filter(func.find_in_set('17', User.department))]
|
||||
# 数字化部emails = [item.email for item in db.query(User).filter(func.find_in_set('17', User.department))]
|
||||
|
||||
# task_args = [["", email, daily_pdf_upload_notice] for email in emails]
|
||||
|
||||
# 测试
|
||||
task_args = [["每日运行日报已上传", email, daily_pdf_upload_notice] for email in test_email]
|
||||
task_args = [["每日运行日报已上传", email, daily_pdf_upload_notice] for email in emails]
|
||||
print(task_args)
|
||||
self.email_send_thread(task_args)
|
||||
|
||||
def start_timer_to_notice_daily_fill(self):
|
||||
|
||||
print('邮件发送服务已启动')
|
||||
sended = False
|
||||
while True:
|
||||
time.sleep(15)
|
||||
|
|
|
@ -55,9 +55,34 @@ def daily_get(req: DailySchemas.DailyGetReq, db: Session = Depends(get_db),
|
|||
return DailySchemas.DailyGetRes(**item.to_dict(), comments=comments)
|
||||
|
||||
|
||||
json_filepath = os.path.join(os.getcwd(), 'Config', 'sensitive_word.json')
|
||||
# 将列表保存为 json 文件
|
||||
with open(json_filepath, 'r', encoding='utf-8') as json_file:
|
||||
words = json.load(json_file)
|
||||
|
||||
|
||||
class SensitiveWordChecker:
|
||||
def __init__(self, sensitive_words):
|
||||
self.automaton = Automaton()
|
||||
for idx, word in enumerate(sensitive_words):
|
||||
self.automaton.add_word(word, (idx, word))
|
||||
self.automaton.make_automaton()
|
||||
|
||||
def check(self, text):
|
||||
return {item for _, item in self.automaton.iter(text)}
|
||||
|
||||
|
||||
checker = SensitiveWordChecker(words)
|
||||
|
||||
|
||||
@router.post("/daily_add", response_model=DailySchemas.DailyAddRes, summary="添加日报")
|
||||
def daily_add(req: DailySchemas.DailyAddReq, db: Session = Depends(get_db),
|
||||
token_data: TokenData = Depends(token_data_depend)):
|
||||
if req.content:
|
||||
bad_words = [item[1] for item in checker.check(req.content)]
|
||||
if bad_words:
|
||||
raise HTTPException(detail=f"内容包含敏感词:{','.join(bad_words)}", status_code=305)
|
||||
|
||||
if req.fill_user != token_data.email:
|
||||
raise HTTPException(detail="填报人与email不符", status_code=305)
|
||||
# 本部门填报权限
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
from Mods.Notice.Utils import daily_notice
|
||||
daily_notice.start_timer_to_notice_daily_fill()
|
2
main.py
2
main.py
|
@ -41,6 +41,6 @@ app.include_router(ModsRouter.router)
|
|||
# 中间件
|
||||
# app.exception_handler(Exception)(exception_handler)
|
||||
# app.exception_handler(RequestValidationError)(validation_exception_handler)
|
||||
daily_notice.init()
|
||||
# daily_notice.init()
|
||||
|
||||
uvicorn.run(app=app, host="0.0.0.0", port=8006, log_config=uvicorn_log_config)
|
||||
|
|
Loading…
Reference in New Issue