avcon.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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": 500,
  172. "msg": "无法获取视频终端"
  173. }
  174. def fomat_device_group_result(data: dict, result: dict) -> dict:
  175. if "child_group" in data:
  176. for n in data["child_group"]:
  177. new_item = {
  178. "id": n['group_id'],
  179. "label": n['group_name'],
  180. "order_id": n['order_id']
  181. }
  182. result1 = []
  183. fomat_device_result(n, result1)
  184. new_item["children"] = result1
  185. result.append(new_item)
  186. @router.get("/get_device_list/{group_id}")
  187. async def get_device_list(
  188. group_id: str,
  189. body = Depends(remove_xss_json),
  190. db: Session = Depends(get_db),
  191. user_id = Depends(valid_access_token)
  192. ):
  193. try:
  194. result = []
  195. data = AvconH5API.get_group_device(group_id=group_id)
  196. for n in data:
  197. new_item = {
  198. "id": n['dev_id'],
  199. "name": n['dev_name'],
  200. "dept": get_avcon_type_text(n['dev_type']),
  201. "mobile": n['dev_id']
  202. }
  203. result.append(new_item)
  204. return {
  205. "code": 0,
  206. "msg": "success",
  207. "data": result
  208. }
  209. except Exception as e:
  210. traceback.print_exc()
  211. return {
  212. "code": 500,
  213. "msg": "无法获取视频终端"
  214. }
  215. def get_avcon_type_text(type: str) -> str:
  216. if type == '001':
  217. return '指挥视频终端'
  218. elif type == '060':
  219. return '营区监控'
  220. elif type == '085':
  221. return '监控网关服务器'
  222. elif type == '100':
  223. return 'H.323终端'
  224. return "未知终端"
  225. # 无人机
  226. @router.get("/get_drone_tree")
  227. async def get_drone_tree(
  228. equipment: str = Query('', description='设备类型'),
  229. body = Depends(remove_xss_json),
  230. db: Session = Depends(get_db),
  231. user_id = Depends(valid_access_token)
  232. ):
  233. try:
  234. result = []
  235. equipment_type = "无人机视频"
  236. print('equipment:', equipment)
  237. data = AvconH5API.get_search_region(equipment_type)
  238. if data is not None:
  239. result1 = []
  240. fomat_device_result(data[0], result1)
  241. result.append({
  242. "id": data[0]["group_id"],
  243. "label": data[0]["group_name"],
  244. "children": result1
  245. })
  246. result = [
  247. {
  248. "label": '无人机设备',
  249. "children": [
  250. {
  251. "label": '茂名市应急管理局',
  252. "children": [
  253. {
  254. "id": "1",
  255. "label": '应急无人机(例子1)',
  256. "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"
  257. }
  258. ]
  259. },
  260. {
  261. "label": '电白区应急管理局',
  262. "children": [
  263. {
  264. "id": "2",
  265. "label": '应急无人机(例子2)',
  266. "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"
  267. }
  268. ]
  269. },
  270. {
  271. "label": '茂南区应急管理局',
  272. "children": [
  273. {
  274. "id": "3",
  275. "label": '应急无人机(例子3)',
  276. "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"
  277. }
  278. ]
  279. }
  280. ]
  281. }
  282. ]
  283. return {
  284. "code": 0,
  285. "msg": "success",
  286. "data": result
  287. }
  288. except Exception as e:
  289. traceback.print_exc()
  290. return {
  291. "code": 500,
  292. "msg": "无法获取视频终端"
  293. }
  294. def fomat_device_result(data: dict, result: dict) -> dict:
  295. if "child_group" in data:
  296. for n in data["child_group"]:
  297. new_item = {
  298. "id": n['group_id'],
  299. "label": n['group_name'],
  300. "order_id": n['order_id']
  301. }
  302. result1 = []
  303. fomat_device_result(n, result1)
  304. new_item["children"] = result1
  305. result.append(new_item)
  306. if "child_device" in data:
  307. for n in data["child_device"]:
  308. new_item = {
  309. "id": n['dev_id'],
  310. "label": n['dev_name'],
  311. "dev_type": n['dev_type'],
  312. # "order_id": n['order_id'],
  313. "isLeaf": True
  314. }
  315. result.append(new_item)