|
@@ -10,7 +10,7 @@ from sqlalchemy import text, exists, and_, or_, not_
|
|
from sqlalchemy.orm import Session
|
|
from sqlalchemy.orm import Session
|
|
from models import *
|
|
from models import *
|
|
import json
|
|
import json
|
|
-import random
|
|
|
|
|
|
+import os
|
|
from sqlalchemy import create_engine, select
|
|
from sqlalchemy import create_engine, select
|
|
from typing import Optional
|
|
from typing import Optional
|
|
from utils.StripTagsHTMLParser import *
|
|
from utils.StripTagsHTMLParser import *
|
|
@@ -27,6 +27,22 @@ from config import settings
|
|
|
|
|
|
router = APIRouter()
|
|
router = APIRouter()
|
|
|
|
|
|
|
|
+EXAMINE_TYPE_DICT = {
|
|
|
|
+ 0: "草稿",
|
|
|
|
+ 10: "提交",
|
|
|
|
+ 20: "领导审批",
|
|
|
|
+ 30: "重新提交"
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+EXAMINE_SUB_TYPE_DICT = {
|
|
|
|
+ 0: "草稿",
|
|
|
|
+ 10: "提交",
|
|
|
|
+ 20: "待审批",
|
|
|
|
+ 21: "审批通过",
|
|
|
|
+ 22: "审批不通过",
|
|
|
|
+ 30: "重新提交"
|
|
|
|
+}
|
|
|
|
+
|
|
# 信息发布创建
|
|
# 信息发布创建
|
|
@router.post('/create')
|
|
@router.post('/create')
|
|
async def create_emergency_plan(
|
|
async def create_emergency_plan(
|
|
@@ -39,6 +55,8 @@ async def create_emergency_plan(
|
|
dept_name = ''
|
|
dept_name = ''
|
|
|
|
|
|
user_row = db.query(SysUser).filter(SysUser.user_id == user_id).first()
|
|
user_row = db.query(SysUser).filter(SysUser.user_id == user_id).first()
|
|
|
|
+ user_name = user_row.user_name
|
|
|
|
+ nick_name = user_row.nick_name
|
|
dept_id = user_row.dept_id
|
|
dept_id = user_row.dept_id
|
|
|
|
|
|
dept_row = db.query(SysDept).filter(SysDept.dept_id == dept_id).first()
|
|
dept_row = db.query(SysDept).filter(SysDept.dept_id == dept_id).first()
|
|
@@ -72,36 +90,93 @@ async def create_emergency_plan(
|
|
|
|
|
|
# 发送人员
|
|
# 发送人员
|
|
for u in body['users']:
|
|
for u in body['users']:
|
|
- user_id = u['user_id']
|
|
|
|
|
|
+ send_user_id = u['user_id']
|
|
|
|
+ send_nick_name = u['nick_name']
|
|
|
|
+ send_user_name = ''
|
|
|
|
+ send_dept_name = ''
|
|
|
|
|
|
user_row = db.query(SysUser).filter(SysUser.user_id == user_id).first()
|
|
user_row = db.query(SysUser).filter(SysUser.user_id == user_id).first()
|
|
- dept_id = user_row.dept_id
|
|
|
|
-
|
|
|
|
- dept_row = db.query(SysDept).filter(SysDept.dept_id == dept_id).first()
|
|
|
|
- dept_name = dept_row.dept_name
|
|
|
|
|
|
+ if user_row is not None:
|
|
|
|
+ send_user_name = user_row.user_name
|
|
|
|
+ send_dept_row = db.query(SysDept).filter(SysDept.dept_id == user_row.dept_id).first()
|
|
|
|
+ send_dept_name = send_dept_row.dept_name
|
|
|
|
|
|
new_resp = InfoPublishResponses(
|
|
new_resp = InfoPublishResponses(
|
|
publish_id = new_publish_id,
|
|
publish_id = new_publish_id,
|
|
- user_id = user_id,
|
|
|
|
- user_name = user_row.user_name,
|
|
|
|
- nick_name = user_row.nick_name,
|
|
|
|
- dept_name = dept_row.dept_name,
|
|
|
|
|
|
+ user_id = send_user_id,
|
|
|
|
+ user_name = send_user_name,
|
|
|
|
+ nick_name = send_nick_name,
|
|
|
|
+ dept_name = send_dept_name,
|
|
sent_status = 0,
|
|
sent_status = 0,
|
|
- response_type = body['response_type']
|
|
|
|
|
|
+ response_type = body['response_type'],
|
|
|
|
+ publish_channel = body['publish_channel']
|
|
)
|
|
)
|
|
db.add(new_resp)
|
|
db.add(new_resp)
|
|
db.commit()
|
|
db.commit()
|
|
|
|
|
|
# 附件
|
|
# 附件
|
|
if 'attachs' in body:
|
|
if 'attachs' in body:
|
|
- for n in body['attachs']:
|
|
|
|
- pass
|
|
|
|
|
|
+ infopublish_files = [
|
|
|
|
+ InfoPublishFile(
|
|
|
|
+ file_name=fileName["name"],
|
|
|
|
+ storage_file_name=fileName["url"],
|
|
|
|
+ file_path=f'/data/upload/mergefile/uploads/{fileName["url"]}',
|
|
|
|
+ file_size=os.path.getsize(f'/data/upload/mergefile/uploads/{fileName["url"]}'),
|
|
|
|
+ foreign_key=str(new_publish_id),
|
|
|
|
+ from_scenario="infopublish_attach_file",
|
|
|
|
+ update_time=datetime.now(),
|
|
|
|
+ create_time=datetime.now(),
|
|
|
|
+ create_by=user_id,
|
|
|
|
+ create_dept=dept_id,
|
|
|
|
+ del_flag='0',
|
|
|
|
+ status=0,
|
|
|
|
+ )
|
|
|
|
+ for fileName in body['attachs']
|
|
|
|
+ ]
|
|
|
|
+ db.add_all(infopublish_files)
|
|
|
|
+ db.commit()
|
|
|
|
|
|
# 审批附件
|
|
# 审批附件
|
|
if 'examine_attachs' in body:
|
|
if 'examine_attachs' in body:
|
|
- for n in body['examine_attachs']:
|
|
|
|
- pass
|
|
|
|
-
|
|
|
|
|
|
+ infopublish_files = [
|
|
|
|
+ InfoPublishFile(
|
|
|
|
+ file_name=fileName["name"],
|
|
|
|
+ storage_file_name=fileName["url"],
|
|
|
|
+ file_path=f'/data/upload/mergefile/uploads/{fileName["url"]}',
|
|
|
|
+ file_size=os.path.getsize(f'/data/upload/mergefile/uploads/{fileName["url"]}'),
|
|
|
|
+ foreign_key=str(new_publish_id),
|
|
|
|
+ from_scenario="infopublish_examine_attach_file",
|
|
|
|
+ update_time=datetime.now(),
|
|
|
|
+ create_time=datetime.now(),
|
|
|
|
+ create_by=user_id,
|
|
|
|
+ create_dept=dept_id,
|
|
|
|
+ del_flag='0',
|
|
|
|
+ status=0,
|
|
|
|
+ )
|
|
|
|
+ for fileName in body['examine_attachs']
|
|
|
|
+ ]
|
|
|
|
+ db.add_all(infopublish_files)
|
|
|
|
+ db.commit()
|
|
|
|
+
|
|
|
|
+ # 审批记录
|
|
|
|
+ infopublish_examine = InfoPublishExamine(
|
|
|
|
+ publish_id = new_publish_id,
|
|
|
|
+ examine_type = 10, # 提交
|
|
|
|
+ examine_sub_type = 10, # 提交
|
|
|
|
+ examine_time = datetime.now(),
|
|
|
|
+ content = '',
|
|
|
|
+ user_id = user_id,
|
|
|
|
+ user_name = user_name,
|
|
|
|
+ nick_name = nick_name,
|
|
|
|
+ del_flag = '0'
|
|
|
|
+ )
|
|
|
|
+ db.add(infopublish_examine)
|
|
|
|
+ db.commit()
|
|
|
|
+
|
|
|
|
+ # 改提交、待审批状态
|
|
|
|
+ db.query(InfoPublishBase).filter(InfoPublishBase.id == new_publish_id).update({"publish_status": 1, "examine_status": 1})
|
|
|
|
+ db.commit()
|
|
|
|
+
|
|
return {
|
|
return {
|
|
"code": 200,
|
|
"code": 200,
|
|
"msg": "信息创建成功",
|
|
"msg": "信息创建成功",
|
|
@@ -215,12 +290,36 @@ async def get_edit_info(
|
|
data['add_time'] = get_datetime_str(data['add_time'])
|
|
data['add_time'] = get_datetime_str(data['add_time'])
|
|
data['publish_time'] = get_datetime_str(data['publish_time'])
|
|
data['publish_time'] = get_datetime_str(data['publish_time'])
|
|
|
|
|
|
|
|
+ # 反馈 && 未反馈
|
|
|
|
+ data['feedback_count'] = db.query(InfoPublishResponses).filter(and_(InfoPublishResponses.publish_id == info_id, InfoPublishResponses.sent_status > 0, InfoPublishResponses.response_type > 0)).count()
|
|
|
|
+ data['unresponsive_count'] = db.query(InfoPublishResponses).filter(and_(InfoPublishResponses.publish_id == info_id, InfoPublishResponses.sent_status > 0, InfoPublishResponses.response_type > 0)).count()
|
|
|
|
+
|
|
|
|
+ # 附件
|
|
|
|
+ rows = db.query(InfoPublishFile).filter(and_(InfoPublishFile.from_scenario=="infopublish_attach_file", InfoPublishFile.foreign_key == info_id, InfoPublishFile.del_flag == '0')).all()
|
|
|
|
+ data['attachs'] = [
|
|
|
|
+ {
|
|
|
|
+ "name": row.file_name,
|
|
|
|
+ "url": row.storage_file_name
|
|
|
|
+ }
|
|
|
|
+ for row in rows
|
|
|
|
+ ]
|
|
|
|
+
|
|
|
|
+ # 审批附件
|
|
|
|
+ rows = db.query(InfoPublishFile).filter(and_(InfoPublishFile.from_scenario=="infopublish_examine_attach_file", InfoPublishFile.foreign_key == info_id, InfoPublishFile.del_flag == '0')).all()
|
|
|
|
+ data['examine_attachs'] = [
|
|
|
|
+ {
|
|
|
|
+ "name": row.file_name,
|
|
|
|
+ "url": row.storage_file_name
|
|
|
|
+ }
|
|
|
|
+ for row in rows
|
|
|
|
+ ]
|
|
|
|
+
|
|
data["examines"] = []
|
|
data["examines"] = []
|
|
- rows = db.query(InfoPublishBase).filter(InfoPublishExamine.publish_id == info_id).filter(InfoPublishExamine.del_flag == '0').all()
|
|
|
|
|
|
+ rows = db.query(InfoPublishExamine).filter(InfoPublishExamine.publish_id == info_id).filter(InfoPublishExamine.del_flag == '0').all()
|
|
for row in rows:
|
|
for row in rows:
|
|
data["examines"].append({
|
|
data["examines"].append({
|
|
- "examine_type": row.examine_type,
|
|
|
|
- "examine_sub_type": row.examine_sub_type,
|
|
|
|
|
|
+ "examine_type": EXAMINE_TYPE_DICT[row.examine_type],
|
|
|
|
+ "examine_sub_type": EXAMINE_SUB_TYPE_DICT[row.examine_sub_type],
|
|
"content": row.content,
|
|
"content": row.content,
|
|
"examine_time": get_datetime_str(row.examine_time),
|
|
"examine_time": get_datetime_str(row.examine_time),
|
|
"user_id": row.user_id,
|
|
"user_id": row.user_id,
|
|
@@ -293,8 +392,8 @@ async def post_examine_info(
|
|
}
|
|
}
|
|
|
|
|
|
# 信息发布查看发送列表
|
|
# 信息发布查看发送列表
|
|
-@router.get("send_list")
|
|
|
|
-async def get_send_list(
|
|
|
|
|
|
+@router.get("/sent_list")
|
|
|
|
+async def get_sent_list(
|
|
info_id: str = Query('', description='信息ID'),
|
|
info_id: str = Query('', description='信息ID'),
|
|
keywords: str = Query('', description='关键字'),
|
|
keywords: str = Query('', description='关键字'),
|
|
sort_by: str = Query('', description='排序字段'),
|
|
sort_by: str = Query('', description='排序字段'),
|
|
@@ -305,8 +404,7 @@ async def get_send_list(
|
|
):
|
|
):
|
|
try:
|
|
try:
|
|
# 应用查询条件
|
|
# 应用查询条件
|
|
- where = ()
|
|
|
|
- where = and_(where, InfoPublishResponses.publish_id == info_id)
|
|
|
|
|
|
+ where = and_(InfoPublishResponses.publish_id == info_id)
|
|
|
|
|
|
# 计算总条目数
|
|
# 计算总条目数
|
|
q = db.query(func.count(InfoPublishResponses.id))
|
|
q = db.query(func.count(InfoPublishResponses.id))
|
|
@@ -318,18 +416,21 @@ async def get_send_list(
|
|
q = q.filter(where)
|
|
q = q.filter(where)
|
|
rows = q.order_by(InfoPublishResponses.id.desc()).offset((page - 1) * page_size).limit(page_size).all()
|
|
rows = q.order_by(InfoPublishResponses.id.desc()).offset((page - 1) * page_size).limit(page_size).all()
|
|
|
|
|
|
- data = []
|
|
|
|
- for row in rows:
|
|
|
|
- data.append({
|
|
|
|
|
|
+ data = [
|
|
|
|
+ {
|
|
"user_id": row.user_id,
|
|
"user_id": row.user_id,
|
|
"user_name": row.user_name,
|
|
"user_name": row.user_name,
|
|
"nick_name": row.nick_name,
|
|
"nick_name": row.nick_name,
|
|
"dept_name": row.dept_name,
|
|
"dept_name": row.dept_name,
|
|
"sent_status": row.sent_status,
|
|
"sent_status": row.sent_status,
|
|
"sent_time": get_datetime_str(row.sent_time),
|
|
"sent_time": get_datetime_str(row.sent_time),
|
|
- "response_type": row.response_type
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
|
|
+ "response_type": row.response_type,
|
|
|
|
+ "publish_channel": row.publish_channel,
|
|
|
|
+ "yzy_account": row.yzy_account
|
|
|
|
+ }
|
|
|
|
+ for row in rows
|
|
|
|
+ ]
|
|
|
|
+
|
|
# 返回结果
|
|
# 返回结果
|
|
return {
|
|
return {
|
|
"code": 200,
|
|
"code": 200,
|
|
@@ -338,6 +439,33 @@ async def get_send_list(
|
|
"total": total
|
|
"total": total
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ except Exception as e:
|
|
|
|
+ # 处理异常
|
|
|
|
+ traceback.print_exc()
|
|
|
|
+ raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
+
|
|
|
|
+# 列出可用模板
|
|
|
|
+@router.post("/template_list")
|
|
|
|
+def template_list(db: Session = Depends(get_db)):
|
|
|
|
+ try:
|
|
|
|
+ rows = db.query(InfoPublishTemplate).filter(InfoPublishTemplate.del_flag == '0').all()
|
|
|
|
+
|
|
|
|
+ data = [
|
|
|
|
+ {
|
|
|
|
+ "id": row.id,
|
|
|
|
+ "name": row.name,
|
|
|
|
+ "content": row.content
|
|
|
|
+ }
|
|
|
|
+ for row in rows
|
|
|
|
+ ]
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ "code": 200,
|
|
|
|
+ "msg": "查询成功",
|
|
|
|
+ "data": data,
|
|
|
|
+ "total": len(data)
|
|
|
|
+ }
|
|
|
|
+
|
|
except Exception as e:
|
|
except Exception as e:
|
|
# 处理异常
|
|
# 处理异常
|
|
traceback.print_exc()
|
|
traceback.print_exc()
|