avcon.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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 import AvconH5API, AvconMiniAPI
  17. from models import *
  18. '''
  19. 融合通信相关接口
  20. '''
  21. router = APIRouter()
  22. @router.get('/get_video_list')
  23. async def get_video_list(
  24. db: Session = Depends(get_db),
  25. user_id=Depends(valid_access_token)
  26. ):
  27. return AvconH5API.get_channel_all()
  28. @router.get('/get_mini_video_list')
  29. async def get_mini_video_list(
  30. db: Session = Depends(get_db)
  31. ):
  32. # domain = AvconMiniAPI.get_config("DOMAIN")
  33. # rsa_public_key = AvconMiniAPI.get_config("RSA_PUBLIC_KEY")
  34. # return domain + " / " + rsa_public_key
  35. # return AvconMiniAPI.get_group_page()
  36. # return AvconMiniAPI.get_group_device("G6@mm.zw.yj")
  37. # return AvconMiniAPI.get_device_info("19.152.196.150@mm.zw.yj")
  38. # return AvconMiniAPI.get_device_all()
  39. # return AvconMiniAPI.get_device_channel("19.152.196.150@mm.zw.yj")
  40. # return AvconMiniAPI.get_device_channel_gps("19.152.196.150@mm.zw.yj")
  41. return AvconMiniAPI.get_channel_all()
  42. @router.post("/get_start_mini_param")
  43. async def get_start_mini_param(
  44. body = Depends(remove_xss_json),
  45. db: Session = Depends(get_db),
  46. user_id = Depends(valid_access_token)
  47. ):
  48. userid = get_req_param_optional(body, "userid")
  49. if userid == "":
  50. user_info = db.query(AvconUser).filter(AvconUser.user_id).first()
  51. if user_info is None:
  52. return {
  53. "code": 500,
  54. "msg": "当前账号对应的融合设备为空,请联系管理员配置。"
  55. }
  56. userid = user_info.dev_id
  57. password = get_req_param_optional(body, "password")
  58. if password == "":
  59. password = "123"
  60. windowpos = get_req_param(body, "windowpos")
  61. x = windowpos['x']
  62. y = windowpos['y']
  63. width = windowpos['width']
  64. height = windowpos['height']
  65. top = windowpos['top']
  66. # 进入会议后需要广播的人员列表
  67. members = get_req_param(body, "members")
  68. params = {
  69. "mode": "mini",
  70. "cmd": "enterroom",
  71. "serverip": "19.152.196.106",
  72. "userid": userid,
  73. "password": password,
  74. "windowpos": {"x": x,"y": y,"width": width,"height": height,"top": top},
  75. "members": members
  76. }
  77. logger.info("发起融合通信mini客户端: {}", params)
  78. json_str = json.dumps(params, ensure_ascii=False)
  79. base64_str = base64.b64encode(json_str.encode('utf-8')).decode('utf-8')
  80. return {
  81. "code": 0,
  82. "msg": "success",
  83. "data": "" + "avcon6://" + base64_str
  84. }
  85. @router.post("/get_start_mini_with_no_param")
  86. async def get_start_mini_param(
  87. body = Depends(remove_xss_json),
  88. db: Session = Depends(get_db),
  89. user_id = Depends(valid_access_token)
  90. ):
  91. userid = get_req_param_optional(body, "userid")
  92. if userid == "":
  93. user_info = db.query(AvconUser).filter(AvconUser.user_id).first()
  94. if user_info is None:
  95. return {
  96. "code": 500,
  97. "msg": "当前账号对应的融合设备为空,请联系管理员配置。"
  98. }
  99. userid = user_info.dev_id
  100. password = get_req_param_optional(body, "password")
  101. if password == "":
  102. password = "123"
  103. roomcode = get_req_param_optional(body, "roomcode")
  104. windowpos = get_req_param(body, "windowpos")
  105. x = windowpos['x']
  106. y = windowpos['y']
  107. width = windowpos['width']
  108. height = windowpos['height']
  109. top = windowpos['top']
  110. params = {
  111. "mode": "mini",
  112. "cmd": "enterroom",
  113. "serverip": "19.152.196.106",
  114. "userid": userid,
  115. "password": password,
  116. "roomcode": roomcode,
  117. "windowpos": {"x": x,"y": y,"width": width,"height": height,"top": top},
  118. }
  119. logger.info("发起融合通信mini客户端入会: {}", params)
  120. json_str = json.dumps(params, ensure_ascii=False)
  121. base64_str = base64.b64encode(json_str.encode('utf-8')).decode('utf-8')
  122. return {
  123. "code": 0,
  124. "msg": "success",
  125. "data": "" + "avcon6://" + base64_str
  126. }
  127. # 视频会商
  128. @router.get("/get_device_tree")
  129. async def get_device_tree(
  130. body = Depends(remove_xss_json),
  131. db: Session = Depends(get_db),
  132. user_id = Depends(valid_access_token)
  133. ):
  134. try:
  135. result = []
  136. data = AvconH5API.get_search_region("指挥终端")
  137. if data is not None:
  138. result1 = []
  139. fomat_device_group_result(data[0], result1)
  140. result.append({
  141. "id": data[0]["group_id"],
  142. "label": data[0]["group_name"],
  143. "children": result1
  144. })
  145. data = AvconH5API.get_search_region("H323会议视频")
  146. if data is not None:
  147. result1 = []
  148. fomat_device_group_result(data[0], result1)
  149. result.append({
  150. "id": data[0]["group_id"],
  151. "label": data[0]["group_name"],
  152. "children": result1
  153. })
  154. data = AvconH5API.get_search_region("手机App")
  155. if data is not None:
  156. result1 = []
  157. fomat_device_group_result(data[0], result1)
  158. result.append({
  159. "id": data[0]["group_id"],
  160. "label": data[0]["group_name"],
  161. "children": result1
  162. })
  163. return {
  164. "code": 0,
  165. "msg": "success",
  166. "data": result
  167. }
  168. except Exception as e:
  169. traceback.print_exc()
  170. return {
  171. "code": 0,
  172. "msg": "无法获取视频终端",
  173. "data": []
  174. }
  175. #
  176. #return {
  177. # "code": 500,
  178. # "msg": "无法获取视频终端"
  179. #}
  180. def fomat_device_group_result(data: dict, result: dict) -> dict:
  181. if "child_group" in data:
  182. for n in data["child_group"]:
  183. new_item = {
  184. "id": n['group_id'],
  185. "label": n['group_name'],
  186. "order_id": n['order_id']
  187. }
  188. result1 = []
  189. fomat_device_result(n, result1)
  190. new_item["children"] = result1
  191. result.append(new_item)
  192. @router.get("/get_device_list/{group_id}")
  193. async def get_device_list(
  194. group_id: str,
  195. body = Depends(remove_xss_json),
  196. db: Session = Depends(get_db),
  197. user_id = Depends(valid_access_token)
  198. ):
  199. try:
  200. result = []
  201. data = AvconH5API.get_group_device(group_id=group_id)
  202. for n in data:
  203. new_item = {
  204. "id": n['dev_id'],
  205. "name": n['dev_name'],
  206. "dept": get_avcon_type_text(n['dev_type']),
  207. "mobile": n['dev_id']
  208. }
  209. result.append(new_item)
  210. return {
  211. "code": 0,
  212. "msg": "success",
  213. "data": result
  214. }
  215. except Exception as e:
  216. traceback.print_exc()
  217. return {
  218. "code": 500,
  219. "msg": "无法获取视频终端"
  220. }
  221. def get_avcon_type_text(type: str) -> str:
  222. if type == '001':
  223. return '指挥视频终端'
  224. elif type == '060':
  225. return '营区监控'
  226. elif type == '085':
  227. return '监控网关服务器'
  228. elif type == '100':
  229. return 'H.323终端'
  230. return "未知终端"
  231. # 无人机
  232. @router.get("/get_drone_tree")
  233. async def get_drone_tree(
  234. equipment: str = Query('', description='设备类型'),
  235. body = Depends(remove_xss_json),
  236. db: Session = Depends(get_db),
  237. user_id = Depends(valid_access_token)
  238. ):
  239. try:
  240. result = []
  241. equipment_type = "无人机视频"
  242. print('equipment:', equipment)
  243. data = AvconH5API.get_search_region(equipment_type)
  244. if data is not None:
  245. result1 = []
  246. fomat_device_result(data[0], result1)
  247. result.append({
  248. "id": data[0]["group_id"],
  249. "label": data[0]["group_name"],
  250. "children": result1
  251. })
  252. result = [
  253. {
  254. "label": '无人机设备',
  255. "children": [
  256. {
  257. "label": '茂名市应急管理局',
  258. "children": [
  259. {
  260. "id": "1",
  261. "label": '应急无人机(例子1)',
  262. "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"
  263. }
  264. ]
  265. },
  266. {
  267. "label": '电白区应急管理局',
  268. "children": [
  269. {
  270. "id": "2",
  271. "label": '应急无人机(例子2)',
  272. "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"
  273. }
  274. ]
  275. },
  276. {
  277. "label": '茂南区应急管理局',
  278. "children": [
  279. {
  280. "id": "3",
  281. "label": '应急无人机(例子3)',
  282. "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"
  283. }
  284. ]
  285. }
  286. ]
  287. }
  288. ]
  289. return {
  290. "code": 0,
  291. "msg": "success",
  292. "data": result
  293. }
  294. except Exception as e:
  295. traceback.print_exc()
  296. return {
  297. "code": 200,
  298. "msg": "无法获取视频终端",
  299. "data": []
  300. }
  301. def fomat_device_result(data: dict, result: dict) -> dict:
  302. if "child_group" in data:
  303. for n in data["child_group"]:
  304. new_item = {
  305. "id": n['group_id'],
  306. "label": n['group_name'],
  307. "order_id": n['order_id']
  308. }
  309. result1 = []
  310. fomat_device_result(n, result1)
  311. new_item["children"] = result1
  312. result.append(new_item)
  313. if "child_device" in data:
  314. for n in data["child_device"]:
  315. new_item = {
  316. "id": n['dev_id'],
  317. "label": n['dev_name'],
  318. "dev_type": n['dev_type'],
  319. # "order_id": n['order_id'],
  320. "isLeaf": True
  321. }
  322. result.append(new_item)