|
@@ -1,19 +1,21 @@
|
|
|
+import time
|
|
|
import traceback
|
|
|
|
|
|
+import oss2
|
|
|
from django.utils.decorators import method_decorator
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
from django.views.generic import TemplateView
|
|
|
from django.views.generic.base import View
|
|
|
|
|
|
+from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET
|
|
|
from Ansjer.config import SERVER_DOMAIN
|
|
|
-from Model.models import Equipment_Info, Device_Info, Device_User
|
|
|
+from Model.models import Device_Info, VodHlsModel, Equipment_Info
|
|
|
+from Model.models import Device_User
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Object.UidTokenObject import UidTokenObject
|
|
|
from Service.CommonService import CommonService
|
|
|
-
|
|
|
from Service.ModelService import ModelService
|
|
|
-import time
|
|
|
|
|
|
'''
|
|
|
http://192.168.136.45:8077/equipment/info?token=test&operation=add&devUid=2N1K3LE78TYJ38CE111A&Channel=0&eventType=1&eventTime=1234567890&operation=add&alarm=21342134&receiveTime=1234567891234567
|
|
@@ -112,6 +114,68 @@ class EquipmentInfo(View):
|
|
|
return response.json(500)
|
|
|
|
|
|
def query_info(self, request_dict, userID, response):
|
|
|
+ page = int(request_dict.get('page', None))
|
|
|
+ line = int(request_dict.get('line', None))
|
|
|
+ nowTime = int(time.time())
|
|
|
+ if not page or not line:
|
|
|
+ return response.json(444, 'page,line')
|
|
|
+
|
|
|
+ qs = Equipment_Info.objects.filter(userID_id=userID, addTime__gte=nowTime - 3600 * 24 * 27)
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
+ if uid:
|
|
|
+ qs = qs.filter(devUid=uid)
|
|
|
+ dvqs = Device_Info.objects.filter(UID=uid).values('Type', 'NickName')
|
|
|
+ uid_type_dict = {uid: {'type': dvqs[0]['Type'], 'NickName': dvqs[0]['NickName']}}
|
|
|
+ else:
|
|
|
+ dvqs = Device_Info.objects.filter(userID_id=userID).values('UID', 'Type', 'NickName')
|
|
|
+ uid_type_dict = {}
|
|
|
+ for dv in dvqs:
|
|
|
+ uid_type_dict[dv['UID']] = {'type': dv['Type'], 'NickName': dv['NickName']}
|
|
|
+ print(uid_type_dict)
|
|
|
+ if not qs.exists():
|
|
|
+ return response.json(0, {'datas': [], 'count': 0})
|
|
|
+ qs = qs.values('id', 'devUid', 'devNickName', 'Channel', 'eventType', 'status', 'alarm', 'eventTime',
|
|
|
+ 'receiveTime', 'is_st')
|
|
|
+ count = qs.count()
|
|
|
+ qr = qs[(page - 1) * line:page * line]
|
|
|
+ res = []
|
|
|
+ auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
+ img_bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|
|
|
+ # vod_time_list = []
|
|
|
+ for p in qr:
|
|
|
+ devUid = p['devUid']
|
|
|
+ eventTime = p['eventTime']
|
|
|
+ channel = p['Channel']
|
|
|
+ if p['is_st'] == 1:
|
|
|
+ p['img'] = img_bucket.sign_url('GET', '{uid}/{channel}/{time}.jpeg'.
|
|
|
+ format(uid=devUid, channel=p['Channel'], time=eventTime), 300)
|
|
|
+ p['img_list'] = [img_bucket.sign_url('GET', '{uid}/{channel}/{time}.jpeg'.
|
|
|
+ format(uid=devUid, channel=channel, time=eventTime), 300)]
|
|
|
+ elif p['is_st'] == 2:
|
|
|
+ # 列表装载回放时间戳标记
|
|
|
+ vodqs = VodHlsModel.objects.filter(uid=devUid, channel=channel, time=int(eventTime)) \
|
|
|
+ .values("bucket__bucket", "bucket__endpoint")
|
|
|
+ print(vodqs)
|
|
|
+ if vodqs.exists():
|
|
|
+ bucket_name = vodqs[0]['bucket__bucket']
|
|
|
+ endpoint = vodqs[0]['bucket__endpoint']
|
|
|
+ bucket = oss2.Bucket(auth, endpoint, bucket_name)
|
|
|
+ ts = '{uid}/vod{channel}/{etime}/ts0.ts'.format(uid=devUid, channel=p['Channel'], etime=eventTime)
|
|
|
+ thumb0 = bucket.sign_url('GET', ts, 3600, params={'x-oss-process': 'video/snapshot,t_0000,w_700'})
|
|
|
+ thumb1 = bucket.sign_url('GET', ts, 3600, params={'x-oss-process': 'video/snapshot,t_1000,w_700'})
|
|
|
+ thumb2 = bucket.sign_url('GET', ts, 3600, params={'x-oss-process': 'video/snapshot,t_2000,w_700'})
|
|
|
+ # thumb3 = bucket.sign_url('GET', ts, 3600, params={'x-oss-process': 'video/snapshot,t_3000,w_700'})
|
|
|
+ p['img_list'] = [thumb0, thumb1, thumb2]
|
|
|
+ if devUid in uid_type_dict.keys():
|
|
|
+ p['uid_type'] = uid_type_dict[devUid]['type']
|
|
|
+ p['devNickName'] = uid_type_dict[devUid]['NickName']
|
|
|
+ else:
|
|
|
+ p['uid_type'] = ''
|
|
|
+ res.append(p)
|
|
|
+ return response.json(0, {'datas': res, 'count': count})
|
|
|
+
|
|
|
+
|
|
|
+ def query_info_backup(self, request_dict, userID, response):
|
|
|
page = int(request_dict.get('page', None))
|
|
|
line = int(request_dict.get('line', None))
|
|
|
if not page or not line:
|