device.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. from fastapi import APIRouter, Request, Depends, Form, Body, File, UploadFile
  4. from database import get_db
  5. from utils.StripTagsHTMLParser import *
  6. from sqlalchemy.orm import Session
  7. from datetime import datetime, timedelta
  8. import jwt
  9. from passlib.context import CryptContext
  10. from models import *
  11. from sqlalchemy import text, exists, and_, or_, not_
  12. from sqlalchemy.sql import func
  13. from models import *
  14. from extensions import logger
  15. from utils import *
  16. import traceback
  17. router = APIRouter()
  18. # 2.2.1.7.设备基本信息
  19. @router.post('/info', description='提交设备基本信息')
  20. async def post_device_info(
  21. request: Request,
  22. db: Session = Depends(get_db),
  23. data: dict = Depends(remove_xss_json)
  24. ):
  25. try:
  26. id = get_req_param(data, 'id')
  27. company_industry = db.query(DangerBaseDeviceInfo).filter(DangerBaseDeviceInfo.id == id).first()
  28. if company_industry is None:
  29. new_entity = DangerBaseDeviceInfo(**data)
  30. db.add(new_entity)
  31. else:
  32. db.query(DangerBaseDeviceInfo).filter(DangerBaseDeviceInfo.id == id).update(data)
  33. db.commit()
  34. return {
  35. "code":1,
  36. "message":"成功",
  37. "data":{}
  38. }
  39. except Exception as e:
  40. traceback.print_exc()
  41. return {
  42. "code":0,
  43. "message":"更新异常,错误信息:" + str(e),
  44. "data":{}
  45. }
  46. # 2.2.1.8.特种设备登记信息
  47. @router.post('/special', description='提交特种设备登记信息')
  48. async def post_company_industry(
  49. request: Request,
  50. db: Session = Depends(get_db),
  51. data: dict = Depends(remove_xss_json)
  52. ):
  53. try:
  54. id = get_req_param(data, 'id')
  55. company_industry = db.query(DangerBaseDeviceSpecial).filter(DangerBaseDeviceSpecial.id == id).first()
  56. if company_industry is None:
  57. new_entity = DangerBaseDeviceSpecial(**data)
  58. db.add(new_entity)
  59. else:
  60. db.query(DangerBaseDeviceSpecial).filter(DangerBaseDeviceSpecial.id == id).update(data)
  61. db.commit()
  62. return {
  63. "code":1,
  64. "message":"成功",
  65. "data":{}
  66. }
  67. except Exception as e:
  68. traceback.print_exc()
  69. return {
  70. "code":0,
  71. "message":"更新异常,错误信息:" + str(e),
  72. "data":{}
  73. }
  74. # 2.2.1.9.安全阀信息
  75. @router.post('/safetyValve', description='提交安全阀信息')
  76. async def post_company_industry(
  77. request: Request,
  78. db: Session = Depends(get_db),
  79. data: dict = Depends(remove_xss_json)
  80. ):
  81. try:
  82. id = get_req_param(data, 'id')
  83. company_industry = db.query(DangerBaseDeviceSafetyValve).filter(DangerBaseDeviceSafetyValve.id == id).first()
  84. if company_industry is None:
  85. new_entity = DangerBaseDeviceSafetyValve(**data)
  86. db.add(new_entity)
  87. else:
  88. db.query(DangerBaseDeviceSafetyValve).filter(DangerBaseDeviceSafetyValve.id == id).update(data)
  89. db.commit()
  90. return {
  91. "code":1,
  92. "message":"成功",
  93. "data":{}
  94. }
  95. except Exception as e:
  96. traceback.print_exc()
  97. return {
  98. "code":0,
  99. "message":"更新异常,错误信息:" + str(e),
  100. "data":{}
  101. }
  102. # 2.2.1.10.爆破片信息
  103. @router.post('/burst', description='提交爆破片信息')
  104. async def post_company_industry(
  105. request: Request,
  106. db: Session = Depends(get_db),
  107. data: dict = Depends(remove_xss_json)
  108. ):
  109. try:
  110. id = get_req_param(data, 'id')
  111. company_industry = db.query(DangerBaseDeviceBurst).filter(DangerBaseDeviceBurst.id == id).first()
  112. if company_industry is None:
  113. new_entity = DangerBaseDeviceBurst(**data)
  114. db.add(new_entity)
  115. else:
  116. db.query(DangerBaseDeviceBurst).filter(DangerBaseDeviceBurst.id == id).update(data)
  117. db.commit()
  118. return {
  119. "code":1,
  120. "message":"成功",
  121. "data":{}
  122. }
  123. except Exception as e:
  124. traceback.print_exc()
  125. return {
  126. "code":0,
  127. "message":"更新异常,错误信息:" + str(e),
  128. "data":{}
  129. }
  130. # 2.2.1.11.安全仪表连锁信息
  131. @router.post('/instrument', description='提交安全仪表连锁信息')
  132. async def post_company_industry(
  133. request: Request,
  134. db: Session = Depends(get_db),
  135. data: dict = Depends(remove_xss_json)
  136. ):
  137. try:
  138. id = get_req_param(data, 'id')
  139. company_industry = db.query(DangerBaseDeviceInstrument).filter(DangerBaseDeviceInstrument.id == id).first()
  140. if company_industry is None:
  141. new_entity = DangerBaseDeviceInstrument(**data)
  142. db.add(new_entity)
  143. else:
  144. db.query(DangerBaseDeviceInstrument).filter(DangerBaseDeviceInstrument.id == id).update(data)
  145. db.commit()
  146. return {
  147. "code":1,
  148. "message":"成功",
  149. "data":{}
  150. }
  151. except Exception as e:
  152. traceback.print_exc()
  153. return {
  154. "code":0,
  155. "message":"更新异常,错误信息:" + str(e),
  156. "data":{}
  157. }
  158. # 2.2.1.17.1.1.监测设备信息
  159. @router.post('/detect', description='提交监测设备信息')
  160. async def post_device_detect(
  161. request: Request,
  162. db: Session = Depends(get_db),
  163. data: dict = Depends(remove_xss_json)
  164. ):
  165. try:
  166. id = get_req_param(data, 'id')
  167. company_industry = db.query(DangerBaseDeviceDetect).filter(DangerBaseDeviceDetect.id == id).first()
  168. if company_industry is None:
  169. new_entity = DangerBaseDeviceDetect(**data)
  170. db.add(new_entity)
  171. else:
  172. db.query(DangerBaseDeviceDetect).filter(DangerBaseDeviceDetect.id == id).update(data)
  173. db.commit()
  174. return {
  175. "code":1,
  176. "message":"成功",
  177. "data":{}
  178. }
  179. except Exception as e:
  180. traceback.print_exc()
  181. return {
  182. "code":0,
  183. "message":"更新异常,错误信息:" + str(e),
  184. "data":{}
  185. }
  186. # 2.2.1.17.1.2.储罐基础信息
  187. @router.post('/tank', description='提交储罐基础信息')
  188. async def post_device_tank(
  189. request: Request,
  190. db: Session = Depends(get_db),
  191. data: dict = Depends(remove_xss_json)
  192. ):
  193. try:
  194. id = get_req_param(data, 'id')
  195. company_industry = db.query(DangerBaseDeviceTank).filter(DangerBaseDeviceTank.id == id).first()
  196. if company_industry is None:
  197. new_entity = DangerBaseDeviceTank(**data)
  198. db.add(new_entity)
  199. else:
  200. db.query(DangerBaseDeviceTank).filter(DangerBaseDeviceTank.id == id).update(data)
  201. db.commit()
  202. return {
  203. "code":1,
  204. "message":"成功",
  205. "data":{}
  206. }
  207. except Exception as e:
  208. traceback.print_exc()
  209. return {
  210. "code":0,
  211. "message":"更新异常,错误信息:" + str(e),
  212. "data":{}
  213. }
  214. # 2.2.1.17.1.3.装置基础信息
  215. @router.post('/system', description='提交装置基础信息')
  216. async def post_device_system(
  217. request: Request,
  218. db: Session = Depends(get_db),
  219. data: dict = Depends(remove_xss_json)
  220. ):
  221. try:
  222. id = get_req_param(data, 'id')
  223. company_industry = db.query(DangerBaseDeviceSystem).filter(DangerBaseDeviceSystem.id == id).first()
  224. if company_industry is None:
  225. new_entity = DangerBaseDeviceSystem(**data)
  226. db.add(new_entity)
  227. else:
  228. db.query(DangerBaseDeviceSystem).filter(DangerBaseDeviceSystem.id == id).update(data)
  229. db.commit()
  230. return {
  231. "code":1,
  232. "message":"成功",
  233. "data":{}
  234. }
  235. except Exception as e:
  236. traceback.print_exc()
  237. return {
  238. "code":0,
  239. "message":"更新异常,错误信息:" + str(e),
  240. "data":{}
  241. }
  242. # 2.2.1.17.1.4.气体泄漏点基础信息
  243. @router.post('/gas', description='提交气体泄漏点基础信息')
  244. async def post_device_gas(
  245. request: Request,
  246. db: Session = Depends(get_db),
  247. data: dict = Depends(remove_xss_json)
  248. ):
  249. try:
  250. id = get_req_param(data, 'id')
  251. company_industry = db.query(DangerBaseDeviceGas).filter(DangerBaseDeviceGas.id == id).first()
  252. if company_industry is None:
  253. new_entity = DangerBaseDeviceGas(**data)
  254. db.add(new_entity)
  255. else:
  256. db.query(DangerBaseDeviceGas).filter(DangerBaseDeviceGas.id == id).update(data)
  257. db.commit()
  258. return {
  259. "code":1,
  260. "message":"成功",
  261. "data":{}
  262. }
  263. except Exception as e:
  264. traceback.print_exc()
  265. return {
  266. "code":0,
  267. "message":"更新异常,错误信息:" + str(e),
  268. "data":{}
  269. }
  270. # 2.2.1.17.1.5.仓库基础信息
  271. @router.post('/store', description='提交仓库基础信息')
  272. async def post_device_store(
  273. request: Request,
  274. db: Session = Depends(get_db),
  275. data: dict = Depends(remove_xss_json)
  276. ):
  277. try:
  278. id = get_req_param(data, 'id')
  279. company_industry = db.query(DangerBaseDeviceStore).filter(DangerBaseDeviceStore.id == id).first()
  280. if company_industry is None:
  281. new_entity = DangerBaseDeviceStore(**data)
  282. db.add(new_entity)
  283. else:
  284. db.query(DangerBaseDeviceStore).filter(DangerBaseDeviceStore.id == id).update(data)
  285. db.commit()
  286. return {
  287. "code":1,
  288. "message":"成功",
  289. "data":{}
  290. }
  291. except Exception as e:
  292. traceback.print_exc()
  293. return {
  294. "code":0,
  295. "message":"更新异常,错误信息:" + str(e),
  296. "data":{}
  297. }
  298. # 2.2.1.17.1.6.装卸台基础信息
  299. @router.post('/dock', description='提交仓库基础信息')
  300. async def post_device_dock(
  301. request: Request,
  302. db: Session = Depends(get_db),
  303. data: dict = Depends(remove_xss_json)
  304. ):
  305. try:
  306. id = get_req_param(data, 'id')
  307. company_industry = db.query(DangerBaseDeviceStore).filter(DangerBaseDeviceStore.id == id).first()
  308. if company_industry is None:
  309. new_entity = DangerBaseDeviceStore(**data)
  310. db.add(new_entity)
  311. else:
  312. db.query(DangerBaseDeviceStore).filter(DangerBaseDeviceStore.id == id).update(data)
  313. db.commit()
  314. return {
  315. "code":1,
  316. "message":"成功",
  317. "data":{}
  318. }
  319. except Exception as e:
  320. traceback.print_exc()
  321. return {
  322. "code":0,
  323. "message":"更新异常,错误信息:" + str(e),
  324. "data":{}
  325. }
  326. # 2.2.1.17.1.7.设备停用记录表
  327. @router.post('/stop', description='提交设备停用记录表')
  328. async def post_device_stop(
  329. request: Request,
  330. db: Session = Depends(get_db),
  331. data: dict = Depends(remove_xss_json)
  332. ):
  333. try:
  334. id = get_req_param(data, 'id')
  335. company_industry = db.query(DangerBaseDeviceStop).filter(DangerBaseDeviceStop.id == id).first()
  336. if company_industry is None:
  337. new_entity = DangerBaseDeviceStop(**data)
  338. db.add(new_entity)
  339. else:
  340. db.query(DangerBaseDeviceStop).filter(DangerBaseDeviceStop.id == id).update(data)
  341. db.commit()
  342. return {
  343. "code":1,
  344. "message":"成功",
  345. "data":{}
  346. }
  347. except Exception as e:
  348. traceback.print_exc()
  349. return {
  350. "code":0,
  351. "message":"更新异常,错误信息:" + str(e),
  352. "data":{}
  353. }
  354. # 2.2.1.17.1.8.设备介质基础信息表
  355. @router.post('/medium', description='提交设备介质基础信息表')
  356. async def post_device_medium(
  357. request: Request,
  358. db: Session = Depends(get_db),
  359. data: dict = Depends(remove_xss_json)
  360. ):
  361. try:
  362. id = get_req_param(data, 'id')
  363. company_industry = db.query(DangerBaseDeviceMedium).filter(DangerBaseDeviceMedium.id == id).first()
  364. if company_industry is None:
  365. new_entity = DangerBaseDeviceMedium(**data)
  366. db.add(new_entity)
  367. else:
  368. db.query(DangerBaseDeviceMedium).filter(DangerBaseDeviceMedium.id == id).update(data)
  369. db.commit()
  370. return {
  371. "code":1,
  372. "message":"成功",
  373. "data":{}
  374. }
  375. except Exception as e:
  376. traceback.print_exc()
  377. return {
  378. "code":0,
  379. "message":"更新异常,错误信息:" + str(e),
  380. "data":{}
  381. }
  382. # 2.2.1.17.1.9.设备介质组分信息表
  383. @router.post('/mediumGroup', description='提交设备介质组分信息表')
  384. async def post_device_mediumGroup(
  385. request: Request,
  386. db: Session = Depends(get_db),
  387. data: dict = Depends(remove_xss_json)
  388. ):
  389. try:
  390. id = get_req_param(data, 'id')
  391. company_industry = db.query(DangerBaseDeviceMediumGroup).filter(DangerBaseDeviceMediumGroup.id == id).first()
  392. if company_industry is None:
  393. new_entity = DangerBaseDeviceMediumGroup(**data)
  394. db.add(new_entity)
  395. else:
  396. db.query(DangerBaseDeviceMediumGroup).filter(DangerBaseDeviceMediumGroup.id == id).update(data)
  397. db.commit()
  398. return {
  399. "code":1,
  400. "message":"成功",
  401. "data":{}
  402. }
  403. except Exception as e:
  404. traceback.print_exc()
  405. return {
  406. "code":0,
  407. "message":"更新异常,错误信息:" + str(e),
  408. "data":{}
  409. }
  410. # 2.2.1.12.装置开停车和大检修备案
  411. # 2.2.1.12.1.装置大检修备案
  412. @router.post('/systemMaintenance', description='提交装置大检修备案记录信息')
  413. async def post_systemMaintenance(
  414. request: Request,
  415. db: Session = Depends(get_db),
  416. data: dict = Depends(remove_xss_json)
  417. ):
  418. try:
  419. id = get_req_param(data, 'id')
  420. company_industry = db.query(DangerBaseDeviceSystemMaintenance).filter(DangerBaseDeviceSystemMaintenance.id == id).first()
  421. if company_industry is None:
  422. new_entity = DangerBaseDeviceSystemMaintenance(**data)
  423. db.add(new_entity)
  424. else:
  425. db.query(DangerBaseDeviceSystemMaintenance).filter(DangerBaseDeviceSystemMaintenance.id == id).update(data)
  426. db.commit()
  427. return {
  428. "code":1,
  429. "message":"成功",
  430. "data":{}
  431. }
  432. except Exception as e:
  433. traceback.print_exc()
  434. return {
  435. "code":0,
  436. "message":"更新异常,错误信息:" + str(e),
  437. "data":{}
  438. }
  439. # 2.2.1.12.2.装置开停车管理
  440. @router.post('/systemStartStop', description='提交装置开停车管理信息')
  441. async def index(
  442. request: Request,
  443. db: Session = Depends(get_db),
  444. data: dict = Depends(remove_xss_json)
  445. ):
  446. try:
  447. id = get_req_param(data, 'id')
  448. company_industry = db.query(DangerBaseDeviceSystemStartstop).filter(DangerBaseDeviceSystemStartstop.id == id).first()
  449. if company_industry is None:
  450. new_entity = DangerBaseDeviceSystemStartstop(**data)
  451. db.add(new_entity)
  452. else:
  453. db.query(DangerBaseDeviceSystemStartstop).filter(DangerBaseDeviceSystemStartstop.id == id).update(data)
  454. db.commit()
  455. return {
  456. "code":1,
  457. "message":"成功",
  458. "data":{}
  459. }
  460. except Exception as e:
  461. traceback.print_exc()
  462. return {
  463. "code":0,
  464. "message":"更新异常,错误信息:" + str(e),
  465. "data":{}
  466. }