123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- from fastapi import APIRouter, Request, Depends,Query,HTTPException
- from database import get_db
- from sqlalchemy.orm import Session
- from sqlalchemy import case,or_
- from sqlalchemy import text
- from utils import *
- from utils.ry_system_util import *
- from utils.video_util import *
- from common.security import valid_access_token
- from fastapi.responses import JSONResponse
- import traceback
- import base64
- from datetime import datetime
- from common import AvconH5API, AvconMiniAPI
- from models import *
- '''
- 融合通信相关接口
- '''
- router = APIRouter()
- @router.get('/get_video_list')
- async def get_video_list(
- db: Session = Depends(get_db),
- user_id=Depends(valid_access_token)
- ):
- return AvconH5API.get_channel_all()
- @router.get('/get_mini_video_list')
- async def get_mini_video_list(
- db: Session = Depends(get_db)
- ):
- # domain = AvconMiniAPI.get_config("DOMAIN")
- # rsa_public_key = AvconMiniAPI.get_config("RSA_PUBLIC_KEY")
- # return domain + " / " + rsa_public_key
- # return AvconMiniAPI.get_group_page()
- # return AvconMiniAPI.get_group_device("G6@mm.zw.yj")
- # return AvconMiniAPI.get_device_info("19.152.196.150@mm.zw.yj")
- # return AvconMiniAPI.get_device_all()
- # return AvconMiniAPI.get_device_channel("19.152.196.150@mm.zw.yj")
- # return AvconMiniAPI.get_device_channel_gps("19.152.196.150@mm.zw.yj")
- return AvconMiniAPI.get_channel_all()
- @router.post("/get_start_mini_param")
- async def get_start_mini_param(
- body = Depends(remove_xss_json),
- db: Session = Depends(get_db),
- user_id = Depends(valid_access_token)
- ):
- userid = get_req_param_optional(body, "userid")
- if userid == "":
- user_info = db.query(AvconUser).filter(AvconUser.user_id).first()
- if user_info is None:
- return {
- "code": 500,
- "msg": "当前账号对应的融合设备为空,请联系管理员配置。"
- }
- userid = user_info.dev_id
- password = get_req_param_optional(body, "password")
- if password == "":
- password = "123"
- windowpos = get_req_param(body, "windowpos")
- x = windowpos['x']
- y = windowpos['y']
- width = windowpos['width']
- height = windowpos['height']
- top = windowpos['top']
- # 进入会议后需要广播的人员列表
- members = get_req_param(body, "members")
- params = {
- "mode": "mini",
- "cmd": "enterroom",
- "serverip": "19.152.196.106",
- "userid": userid,
- "password": password,
- "windowpos": {"x": x,"y": y,"width": width,"height": height,"top": top},
- "members": members
- }
-
- logger.info("发起融合通信mini客户端: {}", params)
- json_str = json.dumps(params, ensure_ascii=False)
- base64_str = base64.b64encode(json_str.encode('utf-8')).decode('utf-8')
- return {
- "code": 0,
- "msg": "success",
- "data": "" + "avcon6://" + base64_str
- }
- @router.post("/get_start_mini_with_no_param")
- async def get_start_mini_param(
- body = Depends(remove_xss_json),
- db: Session = Depends(get_db),
- user_id = Depends(valid_access_token)
- ):
- userid = get_req_param_optional(body, "userid")
- if userid == "":
- user_info = db.query(AvconUser).filter(AvconUser.user_id).first()
- if user_info is None:
- return {
- "code": 500,
- "msg": "当前账号对应的融合设备为空,请联系管理员配置。"
- }
- userid = user_info.dev_id
- password = get_req_param_optional(body, "password")
- if password == "":
- password = "123"
- roomcode = get_req_param_optional(body, "roomcode")
- windowpos = get_req_param(body, "windowpos")
- x = windowpos['x']
- y = windowpos['y']
- width = windowpos['width']
- height = windowpos['height']
- top = windowpos['top']
- params = {
- "mode": "mini",
- "cmd": "enterroom",
- "serverip": "19.152.196.106",
- "userid": userid,
- "password": password,
- "roomcode": roomcode,
- "windowpos": {"x": x,"y": y,"width": width,"height": height,"top": top},
- }
-
- logger.info("发起融合通信mini客户端入会: {}", params)
- json_str = json.dumps(params, ensure_ascii=False)
- base64_str = base64.b64encode(json_str.encode('utf-8')).decode('utf-8')
- return {
- "code": 0,
- "msg": "success",
- "data": "" + "avcon6://" + base64_str
- }
- # 视频会商
- @router.get("/get_device_tree")
- async def get_device_tree(
- body = Depends(remove_xss_json),
- db: Session = Depends(get_db),
- user_id = Depends(valid_access_token)
- ):
- try:
- result = []
- data = AvconH5API.get_search_region("指挥终端")
- if data is not None:
- result1 = []
- fomat_device_group_result(data[0], result1)
- result.append({
- "id": data[0]["group_id"],
- "label": data[0]["group_name"],
- "children": result1
- })
-
- data = AvconH5API.get_search_region("H323会议视频")
- if data is not None:
- result1 = []
- fomat_device_group_result(data[0], result1)
- result.append({
- "id": data[0]["group_id"],
- "label": data[0]["group_name"],
- "children": result1
- })
-
- data = AvconH5API.get_search_region("手机App")
- if data is not None:
- result1 = []
- fomat_device_group_result(data[0], result1)
- result.append({
- "id": data[0]["group_id"],
- "label": data[0]["group_name"],
- "children": result1
- })
- return {
- "code": 0,
- "msg": "success",
- "data": result
- }
- except Exception as e:
- traceback.print_exc()
- return {
- "code": 0,
- "msg": "无法获取视频终端",
- "data": []
- }
-
- #
- #return {
- # "code": 500,
- # "msg": "无法获取视频终端"
- #}
-
- def fomat_device_group_result(data: dict, result: dict) -> dict:
- if "child_group" in data:
- for n in data["child_group"]:
- new_item = {
- "id": n['group_id'],
- "label": n['group_name'],
- "order_id": n['order_id']
- }
- result1 = []
- fomat_device_result(n, result1)
- new_item["children"] = result1
- result.append(new_item)
-
- @router.get("/get_device_list/{group_id}")
- async def get_device_list(
- group_id: str,
- body = Depends(remove_xss_json),
- db: Session = Depends(get_db),
- user_id = Depends(valid_access_token)
- ):
- try:
- result = []
- data = AvconH5API.get_group_device(group_id=group_id)
- for n in data:
- new_item = {
- "id": n['dev_id'],
- "name": n['dev_name'],
- "dept": get_avcon_type_text(n['dev_type']),
- "mobile": n['dev_id']
- }
- result.append(new_item)
- return {
- "code": 0,
- "msg": "success",
- "data": result
- }
- except Exception as e:
- traceback.print_exc()
- return {
- "code": 500,
- "msg": "无法获取视频终端"
- }
- def get_avcon_type_text(type: str) -> str:
- if type == '001':
- return '指挥视频终端'
- elif type == '060':
- return '营区监控'
- elif type == '085':
- return '监控网关服务器'
- elif type == '100':
- return 'H.323终端'
-
- return "未知终端"
- # 无人机
- @router.get("/get_drone_tree")
- async def get_drone_tree(
- equipment: str = Query('', description='设备类型'),
- body = Depends(remove_xss_json),
- db: Session = Depends(get_db),
- user_id = Depends(valid_access_token)
- ):
- try:
- result = []
- equipment_type = "无人机视频"
- print('equipment:', equipment)
- data = AvconH5API.get_search_region(equipment_type)
- if data is not None:
- result1 = []
- fomat_device_result(data[0], result1)
- result.append({
- "id": data[0]["group_id"],
- "label": data[0]["group_name"],
- "children": result1
- })
- result = [
- {
- "label": '无人机设备',
- "children": [
- {
- "label": '茂名市应急管理局',
- "children": [
- {
- "id": "1",
- "label": '应急无人机(例子1)',
- "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"
- }
- ]
- },
- {
- "label": '电白区应急管理局',
- "children": [
- {
- "id": "2",
- "label": '应急无人机(例子2)',
- "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"
- }
- ]
- },
- {
- "label": '茂南区应急管理局',
- "children": [
- {
- "id": "3",
- "label": '应急无人机(例子3)',
- "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"
- }
- ]
- }
- ]
- }
- ]
-
- return {
- "code": 0,
- "msg": "success",
- "data": result
- }
- except Exception as e:
- traceback.print_exc()
- return {
- "code": 200,
- "msg": "无法获取视频终端",
- "data": []
- }
-
- def fomat_device_result(data: dict, result: dict) -> dict:
- if "child_group" in data:
- for n in data["child_group"]:
- new_item = {
- "id": n['group_id'],
- "label": n['group_name'],
- "order_id": n['order_id']
- }
- result1 = []
- fomat_device_result(n, result1)
- new_item["children"] = result1
- result.append(new_item)
- if "child_device" in data:
- for n in data["child_device"]:
- new_item = {
- "id": n['dev_id'],
- "label": n['dev_name'],
- "dev_type": n['dev_type'],
- # "order_id": n['order_id'],
- "isLeaf": True
- }
- result.append(new_item)
|