person_new.py 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  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(None, 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. if zrlx=='sf':
  330. return JSONResponse(status_code=404,content={"code":404,"msg":"责任人类型未查询到"})
  331. # 构建查询
  332. query = db.query(ThreeProofingResponsiblePerson)
  333. query = query.filter(ThreeProofingResponsiblePerson.del_flag == '0')
  334. query = query.filter(ThreeProofingResponsiblePerson.responsible_type.like(f'%{lx}%'))
  335. if 'zjResponsible' in roles:
  336. for i in db.query(ThreeProofingResponsibleAdmin.area_code).filter(ThreeProofingResponsibleAdmin.user_id==user_id).all():
  337. query = query.filter(ThreeProofingResponsiblePerson.area_code2.like(f'%{i.area_code}%'))
  338. # 应用查询条件
  339. if type_parent_id:
  340. person_list = get_person_list_by_type_parent_id(db,type_parent_id)
  341. query = query.filter(ThreeProofingResponsiblePerson.id.in_(person_list))
  342. if Name:
  343. query = query.filter(ThreeProofingResponsiblePerson.name.like(f'%{Name}%'))
  344. def get_area_chli(area_list : list,parent_id : int):
  345. areas = parent_id_get_area_info(db,parent_id)
  346. if areas:
  347. for area in areas:
  348. area_list.append(area.id)
  349. get_area_chli(area_list, area.id)
  350. return area_list
  351. # if area_code:
  352. # query = query.filter(ThreeProofingResponsiblePerson.area_code.in_(get_area_chli([area_code],area_code)))
  353. # '''440900000000'''
  354. if area_code:
  355. area_info = id_get_area_info(db,area_code)
  356. if area_info:
  357. area_code = area_info.area_code
  358. area_code=area_code.replace('0000000000','').replace('00000000','').replace('000000','').replace('000','')
  359. query = query.filter(ThreeProofingResponsiblePerson.area_code2.like(f'%{area_code}%') )
  360. # if area_code:
  361. # query = query.filter(ThreeProofingResponsiblePerson.area_code==area_code)
  362. # 计算总条目数
  363. total_items = query.count()
  364. # 排序
  365. query = query.order_by(ThreeProofingResponsiblePerson.order_num.asc())
  366. query = query.order_by(ThreeProofingResponsiblePerson.create_time.desc())
  367. # 执行分页查询
  368. contact_infos = query.offset((page - 1) * pageSize).limit(pageSize).all()
  369. for info in contact_infos:
  370. if three_proofing_responsible_person_data.sign_valid_row(info) == False:
  371. raise HmacException(500, "三防责任人管理人员信息表验证异常,已被非法篡改")
  372. # 将查询结果转换为列表形式的字典
  373. contact_infos_list = []
  374. for info in contact_infos:
  375. type_parent_id_list = get_type_parent_id_by_person_id(db,info.id)
  376. type_parent_list = []
  377. type_parent_list2 = []
  378. for type_parent in type_parent_id_list:
  379. if type_parent not in type_parent_list2:
  380. dict_data = get_dict_data_info(db,'three_proofing',type_parent)
  381. type_parent_list2.append(type_parent)
  382. type_parent_list.append({"type_parent_id":type_parent,"type_parent":dict_data.dict_label})
  383. area_info = id_get_area_info(db,info.area_code)
  384. user_info = user_id_get_user_info(db,info.create_by)
  385. nick_name = ''
  386. if user_info:
  387. nick_name = user_info.nick_name
  388. area_list = db_area.id_get_area_parent_list(db,info.area_code,[])
  389. if info.order_num ==-1:
  390. order_num = ''
  391. else:
  392. order_num = str(info.order_num)
  393. contact_infos_list.append({
  394. "id": info.id,
  395. "unit_id": info.unit_id,
  396. "unit_name": info.unit_name,
  397. "name": info.name,
  398. "area_list":area_list,
  399. "area_code": info.area_code,
  400. "area_name": area_info.area_name,
  401. "position": info.position,
  402. "phone": mpfun.dec_data(info.phone),
  403. "telephone": mpfun.dec_data(info.telephone),
  404. "responsible_type":info.responsible_type,
  405. "order_num": order_num,
  406. "online_status":'0',
  407. "create_time": info.create_time.strftime('%Y-%m-%d %H:%M:%S'),
  408. "create_by":info.create_by,
  409. "create_user":nick_name,
  410. "type_parent_list":type_parent_list
  411. })
  412. # 返回结果+
  413. return {
  414. "code": 200,
  415. "msg": "成功",
  416. "data": contact_infos_list,
  417. "total": total_items
  418. }
  419. except HmacException as e:
  420. return {
  421. "code": e.code,
  422. "msg": e.msg
  423. }
  424. except Exception as e:
  425. # 处理异常
  426. traceback.print_exc()
  427. raise HTTPException(status_code=500, detail=str(e))
  428. @router.get('/{zrlx}/export')
  429. async def get_emergency_contact_list(
  430. zrlx:str,
  431. request: Request,
  432. type_parent_id: str = Query(None, description='单位名称'),
  433. area_code: str = Query(None, description='单位名称'),
  434. Name: str = Query(None, description='联系人'),
  435. page: int = Query(1, gt=0, description='页码'),
  436. pageSize: int = Query(10, gt=0, description='每页条目数量'),
  437. db: Session = Depends(get_db),
  438. auth_user: AuthUser = Depends(find_auth_user),
  439. user_id=Depends(valid_access_token)
  440. ):
  441. try:
  442. roles = []
  443. role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
  444. for role in role_ids:
  445. role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
  446. roles.append(role_info.role_key)
  447. if "superadmin" in roles or "super_ld" in roles or "super_worker" in roles or "zjResponsible" in roles:
  448. pass
  449. else:
  450. return JSONResponse(status_code=404, content={"code": 404, "msg": "权限不足"})
  451. lx = '三防'
  452. if zrlx=='sf':
  453. lx = '三防'
  454. if zrlx=='sf1':
  455. lx = '森防'
  456. if zrlx=='wh':
  457. lx = '危化'
  458. if zrlx=='sf':
  459. return JSONResponse(status_code=404,content={"code":404,"msg":"责任人类型未查询到"})
  460. # 构建查询
  461. query = db.query(ThreeProofingResponsiblePerson)
  462. query = query.filter(ThreeProofingResponsiblePerson.del_flag == '0')
  463. query = query.filter(ThreeProofingResponsiblePerson.responsible_type.like(f'%{lx}%'))
  464. if 'zjResponsible' in roles:
  465. for i in db.query(ThreeProofingResponsibleAdmin.area_code).filter(ThreeProofingResponsibleAdmin.user_id==user_id).all():
  466. query = query.filter(ThreeProofingResponsiblePerson.area_code2.like(f'%{i.area_code}%'))
  467. # 应用查询条件
  468. if type_parent_id:
  469. person_list = get_person_list_by_type_parent_id(db, type_parent_id)
  470. query = query.filter(ThreeProofingResponsiblePerson.id.in_(person_list))
  471. if Name:
  472. query = query.filter(ThreeProofingResponsiblePerson.name.like(f'%{Name}%'))
  473. def get_area_chli(area_list: list, parent_id: int):
  474. areas = parent_id_get_area_info(db, parent_id)
  475. if areas:
  476. for area in areas:
  477. area_list.append(area.id)
  478. get_area_chli(area_list, area.id)
  479. return area_list
  480. # if area_code:
  481. # query = query.filter(ThreeProofingResponsiblePerson.area_code.in_(get_area_chli([area_code],area_code)))
  482. # '''440900000000'''
  483. if area_code:
  484. area_info = id_get_area_info(db, area_code)
  485. if area_info:
  486. area_code = area_info.area_code
  487. area_code = area_code.replace('0000000000', '').replace('00000000', '').replace('000000', '').replace(
  488. '000', '')
  489. query = query.filter(ThreeProofingResponsiblePerson.area_code2.like(f'%{area_code}%'))
  490. # if area_code:
  491. # query = query.filter(ThreeProofingResponsiblePerson.area_code==area_code)
  492. # 计算总条目数
  493. total_items = query.count()
  494. # 排序
  495. query = query.order_by(ThreeProofingResponsiblePerson.order_num.asc())
  496. query = query.order_by(ThreeProofingResponsiblePerson.create_time.desc())
  497. # 执行分页查询
  498. contact_infos = query.all()
  499. for info in contact_infos:
  500. if three_proofing_responsible_person_data.sign_valid_row(info) == False:
  501. raise HmacException(500, "三防责任人管理人员信息表验证异常,已被非法篡改")
  502. # 将查询结果转换为列表形式的字典
  503. contact_infos_list = []
  504. for info in contact_infos:
  505. type_parent_id_list = get_type_parent_id_by_person_id(db, info.id)
  506. type_parent_list = []
  507. type_parent_list2 = []
  508. for type_parent in type_parent_id_list:
  509. if type_parent not in type_parent_list2:
  510. dict_data = get_dict_data_info(db, 'three_proofing', type_parent)
  511. type_parent_list2.append(type_parent)
  512. type_parent_list.append(dict_data.dict_label)
  513. area_info = id_get_area_info(db, info.area_code)
  514. user_info = user_id_get_user_info(db, info.create_by)
  515. area_list = db_area.id_get_area_parent_list(db, info.area_code, [])
  516. area_list = '/'.join([i['label'] for i in area_list])
  517. if info.order_num == -1:
  518. order_num = ''
  519. else:
  520. order_num = str(info.order_num)
  521. contact_infos_list.append({
  522. "id": info.id,
  523. "单位ID": info.unit_id,
  524. "单位名称": info.unit_name,
  525. "姓名": info.name,
  526. "区划列表": area_list,
  527. "区划编码": info.area_code,
  528. "区划": area_info.area_name,
  529. "职务": info.position,
  530. "手机号码": mpfun.dec_data(info.phone),
  531. "办公电话": mpfun.dec_data(info.telephone),
  532. "责任人类型":info.responsible_type,
  533. "排序顺序": order_num,
  534. "创建时间": info.create_time.strftime('%Y-%m-%d %H:%M:%S'),
  535. "责任类型": '、'.join(type_parent_list)
  536. })
  537. # 返回结果+
  538. import pandas as pd
  539. from io import BytesIO
  540. # 将查询结果转换为 DataFrame
  541. df = pd.DataFrame(contact_infos_list)
  542. # 将 DataFrame 导出为 Excel 文件
  543. output = BytesIO()
  544. with pd.ExcelWriter(output, engine='openpyxl') as writer:
  545. df.to_excel(writer, index=False)
  546. # 设置响应头
  547. output.seek(0)
  548. from urllib.parse import quote
  549. encoded_filename = f'三防责任人清单{datetime.now().strftime("%Y%m%d%H%mi%s")}.xlsx'
  550. encoded_filename = quote(encoded_filename, encoding='utf-8')
  551. headers = {
  552. 'Content-Disposition': f'attachment; filename*=UTF-8\'\'{encoded_filename}',
  553. 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  554. }
  555. db_czrz.log(db, auth_user, "三防责任人管理", f"三防责任人清单导出数据成功", request.client.host)
  556. # 返回文件流
  557. return StreamingResponse(output, headers=headers)
  558. #
  559. # return {
  560. # "code": 200,
  561. # "msg": "成功",
  562. # "data": contact_infos_list,
  563. # "total": total_items
  564. # }
  565. except HmacException as e:
  566. return JSONResponse(status_code=e.code, content={
  567. "code": e.code,
  568. "msg": e.msg
  569. })
  570. # return {
  571. # "code": e.code,
  572. # "msg": e.msg
  573. # }
  574. except Exception as e:
  575. # 处理异常
  576. traceback.print_exc()
  577. return JSONResponse(status_code=500, content={"code": 500, "msg": f"Internal server error: {str(e)}"})
  578. @router.get('/info/{id}')
  579. async def get_emergency_contact_id_info(
  580. id: str,
  581. db: Session = Depends(get_db),
  582. user_id=Depends(valid_access_token)
  583. ):
  584. try:
  585. roles = []
  586. role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
  587. for role in role_ids:
  588. role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
  589. roles.append(role_info.role_key)
  590. if "superadmin" in roles or "super_ld" in roles or "super_worker" in roles or "zjResponsible" in roles:
  591. pass
  592. else:
  593. return JSONResponse(status_code=404, content={"code": 404, "msg": "权限不足"})
  594. contact = get_person_info_by_id(db,id)
  595. if not contact:
  596. return JSONResponse(status_code=404, content={
  597. 'errcode': 404,
  598. 'errmsg': '联系人不存在'
  599. })
  600. # 将查询结果转换为列表形式的字典
  601. area_info = id_get_area_info(db,contact.area_code)
  602. user_info = user_id_get_user_info(db,contact.create_by)
  603. nick_name = ''
  604. if user_info:
  605. nick_name = user_info.nick_name
  606. area_list = db_area.id_get_area_parent_list(db, contact.area_code, [])
  607. if contact.order_num == -1:
  608. order_num = ''
  609. else:
  610. order_num = str(contact.order_num)
  611. contact_result = {
  612. "id": contact.id,
  613. "unit_id": contact.unit_id,
  614. "unit_name": contact.unit_name,
  615. "name": contact.name,
  616. "area_list":area_list,
  617. "area_code":contact.area_code,
  618. "area_name": area_info.area_name,
  619. "position": contact.position,
  620. "phone": mpfun.dec_data(contact.phone),
  621. "telephone":mpfun.dec_data(contact.telephone),
  622. "responsible_type":contact.responsible_type,
  623. "order_num":order_num,
  624. "online_status":'0',
  625. "create_time": contact.create_time.strftime('%Y-%m-%d %H:%M:%S'),
  626. "create_by":contact.create_by,
  627. "create_user":nick_name,
  628. "type_list":[]
  629. }
  630. type_parent_id_list = []
  631. type_list = get_person_type_by_person_id(db,contact.id)
  632. for type_info in type_list:
  633. if type_info.type_parent_id not in type_parent_id_list:
  634. type_parent_id_list.append(type_info.type_parent_id)
  635. for type_parent_id in type_parent_id_list:
  636. dict_data = get_dict_data_info(db, 'three_proofing', type_parent_id)
  637. type_data = {"type_parent_id": type_parent_id, "type_parent": dict_data.dict_label,"children":[],"labelData":[]}
  638. for type_info in get_person_type_by_person_id_and_type_parent_id(db,contact.id,type_parent_id):
  639. type_data_info = get_type_info_by_id(db,type_info.type_id)
  640. # type_data['children'].append({"id": type_info.type_id, "label": type_data_info.type_name})
  641. type_data['children'].append(type_info.type_id)
  642. type_data['labelData'].append( type_data_info.type_name)
  643. other_info = get_person_other_info_by_person_id_and_type_parent_id(db, contact.id, type_parent_id)
  644. if other_info:
  645. type_data['dept_name'] = other_info.dept_name
  646. type_data['denger_point_name'] = other_info.denger_point_name
  647. type_data['other_type_2_name'] = other_info.other_type_2_name
  648. other_type_list = get_person_other_type_by_person_id_and_type_parent_id(db, contact.id, type_parent_id)
  649. if other_type_list:
  650. type_data['children2'] = []
  651. type_data['other_type_label'] = []
  652. for other_type in other_type_list:
  653. other_type_info = get_other_type_info_by_id(db, other_type.other_type_id)
  654. label= ''
  655. if other_type_info:
  656. label = other_type_info.type_name
  657. # type_data['children2'].append({"id": other_type.other_type_id, "label": label})
  658. type_data['children2'].append(other_type.other_type_id)
  659. type_data['other_type_label'].append(label)
  660. contact_result['type_list'].append(type_data)
  661. # 返回结果
  662. return {
  663. "code": 200,
  664. "msg": "成功",
  665. "data": contact_result
  666. }
  667. except Exception as e:
  668. # 处理异常
  669. traceback.print_exc()
  670. raise HTTPException(status_code=500, detail=str(e))
  671. @router.delete('/delete')
  672. async def delete_emergency_plans(
  673. request: Request,
  674. ids: list,
  675. db: Session = Depends(get_db),
  676. body=Depends(remove_xss_json),
  677. auth_user: AuthUser = Depends(find_auth_user),
  678. user_id=Depends(valid_access_token)
  679. ):
  680. try:
  681. roles = []
  682. role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
  683. for role in role_ids:
  684. role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
  685. roles.append(role_info.role_key)
  686. if "superadmin" in roles or "super_ld" in roles or "super_worker" in roles or "zjResponsible" in roles:
  687. pass
  688. else:
  689. return JSONResponse(status_code=404, content={"code": 404, "msg": "权限不足"})
  690. # 提取请求数据
  691. query = db.query(ThreeProofingResponsiblePerson)
  692. query = query.filter(ThreeProofingResponsiblePerson.del_flag != '2')
  693. query = query.filter(ThreeProofingResponsiblePerson.id.in_(ids))
  694. contacts = query.all()
  695. if not contacts:
  696. return JSONResponse(status_code=404, content={
  697. 'errcode': 404,
  698. 'errmsg': '联系人不存在'
  699. })
  700. for contact in contacts:
  701. contact.del_flag = '2'
  702. contact.update_by = user_id
  703. contact.update_time = datetime.now()
  704. contact.sign = three_proofing_responsible_person_data.get_sign_hmac(contact)
  705. # 更新到数据库会话并提交
  706. db.commit()
  707. db_czrz.log(db, auth_user, "系统管理", f"后台管理删除三防责任人管理人员信息成功", request.client.host)
  708. # 返回创建成功的响应
  709. return {
  710. "code": 200,
  711. "msg": "删除成功",
  712. "data": None
  713. }
  714. except Exception as e:
  715. # 处理异常
  716. traceback.print_exc()
  717. raise HTTPException(status_code=500, detail=str(e))
  718. @router.delete('/delete/{id}')
  719. async def delete_emergency_plans(
  720. zrlx:str,
  721. request: Request,
  722. id: int,
  723. db: Session = Depends(get_db),
  724. body=Depends(remove_xss_json),
  725. auth_user: AuthUser = Depends(find_auth_user),
  726. user_id=Depends(valid_access_token)
  727. ):
  728. try:
  729. roles = []
  730. role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
  731. for role in role_ids:
  732. role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
  733. roles.append(role_info.role_key)
  734. if "superadmin" in roles or "super_ld" in roles or "super_worker" in roles or "zjResponsible" in roles:
  735. pass
  736. else:
  737. return JSONResponse(status_code=404, content={"code": 404, "msg": "权限不足"})
  738. contact = get_person_info_by_id(db, id)
  739. if not contact:
  740. return JSONResponse(status_code=404, content={
  741. 'errcode': 404,
  742. 'errmsg': '联系人不存在'
  743. })
  744. contact.del_flag = '2'
  745. contact.update_by = user_id
  746. contact.update_time = datetime.now()
  747. contact.sign = three_proofing_responsible_person_data.get_sign_hmac(contact)
  748. # 更新到数据库会话并提交
  749. db.commit()
  750. db_czrz.log(db, auth_user, "系统管理", f"后台管理删除三防责任人管理人员信息成功", request.client.host)
  751. # 返回创建成功的响应
  752. return {
  753. "code": 200,
  754. "msg": "删除成功",
  755. "data": None
  756. }
  757. except Exception as e:
  758. # 处理异常
  759. traceback.print_exc()
  760. raise HTTPException(status_code=500, detail=str(e))
  761. def string_type_parent_id_create_data(db,string,type_parent_id,file_info,new_person,user_id,row) :
  762. type_name_list = [i for i in string.split(',')]
  763. reslte = []
  764. for type_name in type_name_list:
  765. type_id = get_type_id_by_type_parent_id_and_type_name(db, type_parent_id, type_name)
  766. if type_id:
  767. new_person_type = ThreeProofingResponsiblePersonType(
  768. type_parent_id=type_parent_id,
  769. type_id=type_id,
  770. person_id=new_person.id,
  771. create_by=user_id
  772. )
  773. reslte.append(new_person_type)
  774. else:
  775. file_info.remark= file_info.remark+f'\n行<{row+1}>责任类别未找到<{type_name}>'
  776. return reslte ,False
  777. return reslte ,True
  778. def other_type_string_type_parent_id_create_data(db,string,type_parent_id,file_info,new_person,user_id,row) :
  779. type_name_list = [i for i in string.split(',')]
  780. reslte = []
  781. for other_type_name in type_name_list:
  782. other_type_id = get_other_type_id_by_type_parent_id_and_other_type_name(db, type_parent_id, other_type_name)
  783. if other_type_id:
  784. new_person_type = ThreeProofingResponsiblePersonOtherType(
  785. type_parent_id=type_parent_id,
  786. other_type_id=other_type_id,
  787. person_id=new_person.id,
  788. create_by=user_id
  789. )
  790. reslte.append(new_person_type)
  791. else:
  792. file_info.remark= file_info.remark+f'\n行<{row+1}>责任类别未找到<{other_type_name}>'
  793. file_info.error_num +=1
  794. return reslte ,False
  795. return reslte ,True
  796. def import_data(db,file_path,user_id,file_info):
  797. import_status = True
  798. try:
  799. book = xlrd.open_workbook(file_path)
  800. sheet = book.sheet_by_index(0)
  801. except :
  802. file_info.remark = file_info.remark + f'\n文件打开失败,请核实文件格式为xlsx/xlx>'
  803. file_info.error_num +=1
  804. import_status = False
  805. data = []
  806. for row in range(4, sheet.nrows):
  807. # 姓名
  808. name = sheet.cell(row, 0).value
  809. if name == '':
  810. file_info.remark = file_info.remark+f'\n行<{row+1}>姓名不能为空<{name}>'
  811. file_info.error_num +=1
  812. import_status = False
  813. # 所属单位
  814. unit_name = sheet.cell(row, 1).value
  815. if unit_name == '':
  816. file_info.remark = file_info.remark+f'\n行<{row+1}>所属单位不能为空<{unit_name}>'
  817. file_info.error_num +=1
  818. import_status = False
  819. unit_id = db_dept.get_dept_id_by_name(db, unit_name)
  820. # 职务
  821. position = sheet.cell(row, 2).value
  822. if position =='':
  823. file_info.remark = file_info.remark+f'\n行<{row+1}>职务不能为空<{position}>'
  824. file_info.error_num +=1
  825. import_status = False
  826. # 电话号码(如有多个手机号请用“,”分隔)
  827. phone = str(sheet.cell(row, 3).value)
  828. if phone =='':
  829. file_info.remark = file_info.remark+f'\n行<{row+1}>电话号码不能为空<{phone}>'
  830. file_info.error_num +=1
  831. import_status = False
  832. phone_list = [i for i in phone.split(',')]
  833. user_id_1=-1
  834. for i in phone_list:
  835. user_id_1 = db_user.get_user_id_by_phonenumber(db, i)
  836. if user_id_1 != -1:
  837. break
  838. # 办公电话
  839. # (选填,格式:区号-电话号码)
  840. telephone = sheet.cell(row, 4).value
  841. # 排位顺序
  842. # (选填,请输入排序号1-9999,排序号数值越小越靠前,不填则默认排至最末)
  843. order_num = sheet.cell(row, 5).value
  844. if order_num == '':
  845. order_num=-1
  846. area_name = sheet.cell(row, 7).value
  847. if area_name=='':
  848. area_code=2
  849. area_code2='440900000000'
  850. else:
  851. area_code=get_area_info_by_area_name(db,area_name)
  852. if area_code is None:
  853. file_info.remark = file_info.remark+f'\n行<{row+1}>责任区域未找到'
  854. file_info.error_num +=1
  855. import_status = False
  856. area_code2 = area_code.area_code
  857. area_code = area_code.id
  858. new_person = ThreeProofingResponsiblePerson(
  859. unit_id=unit_id,
  860. unit_name=unit_name,
  861. name=name,
  862. area_code2=area_code2,
  863. area_code=area_code,
  864. position=position,
  865. phone=phone.replace,
  866. telephone=telephone,
  867. user_id=user_id_1,
  868. order_num=order_num,
  869. create_by=user_id,
  870. sign = ''
  871. )
  872. data.append(new_person)
  873. db.add(new_person)
  874. db.commit()
  875. # 党委政府
  876. a1 = sheet.cell(row, 6).value
  877. if a1 != '':
  878. new_type_list,status = string_type_parent_id_create_data(db,a1,'1',file_info,new_person,user_id,row)
  879. if status:
  880. db.add_all(new_type_list)
  881. data +=new_type_list
  882. else:
  883. import_status = status
  884. # type_name_list = [i for i in a1.split(',')]
  885. # for type_name in type_name_list:
  886. # type_id = get_type_id_by_type_parent_id_and_type_name(db, '1', type_name)
  887. # if type_id:
  888. # pass
  889. # 三防指挥部
  890. b1 = sheet.cell(row, 8).value
  891. if b1 != '':
  892. new_type_list,status = string_type_parent_id_create_data(db,b1,'2',file_info,new_person,user_id,row)
  893. if status:
  894. db.add_all(new_type_list)
  895. data +=new_type_list
  896. else:
  897. import_status = status
  898. b2 = sheet.cell(row, 9).value
  899. # 应急部门
  900. c1 = sheet.cell(row, 10).value
  901. if c1!='':
  902. new_type_list, status = string_type_parent_id_create_data(db, c1, '3', file_info, new_person, user_id,row)
  903. if status:
  904. db.add_all(new_type_list)
  905. data += new_type_list
  906. else:
  907. import_status = status
  908. # 成员单位
  909. d1 = sheet.cell(row, 11).value
  910. if d1!='':
  911. new_type_list, status = string_type_parent_id_create_data(db, d1, '4', file_info, new_person, user_id,row)
  912. if status:
  913. db.add_all(new_type_list)
  914. data += new_type_list
  915. else:
  916. import_status = status
  917. d2 = sheet.cell(row, 12).value
  918. if d2!='':
  919. dept_name = d2
  920. new_person_other_info = ThreeProofingResponsiblePersonOtherInfo(
  921. type_parent_id='4',
  922. dept_name=dept_name,
  923. person_id=new_person.id,
  924. create_by=user_id
  925. )
  926. db.add(new_person_other_info)
  927. data.append(new_person_other_info)
  928. # 重点部门
  929. e1 = sheet.cell(row, 13).value
  930. if e1!='':
  931. new_type_list, status = string_type_parent_id_create_data(db, e1, '5', file_info, new_person, user_id,row)
  932. if status:
  933. db.add_all(new_type_list)
  934. data += new_type_list
  935. else:
  936. import_status = status
  937. e2 = sheet.cell(row, 14).value
  938. if e2!='':
  939. dept_name = e2
  940. new_person_other_info = ThreeProofingResponsiblePersonOtherInfo(
  941. type_parent_id='5',
  942. dept_name=dept_name,
  943. person_id=new_person.id,
  944. create_by=user_id
  945. )
  946. db.add(new_person_other_info)
  947. data.append(new_person_other_info)
  948. e3 = sheet.cell(row, 15).value
  949. if e3!='':
  950. new_type_list,status = other_type_string_type_parent_id_create_data(db,e3,'5',file_info,new_person,user_id,row)
  951. if status:
  952. db.add_all(new_type_list)
  953. data +=new_type_list
  954. else:
  955. import_status = status
  956. # 行政村
  957. f1 = sheet.cell(row, 16).value
  958. if f1!='':
  959. new_type_list, status = string_type_parent_id_create_data(db, f1, '6', file_info, new_person, user_id,row)
  960. if status:
  961. db.add_all(new_type_list)
  962. data += new_type_list
  963. else:
  964. import_status = status
  965. # 水利工程
  966. g1 = sheet.cell(row, 17).value
  967. if g1!='':
  968. new_type_list, status = string_type_parent_id_create_data(db, g1, '7', file_info, new_person, user_id,row)
  969. if status:
  970. db.add_all(new_type_list)
  971. data += new_type_list
  972. else:
  973. import_status = status
  974. g2 = sheet.cell(row, 18).value
  975. if g2!='':
  976. dept_name = g2
  977. new_person_other_info = ThreeProofingResponsiblePersonOtherInfo(
  978. type_parent_id='7',
  979. dept_name=dept_name,
  980. person_id=new_person.id,
  981. create_by=user_id
  982. )
  983. db.add(new_person_other_info)
  984. data.append(new_person_other_info)
  985. g3 = sheet.cell(row, 19).value
  986. if g3!='':
  987. new_type_list, status = other_type_string_type_parent_id_create_data(db, g3, '11', file_info, new_person, user_id,
  988. row)
  989. if status:
  990. db.add_all(new_type_list)
  991. data += new_type_list
  992. else:
  993. import_status = status
  994. # 受威胁转移
  995. h1 = sheet.cell(row, 20).value
  996. if h1!='':
  997. new_type_list, status = string_type_parent_id_create_data(db, h1, '8', file_info, new_person, user_id,row)
  998. if status:
  999. db.add_all(new_type_list)
  1000. data += new_type_list
  1001. else:
  1002. import_status = status
  1003. # 抢险队伍
  1004. j1 = sheet.cell(row, 21).value
  1005. if j1!='':
  1006. new_type_list, status = string_type_parent_id_create_data(db, j1, '9', file_info, new_person, user_id,row)
  1007. if status:
  1008. db.add_all(new_type_list)
  1009. data += new_type_list
  1010. else:
  1011. import_status = status
  1012. j2 = sheet.cell(row, 22).value
  1013. if j2!='':
  1014. new_type_list, status = other_type_string_type_parent_id_create_data(db, j2, '9', file_info, new_person, user_id,
  1015. row)
  1016. if status:
  1017. db.add_all(new_type_list)
  1018. data += new_type_list
  1019. else:
  1020. import_status = status
  1021. # 地质灾害
  1022. k1 = sheet.cell(row, 23).value
  1023. if k1!='':
  1024. new_type_list, status = string_type_parent_id_create_data(db, k1, '10', file_info, new_person, user_id,row)
  1025. if status:
  1026. db.add_all(new_type_list)
  1027. data += new_type_list
  1028. else:
  1029. import_status = status
  1030. k2 = sheet.cell(row, 24).value
  1031. if k2!='':
  1032. denger_point_name = k2
  1033. new_person_other_info = ThreeProofingResponsiblePersonOtherInfo(
  1034. type_parent_id='10',
  1035. denger_point_name=denger_point_name,
  1036. person_id=new_person.id,
  1037. create_by=user_id
  1038. )
  1039. db.add(new_person_other_info)
  1040. data.append(new_person_other_info)
  1041. # 其他
  1042. l1 = sheet.cell(row, 25).value
  1043. if l1!='':
  1044. new_type_list, status = string_type_parent_id_create_data(db, l1, '11', file_info, new_person, user_id,row)
  1045. if status:
  1046. db.add_all(new_type_list)
  1047. data += new_type_list
  1048. else:
  1049. import_status = status
  1050. l2 = sheet.cell(row, 26).value
  1051. if l2!='':
  1052. other_type_2_name = l2
  1053. new_person_other_info = ThreeProofingResponsiblePersonOtherInfo(
  1054. type_parent_id='11',
  1055. other_type_2_name=other_type_2_name,
  1056. person_id=new_person.id,
  1057. create_by=user_id
  1058. )
  1059. db.add(new_person_other_info)
  1060. data.append(new_person_other_info)
  1061. db.commit()
  1062. if import_status == False:
  1063. # print(1111111)
  1064. for info in data:
  1065. db.delete(info)
  1066. file_info.status = 2
  1067. db.commit()
  1068. three_proofing_responsible_person_data.sign_table()
  1069. @router.post('/createImport')
  1070. async def create_contact(
  1071. zrlx:str,
  1072. request: Request,
  1073. background_tasks: BackgroundTasks,
  1074. db: Session = Depends(get_db),
  1075. body=Depends(remove_xss_json),
  1076. auth_user: AuthUser = Depends(find_auth_user),
  1077. user_id=Depends(valid_access_token)
  1078. ):
  1079. try:
  1080. roles = []
  1081. role_ids = db.query(SysUserRole).filter(SysUserRole.user_id == user_id).all()
  1082. for role in role_ids:
  1083. role_info = db.query(SysRole).filter(SysRole.role_id == role.role_id).first()
  1084. roles.append(role_info.role_key)
  1085. if "superadmin" in roles or "super_ld" in roles or "super_worker" in roles or "zjResponsible" in roles:
  1086. pass
  1087. else:
  1088. return JSONResponse(status_code=404, content={"code": 404, "msg": "权限不足"})
  1089. # 提取请求数据
  1090. filename = body['filename']
  1091. file_name_desc = body['file_name_desc']
  1092. if len(filename) == 0:
  1093. raise Exception()
  1094. file_path = f'/data/upload/mergefile/uploads/{filename}'
  1095. # 检查文件是否存在
  1096. if not os.path.isfile(file_path):
  1097. return JSONResponse(status_code=404, content={
  1098. 'errcode': 404,
  1099. 'errmsg': f'{filename}不存在'
  1100. })
  1101. new_file = ThreeProofingResponsiblePersonImportFileStatus(
  1102. file_uuid=filename,
  1103. file_name = file_name_desc,
  1104. status = '1',
  1105. remark = '',
  1106. user_id=user_id
  1107. )
  1108. db.add(new_file)
  1109. db.commit()
  1110. # background_tasks.add_task(import_data,db,file_path, user_id,new_file)
  1111. db_czrz.log(db, auth_user, "系统管理", f"后台管理导入责任人管理人员信息成功", request.client.host)
  1112. # 返回创建成功的响应
  1113. return {
  1114. "code": 200,
  1115. "msg": "成功",
  1116. "data": None
  1117. }
  1118. except AppException as e:
  1119. return {
  1120. "code": 500,
  1121. "msg": e.msg
  1122. }
  1123. except Exception as e:
  1124. traceback.print_exc()
  1125. # 处理异常
  1126. db.rollback()
  1127. raise HTTPException(status_code=500, detail=str(e))