|
@@ -310,26 +310,27 @@ 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))
|
|
|
- startTime = request_dict.get('startTime', None)
|
|
|
- endTime = request_dict.get('endTime', None)
|
|
|
- eventType = request_dict.get('eventType', None)
|
|
|
+ start_time = request_dict.get('startTime', None)
|
|
|
+ end_time = request_dict.get('endTime', None)
|
|
|
+ event_type = request_dict.get('eventType', None)
|
|
|
region = int(request_dict.get('region', None))
|
|
|
uids = request_dict.get('uids', None)
|
|
|
|
|
|
try:
|
|
|
- # 根据时间筛选消息推送
|
|
|
- if startTime and endTime:
|
|
|
- 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)
|
|
|
- equipment_info_qs, count = EquipmentInfoService.\
|
|
|
- get_equipment_info_week_all(page, line, userID, def_time, endTime, eventType, uids)
|
|
|
-
|
|
|
+ uid_list = []
|
|
|
if uids:
|
|
|
uid_list = uids.split(',')
|
|
|
+
|
|
|
+ if not start_time and not end_time:
|
|
|
+ # 默认查询近七天内数据
|
|
|
+ end_time = int(time.time())
|
|
|
+ start_time = LocalDateTimeUtil.get_before_days_timestamp(end_time, 7)
|
|
|
+
|
|
|
+ equipment_info_qs, count = EquipmentInfoService.\
|
|
|
+ union_equipment_info(userID, uid_list, event_type, start_time, end_time, page, line)
|
|
|
+
|
|
|
+ # 查询设备类型,昵称
|
|
|
+ if 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:
|
|
@@ -347,50 +348,55 @@ class DetectControllerViewV2(View):
|
|
|
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(
|
|
|
+ aws_s3 = 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'
|
|
|
)
|
|
|
+ aws_s3_cn = 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'
|
|
|
+ )
|
|
|
+
|
|
|
# ai消息标识所有组合标签
|
|
|
ai_all_event_type = EquipmentInfoService.get_all_comb_event_type()
|
|
|
for equipment_info in equipment_info_qs:
|
|
|
- devUid = equipment_info['devUid']
|
|
|
- eventTime = equipment_info['eventTime']
|
|
|
+ uid = equipment_info['devUid']
|
|
|
+ event_time = equipment_info['eventTime']
|
|
|
channel = equipment_info['Channel']
|
|
|
storage_location = equipment_info['storage_location']
|
|
|
+ border_coords = equipment_info['borderCoords']
|
|
|
+ event_type = equipment_info['eventType']
|
|
|
+ event_tag = equipment_info['eventTag']
|
|
|
+
|
|
|
if equipment_info['is_st'] == 1:
|
|
|
- thumbspng = '{uid}/{channel}/{time}.jpeg'.format(uid=devUid, channel=equipment_info['Channel'], time=eventTime)
|
|
|
+ thumbspng = '{}/{}/{}.jpeg'.format(uid, channel, event_time)
|
|
|
if storage_location == 1: # 阿里云oss
|
|
|
- response_url = oss_img_bucket.sign_url('GET', thumbspng, 300)
|
|
|
- equipment_info['img'] = response_url
|
|
|
- equipment_info['img_list'] = [response_url]
|
|
|
+ img_url = oss_img_bucket.sign_url('GET', thumbspng, 300)
|
|
|
else:
|
|
|
params = {'Key': thumbspng}
|
|
|
- if region == 1:
|
|
|
+ if region == 1: # AWS国外
|
|
|
params['Bucket'] = 'foreignpush'
|
|
|
- response_url = aws_s3_guowai.generate_presigned_url('get_object', Params=params,
|
|
|
- ExpiresIn=300)
|
|
|
- else:
|
|
|
+ img_url = aws_s3.generate_presigned_url(
|
|
|
+ 'get_object', Params=params, ExpiresIn=300)
|
|
|
+ else: # AWS国内
|
|
|
params['Bucket'] = 'push'
|
|
|
- response_url = aws_s3_guonei.generate_presigned_url('get_object', Params=params, ExpiresIn=300)
|
|
|
- equipment_info['img'] = response_url
|
|
|
- equipment_info['img_list'] = [response_url]
|
|
|
+ img_url = aws_s3_cn.generate_presigned_url(
|
|
|
+ 'get_object', Params=params, ExpiresIn=300)
|
|
|
+
|
|
|
+ equipment_info['img'] = img_url
|
|
|
+ equipment_info['img_list'] = [img_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,
|
|
|
- start_time=int(eventTime)).values("bucket_id")
|
|
|
+ vodqs = split_vod_hls_obj.get_vod_hls_data(
|
|
|
+ uid=uid, channel=channel, start_time=int(event_time)).values('bucket_id')
|
|
|
if not vodqs.exists():
|
|
|
return response.json(173)
|
|
|
vod_bucket_qs = VodBucketModel.objects.filter(id=vodqs[0]['bucket_id']).values('bucket', 'endpoint')
|
|
@@ -399,67 +405,61 @@ 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=equipment_info['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'})
|
|
|
+ ts = '{}/vod{}/{}/ts0.ts'.format(uid, channel, event_time)
|
|
|
+ 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'})
|
|
|
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)
|
|
|
- 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)
|
|
|
- equipment_info['img_list'] = [thumb]
|
|
|
+ else:
|
|
|
+ params = {'Key': ts}
|
|
|
+ if region == 1: # AWS国外
|
|
|
+ params['Bucket'] = 'foreignpush'
|
|
|
+ img_url = aws_s3.generate_presigned_url(
|
|
|
+ 'get_object', Params=params, ExpiresIn=300)
|
|
|
+ else: # AWS国内
|
|
|
+ params['Bucket'] = 'push'
|
|
|
+ img_url = aws_s3_cn.generate_presigned_url(
|
|
|
+ 'get_object', Params=params, ExpiresIn=300)
|
|
|
+ equipment_info['img_list'] = [img_url]
|
|
|
+
|
|
|
elif equipment_info['is_st'] == 3 or equipment_info['is_st'] == 4:
|
|
|
# 列表装载回放时间戳标记
|
|
|
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)
|
|
|
- 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
|
|
|
- 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
|
|
|
- equipment_info['img_list'].append(img)
|
|
|
-
|
|
|
- if devUid in uid_type_dict.keys():
|
|
|
- equipment_info['uid_type'] = uid_type_dict[devUid]['type']
|
|
|
- equipment_info['devNickName'] = uid_type_dict[devUid]['NickName']
|
|
|
+ thumbspng = '{}/{}/{}_{}.jpeg'.format(uid, channel, event_time, i)
|
|
|
+ if storage_location == 1: # 阿里云oss
|
|
|
+ img_url = oss_img_bucket.sign_url('GET', thumbspng, 300)
|
|
|
+ else:
|
|
|
+ params = {'Key': thumbspng}
|
|
|
+ if region == 1: # 国外AWS
|
|
|
+ params['Bucket'] = 'foreignpush'
|
|
|
+ img_url = aws_s3.generate_presigned_url(
|
|
|
+ 'get_object', Params=params, ExpiresIn=300)
|
|
|
+ else: # 国内AWS
|
|
|
+ params['Bucket'] = 'push'
|
|
|
+ img_url = aws_s3_cn.generate_presigned_url(
|
|
|
+ 'get_object', Params=params, ExpiresIn=300)
|
|
|
+ equipment_info['img_list'].append(img_url)
|
|
|
+
|
|
|
+ if uid in uid_type_dict.keys():
|
|
|
+ equipment_info['uid_type'] = uid_type_dict[uid]['type']
|
|
|
+ equipment_info['devNickName'] = uid_type_dict[uid]['NickName']
|
|
|
else:
|
|
|
equipment_info['uid_type'] = ''
|
|
|
|
|
|
- equipment_info['borderCoords'] = '' if equipment_info['borderCoords'] == '' else json.loads(equipment_info['borderCoords']) # ai消息坐标信息
|
|
|
+ equipment_info['borderCoords'] = '' if border_coords == '' else json.loads(border_coords) # ai消息坐标信息
|
|
|
equipment_info['ai_event_type_list'] = []
|
|
|
# 如果是ai消息类型,则分解eventType, 如:123 -> [1,2,3]
|
|
|
- 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'])
|
|
|
+ if border_coords and event_type in ai_all_event_type:
|
|
|
+ equipment_info['ai_event_type_list'] = list(map(int, str(event_type)))
|
|
|
+ if EquipmentInfoService.is_combo_tag(event_type, event_tag):
|
|
|
+ equipment_info['ai_event_type_list'] += EquipmentInfoService.get_combo_types(event_type, event_tag)
|
|
|
+
|
|
|
res.append(equipment_info)
|
|
|
return response.json(0, {'datas': res, 'count': count})
|
|
|
except Exception as e:
|
|
|
- print(repr(e))
|
|
|
+ print('error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
return response.json(474)
|
|
|
|
|
|
def do_update_interval(self, userID, request_dict, response):
|