|
@@ -300,156 +300,159 @@ class DetectControllerViewV2(View):
|
|
|
|
|
|
# qs = Equipment_Info.objects.filter(userID_id=userID).order_by('-eventTime')
|
|
|
# qs = qs.filter(eventTime__gt=now_time - 3600 * 168)
|
|
|
- # 根据时间筛选消息推送
|
|
|
- if startTime and endTime:
|
|
|
- qs, count = EquipmentInfoService.find_by_start_time_equipment_info(page, line, userID, startTime,
|
|
|
- endTime, eventType,
|
|
|
- request_dict.get('uids', None))
|
|
|
+ try:
|
|
|
+ # 根据时间筛选消息推送
|
|
|
+ if startTime and endTime:
|
|
|
+ qs, count = EquipmentInfoService.find_by_start_time_equipment_info(page, line, userID, startTime,
|
|
|
+ endTime, eventType,
|
|
|
+ request_dict.get('uids', None))
|
|
|
|
|
|
- else:
|
|
|
- # 默认查询近七天消息推送
|
|
|
- qs, count = EquipmentInfoService.get_equipment_info_week_all(page, line, userID, startTime, endTime,
|
|
|
- eventType,
|
|
|
- request_dict.get('uids', None))
|
|
|
- # if startTime and endTime:
|
|
|
- # qs = qs.filter(eventTime__range=(startTime, endTime))
|
|
|
- # if eventType:
|
|
|
- # if ',' in eventType: # 兼容AI查询
|
|
|
- # eventTypeList = eventType.split(',')
|
|
|
- # eventTypeList = [int(i.strip()) for i in eventTypeList]
|
|
|
- # qs = qs.filter(eventType__in=eventTypeList)
|
|
|
- # else:
|
|
|
- # qs = qs.filter(eventType=eventType)
|
|
|
- uids = request_dict.get('uids', None)
|
|
|
- if uids:
|
|
|
- uid_list = uids.split(',')
|
|
|
- # qs = qs.filter(devUid__in=uid_list)
|
|
|
- dvqs = Device_Info.objects.filter(UID__in=uid_list, 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']}
|
|
|
- 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 or count == 0 or not qs.exists():
|
|
|
- return response.json(0, {'datas': [], 'count': 0})
|
|
|
- # qs = qs.values('id', 'devUid', 'devNickName', 'Channel', 'eventType', 'status', 'alarm', 'eventTime',
|
|
|
- # 'receiveTime', 'is_st', 'addTime', 'storage_location', 'borderCoords')
|
|
|
-
|
|
|
- # count = qs.count()
|
|
|
- # qr = qs[(page - 1) * line:page * line]
|
|
|
- qr = qs
|
|
|
- res = []
|
|
|
- auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
- oss_img_bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|
|
|
- aws_s3_guonei = boto3.client(
|
|
|
- 's3',
|
|
|
- aws_access_key_id=AWS_ACCESS_KEY_ID[0],
|
|
|
- aws_secret_access_key=AWS_SECRET_ACCESS_KEY[0],
|
|
|
- config=botocore.client.Config(signature_version='s3v4'),
|
|
|
- region_name='cn-northwest-1'
|
|
|
- )
|
|
|
- aws_s3_guowai = boto3.client(
|
|
|
- 's3',
|
|
|
- aws_access_key_id=AWS_ACCESS_KEY_ID[1],
|
|
|
- aws_secret_access_key=AWS_SECRET_ACCESS_KEY[1],
|
|
|
- config=botocore.client.Config(signature_version='s3v4'),
|
|
|
- region_name='us-east-1'
|
|
|
- )
|
|
|
- # vod_time_list = []
|
|
|
- # ai消息标识所有组合标签
|
|
|
- ai_all_event_type = EquipmentInfoService.get_all_comb_event_type()
|
|
|
- for p in qr:
|
|
|
- devUid = p['devUid']
|
|
|
- eventTime = p['eventTime']
|
|
|
- channel = p['Channel']
|
|
|
- storage_location = p['storage_location']
|
|
|
- if p['is_st'] == 1:
|
|
|
- thumbspng = '{uid}/{channel}/{time}.jpeg'.format(uid=devUid, channel=p['Channel'], time=eventTime)
|
|
|
- if storage_location == 1: # oss
|
|
|
- response_url = oss_img_bucket.sign_url('GET', thumbspng, 300)
|
|
|
- p['img'] = response_url
|
|
|
- p['img_list'] = [response_url]
|
|
|
- elif region == 2 and storage_location == 2: # 2:国内,aws
|
|
|
- response_url = aws_s3_guonei.generate_presigned_url('get_object',
|
|
|
- Params={'Bucket': 'push', 'Key': thumbspng},
|
|
|
- ExpiresIn=300)
|
|
|
- p['img'] = response_url
|
|
|
- p['img_list'] = [response_url]
|
|
|
- elif region == 1 and storage_location == 2: # 1:国外,aws
|
|
|
- response_url = aws_s3_guowai.generate_presigned_url('get_object',
|
|
|
- Params={'Bucket': 'foreignpush',
|
|
|
- 'Key': thumbspng},
|
|
|
- ExpiresIn=300)
|
|
|
- p['img'] = response_url
|
|
|
- p['img_list'] = [response_url]
|
|
|
-
|
|
|
- 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)
|
|
|
- if storage_location == 1: # oss
|
|
|
- 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]
|
|
|
- elif region == 2 and storage_location == 2: # 2:国内,aws
|
|
|
- thumb = aws_s3_guonei.generate_presigned_url('get_object',
|
|
|
- Params={'Bucket': 'push', 'Key': ts},
|
|
|
- ExpiresIn=3600)
|
|
|
- p['img_list'] = [thumb]
|
|
|
- elif region == 1 and storage_location == 2: # 1:国外,aws
|
|
|
- thumb = aws_s3_guowai.generate_presigned_url('get_object',
|
|
|
- Params={'Bucket': 'foreignpush', 'Key': ts},
|
|
|
- ExpiresIn=3600)
|
|
|
- p['img_list'] = [thumb]
|
|
|
- elif p['is_st'] == 3 or p['is_st'] == 4:
|
|
|
- # 列表装载回放时间戳标记
|
|
|
- p['img_list'] = []
|
|
|
- for i in range(p['is_st']):
|
|
|
- thumbspng = '{uid}/{channel}/{time}_{st}.jpeg'.format(uid=devUid, channel=p['Channel'],
|
|
|
- time=eventTime, st=i)
|
|
|
+ else:
|
|
|
+ # 默认查询近七天消息推送
|
|
|
+ qs, count = EquipmentInfoService.get_equipment_info_week_all(page, line, userID, startTime, endTime,
|
|
|
+ eventType,
|
|
|
+ request_dict.get('uids', None))
|
|
|
+ # if startTime and endTime:
|
|
|
+ # qs = qs.filter(eventTime__range=(startTime, endTime))
|
|
|
+ # if eventType:
|
|
|
+ # if ',' in eventType: # 兼容AI查询
|
|
|
+ # eventTypeList = eventType.split(',')
|
|
|
+ # eventTypeList = [int(i.strip()) for i in eventTypeList]
|
|
|
+ # qs = qs.filter(eventType__in=eventTypeList)
|
|
|
+ # else:
|
|
|
+ # qs = qs.filter(eventType=eventType)
|
|
|
+ uids = request_dict.get('uids', None)
|
|
|
+ if uids:
|
|
|
+ uid_list = uids.split(',')
|
|
|
+ # qs = qs.filter(devUid__in=uid_list)
|
|
|
+ dvqs = Device_Info.objects.filter(UID__in=uid_list, 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']}
|
|
|
+ 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 or count == 0 or not qs.exists():
|
|
|
+ return response.json(0, {'datas': [], 'count': 0})
|
|
|
+ # qs = qs.values('id', 'devUid', 'devNickName', 'Channel', 'eventType', 'status', 'alarm', 'eventTime',
|
|
|
+ # 'receiveTime', 'is_st', 'addTime', 'storage_location', 'borderCoords')
|
|
|
+
|
|
|
+ # count = qs.count()
|
|
|
+ # qr = qs[(page - 1) * line:page * line]
|
|
|
+ qr = qs
|
|
|
+ res = []
|
|
|
+ auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
+ oss_img_bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|
|
|
+ aws_s3_guonei = boto3.client(
|
|
|
+ 's3',
|
|
|
+ aws_access_key_id=AWS_ACCESS_KEY_ID[0],
|
|
|
+ aws_secret_access_key=AWS_SECRET_ACCESS_KEY[0],
|
|
|
+ config=botocore.client.Config(signature_version='s3v4'),
|
|
|
+ region_name='cn-northwest-1'
|
|
|
+ )
|
|
|
+ aws_s3_guowai = boto3.client(
|
|
|
+ 's3',
|
|
|
+ aws_access_key_id=AWS_ACCESS_KEY_ID[1],
|
|
|
+ aws_secret_access_key=AWS_SECRET_ACCESS_KEY[1],
|
|
|
+ config=botocore.client.Config(signature_version='s3v4'),
|
|
|
+ region_name='us-east-1'
|
|
|
+ )
|
|
|
+ # vod_time_list = []
|
|
|
+ # ai消息标识所有组合标签
|
|
|
+ ai_all_event_type = EquipmentInfoService.get_all_comb_event_type()
|
|
|
+ for p in qr:
|
|
|
+ devUid = p['devUid']
|
|
|
+ eventTime = p['eventTime']
|
|
|
+ channel = p['Channel']
|
|
|
+ storage_location = p['storage_location']
|
|
|
+ if p['is_st'] == 1:
|
|
|
+ thumbspng = '{uid}/{channel}/{time}.jpeg'.format(uid=devUid, channel=p['Channel'], time=eventTime)
|
|
|
if storage_location == 1: # oss
|
|
|
- img = oss_img_bucket.sign_url('GET', thumbspng, 300)
|
|
|
- p['img_list'].append(img)
|
|
|
- elif region == 2 and storage_location == 2: # 2:国内,aws
|
|
|
+ response_url = oss_img_bucket.sign_url('GET', thumbspng, 300)
|
|
|
+ p['img'] = response_url
|
|
|
+ p['img_list'] = [response_url]
|
|
|
+ elif region == 2 and storage_location == 2: # 2:国内,aws
|
|
|
response_url = aws_s3_guonei.generate_presigned_url('get_object',
|
|
|
Params={'Bucket': 'push', 'Key': thumbspng},
|
|
|
ExpiresIn=300)
|
|
|
- img = response_url
|
|
|
- p['img_list'].append(img)
|
|
|
- elif region == 1 and storage_location == 2: # 1:国外,aws
|
|
|
+ p['img'] = response_url
|
|
|
+ p['img_list'] = [response_url]
|
|
|
+ elif region == 1 and storage_location == 2: # 1:国外,aws
|
|
|
response_url = aws_s3_guowai.generate_presigned_url('get_object',
|
|
|
Params={'Bucket': 'foreignpush',
|
|
|
'Key': thumbspng},
|
|
|
ExpiresIn=300)
|
|
|
- img = response_url
|
|
|
- p['img_list'].append(img)
|
|
|
- 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'] = ''
|
|
|
-
|
|
|
- p['borderCoords'] = '' if p['borderCoords'] == '' else json.loads(p['borderCoords']) # ai消息坐标信息
|
|
|
- p['ai_event_type_list'] = []
|
|
|
- if p['eventType'] in ai_all_event_type: # 如果是ai消息类型,则分解eventType, 如:123 -> [1,2,3]
|
|
|
- p['ai_event_type_list'] = list(map(int, str(p['eventType'])))
|
|
|
- res.append(p)
|
|
|
- return response.json(0, {'datas': res, 'count': count})
|
|
|
+ p['img'] = response_url
|
|
|
+ p['img_list'] = [response_url]
|
|
|
+
|
|
|
+ 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)
|
|
|
+ if storage_location == 1: # oss
|
|
|
+ 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]
|
|
|
+ elif region == 2 and storage_location == 2: # 2:国内,aws
|
|
|
+ thumb = aws_s3_guonei.generate_presigned_url('get_object',
|
|
|
+ Params={'Bucket': 'push', 'Key': ts},
|
|
|
+ ExpiresIn=3600)
|
|
|
+ p['img_list'] = [thumb]
|
|
|
+ elif region == 1 and storage_location == 2: # 1:国外,aws
|
|
|
+ thumb = aws_s3_guowai.generate_presigned_url('get_object',
|
|
|
+ Params={'Bucket': 'foreignpush', 'Key': ts},
|
|
|
+ ExpiresIn=3600)
|
|
|
+ p['img_list'] = [thumb]
|
|
|
+ elif p['is_st'] == 3 or p['is_st'] == 4:
|
|
|
+ # 列表装载回放时间戳标记
|
|
|
+ p['img_list'] = []
|
|
|
+ for i in range(p['is_st']):
|
|
|
+ thumbspng = '{uid}/{channel}/{time}_{st}.jpeg'.format(uid=devUid, channel=p['Channel'],
|
|
|
+ time=eventTime, st=i)
|
|
|
+ if storage_location == 1: # oss
|
|
|
+ img = oss_img_bucket.sign_url('GET', thumbspng, 300)
|
|
|
+ p['img_list'].append(img)
|
|
|
+ elif region == 2 and storage_location == 2: # 2:国内,aws
|
|
|
+ response_url = aws_s3_guonei.generate_presigned_url('get_object',
|
|
|
+ Params={'Bucket': 'push', 'Key': thumbspng},
|
|
|
+ ExpiresIn=300)
|
|
|
+ img = response_url
|
|
|
+ p['img_list'].append(img)
|
|
|
+ elif region == 1 and storage_location == 2: # 1:国外,aws
|
|
|
+ response_url = aws_s3_guowai.generate_presigned_url('get_object',
|
|
|
+ Params={'Bucket': 'foreignpush',
|
|
|
+ 'Key': thumbspng},
|
|
|
+ ExpiresIn=300)
|
|
|
+ img = response_url
|
|
|
+ p['img_list'].append(img)
|
|
|
+ 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'] = ''
|
|
|
+
|
|
|
+ p['borderCoords'] = '' if p['borderCoords'] == '' else json.loads(p['borderCoords']) # ai消息坐标信息
|
|
|
+ p['ai_event_type_list'] = []
|
|
|
+ if p['eventType'] in ai_all_event_type: # 如果是ai消息类型,则分解eventType, 如:123 -> [1,2,3]
|
|
|
+ p['ai_event_type_list'] = list(map(int, str(p['eventType'])))
|
|
|
+ res.append(p)
|
|
|
+ return response.json(0, {'datas': res, 'count': count})
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(474)
|
|
|
|
|
|
def do_update_interval(self, userID, request_dict, response):
|
|
|
uid = request_dict.get('uid', None)
|