|
@@ -304,13 +304,41 @@ class FeedBackView(View):
|
|
if not all([equipment_info_id, uid, is_st, event_type, event_time, channel]):
|
|
if not all([equipment_info_id, uid, is_st, event_type, event_time, channel]):
|
|
return response.json(444)
|
|
return response.json(444)
|
|
is_st, event_type, channel = int(is_st), int(event_type), int(channel)
|
|
is_st, event_type, channel = int(is_st), int(event_type), int(channel)
|
|
|
|
+ # 查询数据是否存在
|
|
push_inaccurate_feedback_qs = PushInaccurateFeedback.objects.filter(equipment_info_id=equipment_info_id,
|
|
push_inaccurate_feedback_qs = PushInaccurateFeedback.objects.filter(equipment_info_id=equipment_info_id,
|
|
user_id=user_id, uid=uid, channel=channel,
|
|
user_id=user_id, uid=uid, channel=channel,
|
|
event_type=event_type, event_time=event_time,
|
|
event_type=event_type, event_time=event_time,
|
|
is_st=is_st)
|
|
is_st=is_st)
|
|
if push_inaccurate_feedback_qs.exists():
|
|
if push_inaccurate_feedback_qs.exists():
|
|
return response.json(174)
|
|
return response.json(174)
|
|
- return response.json(0)
|
|
|
|
|
|
+ # 查询图片是否存在s3
|
|
|
|
+ if CONFIG_INFO == CONFIG_TEST or CONFIG_INFO == CONFIG_CN: # 国内
|
|
|
|
+ region_name = AWS_IOT_SES_ACCESS_CHINA_REGION
|
|
|
|
+ aws_access_key_id = AWS_ACCESS_KEY_ID[0]
|
|
|
|
+ secret_access_key = AWS_SECRET_ACCESS_KEY[0]
|
|
|
|
+ bucket = 'push'
|
|
|
|
+ else: # 国外
|
|
|
|
+ region_name = AWS_SES_ACCESS_REGION
|
|
|
|
+ aws_access_key_id = AWS_ACCESS_KEY_ID[1]
|
|
|
|
+ secret_access_key = AWS_SECRET_ACCESS_KEY[1]
|
|
|
|
+ bucket = 'foreignpush'
|
|
|
|
+ if is_st == 3:
|
|
|
|
+ key = '{uid}/{channel}/{event_time}.jpeg'.format(uid=uid, channel=channel, event_time=event_time)
|
|
|
|
+ else:
|
|
|
|
+ key = '{uid}/{channel}/{event_time}_0.jpeg'.format(uid=uid, channel=channel, event_time=event_time)
|
|
|
|
+ try:
|
|
|
|
+ s3 = AmazonS3Util(
|
|
|
|
+ aws_access_key_id=aws_access_key_id,
|
|
|
|
+ secret_access_key=secret_access_key,
|
|
|
|
+ region_name=region_name
|
|
|
|
+ )
|
|
|
|
+ have_object = s3.get_object(bucket, key)
|
|
|
|
+ if have_object:
|
|
|
|
+ return response.json(0)
|
|
|
|
+ else:
|
|
|
|
+ return response.json(174)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return response.json(500, repr(e))
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
def push_inaccurate(user_id, request_dict, response):
|
|
def push_inaccurate(user_id, request_dict, response):
|
|
@@ -345,22 +373,14 @@ class FeedBackView(View):
|
|
file_path = '{uid}/{channel}/{event_time}.jpeg'.format(uid=uid,
|
|
file_path = '{uid}/{channel}/{event_time}.jpeg'.format(uid=uid,
|
|
channel=channel,
|
|
channel=channel,
|
|
event_time=event_time)
|
|
event_time=event_time)
|
|
- try:
|
|
|
|
- s3.copy_obj(source_bucket, 'push-inaccurate', file_path)
|
|
|
|
- except Exception as e:
|
|
|
|
- if e.response['Error']['Code'] == "404":
|
|
|
|
- return response.json(173)
|
|
|
|
|
|
+ s3.copy_obj(source_bucket, 'push-inaccurate', file_path)
|
|
else:
|
|
else:
|
|
for index in range(3):
|
|
for index in range(3):
|
|
file_path = '{uid}/{channel}/{event_time}_{index}.jpeg'.format(uid=uid,
|
|
file_path = '{uid}/{channel}/{event_time}_{index}.jpeg'.format(uid=uid,
|
|
channel=channel,
|
|
channel=channel,
|
|
event_time=event_time,
|
|
event_time=event_time,
|
|
index=index)
|
|
index=index)
|
|
- try:
|
|
|
|
- s3.copy_obj(source_bucket, 'push-inaccurate', file_path)
|
|
|
|
- except Exception as e:
|
|
|
|
- if e.response['Error']['Code'] == "404":
|
|
|
|
- continue
|
|
|
|
|
|
+ s3.copy_obj(source_bucket, 'push-inaccurate', file_path)
|
|
PushInaccurateFeedback.objects.create(equipment_info_id=equipment_info_id,
|
|
PushInaccurateFeedback.objects.create(equipment_info_id=equipment_info_id,
|
|
user_id=user_id, event_type=event_type,
|
|
user_id=user_id, event_type=event_type,
|
|
uid=uid, channel=channel, add_time=now_time,
|
|
uid=uid, channel=channel, add_time=now_time,
|