person_new.py 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. from fastapi import APIRouter, Request, Depends, HTTPException, Query, BackgroundTasks
  2. from sqlalchemy.exc import IntegrityError
  3. from fastapi.responses import HTMLResponse, FileResponse
  4. from fastapi.responses import JSONResponse,StreamingResponse
  5. from database import get_db
  6. from sqlalchemy import text, exists, and_, or_, not_
  7. from sqlalchemy.orm import Session
  8. from models import *
  9. import json
  10. import random
  11. import os
  12. from sqlalchemy import create_engine, select
  13. from typing import Optional
  14. from utils.StripTagsHTMLParser import *
  15. from utils.three_proofing_responsible_util import *
  16. from utils.ry_system_util import *
  17. from common.db import db_event_management, db_user, db_area, db_emergency_plan
  18. from common.security import valid_access_token
  19. import traceback
  20. from utils import *
  21. from datetime import datetime, timedelta
  22. import pandas as pd
  23. import xlrd
  24. from common.db import db_dept
  25. from exceptions import AppException, HmacException
  26. from common.enc import mpfun, three_proofing_responsible_person_data
  27. from common.db import db_czrz
  28. from common.auth_user import *
  29. router = APIRouter()
  30. @router.post('/create')
  31. async def create_contact(
  32. request: Request,
  33. auth_user: AuthUser = Depends(find_auth_user),
  34. db: Session = Depends(get_db),
  35. body=Depends(remove_xss_json),
  36. user_id=Depends(valid_access_token)
  37. ):
  38. try:
  39. # user_info = user_id_get_user_info(db,user_id)
  40. roles = []
  41. role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
  42. for role in role_ids:
  43. role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
  44. roles.append( role_info.role_key)
  45. if "superadmin"in roles or "super_ld"in roles or "super_worker"in roles or "zjResponsible"in roles :
  46. pass
  47. else:
  48. return JSONResponse(status_code=404,content={"code":404,"msg":"权限不足"})
  49. zrlx = body['responsible_type']
  50. # 提取请求数据
  51. unit_name = body['unit_name']
  52. name = body['name']
  53. area_code = body['area_code']
  54. area_info = id_get_area_info(db, body['area_code'])
  55. area_code2 = '440900000000'
  56. if area_info:
  57. area_code2 = area_info.area_code
  58. position = body['position']
  59. phone = body['phone']
  60. telephone= ''
  61. if 'telephone' in body:
  62. telephone=body['telephone']
  63. order_num = -1
  64. if 'order_num'in body:
  65. order_num=body['order_num']
  66. unit_id = db_dept.get_dept_id_by_name(db, unit_name)
  67. user_id_1 = db_user.get_user_id_by_phonenumber(db,phone)
  68. phone = mpfun.enc_data(body['phone'])
  69. # 创建新的记录
  70. new_person = ThreeProofingResponsiblePerson(
  71. unit_id=unit_id,
  72. unit_name=unit_name,
  73. name=name,
  74. area_code2=area_code2,
  75. area_code=area_code,
  76. position=position,
  77. phone=phone,
  78. responsible_type= zrlx,
  79. telephone=telephone,
  80. user_id = user_id_1,
  81. order_num=order_num,
  82. create_by=user_id
  83. )
  84. # 添加到数据库会话并提交
  85. if '森防' in zrlx or '危化' in zrlx:
  86. return {
  87. "code": 200,
  88. "msg": "创建成功",
  89. "data": None
  90. }
  91. type_list = body['type_list']
  92. if isinstance(type_list,list) and len(type_list)>0:
  93. db.add(new_person)
  94. db.commit()
  95. three_proofing_responsible_person_data.sign_table()
  96. else:
  97. return JSONResponse(status_code=404,content={
  98. 'code': 404,
  99. 'msg': '责任类型不能为空'
  100. })
  101. try:
  102. for type_info in type_list:
  103. type_parent_id = type_info['type_parent_id']#get_type_parent_id_by_type_id(db,type_id)
  104. for type_id in type_info['children']:
  105. new_person_type = ThreeProofingResponsiblePersonType(
  106. type_parent_id = type_parent_id,
  107. type_id = type_id,
  108. person_id = new_person.id,
  109. create_by=user_id
  110. )
  111. db.add(new_person_type)
  112. if type_parent_id in ('5','7','9'):
  113. if 'children2' in type_info:
  114. for other_type_id in type_info['children2']:
  115. new_person_other_type = ThreeProofingResponsiblePersonOtherType(
  116. type_parent_id=type_parent_id,
  117. other_type_id=other_type_id,
  118. person_id=new_person.id,
  119. create_by=user_id
  120. )
  121. db.add(new_person_other_type)
  122. if type_parent_id in ('4','5','7','10','11'):
  123. dept_name = None
  124. if 'dept_name' in type_info:
  125. dept_name = type_info['dept_name']
  126. other_type_2_name = None
  127. if 'other_type_2_name' in type_info:
  128. other_type_2_name = type_info['other_type_2_name']
  129. denger_point_name = None
  130. if 'denger_point_name' in type_info:
  131. denger_point_name = type_info['denger_point_name']
  132. new_person_other_info = ThreeProofingResponsiblePersonOtherInfo(
  133. type_parent_id = type_parent_id,
  134. dept_name = dept_name,
  135. other_type_2_name = other_type_2_name,
  136. denger_point_name = denger_point_name,
  137. person_id = new_person.id,
  138. create_by=user_id
  139. )
  140. db.add(new_person_other_info)
  141. except:
  142. db.rollback()
  143. traceback.print_exc()
  144. new_person.del_flag='2'
  145. db.commit()
  146. db_czrz.log(db, auth_user, "系统管理", f"后台管理新建三防责任人管理人员信息成功", request.client.host)
  147. # 返回创建成功的响应
  148. return {
  149. "code": 200,
  150. "msg": "创建成功",
  151. "data": None
  152. }
  153. except Exception as e:
  154. # 处理异常
  155. db.rollback()
  156. traceback.print_exc()
  157. raise HTTPException(status_code=500, detail=str(e))
  158. @router.put('/location_update')
  159. async def update_contact(
  160. request: Request,
  161. auth_user: AuthUser = Depends(find_auth_user),
  162. db: Session = Depends(get_db),
  163. body=Depends(remove_xss_json),
  164. user_id=Depends(valid_access_token)
  165. ):
  166. try:
  167. query = db.query(ThreeProofingResponsiblePerson)
  168. query = query.filter(ThreeProofingResponsiblePerson.del_flag == '0')
  169. query = query.filter(ThreeProofingResponsiblePerson.user_id == user_id)
  170. for info in query.all():
  171. info.longitude = body['longitude']
  172. info.latitude = body['latitude']
  173. info.location_time = datetime.now
  174. db.commit()
  175. except Exception as e:
  176. # 处理异常
  177. db.rollback()
  178. traceback.print_exc()
  179. raise HTTPException(status_code=500, detail=str(e))
  180. @router.put('/update')
  181. async def update_contact(
  182. zrlx:str,
  183. request: Request,
  184. auth_user: AuthUser = Depends(find_auth_user),
  185. db: Session = Depends(get_db),
  186. body=Depends(remove_xss_json),
  187. user_id=Depends(valid_access_token)
  188. ):
  189. try:
  190. roles = []
  191. role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
  192. for role in role_ids:
  193. role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
  194. roles.append(role_info.role_key)
  195. if "superadmin" in roles or "super_ld" in roles or "super_worker" in roles or "zjResponsible" in roles:
  196. pass
  197. else:
  198. return JSONResponse(status_code=404, content={"code": 404, "msg": "权限不足"})
  199. # 提取请求数据
  200. id = body['id']
  201. person = get_person_info_by_id(db,id)
  202. if not person:
  203. return JSONResponse(status_code=404, content={
  204. 'errcode': 404,
  205. 'errmsg': '责任人不存在'
  206. })
  207. person.unit_name = body['unit_name']
  208. person.name = body['name']
  209. person.area_code = body['area_code']
  210. area_info = id_get_area_info(db, body['area_code'])
  211. if area_info:
  212. person.area_code2 = area_info.area_code
  213. person.position = body['position']
  214. person.phone = mpfun.enc_data(body['phone'])
  215. person.responsible_type = body['responsible_type']
  216. if 'telephone' in body:
  217. person.telephone = mpfun.enc_data(body['telephone'])
  218. person.order_num = body['order_num']
  219. if body['order_num']=='':
  220. person.order_num = -1
  221. person.unit_id = db_dept.get_dept_id_by_name(db, body['unit_name'])
  222. person.update_by = user_id
  223. person.update_time = datetime.now()
  224. person.sign = three_proofing_responsible_person_data.get_sign_hmac(person)
  225. type_list = body['type_list']
  226. old_person_type_list=get_person_type_by_person_id(db,person.id)
  227. for old_person_type in old_person_type_list:
  228. old_person_type.del_flag='2'
  229. old_person_other_info_list = get_person_other_info_by_person_id(db,person.id)
  230. for old_person_other_info in old_person_other_info_list:
  231. old_person_other_info.del_flag = '2'
  232. old_person_other_type_list = get_person_other_type_by_person_id(db,person.id)
  233. for old_person_other_type in old_person_other_type_list:
  234. old_person_other_type.del_flag = '2'
  235. for type_info in type_list:
  236. type_parent_id = type_info['type_parent_id'] # get_type_parent_id_by_type_id(db,type_id)
  237. for type_id in type_info['children']:
  238. new_person_type = ThreeProofingResponsiblePersonType(
  239. type_parent_id=type_parent_id,
  240. type_id=type_id,
  241. person_id=id,
  242. create_by=user_id
  243. )
  244. db.add(new_person_type)
  245. if type_parent_id in ('5', '7', '9'):
  246. if 'children2' in type_info:
  247. for other_type_id in type_info['children2']:
  248. new_person_other_type = ThreeProofingResponsiblePersonOtherType(
  249. type_parent_id=type_parent_id,
  250. other_type_id=other_type_id,
  251. person_id=person.id,
  252. create_by=user_id
  253. )
  254. db.add(new_person_other_type)
  255. if type_parent_id in ('4', '5', '7', '10', '11'):
  256. dept_name = None
  257. if 'dept_name' in type_info:
  258. dept_name = type_info['dept_name']
  259. other_type_2_name = None
  260. if 'other_type_2_name' in type_info:
  261. other_type_2_name = type_info['other_type_2_name']
  262. denger_point_name = None
  263. if 'denger_point_name' in type_info:
  264. denger_point_name = type_info['denger_point_name']
  265. new_person_other_info = ThreeProofingResponsiblePersonOtherInfo(
  266. type_parent_id=type_parent_id,
  267. dept_name=dept_name,
  268. other_type_2_name=other_type_2_name,
  269. denger_point_name=denger_point_name,
  270. person_id=person.id,
  271. create_by=user_id
  272. )
  273. db.add(new_person_other_info)
  274. # 更新到数据库会话并提交
  275. db.commit()
  276. db_czrz.log(db, auth_user, "系统管理", f"后台管理更新三防责任人管理人员信息成功", request.client.host)
  277. # 返回创建成功的响应
  278. return {
  279. "code": 200,
  280. "msg": "更新成功",
  281. "data": None
  282. }
  283. except Exception as e:
  284. # 处理异常
  285. db.rollback()
  286. traceback.print_exc()
  287. raise HTTPException(status_code=500, detail=str(e))
  288. @router.get('/admin_area_list')
  289. async def get_emergency_contact_list(
  290. db: Session = Depends(get_db),
  291. user_id=Depends(valid_access_token)
  292. ):
  293. result = []
  294. for i in db.query(ThreeProofingResponsibleAdmin.area_code).filter(ThreeProofingResponsibleAdmin.user_id==user_id).all():
  295. result.append(i.area_code)
  296. return {
  297. "code": 200,
  298. "msg": "成功",
  299. "data": result
  300. }
  301. @router.get('/list')
  302. async def get_emergency_contact_list(
  303. zrlx:str= Query('sf;sf1;wh;', description='责任类型'),
  304. type_parent_id: str = Query(None, description='单位名称'),
  305. area_code:str = Query(None, description='单位名称'),
  306. Name: str = Query(None, description='联系人'),
  307. page: int = Query(1, gt=0, description='页码'),
  308. pageSize: int = Query(10, gt=0, description='每页条目数量'),
  309. db: Session = Depends(get_db),
  310. user_id=Depends(valid_access_token)
  311. ):
  312. try:
  313. roles = []
  314. role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
  315. for role in role_ids:
  316. role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
  317. roles.append(role_info.role_key)
  318. if "superadmin" in roles or "super_ld" in roles or "super_worker" in roles or "zjResponsible" in roles:
  319. pass
  320. else:
  321. return JSONResponse(status_code=404, content={"code": 404, "msg": "权限不足"})
  322. lx = []
  323. if 'sf;' in zrlx:
  324. lx.append('三防')
  325. if 'sf1;' in zrlx:
  326. lx.append( '森防')
  327. if 'wh;' in zrlx:
  328. lx.append('危化')
  329. # 构建查询
  330. query = db.query(ThreeProofingResponsiblePerson)
  331. query = query.filter(ThreeProofingResponsiblePerson.del_flag == '0')
  332. for i in lx:
  333. query = query.filter(ThreeProofingResponsiblePerson.responsible_type.like(f'%{i}%'))
  334. if 'zjResponsible' in roles:
  335. for i in db.query(ThreeProofingResponsibleAdmin.area_code).filter(ThreeProofingResponsibleAdmin.user_id==user_id).all():
  336. query = query.filter(ThreeProofingResponsiblePerson.area_code2.like(f'%{i.area_code}%'))
  337. # 应用查询条件
  338. if type_parent_id:
  339. person_list = get_person_list_by_type_parent_id(db,type_parent_id)
  340. query = query.filter(ThreeProofingResponsiblePerson.id.in_(person_list))
  341. if Name:
  342. query = query.filter(ThreeProofingResponsiblePerson.name.like(f'%{Name}%'))
  343. def get_area_chli(area_list : list,parent_id : int):
  344. areas = parent_id_get_area_info(db,parent_id)
  345. if areas:
  346. for area in areas:
  347. area_list.append(area.id)
  348. get_area_chli(area_list, area.id)
  349. return area_list
  350. # if area_code:
  351. # query = query.filter(ThreeProofingResponsiblePerson.area_code.in_(get_area_chli([area_code],area_code)))
  352. # '''440900000000'''
  353. if area_code:
  354. area_info = id_get_area_info(db,area_code)
  355. if area_info:
  356. area_code = area_info.area_code
  357. area_code=area_code.replace('0000000000','').replace('00000000','').replace('000000','').replace('000','')
  358. query = query.filter(ThreeProofingResponsiblePerson.area_code2.like(f'%{area_code}%') )
  359. # if area_code:
  360. # query = query.filter(ThreeProofingResponsiblePerson.area_code==area_code)
  361. # 计算总条目数
  362. total_items = query.count()
  363. # 排序
  364. query = query.order_by(ThreeProofingResponsiblePerson.order_num.asc())
  365. query = query.order_by(ThreeProofingResponsiblePerson.create_time.desc())
  366. # 执行分页查询
  367. contact_infos = query.offset((page - 1) * pageSize).limit(pageSize).all()
  368. for info in contact_infos:
  369. if three_proofing_responsible_person_data.sign_valid_row(info) == False:
  370. raise HmacException(500, "三防责任人管理人员信息表验证异常,已被非法篡改")
  371. # 将查询结果转换为列表形式的字典
  372. contact_infos_list = []
  373. for info in contact_infos:
  374. type_parent_id_list = get_type_parent_id_by_person_id(db,info.id)
  375. type_parent_list = []
  376. type_parent_list2 = []
  377. for type_parent in type_parent_id_list:
  378. if type_parent not in type_parent_list2:
  379. dict_data = get_dict_data_info(db,'three_proofing',type_parent)
  380. type_parent_list2.append(type_parent)
  381. type_parent_list.append({"type_parent_id":type_parent,"type_parent":dict_data.dict_label})
  382. area_info = id_get_area_info(db,info.area_code)
  383. user_info = user_id_get_user_info(db,info.create_by)
  384. nick_name = ''
  385. if user_info:
  386. nick_name = user_info.nick_name
  387. area_list = db_area.id_get_area_parent_list(db,info.area_code,[])
  388. if info.order_num ==-1:
  389. order_num = ''
  390. else:
  391. order_num = str(info.order_num)
  392. contact_infos_list.append({
  393. "id": info.id,
  394. "unit_id": info.unit_id,
  395. "unit_name": info.unit_name,
  396. "name": info.name,
  397. "area_list":area_list,
  398. "area_code": info.area_code,
  399. "area_name": area_info.area_name,
  400. "position": info.position,
  401. "phone": mpfun.dec_data(info.phone),
  402. "telephone": mpfun.dec_data(info.telephone),
  403. "responsible_type":info.responsible_type,
  404. "order_num": order_num,
  405. "online_status":'0',
  406. "create_time": info.create_time.strftime('%Y-%m-%d %H:%M:%S'),
  407. "create_by":info.create_by,
  408. "create_user":nick_name,
  409. "type_parent_list":type_parent_list
  410. })
  411. # 返回结果+
  412. return {
  413. "code": 200,
  414. "msg": "成功",
  415. "data": contact_infos_list,
  416. "total": total_items
  417. }
  418. except HmacException as e:
  419. return {
  420. "code": e.code,
  421. "msg": e.msg
  422. }
  423. except Exception as e:
  424. # 处理异常
  425. traceback.print_exc()
  426. raise HTTPException(status_code=500, detail=str(e))
  427. @router.get('/{zrlx}/export')
  428. async def get_emergency_contact_list(
  429. zrlx:str,
  430. request: Request,
  431. type_parent_id: str = Query(None, description='单位名称'),
  432. area_code: str = Query(None, description='单位名称'),
  433. Name: str = Query(None, description='联系人'),
  434. page: int = Query(1, gt=0, description='页码'),
  435. pageSize: int = Query(10, gt=0, description='每页条目数量'),
  436. db: Session = Depends(get_db),
  437. auth_user: AuthUser = Depends(find_auth_user),
  438. user_id=Depends(valid_access_token)
  439. ):
  440. try:
  441. roles = []
  442. role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
  443. for role in role_ids:
  444. role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
  445. roles.append(role_info.role_key)
  446. if "superadmin" in roles or "super_ld" in roles or "super_worker" in roles or "zjResponsible" in roles:
  447. pass
  448. else:
  449. return JSONResponse(status_code=404, content={"code": 404, "msg": "权限不足"})
  450. lx = '三防'
  451. if zrlx=='sf':
  452. lx = '三防'
  453. if zrlx=='sf1':
  454. lx = '森防'
  455. if zrlx=='wh':
  456. lx = '危化'
  457. if zrlx=='sf':
  458. return JSONResponse(status_code=404,content={"code":404,"msg":"责任人类型未查询到"})
  459. # 构建查询
  460. query = db.query(ThreeProofingResponsiblePerson)
  461. query = query.filter(ThreeProofingResponsiblePerson.del_flag == '0')
  462. query = query.filter(ThreeProofingResponsiblePerson.responsible_type.like(f'%{lx}%'))
  463. if 'zjResponsible' in roles:
  464. for i in db.query(ThreeProofingResponsibleAdmin.area_code).filter(ThreeProofingResponsibleAdmin.user_id==user_id).all():
  465. query = query.filter(ThreeProofingResponsiblePerson.area_code2.like(f'%{i.area_code}%'))
  466. # 应用查询条件
  467. if type_parent_id:
  468. person_list = get_person_list_by_type_parent_id(db, type_parent_id)
  469. query = query.filter(ThreeProofingResponsiblePerson.id.in_(person_list))
  470. if Name:
  471. query = query.filter(ThreeProofingResponsiblePerson.name.like(f'%{Name}%'))
  472. def get_area_chli(area_list: list, parent_id: int):
  473. areas = parent_id_get_area_info(db, parent_id)
  474. if areas:
  475. for area in areas:
  476. area_list.append(area.id)
  477. get_area_chli(area_list, area.id)
  478. return area_list
  479. # if area_code:
  480. # query = query.filter(ThreeProofingResponsiblePerson.area_code.in_(get_area_chli([area_code],area_code)))
  481. # '''440900000000'''
  482. if area_code:
  483. area_info = id_get_area_info(db, area_code)
  484. if area_info:
  485. area_code = area_info.area_code
  486. area_code = area_code.replace('0000000000', '').replace('00000000', '').replace('000000', '').replace(
  487. '000', '')
  488. query = query.filter(ThreeProofingResponsiblePerson.area_code2.like(f'%{area_code}%'))
  489. # if area_code:
  490. # query = query.filter(ThreeProofingResponsiblePerson.area_code==area_code)
  491. # 计算总条目数
  492. total_items = query.count()
  493. # 排序
  494. query = query.order_by(ThreeProofingResponsiblePerson.order_num.asc())
  495. query = query.order_by(ThreeProofingResponsiblePerson.create_time.desc())
  496. # 执行分页查询
  497. contact_infos = query.all()
  498. for info in contact_infos:
  499. if three_proofing_responsible_person_data.sign_valid_row(info) == False:
  500. raise HmacException(500, "三防责任人管理人员信息表验证异常,已被非法篡改")
  501. # 将查询结果转换为列表形式的字典
  502. contact_infos_list = []
  503. for info in contact_infos:
  504. type_parent_id_list = get_type_parent_id_by_person_id(db, info.id)
  505. type_parent_list = []
  506. type_parent_list2 = []
  507. for type_parent in type_parent_id_list:
  508. if type_parent not in type_parent_list2:
  509. dict_data = get_dict_data_info(db, 'three_proofing', type_parent)
  510. type_parent_list2.append(type_parent)
  511. type_parent_list.append(dict_data.dict_label)
  512. area_info = id_get_area_info(db, info.area_code)
  513. user_info = user_id_get_user_info(db, info.create_by)
  514. area_list = db_area.id_get_area_parent_list(db, info.area_code, [])
  515. area_list = '/'.join([i['label'] for i in area_list])
  516. if info.order_num == -1:
  517. order_num = ''
  518. else:
  519. order_num = str(info.order_num)
  520. contact_infos_list.append({
  521. "id": info.id,
  522. "单位ID": info.unit_id,
  523. "单位名称": info.unit_name,
  524. "姓名": info.name,
  525. "区划列表": area_list,
  526. "区划编码": info.area_code,
  527. "区划": area_info.area_name,
  528. "职务": info.position,
  529. "手机号码": mpfun.dec_data(info.phone),
  530. "办公电话": mpfun.dec_data(info.telephone),
  531. "责任人类型":info.responsible_type,
  532. "排序顺序": order_num,
  533. "创建时间": info.create_time.strftime('%Y-%m-%d %H:%M:%S'),
  534. "责任类型": '、'.join(type_parent_list)
  535. })
  536. # 返回结果+
  537. import pandas as pd
  538. from io import BytesIO
  539. # 将查询结果转换为 DataFrame
  540. df = pd.DataFrame(contact_infos_list)
  541. # 将 DataFrame 导出为 Excel 文件
  542. output = BytesIO()
  543. with pd.ExcelWriter(output, engine='openpyxl') as writer:
  544. df.to_excel(writer, index=False)
  545. # 设置响应头
  546. output.seek(0)
  547. from urllib.parse import quote
  548. encoded_filename = f'三防责任人清单{datetime.now().strftime("%Y%m%d%H%mi%s")}.xlsx'
  549. encoded_filename = quote(encoded_filename, encoding='utf-8')
  550. headers = {
  551. 'Content-Disposition': f'attachment; filename*=UTF-8\'\'{encoded_filename}',
  552. 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  553. }
  554. db_czrz.log(db, auth_user, "三防责任人管理", f"三防责任人清单导出数据成功", request.client.host)
  555. # 返回文件流
  556. return StreamingResponse(output, headers=headers)
  557. #
  558. # return {
  559. # "code": 200,
  560. # "msg": "成功",
  561. # "data": contact_infos_list,
  562. # "total": total_items
  563. # }
  564. except HmacException as e:
  565. return JSONResponse(status_code=e.code, content={
  566. "code": e.code,
  567. "msg": e.msg
  568. })
  569. # return {
  570. # "code": e.code,
  571. # "msg": e.msg
  572. # }
  573. except Exception as e:
  574. # 处理异常
  575. traceback.print_exc()
  576. return JSONResponse(status_code=500, content={"code": 500, "msg": f"Internal server error: {str(e)}"})
  577. @router.get('/info/{id}')
  578. async def get_emergency_contact_id_info(
  579. id: str,
  580. db: Session = Depends(get_db),
  581. user_id=Depends(valid_access_token)
  582. ):
  583. try:
  584. roles = []
  585. role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
  586. for role in role_ids:
  587. role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
  588. roles.append(role_info.role_key)
  589. if "superadmin" in roles or "super_ld" in roles or "super_worker" in roles or "zjResponsible" in roles:
  590. pass
  591. else:
  592. return JSONResponse(status_code=404, content={"code": 404, "msg": "权限不足"})
  593. contact = get_person_info_by_id(db,id)
  594. if not contact:
  595. return JSONResponse(status_code=404, content={
  596. 'errcode': 404,
  597. 'errmsg': '联系人不存在'
  598. })
  599. # 将查询结果转换为列表形式的字典
  600. area_info = id_get_area_info(db,contact.area_code)
  601. user_info = user_id_get_user_info(db,contact.create_by)
  602. nick_name = ''
  603. if user_info:
  604. nick_name = user_info.nick_name
  605. area_list = db_area.id_get_area_parent_list(db, contact.area_code, [])
  606. if contact.order_num == -1:
  607. order_num = ''
  608. else:
  609. order_num = str(contact.order_num)
  610. contact_result = {
  611. "id": contact.id,
  612. "unit_id": contact.unit_id,
  613. "unit_name": contact.unit_name,
  614. "name": contact.name,
  615. "area_list":area_list,
  616. "area_code":contact.area_code,
  617. "area_name": area_info.area_name,
  618. "position": contact.position,
  619. "phone": mpfun.dec_data(contact.phone),
  620. "telephone":mpfun.dec_data(contact.telephone),
  621. "responsible_type":contact.responsible_type,
  622. "order_num":order_num,
  623. "online_status":'0',
  624. "create_time": contact.create_time.strftime('%Y-%m-%d %H:%M:%S'),
  625. "create_by":contact.create_by,
  626. "create_user":nick_name,
  627. "type_list":[]
  628. }
  629. type_parent_id_list = []
  630. type_list = get_person_type_by_person_id(db,contact.id)
  631. for type_info in type_list:
  632. if type_info.type_parent_id not in type_parent_id_list:
  633. type_parent_id_list.append(type_info.type_parent_id)
  634. for type_parent_id in type_parent_id_list:
  635. dict_data = get_dict_data_info(db, 'three_proofing', type_parent_id)
  636. type_data = {"type_parent_id": type_parent_id, "type_parent": dict_data.dict_label,"children":[],"labelData":[]}
  637. for type_info in get_person_type_by_person_id_and_type_parent_id(db,contact.id,type_parent_id):
  638. type_data_info = get_type_info_by_id(db,type_info.type_id)
  639. # type_data['children'].append({"id": type_info.type_id, "label": type_data_info.type_name})
  640. type_data['children'].append(type_info.type_id)
  641. type_data['labelData'].append( type_data_info.type_name)
  642. other_info = get_person_other_info_by_person_id_and_type_parent_id(db, contact.id, type_parent_id)
  643. if other_info:
  644. type_data['dept_name'] = other_info.dept_name
  645. type_data['denger_point_name'] = other_info.denger_point_name
  646. type_data['other_type_2_name'] = other_info.other_type_2_name
  647. other_type_list = get_person_other_type_by_person_id_and_type_parent_id(db, contact.id, type_parent_id)
  648. if other_type_list:
  649. type_data['children2'] = []
  650. type_data['other_type_label'] = []
  651. for other_type in other_type_list:
  652. other_type_info = get_other_type_info_by_id(db, other_type.other_type_id)
  653. label= ''
  654. if other_type_info:
  655. label = other_type_info.type_name
  656. # type_data['children2'].append({"id": other_type.other_type_id, "label": label})
  657. type_data['children2'].append(other_type.other_type_id)
  658. type_data['other_type_label'].append(label)
  659. contact_result['type_list'].append(type_data)
  660. # 返回结果
  661. return {
  662. "code": 200,
  663. "msg": "成功",
  664. "data": contact_result
  665. }
  666. except Exception as e:
  667. # 处理异常
  668. traceback.print_exc()
  669. raise HTTPException(status_code=500, detail=str(e))
  670. @router.delete('/delete')
  671. async def delete_emergency_plans(
  672. request: Request,
  673. ids: list,
  674. db: Session = Depends(get_db),
  675. body=Depends(remove_xss_json),
  676. auth_user: AuthUser = Depends(find_auth_user),
  677. user_id=Depends(valid_access_token)
  678. ):
  679. try:
  680. roles = []
  681. role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
  682. for role in role_ids:
  683. role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
  684. roles.append(role_info.role_key)
  685. if "superadmin" in roles or "super_ld" in roles or "super_worker" in roles or "zjResponsible" in roles:
  686. pass
  687. else:
  688. return JSONResponse(status_code=404, content={"code": 404, "msg": "权限不足"})
  689. # 提取请求数据
  690. query = db.query(ThreeProofingResponsiblePerson)
  691. query = query.filter(ThreeProofingResponsiblePerson.del_flag != '2')
  692. query = query.filter(ThreeProofingResponsiblePerson.id.in_(ids))
  693. contacts = query.all()
  694. if not contacts:
  695. return JSONResponse(status_code=404, content={
  696. 'errcode': 404,
  697. 'errmsg': '联系人不存在'
  698. })
  699. for contact in contacts:
  700. contact.del_flag = '2'
  701. contact.update_by = user_id
  702. contact.update_time = datetime.now()
  703. contact.sign = three_proofing_responsible_person_data.get_sign_hmac(contact)
  704. # 更新到数据库会话并提交
  705. db.commit()
  706. db_czrz.log(db, auth_user, "系统管理", f"后台管理删除三防责任人管理人员信息成功", request.client.host)
  707. # 返回创建成功的响应
  708. return {
  709. "code": 200,
  710. "msg": "删除成功",
  711. "data": None
  712. }
  713. except Exception as e:
  714. # 处理异常
  715. traceback.print_exc()
  716. raise HTTPException(status_code=500, detail=str(e))
  717. @router.delete('/delete/{id}')
  718. async def delete_emergency_plans(
  719. zrlx:str,
  720. request: Request,
  721. id: int,
  722. db: Session = Depends(get_db),
  723. body=Depends(remove_xss_json),
  724. auth_user: AuthUser = Depends(find_auth_user),
  725. user_id=Depends(valid_access_token)
  726. ):
  727. try:
  728. roles = []
  729. role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
  730. for role in role_ids:
  731. role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
  732. roles.append(role_info.role_key)
  733. if "superadmin" in roles or "super_ld" in roles or "super_worker" in roles or "zjResponsible" in roles:
  734. pass
  735. else:
  736. return JSONResponse(status_code=404, content={"code": 404, "msg": "权限不足"})
  737. contact = get_person_info_by_id(db, id)
  738. if not contact:
  739. return JSONResponse(status_code=404, content={
  740. 'errcode': 404,
  741. 'errmsg': '联系人不存在'
  742. })
  743. contact.del_flag = '2'
  744. contact.update_by = user_id
  745. contact.update_time = datetime.now()
  746. contact.sign = three_proofing_responsible_person_data.get_sign_hmac(contact)
  747. # 更新到数据库会话并提交
  748. db.commit()
  749. db_czrz.log(db, auth_user, "系统管理", f"后台管理删除三防责任人管理人员信息成功", request.client.host)
  750. # 返回创建成功的响应
  751. return {
  752. "code": 200,
  753. "msg": "删除成功",
  754. "data": None
  755. }
  756. except Exception as e:
  757. # 处理异常
  758. traceback.print_exc()
  759. raise HTTPException(status_code=500, detail=str(e))
  760. def string_type_parent_id_create_data(db,string,type_parent_id,file_info,new_person,user_id,row) :
  761. type_name_list = [i for i in string.split(',')]
  762. reslte = []
  763. for type_name in type_name_list:
  764. type_id = get_type_id_by_type_parent_id_and_type_name(db, type_parent_id, type_name)
  765. if type_id:
  766. new_person_type = ThreeProofingResponsiblePersonType(
  767. type_parent_id=type_parent_id,
  768. type_id=type_id,
  769. person_id=new_person.id,
  770. create_by=user_id
  771. )
  772. reslte.append(new_person_type)
  773. else:
  774. file_info.remark= file_info.remark+f'\n行<{row+1}>责任类别未找到<{type_name}>'
  775. return reslte ,False
  776. return reslte ,True
  777. def other_type_string_type_parent_id_create_data(db,string,type_parent_id,file_info,new_person,user_id,row) :
  778. type_name_list = [i for i in string.split(',')]
  779. reslte = []
  780. for other_type_name in type_name_list:
  781. other_type_id = get_other_type_id_by_type_parent_id_and_other_type_name(db, type_parent_id, other_type_name)
  782. if other_type_id:
  783. new_person_type = ThreeProofingResponsiblePersonOtherType(
  784. type_parent_id=type_parent_id,
  785. other_type_id=other_type_id,
  786. person_id=new_person.id,
  787. create_by=user_id
  788. )
  789. reslte.append(new_person_type)
  790. else:
  791. file_info.remark= file_info.remark+f'\n行<{row+1}>责任类别未找到<{other_type_name}>'
  792. file_info.error_num +=1
  793. return reslte ,False
  794. return reslte ,True
  795. def import_data(db,file_path,user_id,file_info):
  796. import_status = True
  797. try:
  798. book = xlrd.open_workbook(file_path)
  799. sheet = book.sheet_by_index(0)
  800. except :
  801. file_info.remark = file_info.remark + f'\n文件打开失败,请核实文件格式为xlsx/xlx>'
  802. file_info.error_num +=1
  803. import_status = False
  804. data = []
  805. for row in range(4, sheet.nrows):
  806. # 姓名
  807. name = sheet.cell(row, 0).value
  808. if name == '':
  809. file_info.remark = file_info.remark+f'\n行<{row+1}>姓名不能为空<{name}>'
  810. file_info.error_num +=1
  811. import_status = False
  812. # 所属单位
  813. unit_name = sheet.cell(row, 1).value
  814. if unit_name == '':
  815. file_info.remark = file_info.remark+f'\n行<{row+1}>所属单位不能为空<{unit_name}>'
  816. file_info.error_num +=1
  817. import_status = False
  818. unit_id = db_dept.get_dept_id_by_name(db, unit_name)
  819. # 职务
  820. position = sheet.cell(row, 2).value
  821. if position =='':
  822. file_info.remark = file_info.remark+f'\n行<{row+1}>职务不能为空<{position}>'
  823. file_info.error_num +=1
  824. import_status = False
  825. # 电话号码(如有多个手机号请用“,”分隔)
  826. phone = str(sheet.cell(row, 3).value)
  827. if phone =='':
  828. file_info.remark = file_info.remark+f'\n行<{row+1}>电话号码不能为空<{phone}>'
  829. file_info.error_num +=1
  830. import_status = False
  831. phone_list = [i for i in phone.split(',')]
  832. user_id_1=-1
  833. for i in phone_list:
  834. user_id_1 = db_user.get_user_id_by_phonenumber(db, i)
  835. if user_id_1 != -1:
  836. break
  837. # 办公电话
  838. # (选填,格式:区号-电话号码)
  839. telephone = sheet.cell(row, 4).value
  840. # 排位顺序
  841. # (选填,请输入排序号1-9999,排序号数值越小越靠前,不填则默认排至最末)
  842. order_num = sheet.cell(row, 5).value
  843. if order_num == '':
  844. order_num=-1
  845. area_name = sheet.cell(row, 7).value
  846. if area_name=='':
  847. area_code=2
  848. area_code2='440900000000'
  849. else:
  850. area_code=get_area_info_by_area_name(db,area_name)
  851. if area_code is None:
  852. file_info.remark = file_info.remark+f'\n行<{row+1}>责任区域未找到'
  853. file_info.error_num +=1
  854. import_status = False
  855. area_code2 = area_code.area_code
  856. area_code = area_code.id
  857. new_person = ThreeProofingResponsiblePerson(
  858. unit_id=unit_id,
  859. unit_name=unit_name,
  860. name=name,
  861. area_code2=area_code2,
  862. area_code=area_code,
  863. position=position,
  864. phone=phone.replace,
  865. telephone=telephone,
  866. user_id=user_id_1,
  867. order_num=order_num,
  868. create_by=user_id,
  869. sign = ''
  870. )
  871. data.append(new_person)
  872. db.add(new_person)
  873. db.commit()
  874. # 党委政府
  875. a1 = sheet.cell(row, 6).value
  876. if a1 != '':
  877. new_type_list,status = string_type_parent_id_create_data(db,a1,'1',file_info,new_person,user_id,row)
  878. if status:
  879. db.add_all(new_type_list)
  880. data +=new_type_list
  881. else:
  882. import_status = status
  883. # type_name_list = [i for i in a1.split(',')]
  884. # for type_name in type_name_list:
  885. # type_id = get_type_id_by_type_parent_id_and_type_name(db, '1', type_name)
  886. # if type_id:
  887. # pass
  888. # 三防指挥部
  889. b1 = sheet.cell(row, 8).value
  890. if b1 != '':
  891. new_type_list,status = string_type_parent_id_create_data(db,b1,'2',file_info,new_person,user_id,row)
  892. if status:
  893. db.add_all(new_type_list)
  894. data +=new_type_list
  895. else:
  896. import_status = status
  897. b2 = sheet.cell(row, 9).value
  898. # 应急部门
  899. c1 = sheet.cell(row, 10).value
  900. if c1!='':
  901. new_type_list, status = string_type_parent_id_create_data(db, c1, '3', file_info, new_person, user_id,row)
  902. if status:
  903. db.add_all(new_type_list)
  904. data += new_type_list
  905. else:
  906. import_status = status
  907. # 成员单位
  908. d1 = sheet.cell(row, 11).value
  909. if d1!='':
  910. new_type_list, status = string_type_parent_id_create_data(db, d1, '4', file_info, new_person, user_id,row)
  911. if status:
  912. db.add_all(new_type_list)
  913. data += new_type_list
  914. else:
  915. import_status = status
  916. d2 = sheet.cell(row, 12).value
  917. if d2!='':
  918. dept_name = d2
  919. new_person_other_info = ThreeProofingResponsiblePersonOtherInfo(
  920. type_parent_id='4',
  921. dept_name=dept_name,
  922. person_id=new_person.id,
  923. create_by=user_id
  924. )
  925. db.add(new_person_other_info)
  926. data.append(new_person_other_info)
  927. # 重点部门
  928. e1 = sheet.cell(row, 13).value
  929. if e1!='':
  930. new_type_list, status = string_type_parent_id_create_data(db, e1, '5', file_info, new_person, user_id,row)
  931. if status:
  932. db.add_all(new_type_list)
  933. data += new_type_list
  934. else:
  935. import_status = status
  936. e2 = sheet.cell(row, 14).value
  937. if e2!='':
  938. dept_name = e2
  939. new_person_other_info = ThreeProofingResponsiblePersonOtherInfo(
  940. type_parent_id='5',
  941. dept_name=dept_name,
  942. person_id=new_person.id,
  943. create_by=user_id
  944. )
  945. db.add(new_person_other_info)
  946. data.append(new_person_other_info)
  947. e3 = sheet.cell(row, 15).value
  948. if e3!='':
  949. new_type_list,status = other_type_string_type_parent_id_create_data(db,e3,'5',file_info,new_person,user_id,row)
  950. if status:
  951. db.add_all(new_type_list)
  952. data +=new_type_list
  953. else:
  954. import_status = status
  955. # 行政村
  956. f1 = sheet.cell(row, 16).value
  957. if f1!='':
  958. new_type_list, status = string_type_parent_id_create_data(db, f1, '6', file_info, new_person, user_id,row)
  959. if status:
  960. db.add_all(new_type_list)
  961. data += new_type_list
  962. else:
  963. import_status = status
  964. # 水利工程
  965. g1 = sheet.cell(row, 17).value
  966. if g1!='':
  967. new_type_list, status = string_type_parent_id_create_data(db, g1, '7', file_info, new_person, user_id,row)
  968. if status:
  969. db.add_all(new_type_list)
  970. data += new_type_list
  971. else:
  972. import_status = status
  973. g2 = sheet.cell(row, 18).value
  974. if g2!='':
  975. dept_name = g2
  976. new_person_other_info = ThreeProofingResponsiblePersonOtherInfo(
  977. type_parent_id='7',
  978. dept_name=dept_name,
  979. person_id=new_person.id,
  980. create_by=user_id
  981. )
  982. db.add(new_person_other_info)
  983. data.append(new_person_other_info)
  984. g3 = sheet.cell(row, 19).value
  985. if g3!='':
  986. new_type_list, status = other_type_string_type_parent_id_create_data(db, g3, '11', file_info, new_person, user_id,
  987. row)
  988. if status:
  989. db.add_all(new_type_list)
  990. data += new_type_list
  991. else:
  992. import_status = status
  993. # 受威胁转移
  994. h1 = sheet.cell(row, 20).value
  995. if h1!='':
  996. new_type_list, status = string_type_parent_id_create_data(db, h1, '8', file_info, new_person, user_id,row)
  997. if status:
  998. db.add_all(new_type_list)
  999. data += new_type_list
  1000. else:
  1001. import_status = status
  1002. # 抢险队伍
  1003. j1 = sheet.cell(row, 21).value
  1004. if j1!='':
  1005. new_type_list, status = string_type_parent_id_create_data(db, j1, '9', file_info, new_person, user_id,row)
  1006. if status:
  1007. db.add_all(new_type_list)
  1008. data += new_type_list
  1009. else:
  1010. import_status = status
  1011. j2 = sheet.cell(row, 22).value
  1012. if j2!='':
  1013. new_type_list, status = other_type_string_type_parent_id_create_data(db, j2, '9', file_info, new_person, user_id,
  1014. row)
  1015. if status:
  1016. db.add_all(new_type_list)
  1017. data += new_type_list
  1018. else:
  1019. import_status = status
  1020. # 地质灾害
  1021. k1 = sheet.cell(row, 23).value
  1022. if k1!='':
  1023. new_type_list, status = string_type_parent_id_create_data(db, k1, '10', file_info, new_person, user_id,row)
  1024. if status:
  1025. db.add_all(new_type_list)
  1026. data += new_type_list
  1027. else:
  1028. import_status = status
  1029. k2 = sheet.cell(row, 24).value
  1030. if k2!='':
  1031. denger_point_name = k2
  1032. new_person_other_info = ThreeProofingResponsiblePersonOtherInfo(
  1033. type_parent_id='10',
  1034. denger_point_name=denger_point_name,
  1035. person_id=new_person.id,
  1036. create_by=user_id
  1037. )
  1038. db.add(new_person_other_info)
  1039. data.append(new_person_other_info)
  1040. # 其他
  1041. l1 = sheet.cell(row, 25).value
  1042. if l1!='':
  1043. new_type_list, status = string_type_parent_id_create_data(db, l1, '11', file_info, new_person, user_id,row)
  1044. if status:
  1045. db.add_all(new_type_list)
  1046. data += new_type_list
  1047. else:
  1048. import_status = status
  1049. l2 = sheet.cell(row, 26).value
  1050. if l2!='':
  1051. other_type_2_name = l2
  1052. new_person_other_info = ThreeProofingResponsiblePersonOtherInfo(
  1053. type_parent_id='11',
  1054. other_type_2_name=other_type_2_name,
  1055. person_id=new_person.id,
  1056. create_by=user_id
  1057. )
  1058. db.add(new_person_other_info)
  1059. data.append(new_person_other_info)
  1060. db.commit()
  1061. if import_status == False:
  1062. # print(1111111)
  1063. for info in data:
  1064. db.delete(info)
  1065. file_info.status = 2
  1066. db.commit()
  1067. three_proofing_responsible_person_data.sign_table()
  1068. @router.post('/createImport')
  1069. async def create_contact(
  1070. zrlx:str,
  1071. request: Request,
  1072. background_tasks: BackgroundTasks,
  1073. db: Session = Depends(get_db),
  1074. body=Depends(remove_xss_json),
  1075. auth_user: AuthUser = Depends(find_auth_user),
  1076. user_id=Depends(valid_access_token)
  1077. ):
  1078. try:
  1079. roles = []
  1080. role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
  1081. for role in role_ids:
  1082. role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
  1083. roles.append(role_info.role_key)
  1084. if "superadmin" in roles or "super_ld" in roles or "super_worker" in roles or "zjResponsible" in roles:
  1085. pass
  1086. else:
  1087. return JSONResponse(status_code=404, content={"code": 404, "msg": "权限不足"})
  1088. # 提取请求数据
  1089. filename = body['filename']
  1090. file_name_desc = body['file_name_desc']
  1091. if len(filename) == 0:
  1092. raise Exception()
  1093. file_path = f'/data/upload/mergefile/uploads/{filename}'
  1094. # 检查文件是否存在
  1095. if not os.path.isfile(file_path):
  1096. return JSONResponse(status_code=404, content={
  1097. 'errcode': 404,
  1098. 'errmsg': f'{filename}不存在'
  1099. })
  1100. new_file = ThreeProofingResponsiblePersonImportFileStatus(
  1101. file_uuid=filename,
  1102. file_name = file_name_desc,
  1103. status = '1',
  1104. remark = '',
  1105. user_id=user_id
  1106. )
  1107. db.add(new_file)
  1108. db.commit()
  1109. # background_tasks.add_task(import_data,db,file_path, user_id,new_file)
  1110. db_czrz.log(db, auth_user, "系统管理", f"后台管理导入责任人管理人员信息成功", request.client.host)
  1111. # 返回创建成功的响应
  1112. return {
  1113. "code": 200,
  1114. "msg": "成功",
  1115. "data": None
  1116. }
  1117. except AppException as e:
  1118. return {
  1119. "code": 500,
  1120. "msg": e.msg
  1121. }
  1122. except Exception as e:
  1123. traceback.print_exc()
  1124. # 处理异常
  1125. db.rollback()
  1126. raise HTTPException(status_code=500, detail=str(e))