|
@@ -310,29 +310,24 @@ class DetectControllerViewV2(View):
|
|
|
def do_query(self, request_dict, response, userID):
|
|
|
page = int(request_dict.get('page', None))
|
|
|
line = int(request_dict.get('line', None))
|
|
|
- if not page or not line:
|
|
|
- return response.json(444, 'page,line')
|
|
|
startTime = request_dict.get('startTime', None)
|
|
|
endTime = request_dict.get('endTime', None)
|
|
|
eventType = request_dict.get('eventType', None)
|
|
|
- region = request_dict.get('region', None)
|
|
|
- if not region:
|
|
|
- return response.json(444, 'region')
|
|
|
- region = int(region)
|
|
|
+ region = int(request_dict.get('region', None))
|
|
|
+ uids = 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))
|
|
|
+ equipment_info_qs, count = EquipmentInfoService.\
|
|
|
+ find_by_start_time_equipment_info(page, line, userID, startTime, endTime, eventType, uids)
|
|
|
|
|
|
else:
|
|
|
# 默认查询近七天消息推送
|
|
|
def_time = LocalDateTimeUtil.get_before_days_timestamp(int(time.time()), 8)
|
|
|
- qs, count = EquipmentInfoService.get_equipment_info_week_all(page, line, userID, def_time, endTime,
|
|
|
- eventType,
|
|
|
- request_dict.get('uids', None))
|
|
|
- uids = request_dict.get('uids', None)
|
|
|
+ equipment_info_qs, count = EquipmentInfoService.\
|
|
|
+ get_equipment_info_week_all(page, line, userID, def_time, endTime, eventType, uids)
|
|
|
+
|
|
|
if uids:
|
|
|
uid_list = uids.split(',')
|
|
|
dvqs = Device_Info.objects.filter(UID__in=uid_list, userID_id=userID).values('UID', 'Type', 'NickName')
|
|
@@ -344,9 +339,11 @@ class DetectControllerViewV2(View):
|
|
|
uid_type_dict = {}
|
|
|
for dv in dvqs:
|
|
|
uid_type_dict[dv['UID']] = {'type': dv['Type'], 'NickName': dv['NickName']}
|
|
|
- if not qs or count == 0 or not qs.exists():
|
|
|
+
|
|
|
+ # 没有推送数据返回空列表
|
|
|
+ if count == 0:
|
|
|
return response.json(0, {'datas': [], 'count': 0})
|
|
|
- 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')
|
|
@@ -364,35 +361,32 @@ class DetectControllerViewV2(View):
|
|
|
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
|
|
|
+ for equipment_info in equipment_info_qs:
|
|
|
+ devUid = equipment_info['devUid']
|
|
|
+ eventTime = equipment_info['eventTime']
|
|
|
+ channel = equipment_info['Channel']
|
|
|
+ storage_location = equipment_info['storage_location']
|
|
|
+ if equipment_info['is_st'] == 1:
|
|
|
+ thumbspng = '{uid}/{channel}/{time}.jpeg'.format(uid=devUid, channel=equipment_info['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:
|
|
|
+ equipment_info['img'] = response_url
|
|
|
+ equipment_info['img_list'] = [response_url]
|
|
|
+ else:
|
|
|
+ params = {'Key': thumbspng}
|
|
|
+ if region == 1:
|
|
|
+ params['Bucket'] = 'foreignpush'
|
|
|
+ response_url = aws_s3_guonei.generate_presigned_url('get_object', Params=params,
|
|
|
+ ExpiresIn=300)
|
|
|
+ else:
|
|
|
+ params['Bucket'] = 'push'
|
|
|
+ response_url = aws_s3_guowai.generate_presigned_url('get_object', Params=params, ExpiresIn=300)
|
|
|
+ equipment_info['img'] = response_url
|
|
|
+ equipment_info['img_list'] = [response_url]
|
|
|
+
|
|
|
+ elif equipment_info['is_st'] == 2:
|
|
|
# 列表装载回放时间戳标记
|
|
|
split_vod_hls_obj = SplitVodHlsObject()
|
|
|
vodqs = split_vod_hls_obj.get_vod_hls_data(uid=devUid, channel=channel,
|
|
@@ -405,7 +399,7 @@ class DetectControllerViewV2(View):
|
|
|
bucket_name = vod_bucket_qs[0]['bucket']
|
|
|
endpoint = vod_bucket_qs[0]['endpoint']
|
|
|
bucket = oss2.Bucket(auth, endpoint, bucket_name)
|
|
|
- ts = '{uid}/vod{channel}/{etime}/ts0.ts'.format(uid=devUid, channel=p['Channel'],
|
|
|
+ ts = '{uid}/vod{channel}/{etime}/ts0.ts'.format(uid=devUid, channel=equipment_info['Channel'],
|
|
|
etime=eventTime)
|
|
|
if storage_location == 1: # oss
|
|
|
thumb0 = bucket.sign_url('GET', ts, 3600,
|
|
@@ -414,56 +408,55 @@ class DetectControllerViewV2(View):
|
|
|
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]
|
|
|
+ equipment_info['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]
|
|
|
+ equipment_info['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:
|
|
|
+ equipment_info['img_list'] = [thumb]
|
|
|
+ elif equipment_info['is_st'] == 3 or equipment_info['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'],
|
|
|
+ equipment_info['img_list'] = []
|
|
|
+ for i in range(equipment_info['is_st']):
|
|
|
+ thumbspng = '{uid}/{channel}/{time}_{st}.jpeg'.format(uid=devUid, channel=equipment_info['Channel'],
|
|
|
time=eventTime, st=i)
|
|
|
if storage_location == 1: # oss
|
|
|
img = oss_img_bucket.sign_url('GET', thumbspng, 300)
|
|
|
- p['img_list'].append(img)
|
|
|
+ equipment_info['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)
|
|
|
+ equipment_info['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)
|
|
|
+ equipment_info['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']
|
|
|
+ equipment_info['uid_type'] = uid_type_dict[devUid]['type']
|
|
|
+ equipment_info['devNickName'] = uid_type_dict[devUid]['NickName']
|
|
|
else:
|
|
|
- p['uid_type'] = ''
|
|
|
+ equipment_info['uid_type'] = ''
|
|
|
|
|
|
- p['borderCoords'] = '' if p['borderCoords'] == '' else json.loads(p['borderCoords']) # ai消息坐标信息
|
|
|
- p['ai_event_type_list'] = []
|
|
|
+ equipment_info['borderCoords'] = '' if equipment_info['borderCoords'] == '' else json.loads(equipment_info['borderCoords']) # ai消息坐标信息
|
|
|
+ equipment_info['ai_event_type_list'] = []
|
|
|
# 如果是ai消息类型,则分解eventType, 如:123 -> [1,2,3]
|
|
|
- if p['borderCoords'] and p['eventType'] in ai_all_event_type:
|
|
|
- p['ai_event_type_list'] = list(map(int, str(p['eventType'])))
|
|
|
- if EquipmentInfoService.is_combo_tag(p['eventType'], p['eventTag']):
|
|
|
- p['ai_event_type_list'] += EquipmentInfoService.get_combo_types(p['eventType'], p['eventTag'])
|
|
|
- res.append(p)
|
|
|
+ if equipment_info['borderCoords'] and equipment_info['eventType'] in ai_all_event_type:
|
|
|
+ equipment_info['ai_event_type_list'] = list(map(int, str(equipment_info['eventType'])))
|
|
|
+ if EquipmentInfoService.is_combo_tag(equipment_info['eventType'], equipment_info['eventTag']):
|
|
|
+ equipment_info['ai_event_type_list'] += EquipmentInfoService.get_combo_types(equipment_info['eventType'], equipment_info['eventTag'])
|
|
|
+ res.append(equipment_info)
|
|
|
return response.json(0, {'datas': res, 'count': count})
|
|
|
except Exception as e:
|
|
|
print(repr(e))
|