|
@@ -31,9 +31,8 @@ router = APIRouter()
|
|
|
|
|
|
|
|
|
|
|
|
-@router.post('/{zrlx}/create')
|
|
|
+@router.post('/create')
|
|
|
async def create_contact(
|
|
|
-zrlx:str,
|
|
|
request: Request,
|
|
|
auth_user: AuthUser = Depends(find_auth_user),
|
|
|
db: Session = Depends(get_db),
|
|
@@ -41,15 +40,18 @@ zrlx:str,
|
|
|
user_id=Depends(valid_access_token)
|
|
|
):
|
|
|
try:
|
|
|
- lx = '三防'
|
|
|
- if zrlx=='sf':
|
|
|
- lx = '三防'
|
|
|
- if zrlx=='sf1':
|
|
|
- lx = '森防'
|
|
|
- if zrlx=='wh':
|
|
|
- lx = '危化'
|
|
|
- if zrlx=='sf':
|
|
|
- return JSONResponse(status_code=404,content={"code":404,"msg":"责任人类型未查询到"})
|
|
|
+ # user_info = user_id_get_user_info(db,user_id)
|
|
|
+ roles = []
|
|
|
+ role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
|
|
|
+ for role in role_ids:
|
|
|
+ role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
|
|
|
+ roles.append( role_info.role_key)
|
|
|
+ if "superadmin"in roles or "super_ld"in roles or "super_worker"in roles or "zjResponsible"in roles :
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ return JSONResponse(status_code=404,content={"code":404,"msg":"权限不足"})
|
|
|
+ zrlx = body['responsible_type']
|
|
|
+
|
|
|
# 提取请求数据
|
|
|
unit_name = body['unit_name']
|
|
|
name = body['name']
|
|
@@ -68,6 +70,7 @@ zrlx:str,
|
|
|
order_num=body['order_num']
|
|
|
unit_id = db_dept.get_dept_id_by_name(db, unit_name)
|
|
|
user_id_1 = db_user.get_user_id_by_phonenumber(db,phone)
|
|
|
+ phone = mpfun.enc_data(body['phone'])
|
|
|
|
|
|
# 创建新的记录
|
|
|
new_person = ThreeProofingResponsiblePerson(
|
|
@@ -78,13 +81,19 @@ zrlx:str,
|
|
|
area_code=area_code,
|
|
|
position=position,
|
|
|
phone=phone,
|
|
|
- responsible_type= lx,
|
|
|
+ responsible_type= zrlx,
|
|
|
telephone=telephone,
|
|
|
user_id = user_id_1,
|
|
|
order_num=order_num,
|
|
|
create_by=user_id
|
|
|
)
|
|
|
# 添加到数据库会话并提交
|
|
|
+ if '森防' in zrlx or '危化' in zrlx:
|
|
|
+ return {
|
|
|
+ "code": 200,
|
|
|
+ "msg": "创建成功",
|
|
|
+ "data": None
|
|
|
+ }
|
|
|
type_list = body['type_list']
|
|
|
if isinstance(type_list,list) and len(type_list)>0:
|
|
|
db.add(new_person)
|
|
@@ -183,7 +192,7 @@ async def update_contact(
|
|
|
traceback.print_exc()
|
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
-@router.put('/{zrlx}/update')
|
|
|
+@router.put('/update')
|
|
|
async def update_contact(
|
|
|
zrlx:str,
|
|
|
request: Request,
|
|
@@ -193,15 +202,16 @@ zrlx:str,
|
|
|
user_id=Depends(valid_access_token)
|
|
|
):
|
|
|
try:
|
|
|
- lx = '三防'
|
|
|
- if zrlx=='sf':
|
|
|
- lx = '三防'
|
|
|
- if zrlx=='sf1':
|
|
|
- lx = '森防'
|
|
|
- if zrlx=='wh':
|
|
|
- lx = '危化'
|
|
|
- if zrlx=='sf':
|
|
|
- return JSONResponse(status_code=404,content={"code":404,"msg":"责任人类型未查询到"})
|
|
|
+ roles = []
|
|
|
+ role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
|
|
|
+ for role in role_ids:
|
|
|
+ role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
|
|
|
+ roles.append(role_info.role_key)
|
|
|
+ if "superadmin" in roles or "super_ld" in roles or "super_worker" in roles or "zjResponsible" in roles:
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ return JSONResponse(status_code=404, content={"code": 404, "msg": "权限不足"})
|
|
|
+
|
|
|
# 提取请求数据
|
|
|
id = body['id']
|
|
|
person = get_person_info_by_id(db,id)
|
|
@@ -221,7 +231,7 @@ zrlx:str,
|
|
|
person.area_code2 = area_info.area_code
|
|
|
person.position = body['position']
|
|
|
person.phone = mpfun.enc_data(body['phone'])
|
|
|
-
|
|
|
+ person.responsible_type = body['responsible_type']
|
|
|
if 'telephone' in body:
|
|
|
person.telephone = mpfun.enc_data(body['telephone'])
|
|
|
person.order_num = body['order_num']
|
|
@@ -305,10 +315,22 @@ zrlx:str,
|
|
|
traceback.print_exc()
|
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
-
|
|
|
-@router.get('/{zrlx}/list')
|
|
|
+@router.get('/admin_area_list')
|
|
|
async def get_emergency_contact_list(
|
|
|
-zrlx:str,
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+ user_id=Depends(valid_access_token)
|
|
|
+):
|
|
|
+ result = []
|
|
|
+ for i in db.query(ThreeProofingResponsibleAdmin.area_code).filter(ThreeProofingResponsibleAdmin.user_id==user_id).all():
|
|
|
+ result.append(i.area_code)
|
|
|
+ return {
|
|
|
+ "code": 200,
|
|
|
+ "msg": "更新成功",
|
|
|
+ "data": result
|
|
|
+ }
|
|
|
+@router.get('/list')
|
|
|
+async def get_emergency_contact_list(
|
|
|
+zrlx:str= Query(None, description='责任类型'),
|
|
|
type_parent_id: str = Query(None, description='单位名称'),
|
|
|
area_code:str = Query(None, description='单位名称'),
|
|
|
Name: str = Query(None, description='联系人'),
|
|
@@ -318,19 +340,31 @@ zrlx:str,
|
|
|
user_id=Depends(valid_access_token)
|
|
|
):
|
|
|
try:
|
|
|
- lx = '三防'
|
|
|
- if zrlx=='sf':
|
|
|
- lx = '三防'
|
|
|
- if zrlx=='sf1':
|
|
|
- lx = '森防'
|
|
|
- if zrlx=='wh':
|
|
|
- lx = '危化'
|
|
|
+ roles = []
|
|
|
+ role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
|
|
|
+ for role in role_ids:
|
|
|
+ role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
|
|
|
+ roles.append(role_info.role_key)
|
|
|
+ if "superadmin" in roles or "super_ld" in roles or "super_worker" in roles or "zjResponsible" in roles:
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ return JSONResponse(status_code=404, content={"code": 404, "msg": "权限不足"})
|
|
|
+ lx = []
|
|
|
+ if 'sf;' in zrlx:
|
|
|
+ lx.append('三防')
|
|
|
+ if 'sf1;' in zrlx:
|
|
|
+ lx.append( '森防')
|
|
|
+ if 'wh;' in zrlx:
|
|
|
+ lx.append('危化')
|
|
|
if zrlx=='sf':
|
|
|
return JSONResponse(status_code=404,content={"code":404,"msg":"责任人类型未查询到"})
|
|
|
# 构建查询
|
|
|
query = db.query(ThreeProofingResponsiblePerson)
|
|
|
query = query.filter(ThreeProofingResponsiblePerson.del_flag == '0')
|
|
|
query = query.filter(ThreeProofingResponsiblePerson.responsible_type.like(f'%{lx}%'))
|
|
|
+ if 'zjResponsible' in roles:
|
|
|
+ for i in db.query(ThreeProofingResponsibleAdmin.area_code).filter(ThreeProofingResponsibleAdmin.user_id==user_id).all():
|
|
|
+ query = query.filter(ThreeProofingResponsiblePerson.area_code2.like(f'%{i.area_code}%'))
|
|
|
# 应用查询条件
|
|
|
if type_parent_id:
|
|
|
person_list = get_person_list_by_type_parent_id(db,type_parent_id)
|
|
@@ -405,6 +439,7 @@ zrlx:str,
|
|
|
"position": info.position,
|
|
|
"phone": mpfun.dec_data(info.phone),
|
|
|
"telephone": mpfun.dec_data(info.telephone),
|
|
|
+ "responsible_type":info.responsible_type,
|
|
|
"order_num": order_num,
|
|
|
"online_status":'0',
|
|
|
"create_time": info.create_time.strftime('%Y-%m-%d %H:%M:%S'),
|
|
@@ -446,6 +481,15 @@ zrlx:str,
|
|
|
user_id=Depends(valid_access_token)
|
|
|
):
|
|
|
try:
|
|
|
+ roles = []
|
|
|
+ role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
|
|
|
+ for role in role_ids:
|
|
|
+ role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
|
|
|
+ roles.append(role_info.role_key)
|
|
|
+ if "superadmin" in roles or "super_ld" in roles or "super_worker" in roles or "zjResponsible" in roles:
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ return JSONResponse(status_code=404, content={"code": 404, "msg": "权限不足"})
|
|
|
lx = '三防'
|
|
|
if zrlx=='sf':
|
|
|
lx = '三防'
|
|
@@ -456,9 +500,14 @@ zrlx:str,
|
|
|
if zrlx=='sf':
|
|
|
return JSONResponse(status_code=404,content={"code":404,"msg":"责任人类型未查询到"})
|
|
|
# 构建查询
|
|
|
+
|
|
|
query = db.query(ThreeProofingResponsiblePerson)
|
|
|
query = query.filter(ThreeProofingResponsiblePerson.del_flag == '0')
|
|
|
query = query.filter(ThreeProofingResponsiblePerson.responsible_type.like(f'%{lx}%'))
|
|
|
+ if 'zjResponsible' in roles:
|
|
|
+ for i in db.query(ThreeProofingResponsibleAdmin.area_code).filter(ThreeProofingResponsibleAdmin.user_id==user_id).all():
|
|
|
+ query = query.filter(ThreeProofingResponsiblePerson.area_code2.like(f'%{i.area_code}%'))
|
|
|
+
|
|
|
# 应用查询条件
|
|
|
if type_parent_id:
|
|
|
person_list = get_person_list_by_type_parent_id(db, type_parent_id)
|
|
@@ -532,6 +581,7 @@ zrlx:str,
|
|
|
"职务": info.position,
|
|
|
"手机号码": mpfun.dec_data(info.phone),
|
|
|
"办公电话": mpfun.dec_data(info.telephone),
|
|
|
+ "责任人类型":info.responsible_type,
|
|
|
"排序顺序": order_num,
|
|
|
"创建时间": info.create_time.strftime('%Y-%m-%d %H:%M:%S'),
|
|
|
"责任类型": '、'.join(type_parent_list)
|
|
@@ -585,23 +635,23 @@ zrlx:str,
|
|
|
return JSONResponse(status_code=500, content={"code": 500, "msg": f"Internal server error: {str(e)}"})
|
|
|
|
|
|
|
|
|
-@router.get('/{zrlx}/info/{id}')
|
|
|
+@router.get('/info/{id}')
|
|
|
async def get_emergency_contact_id_info(
|
|
|
-zrlx:str,
|
|
|
id: str,
|
|
|
db: Session = Depends(get_db),
|
|
|
user_id=Depends(valid_access_token)
|
|
|
):
|
|
|
try:
|
|
|
- lx = '三防'
|
|
|
- if zrlx=='sf':
|
|
|
- lx = '三防'
|
|
|
- if zrlx=='sf1':
|
|
|
- lx = '森防'
|
|
|
- if zrlx=='wh':
|
|
|
- lx = '危化'
|
|
|
- if zrlx=='sf':
|
|
|
- return JSONResponse(status_code=404,content={"code":404,"msg":"责任人类型未查询到"})
|
|
|
+ roles = []
|
|
|
+ role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
|
|
|
+ for role in role_ids:
|
|
|
+ role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
|
|
|
+ roles.append(role_info.role_key)
|
|
|
+ if "superadmin" in roles or "super_ld" in roles or "super_worker" in roles or "zjResponsible" in roles:
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ return JSONResponse(status_code=404, content={"code": 404, "msg": "权限不足"})
|
|
|
+
|
|
|
contact = get_person_info_by_id(db,id)
|
|
|
if not contact:
|
|
|
return JSONResponse(status_code=404, content={
|
|
@@ -630,6 +680,7 @@ zrlx:str,
|
|
|
"position": contact.position,
|
|
|
"phone": mpfun.dec_data(contact.phone),
|
|
|
"telephone":mpfun.dec_data(contact.telephone),
|
|
|
+ "responsible_type":contact.responsible_type,
|
|
|
"order_num":order_num,
|
|
|
"online_status":'0',
|
|
|
"create_time": contact.create_time.strftime('%Y-%m-%d %H:%M:%S'),
|
|
@@ -684,9 +735,8 @@ zrlx:str,
|
|
|
|
|
|
|
|
|
|
|
|
-@router.delete('/{zrlx}/delete')
|
|
|
+@router.delete('/delete')
|
|
|
async def delete_emergency_plans(
|
|
|
-zrlx:str,
|
|
|
request: Request,
|
|
|
ids: list,
|
|
|
db: Session = Depends(get_db),
|
|
@@ -695,15 +745,16 @@ zrlx:str,
|
|
|
user_id=Depends(valid_access_token)
|
|
|
):
|
|
|
try:
|
|
|
- lx = '三防'
|
|
|
- if zrlx=='sf':
|
|
|
- lx = '三防'
|
|
|
- if zrlx=='sf1':
|
|
|
- lx = '森防'
|
|
|
- if zrlx=='wh':
|
|
|
- lx = '危化'
|
|
|
- if zrlx=='sf':
|
|
|
- return JSONResponse(status_code=404,content={"code":404,"msg":"责任人类型未查询到"})
|
|
|
+ roles = []
|
|
|
+ role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
|
|
|
+ for role in role_ids:
|
|
|
+ role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
|
|
|
+ roles.append(role_info.role_key)
|
|
|
+ if "superadmin" in roles or "super_ld" in roles or "super_worker" in roles or "zjResponsible" in roles:
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ return JSONResponse(status_code=404, content={"code": 404, "msg": "权限不足"})
|
|
|
+
|
|
|
# 提取请求数据
|
|
|
query = db.query(ThreeProofingResponsiblePerson)
|
|
|
query = query.filter(ThreeProofingResponsiblePerson.del_flag != '2')
|
|
@@ -736,7 +787,7 @@ zrlx:str,
|
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
|
|
|
-@router.delete('/{zrlx}/delete/{id}')
|
|
|
+@router.delete('/delete/{id}')
|
|
|
async def delete_emergency_plans(
|
|
|
zrlx:str,
|
|
|
request: Request,
|
|
@@ -747,15 +798,16 @@ zrlx:str,
|
|
|
user_id=Depends(valid_access_token)
|
|
|
):
|
|
|
try:
|
|
|
- lx = '三防'
|
|
|
- if zrlx=='sf':
|
|
|
- lx = '三防'
|
|
|
- if zrlx=='sf1':
|
|
|
- lx = '森防'
|
|
|
- if zrlx=='wh':
|
|
|
- lx = '危化'
|
|
|
- if zrlx=='sf':
|
|
|
- return JSONResponse(status_code=404,content={"code":404,"msg":"责任人类型未查询到"})
|
|
|
+ roles = []
|
|
|
+ role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
|
|
|
+ for role in role_ids:
|
|
|
+ role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
|
|
|
+ roles.append(role_info.role_key)
|
|
|
+ if "superadmin" in roles or "super_ld" in roles or "super_worker" in roles or "zjResponsible" in roles:
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ return JSONResponse(status_code=404, content={"code": 404, "msg": "权限不足"})
|
|
|
+
|
|
|
contact = get_person_info_by_id(db, id)
|
|
|
if not contact:
|
|
|
return JSONResponse(status_code=404, content={
|
|
@@ -1122,7 +1174,7 @@ def import_data(db,file_path,user_id,file_info):
|
|
|
|
|
|
three_proofing_responsible_person_data.sign_table()
|
|
|
|
|
|
-@router.post('/{zrlx}/createImport')
|
|
|
+@router.post('/createImport')
|
|
|
async def create_contact(
|
|
|
zrlx:str,
|
|
|
request: Request,
|
|
@@ -1133,15 +1185,16 @@ zrlx:str,
|
|
|
user_id=Depends(valid_access_token)
|
|
|
):
|
|
|
try:
|
|
|
- lx = '三防'
|
|
|
- if zrlx=='sf':
|
|
|
- lx = '三防'
|
|
|
- if zrlx=='sf1':
|
|
|
- lx = '森防'
|
|
|
- if zrlx=='wh':
|
|
|
- lx = '危化'
|
|
|
- if zrlx=='sf':
|
|
|
- return JSONResponse(status_code=404,content={"code":404,"msg":"责任人类型未查询到"})
|
|
|
+ roles = []
|
|
|
+ role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
|
|
|
+ for role in role_ids:
|
|
|
+ role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
|
|
|
+ roles.append(role_info.role_key)
|
|
|
+ if "superadmin" in roles or "super_ld" in roles or "super_worker" in roles or "zjResponsible" in roles:
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ return JSONResponse(status_code=404, content={"code": 404, "msg": "权限不足"})
|
|
|
+
|
|
|
# 提取请求数据
|
|
|
filename = body['filename']
|
|
|
file_name_desc = body['file_name_desc']
|
|
@@ -1166,10 +1219,10 @@ zrlx:str,
|
|
|
)
|
|
|
db.add(new_file)
|
|
|
db.commit()
|
|
|
- background_tasks.add_task(import_data,db,file_path, user_id,new_file)
|
|
|
+ # background_tasks.add_task(import_data,db,file_path, user_id,new_file)
|
|
|
|
|
|
|
|
|
- db_czrz.log(db, auth_user, "系统管理", f"后台管理导入三防责任人管理人员信息成功", request.client.host)
|
|
|
+ db_czrz.log(db, auth_user, "系统管理", f"后台管理导入责任人管理人员信息成功", request.client.host)
|
|
|
|
|
|
# 返回创建成功的响应
|
|
|
return {
|