|
@@ -89,6 +89,7 @@ class DetectControllerViewV2(View):
|
|
|
tz = request_dict.get('tz', '0')
|
|
|
company_secrete = request_dict.get('company_secrete', None)
|
|
|
region = request_dict.get('region', None) # app必须传:2:国内 1:国外
|
|
|
+ electricity_status = request_dict.get('electricity_status', None)
|
|
|
if not region:
|
|
|
return response.json(444, 'region')
|
|
|
region = int(region)
|
|
@@ -101,8 +102,8 @@ class DetectControllerViewV2(View):
|
|
|
tz = tz.replace("GMT", "")
|
|
|
detect_group = request_dict.get('detect_group', None)
|
|
|
interval = request_dict.get('interval', None)
|
|
|
- if not status:
|
|
|
- return response.json(444, 'status')
|
|
|
+ if not status and not electricity_status:
|
|
|
+ return response.json(444, 'status and electricity_status')
|
|
|
if not company_secrete:
|
|
|
return response.json(444, 'company_secrete')
|
|
|
company = CompanyModel.objects.filter(secret=company_secrete)
|
|
@@ -114,41 +115,44 @@ class DetectControllerViewV2(View):
|
|
|
# 判断推送类型对应key是否存在
|
|
|
print('push_type:', push_type)
|
|
|
|
|
|
- if push_type == '0':
|
|
|
- if appBundleId not in APNS_CONFIG.keys():
|
|
|
- return response.json(904)
|
|
|
- elif push_type == '1':
|
|
|
- if appBundleId not in FCM_CONFIG.keys():
|
|
|
- return response.json(904)
|
|
|
- elif push_type == '2':
|
|
|
- if appBundleId not in JPUSH_CONFIG.keys():
|
|
|
- return response.json(904)
|
|
|
- else:
|
|
|
- return response.json(173)
|
|
|
- dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
|
|
|
- status = int(status)
|
|
|
- # 获取用户区域
|
|
|
- # ip = self.ip
|
|
|
- # ipInfo = CommonService.getIpIpInfo(ip=ip, lang='EN')
|
|
|
- # area = ipInfo['country_name']
|
|
|
- # if area == 'China':
|
|
|
- # DETECT_PUSH_DOMAIN_V2 = 'cn.push.dvema.com'
|
|
|
- # else:
|
|
|
- # DETECT_PUSH_DOMAIN_V2 = 'en.push.dvema.com'
|
|
|
-
|
|
|
- nowTime = int(time.time())
|
|
|
- if dvqs.exists():
|
|
|
+ try:
|
|
|
+ if push_type == '0':
|
|
|
+ if appBundleId not in APNS_CONFIG.keys():
|
|
|
+ return response.json(904)
|
|
|
+ elif push_type == '1':
|
|
|
+ if appBundleId not in FCM_CONFIG.keys():
|
|
|
+ return response.json(904)
|
|
|
+ elif push_type == '2':
|
|
|
+ if appBundleId not in JPUSH_CONFIG.keys():
|
|
|
+ return response.json(904)
|
|
|
+ else:
|
|
|
+ return response.json(173)
|
|
|
+ dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
|
|
|
+ # 获取用户区域
|
|
|
+ # ip = self.ip
|
|
|
+ # ipInfo = CommonService.getIpIpInfo(ip=ip, lang='EN')
|
|
|
+ # area = ipInfo['country_name']
|
|
|
+ # if area == 'China':
|
|
|
+ # DETECT_PUSH_DOMAIN_V2 = 'cn.push.dvema.com'
|
|
|
+ # else:
|
|
|
+ # DETECT_PUSH_DOMAIN_V2 = 'en.push.dvema.com'
|
|
|
+
|
|
|
+ nowTime = int(time.time())
|
|
|
+ if not dvqs.exists():
|
|
|
+ return response.json(14)
|
|
|
# 修改状态
|
|
|
- dvqs.update(NotificationMode=status)
|
|
|
+ if status:
|
|
|
+ dvqs.update(NotificationMode=int(status))
|
|
|
uid_set_qs = UidSetModel.objects.filter(uid=uid)
|
|
|
# uid配置信息是否存在
|
|
|
|
|
|
if uid_set_qs.exists():
|
|
|
uid_set_id = uid_set_qs[0].id
|
|
|
qs_data = {
|
|
|
- 'detect_status': status,
|
|
|
'updTime': nowTime,
|
|
|
}
|
|
|
+ if status:
|
|
|
+ qs_data['detect_status'] = int(status)
|
|
|
if interval:
|
|
|
qs_data['detect_interval'] = int(interval)
|
|
|
if detect_group:
|
|
@@ -161,8 +165,9 @@ class DetectControllerViewV2(View):
|
|
|
'uid': uid,
|
|
|
'addTime': nowTime,
|
|
|
'updTime': nowTime,
|
|
|
- 'detect_status': status,
|
|
|
}
|
|
|
+ if status:
|
|
|
+ qs_data['detect_status'] = int(status)
|
|
|
if interval:
|
|
|
qs_data['detect_interval'] = int(interval)
|
|
|
if detect_group:
|
|
@@ -172,12 +177,30 @@ class DetectControllerViewV2(View):
|
|
|
|
|
|
uid_set_id = uid_set_qs.id
|
|
|
|
|
|
- if status == 0:
|
|
|
- UidPushModel.objects.filter(uid_set__uid=uid).delete()
|
|
|
+ # 初始化UidPushModel推送表
|
|
|
+ if electricity_status:
|
|
|
+ uid_push_create_dict = {
|
|
|
+ 'uid_set_id': uid_set_id,
|
|
|
+ 'userID_id': userID,
|
|
|
+ 'appBundleId': appBundleId,
|
|
|
+ 'app_type': app_type,
|
|
|
+ 'push_type': push_type,
|
|
|
+ 'token_val': token_val,
|
|
|
+ 'm_code': m_code,
|
|
|
+ 'addTime': nowTime,
|
|
|
+ 'updTime': nowTime,
|
|
|
+ 'lang': lang,
|
|
|
+ 'tz': tz
|
|
|
+ }
|
|
|
+ # 绑定设备推送
|
|
|
+ UidPushModel.objects.create(**uid_push_create_dict)
|
|
|
+ return response.json(0)
|
|
|
+
|
|
|
+ if status == '0':
|
|
|
# 状态为0的时候删除redis缓存数据
|
|
|
self.do_delete_redis(uid)
|
|
|
return response.json(0)
|
|
|
- elif status == 1:
|
|
|
+ elif status == '1':
|
|
|
uid_push_qs = UidPushModel.objects.filter(userID_id=userID, m_code=m_code, uid_set__uid=uid)
|
|
|
|
|
|
if uid_push_qs.exists():
|
|
@@ -230,8 +253,10 @@ class DetectControllerViewV2(View):
|
|
|
detectUrls = "{DETECT_PUSH_DOMAIN_V2}notifyV2/push?etk={etk}&company_secrete={company_secrete}®ion={region}". \
|
|
|
format(etk=etk, company_secrete=company_secrete, DETECT_PUSH_DOMAIN_V2=urls, region=region)
|
|
|
return response.json(0, {'detectUrl': detectUrl, 'detectUrls': detectUrls})
|
|
|
- else:
|
|
|
- return response.json(14)
|
|
|
+ else:
|
|
|
+ return response.json(173)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, repr(e))
|
|
|
|
|
|
def do_delete_redis(self, uid, detect_interval=0):
|
|
|
keyPattern = '{uid}*'.format(uid=uid)
|