avcon.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. from fastapi import APIRouter, Request, Depends,Query,HTTPException
  4. from database import get_db
  5. from sqlalchemy.orm import Session
  6. from sqlalchemy import case,or_
  7. from sqlalchemy import text
  8. from utils import *
  9. from utils.ry_system_util import *
  10. from utils.video_util import *
  11. from common.security import valid_access_token
  12. from fastapi.responses import JSONResponse
  13. import traceback
  14. import base64
  15. from datetime import datetime
  16. from common.db import db_user, db_czrz
  17. from common import AvconH5API, AvconMiniAPI
  18. from models import *
  19. from common.enc import mpfun
  20. '''
  21. 融合通信相关接口
  22. '''
  23. router = APIRouter()
  24. @router.get('/get_video_list')
  25. async def get_video_list(
  26. db: Session = Depends(get_db),
  27. user_id=Depends(valid_access_token)
  28. ):
  29. return AvconH5API.get_channel_all()
  30. @router.get('/get_mini_video_list')
  31. async def get_mini_video_list(
  32. db: Session = Depends(get_db)
  33. ):
  34. # domain = AvconMiniAPI.get_config("DOMAIN")
  35. # rsa_public_key = AvconMiniAPI.get_config("RSA_PUBLIC_KEY")
  36. # return domain + " / " + rsa_public_key
  37. # return AvconMiniAPI.get_group_page()
  38. # return AvconMiniAPI.get_group_device("G6@mm.zw.yj")
  39. # return AvconMiniAPI.get_device_info("19.152.196.150@mm.zw.yj")
  40. # return AvconMiniAPI.get_device_all()
  41. # return AvconMiniAPI.get_device_channel("19.152.196.150@mm.zw.yj")
  42. # return AvconMiniAPI.get_device_channel_gps("19.152.196.150@mm.zw.yj")
  43. return AvconMiniAPI.get_channel_all()
  44. @router.post("/get_start_mini_param")
  45. async def get_start_mini_param(
  46. request: Request,
  47. body = Depends(remove_xss_json),
  48. db: Session = Depends(get_db),
  49. user_id = Depends(valid_access_token)
  50. ):
  51. userid = get_req_param_optional(body, "userid")
  52. if userid == "":
  53. user_info = db.query(AvconUser).filter(AvconUser.user_id).first()
  54. if user_info is None:
  55. return {
  56. "code": 500,
  57. "msg": "当前账号对应的融合设备为空,请联系管理员配置。"
  58. }
  59. userid = user_info.dev_id
  60. password = get_req_param_optional(body, "password")
  61. if password == "":
  62. password = "123"
  63. windowpos = get_req_param(body, "windowpos")
  64. x = windowpos['x']
  65. y = windowpos['y']
  66. width = windowpos['width']
  67. height = windowpos['height']
  68. top = windowpos['top']
  69. # 进入会议后需要广播的人员列表
  70. members = get_req_param(body, "members")
  71. params = {
  72. "mode": "mini",
  73. "cmd": "enterroom",
  74. "serverip": "19.152.196.106",
  75. "userid": userid,
  76. "password": password,
  77. "windowpos": {"x": x,"y": y,"width": width,"height": height,"top": top},
  78. "members": members
  79. }
  80. logger.info("发起融合通信mini客户端: {}", params)
  81. json_str = json.dumps(params, ensure_ascii=False)
  82. base64_str = base64.b64encode(json_str.encode('utf-8')).decode('utf-8')
  83. try:
  84. user_info = db_user.get_user_info(db, user_id)
  85. db_czrz.log_username(db, user_id, mpfun.dec_data(user_info.user_name), user_info.nick_name, "应急一张图", "发起会议", request.client.host)
  86. except:
  87. traceback.print_exc()
  88. return {
  89. "code": 0,
  90. "msg": "success",
  91. "data": "" + "avcon6://" + base64_str
  92. }
  93. @router.post("/get_start_mini_with_no_param")
  94. async def get_start_mini_param(
  95. body = Depends(remove_xss_json),
  96. db: Session = Depends(get_db),
  97. user_id = Depends(valid_access_token)
  98. ):
  99. userid = get_req_param_optional(body, "userid")
  100. if userid == "":
  101. user_info = db.query(AvconUser).filter(AvconUser.user_id).first()
  102. if user_info is None:
  103. return {
  104. "code": 500,
  105. "msg": "当前账号对应的融合设备为空,请联系管理员配置。"
  106. }
  107. userid = user_info.dev_id
  108. password = get_req_param_optional(body, "password")
  109. if password == "":
  110. password = "123"
  111. roomcode = get_req_param_optional(body, "roomcode")
  112. windowpos = get_req_param(body, "windowpos")
  113. x = windowpos['x']
  114. y = windowpos['y']
  115. width = windowpos['width']
  116. height = windowpos['height']
  117. top = windowpos['top']
  118. params = {
  119. "mode": "mini",
  120. "cmd": "enterroom",
  121. "serverip": "19.152.196.106",
  122. "userid": userid,
  123. "password": password,
  124. "roomcode": roomcode,
  125. "windowpos": {"x": x,"y": y,"width": width,"height": height,"top": top},
  126. }
  127. logger.info("发起融合通信mini客户端入会: {}", params)
  128. json_str = json.dumps(params, ensure_ascii=False)
  129. base64_str = base64.b64encode(json_str.encode('utf-8')).decode('utf-8')
  130. return {
  131. "code": 0,
  132. "msg": "success",
  133. "data": "" + "avcon6://" + base64_str
  134. }
  135. # 视频会商
  136. @router.get("/get_device_tree")
  137. async def get_device_tree(
  138. body = Depends(remove_xss_json),
  139. db: Session = Depends(get_db),
  140. user_id = Depends(valid_access_token)
  141. ):
  142. try:
  143. result = []
  144. data = AvconH5API.get_search_region("指挥终端")
  145. if data is not None:
  146. result1 = []
  147. fomat_device_group_result(data[0], result1)
  148. result.append({
  149. "id": data[0]["group_id"],
  150. "label": data[0]["group_name"],
  151. "children": result1
  152. })
  153. data = AvconH5API.get_search_region("H323会议视频")
  154. if data is not None:
  155. result1 = []
  156. fomat_device_group_result(data[0], result1)
  157. result.append({
  158. "id": data[0]["group_id"],
  159. "label": data[0]["group_name"],
  160. "children": result1
  161. })
  162. data = AvconH5API.get_search_region("手机App")
  163. if data is not None:
  164. result1 = []
  165. fomat_device_group_result(data[0], result1)
  166. result.append({
  167. "id": data[0]["group_id"],
  168. "label": data[0]["group_name"],
  169. "children": result1
  170. })
  171. return {
  172. "code": 0,
  173. "msg": "success",
  174. "data": result
  175. }
  176. except Exception as e:
  177. traceback.print_exc()
  178. return {
  179. "code": 0,
  180. "msg": "无法获取视频终端",
  181. "data": []
  182. }
  183. #
  184. #return {
  185. # "code": 500,
  186. # "msg": "无法获取视频终端"
  187. #}
  188. def fomat_device_group_result(data: dict, result: dict) -> dict:
  189. if "child_group" in data:
  190. for n in data["child_group"]:
  191. new_item = {
  192. "id": n['group_id'],
  193. "label": n['group_name'],
  194. "order_id": n['order_id']
  195. }
  196. result1 = []
  197. fomat_device_result(n, result1)
  198. new_item["children"] = result1
  199. result.append(new_item)
  200. @router.get("/get_device_list/{group_id}")
  201. async def get_device_list(
  202. group_id: str,
  203. body = Depends(remove_xss_json),
  204. db: Session = Depends(get_db),
  205. user_id = Depends(valid_access_token)
  206. ):
  207. try:
  208. result = []
  209. data = AvconH5API.get_group_device(group_id=group_id)
  210. for n in data:
  211. new_item = {
  212. "id": n['dev_id'],
  213. "name": n['dev_name'],
  214. "dept": get_avcon_type_text(n['dev_type']),
  215. "mobile": n['dev_id']
  216. }
  217. result.append(new_item)
  218. return {
  219. "code": 0,
  220. "msg": "success",
  221. "data": result
  222. }
  223. except Exception as e:
  224. traceback.print_exc()
  225. return {
  226. "code": 200,
  227. "msg": "无法获取视频终端",
  228. "data": []
  229. }
  230. def get_avcon_type_text(type: str) -> str:
  231. if type == '001':
  232. return '指挥视频终端'
  233. elif type == '060':
  234. return '营区监控'
  235. elif type == '085':
  236. return '监控网关服务器'
  237. elif type == '100':
  238. return 'H.323终端'
  239. return "未知终端"
  240. # 无人机
  241. @router.get("/get_drone_tree")
  242. async def get_drone_tree(
  243. equipment: str = Query('', description='设备类型'),
  244. body = Depends(remove_xss_json),
  245. db: Session = Depends(get_db),
  246. user_id = Depends(valid_access_token)
  247. ):
  248. try:
  249. result = []
  250. if equipment == '无人机':
  251. # 无人机没有和茂名市局对接,所以只能在融合通信PC端看,下面反馈的静态数据仅供界面有内容看
  252. result = [
  253. {
  254. "id": "1",
  255. "label": '茂名应急无人机'
  256. }
  257. ]
  258. return {
  259. "code": 0,
  260. "msg": "success",
  261. "data": result
  262. }
  263. elif equipment == '单兵设备':
  264. data = AvconH5API.get_search_region("无人机视频")
  265. if data is not None:
  266. result1 = []
  267. fomat_device_result(data[0], result1)
  268. for n in result1:
  269. if n['label'].find("单兵") != -1:
  270. result.append(n)
  271. return {
  272. "code": 0,
  273. "msg": "success",
  274. "data": result
  275. # "data": [{"id": "1", "label": "无人机单兵", "children": result}]
  276. }
  277. '''
  278. if result == []:
  279. result = [
  280. {
  281. "label": '无人机设备',
  282. "children": [
  283. {
  284. "label": '茂名市应急管理局',
  285. "children": [
  286. {
  287. "id": "1",
  288. "label": '应急无人机(例子1)',
  289. "url": "http://19.152.196.223:5050/liveplay.html?liveurl=ws://10.100.100.103:9001/live/mmjk0002@mm.zw.yj_00.flv&channelid=mmjk0002@mm.zw.yj_00"
  290. }
  291. ]
  292. },
  293. {
  294. "label": '电白区应急管理局',
  295. "children": [
  296. {
  297. "id": "2",
  298. "label": '应急无人机(例子2)',
  299. "url": "http://19.152.196.223:5050/liveplay.html?liveurl=ws://10.100.100.103:9001/live/mmjk0002@mm.zw.yj_00.flv&channelid=mmjk0002@mm.zw.yj_00"
  300. }
  301. ]
  302. },
  303. {
  304. "label": '茂南区应急管理局',
  305. "children": [
  306. {
  307. "id": "3",
  308. "label": '应急无人机(例子3)',
  309. "url": "http://19.152.196.223:5050/liveplay.html?liveurl=ws://10.100.100.103:9001/live/mmjk0002@mm.zw.yj_00.flv&channelid=mmjk0002@mm.zw.yj_00"
  310. }
  311. ]
  312. }
  313. ]
  314. }
  315. ]
  316. '''
  317. except Exception as e:
  318. traceback.print_exc()
  319. return {
  320. "code": 200,
  321. "msg": "无法获取视频终端",
  322. "data": []
  323. }
  324. def fomat_device_result(data: dict, result: dict) -> dict:
  325. if "child_group" in data:
  326. for n in data["child_group"]:
  327. new_item = {
  328. "id": n['group_id'],
  329. "label": n['group_name'],
  330. "order_id": n['order_id']
  331. }
  332. result1 = []
  333. fomat_device_result(n, result1)
  334. new_item["children"] = result1
  335. result.append(new_item)
  336. if "child_device" in data:
  337. for n in data["child_device"]:
  338. new_item = {
  339. "id": n['dev_id'],
  340. "label": n['dev_name'],
  341. "dev_type": n['dev_type'],
  342. # "order_id": n['order_id'],
  343. "isLeaf": True
  344. }
  345. result.append(new_item)
  346. # 手机工作台
  347. @router.post("/get_mobile_workstation_info")
  348. async def get_mobile_workstation_info(
  349. db: Session = Depends(get_db),
  350. body = Depends(remove_xss_json),
  351. user_id = Depends(valid_access_token)
  352. ):
  353. try:
  354. current = body['current']
  355. size = body['size']
  356. keywords = body['query']['keywords']
  357. result = []
  358. total = 0
  359. data = AvconH5API.get_search_region("手机App")
  360. if data is not None:
  361. for n in data[0]['child_device']:
  362. dev_id = n['dev_id']
  363. dev_name = n['dev_name']
  364. if keywords == "" or dev_name.find(keywords) != -1:
  365. result.append({
  366. "dev_id": dev_id,
  367. "dev_name": dev_name
  368. })
  369. total = len(result)
  370. result = paginate(result, size, current)
  371. return {
  372. "code": 0,
  373. "msg": "success",
  374. "data": result,
  375. "total": total
  376. }
  377. except Exception as e:
  378. traceback.print_exc()
  379. return {
  380. "code": 200,
  381. "msg": "无法获取视频终端",
  382. "data": [],
  383. "total": 0
  384. }
  385. # 移动指挥车
  386. @router.post("/get_mobile_command_vehicle_list_info")
  387. async def get_mobile_command_vehicle_list_info(
  388. db: Session = Depends(get_db),
  389. body = Depends(remove_xss_json),
  390. user_id = Depends(valid_access_token)
  391. ):
  392. try:
  393. current = body['current']
  394. size = body['size']
  395. keywords = body['query']['keywords']
  396. result = []
  397. total = 0
  398. data = AvconH5API.get_search_region("指挥终端")
  399. if data is not None:
  400. for n in data[0]['child_device']:
  401. dev_id = n['dev_id']
  402. dev_name = n['dev_name']
  403. if keywords == "" or dev_name.find(keywords) != -1:
  404. result.append({
  405. "dev_id": dev_id,
  406. "dev_name": dev_name
  407. })
  408. total = len(result)
  409. result = paginate(result, size, current)
  410. return {
  411. "code": 0,
  412. "msg": "success",
  413. "data": result,
  414. "total": total
  415. }
  416. except Exception as e:
  417. traceback.print_exc()
  418. return {
  419. "code": 200,
  420. "msg": "无法获取视频终端",
  421. "data": [],
  422. "total": 0
  423. }
  424. def paginate(array, page_size, page_number):
  425. start_index = (page_number - 1) * page_size
  426. end_index = start_index + page_size
  427. return array[start_index:end_index]