|
|
@@ -4,11 +4,12 @@ from django.core.cache import cache as default_cache
|
|
|
|
|
|
import json
|
|
|
import ast
|
|
|
+import requests
|
|
|
|
|
|
from django.conf import settings
|
|
|
from .serializers import SearchEquipSerializer, DeviceDetailSerializer
|
|
|
from utils.JWTAuthentication_diy import APIAuthentication
|
|
|
-from utils.permissions import QXZDeviceDetailPermission, ScdDeviceDetailPermission, CbdDeviceDetailPermission, BzyDeviceDetailPermission, XycbDeviceDetailPermission, XctDeviceDetailPermission, GssqDeviceDetailPermission
|
|
|
+from utils.permissions import QXZDeviceDetailPermission, ScdDeviceDetailPermission, CbdDeviceDetailPermission, BzyDeviceDetailPermission, XycbDeviceDetailPermission, XctDeviceDetailPermission, GssqDeviceDetailPermission, JkDeviceDetailPermission
|
|
|
from utils.MyRateThrottle import DeviceDetailRateThrottle, DevicePhotoRateThrottle, QxzDeviceListRateThrottle, ScdDeviceListRateThrottle, CbdDeviceListRateThrottle, BzyDeviceListRateThrottle, XycbDeviceListRateThrottle, XctDeviceListRateThrottle, GssqDeviceListRateThrottle
|
|
|
from utils.utils import DeviceInfoUtils
|
|
|
from utils.db_utils import MongoDBTools
|
|
|
@@ -1016,4 +1017,102 @@ class GssqDeviceDetailView(APIView):
|
|
|
device_data = ast.literal_eval(item)
|
|
|
|
|
|
result["items"].append({"uptime":item["upl_time"],"item_data":device_data})
|
|
|
- return Response(result)
|
|
|
+ return Response(result)
|
|
|
+
|
|
|
+
|
|
|
+class JkDevicePlayAddressView(APIView):
|
|
|
+ authentication_classes = [APIAuthentication]
|
|
|
+ permission_classes = [JkDeviceDetailPermission]
|
|
|
+
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
+ serializer = DeviceDetailSerializer(data=request.query_params)
|
|
|
+ serializer.is_valid(raise_exception=True)
|
|
|
+ request_data = serializer.validated_data
|
|
|
+ print(request_data)
|
|
|
+ uid = request.user
|
|
|
+ jk_dict_cache = default_cache.get(str(uid)+"_jk_list")
|
|
|
+ if jk_dict_cache:
|
|
|
+ d_id = jk_dict_cache[request_data["device_id"]]
|
|
|
+ else:
|
|
|
+ """避免缓存失效"""
|
|
|
+ wheres = {
|
|
|
+ 'device_type_id':12,
|
|
|
+ '$or': [
|
|
|
+ {'owner_uid': uid},
|
|
|
+ {'user_dealer': uid}
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ project = {
|
|
|
+ 'id': '$id',
|
|
|
+ 'device_id': '$device_id'
|
|
|
+ }
|
|
|
+ m = MongoDBTools(db_name='smartfarming', table_name='sa_device')
|
|
|
+ data = m.find_many(wheres=wheres, options=project)
|
|
|
+ jk_dict_cache = []
|
|
|
+ for item in data:
|
|
|
+ jk_dict_cache[item["device_id"]]=item["id"]
|
|
|
+ default_cache.set(str(uid)+"_jk_list", jk_dict_cache,60*5)
|
|
|
+ d_id = jk_dict_cache[request_data["device_id"]]
|
|
|
+
|
|
|
+ result = {"total_counts":0,"itmes":[]}
|
|
|
+
|
|
|
+ data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_camera')
|
|
|
+ data_wheres = {
|
|
|
+ "device_id": request_data["device_id"],
|
|
|
+ }
|
|
|
+ print(data_wheres)
|
|
|
+ data = data_m.find_one(data_wheres)
|
|
|
+ print(data)
|
|
|
+ addr = data["device_info"]
|
|
|
+ account_id = data["account_id"]
|
|
|
+ MongoCameraAccount = MongoDBTools(db_name='smartfarming', table_name='sa_device_camera_account')
|
|
|
+ CameraAccount_data = MongoCameraAccount.find_many({"id":int(account_id)})
|
|
|
+ if CameraAccount_data.count() > 0:
|
|
|
+ account_obj = CameraAccount_data[0]
|
|
|
+ account_type = account_obj["account_type"]
|
|
|
+ token = account_obj["token"]
|
|
|
+ if account_type == 0:
|
|
|
+ device_info = request_data["device_id"].split("-")
|
|
|
+ if len(device_info) == 2:
|
|
|
+ device = device_info[0]
|
|
|
+ channel = device_info[1]
|
|
|
+ elif len(device_info) == 1:
|
|
|
+ device = device_info[0]
|
|
|
+ channel = 1
|
|
|
+ else:
|
|
|
+ return Response({"error":"监控地址有误"})
|
|
|
+
|
|
|
+ yz_url = "https://open.ys7.com/api/lapp/v2/live/address/get"
|
|
|
+ # ezopen 播放地址
|
|
|
+ res = requests.post(f"{yz_url}?accessToken={token}&deviceSerial={device}&channelNo={channel}")
|
|
|
+ res_data = res.json()
|
|
|
+ print(res_data)
|
|
|
+ if res_data.get("code") == '200':
|
|
|
+ ezopen = res_data.get("data", {}).get("url", "")
|
|
|
+ else:
|
|
|
+ return Response({"error":res_data.get("msg")})
|
|
|
+ # hls 播放地址
|
|
|
+ res = requests.post(f"{yz_url}?accessToken={token}&deviceSerial={device}&channelNo={channel}&protocol=2")
|
|
|
+ hls = (res.json()).get("data", {}).get("url", "")
|
|
|
+ if not hls:
|
|
|
+ # 海康设备
|
|
|
+ addr = addr.replace("http://", "https://")
|
|
|
+ data = {
|
|
|
+ "ezopen": ezopen,
|
|
|
+ "token": token,
|
|
|
+ "hls": hls,
|
|
|
+ "type_id": 0
|
|
|
+ }
|
|
|
+ elif account_type == 1:
|
|
|
+ # 大华设备
|
|
|
+ addr = addr.replace("http://cmgw-vpc.lechange.com:8888", "https://cmgw-vpc.lechange.com:8890")
|
|
|
+ addr = eval(addr)
|
|
|
+ addr["type_id"] = -1
|
|
|
+ return str(addr)
|
|
|
+ else:
|
|
|
+ addr = addr.replace("http://", "https://")
|
|
|
+ data = {
|
|
|
+ "hls": addr,
|
|
|
+ "type_id": 0
|
|
|
+ }
|
|
|
+ return Response(data)
|