|
@@ -2,27 +2,23 @@
|
|
# -*- coding: utf-8 -*-
|
|
# -*- coding: utf-8 -*-
|
|
import json
|
|
import json
|
|
import logging
|
|
import logging
|
|
-import random
|
|
|
|
-import requests
|
|
|
|
import time
|
|
import time
|
|
|
|
|
|
|
|
+import requests
|
|
from django.db import transaction
|
|
from django.db import transaction
|
|
from django.views import View
|
|
from django.views import View
|
|
|
|
|
|
-from Controller.DetectController import DetectControllerView
|
|
|
|
-from Controller.DeviceConfirmRegion import Device_Region
|
|
|
|
-from Model.models import SerialNumberModel, CompanySerialModel, UIDCompanySerialModel, CompanyModel, RegionModel, \
|
|
|
|
- CountryModel, UIDModel, Device_Info, iotdeviceInfoModel, UidPushModel, LogModel, MacModel, UidSetModel, UID_Bucket, \
|
|
|
|
- Unused_Uid_Meal, Order_Model, StsCrdModel, VodHlsModel, ExperienceContextModel, Equipment_Info, UidUserModel
|
|
|
|
|
|
+from Ansjer.config import CRCKey, SERVER_DOMAIN_US, SERVER_DOMAIN_CN, CONFIG_INFO, CONFIG_TEST, CONFIG_US, \
|
|
|
|
+ CONFIG_CN
|
|
|
|
+from Model.models import SerialNumberModel, CompanySerialModel, UIDCompanySerialModel, UIDModel, Device_Info, \
|
|
|
|
+ iotdeviceInfoModel, LogModel, UidSetModel, UID_Bucket, \
|
|
|
|
+ Unused_Uid_Meal, Order_Model, StsCrdModel, VodHlsModel, ExperienceContextModel, UidUserModel
|
|
from Object.RedisObject import RedisObject
|
|
from Object.RedisObject import RedisObject
|
|
-from Object.uidManageResponseObject import uidManageResponseObject
|
|
|
|
from Object.TokenObject import TokenObject
|
|
from Object.TokenObject import TokenObject
|
|
|
|
+from Object.uidManageResponseObject import uidManageResponseObject
|
|
from Service.AlgorithmService import AlgorithmBaseOn35
|
|
from Service.AlgorithmService import AlgorithmBaseOn35
|
|
from Service.CommonService import CommonService
|
|
from Service.CommonService import CommonService
|
|
-from Ansjer.config import CRCKey, SERVER_TYPE, SERVER_DOMAIN_US, SERVER_DOMAIN_CN
|
|
|
|
from Service.EquipmentInfoService import EquipmentInfoService
|
|
from Service.EquipmentInfoService import EquipmentInfoService
|
|
-from Service.ModelService import ModelService
|
|
|
|
-from Object.AWS.S3Email import S3Email
|
|
|
|
|
|
|
|
|
|
|
|
class SerialNumberView(View):
|
|
class SerialNumberView(View):
|
|
@@ -45,9 +41,9 @@ class SerialNumberView(View):
|
|
|
|
|
|
if operation == 'getUID':
|
|
if operation == 'getUID':
|
|
return self.do_get_uid(request_dict, response)
|
|
return self.do_get_uid(request_dict, response)
|
|
- elif operation == 'attachUID': # 绑定uid
|
|
|
|
|
|
+ elif operation == 'attachUID': # 绑定uid
|
|
return self.do_attach_uid(request_dict, response, request)
|
|
return self.do_attach_uid(request_dict, response, request)
|
|
- elif operation == 'detachUID': # 解绑uid
|
|
|
|
|
|
+ elif operation == 'detachUID': # 解绑uid
|
|
return self.do_detach_uid(request, request_dict, response)
|
|
return self.do_detach_uid(request, request_dict, response)
|
|
elif operation == 'create':
|
|
elif operation == 'create':
|
|
return self.do_create(request_dict, response)
|
|
return self.do_create(request_dict, response)
|
|
@@ -155,14 +151,8 @@ class SerialNumberView(View):
|
|
|
|
|
|
try:
|
|
try:
|
|
if not country_id:
|
|
if not country_id:
|
|
- # 设备模拟国外环境测试
|
|
|
|
- # if SERVER_TYPE == 'Ansjer.us_config.formal_settings': # 国外正式配置使用固定ip进行测试
|
|
|
|
- # ip = '67.220.90.13'
|
|
|
|
- # else:
|
|
|
|
- # ip = CommonService.get_ip_address(request)
|
|
|
|
-
|
|
|
|
- ip = CommonService.get_ip_address(request)
|
|
|
|
- country_id = Device_Region().get_device_region(ip)
|
|
|
|
|
|
+ # 根据配置信息确定region_id
|
|
|
|
+ country_id = CommonService.confirm_region_id(request)
|
|
|
|
|
|
# 判断序列号是否已和企业关联
|
|
# 判断序列号是否已和企业关联
|
|
company_serial_qs = CompanySerialModel.objects.filter(company__secret=company_id, serial_number=serial)
|
|
company_serial_qs = CompanySerialModel.objects.filter(company__secret=company_id, serial_number=serial)
|
|
@@ -174,7 +164,7 @@ class SerialNumberView(View):
|
|
|
|
|
|
if company_serial.status == 0: # 该序列号未绑定企业
|
|
if company_serial.status == 0: # 该序列号未绑定企业
|
|
return response.json(173)
|
|
return response.json(173)
|
|
- elif company_serial.status == 1: # 绑定uid
|
|
|
|
|
|
+ elif company_serial.status == 1: # 绑定uid
|
|
# redis加锁,防止同一个序列号重复绑定
|
|
# redis加锁,防止同一个序列号重复绑定
|
|
key = serial + 'do_attach_uid'
|
|
key = serial + 'do_attach_uid'
|
|
redisObj = RedisObject()
|
|
redisObj = RedisObject()
|
|
@@ -188,7 +178,7 @@ class SerialNumberView(View):
|
|
# 查询是否存在未绑定序列号的uid
|
|
# 查询是否存在未绑定序列号的uid
|
|
uid_qs = UIDModel.objects.filter(vpg__company_id=company_serial.company.id,
|
|
uid_qs = UIDModel.objects.filter(vpg__company_id=company_serial.company.id,
|
|
vpg__region_id=country_id, status=0, p2p_type=p2p_type). \
|
|
vpg__region_id=country_id, status=0, p2p_type=p2p_type). \
|
|
- order_by('id')
|
|
|
|
|
|
+ order_by('id')
|
|
if not uid_qs.exists():
|
|
if not uid_qs.exists():
|
|
return response.json(375)
|
|
return response.json(375)
|
|
|
|
|
|
@@ -199,7 +189,7 @@ class SerialNumberView(View):
|
|
return response.json(377)
|
|
return response.json(377)
|
|
|
|
|
|
result = UIDModel.objects.filter(id=uid.id, status=0).update(status=2, update_time=now_time)
|
|
result = UIDModel.objects.filter(id=uid.id, status=0).update(status=2, update_time=now_time)
|
|
- if int(result) <= 0: # 更新失败
|
|
|
|
|
|
+ if int(result) <= 0: # 更新失败
|
|
count += 1
|
|
count += 1
|
|
continue
|
|
continue
|
|
|
|
|
|
@@ -216,7 +206,7 @@ class SerialNumberView(View):
|
|
|
|
|
|
full_uid_code = uid.full_uid_code
|
|
full_uid_code = uid.full_uid_code
|
|
if uid.platform in CRCKey.keys():
|
|
if uid.platform in CRCKey.keys():
|
|
- full_uid_code += ':'+CRCKey[uid.platform]
|
|
|
|
|
|
+ full_uid_code += ':' + CRCKey[uid.platform]
|
|
|
|
|
|
res = {
|
|
res = {
|
|
'full_uid_code': CommonService.encode_data(full_uid_code),
|
|
'full_uid_code': CommonService.encode_data(full_uid_code),
|
|
@@ -249,7 +239,7 @@ class SerialNumberView(View):
|
|
redisObj.del_data(key=key)
|
|
redisObj.del_data(key=key)
|
|
return response.json(0, res)
|
|
return response.json(0, res)
|
|
return response.json(5)
|
|
return response.json(5)
|
|
- elif company_serial.status == 2: # 返回uid
|
|
|
|
|
|
+ elif company_serial.status == 2: # 返回uid
|
|
uid_qs = UIDCompanySerialModel.objects.filter(company_serial_id=company_serial.id)
|
|
uid_qs = UIDCompanySerialModel.objects.filter(company_serial_id=company_serial.id)
|
|
if not uid_qs.exists():
|
|
if not uid_qs.exists():
|
|
return response.json(173)
|
|
return response.json(173)
|
|
@@ -257,7 +247,7 @@ class SerialNumberView(View):
|
|
'uid__platform', 'uid__init_string', 'uid__init_string_app')[0]
|
|
'uid__platform', 'uid__init_string', 'uid__init_string_app')[0]
|
|
full_uid_code = uid['uid__full_uid_code']
|
|
full_uid_code = uid['uid__full_uid_code']
|
|
if uid['uid__platform'] in CRCKey.keys():
|
|
if uid['uid__platform'] in CRCKey.keys():
|
|
- full_uid_code += ':'+CRCKey[uid['uid__platform']]
|
|
|
|
|
|
+ full_uid_code += ':' + CRCKey[uid['uid__platform']]
|
|
res = {
|
|
res = {
|
|
'full_uid_code': CommonService.encode_data(full_uid_code),
|
|
'full_uid_code': CommonService.encode_data(full_uid_code),
|
|
'uid': CommonService.encode_data(uid['uid__uid']),
|
|
'uid': CommonService.encode_data(uid['uid__uid']),
|
|
@@ -333,7 +323,7 @@ class SerialNumberView(View):
|
|
try:
|
|
try:
|
|
with transaction.atomic():
|
|
with transaction.atomic():
|
|
uid = uid_serial.uid.uid
|
|
uid = uid_serial.uid.uid
|
|
- company_serial_qs.update(status=1) # 更新序列号状态
|
|
|
|
|
|
+ company_serial_qs.update(status=1) # 更新序列号状态
|
|
# 删除设备相关数据,参考后台的设备重置删除的数据
|
|
# 删除设备相关数据,参考后台的设备重置删除的数据
|
|
Device_Info.objects.filter(UID=uid).delete()
|
|
Device_Info.objects.filter(UID=uid).delete()
|
|
UidSetModel.objects.filter(uid=uid).delete()
|
|
UidSetModel.objects.filter(uid=uid).delete()
|
|
@@ -358,7 +348,7 @@ class SerialNumberView(View):
|
|
except AssertionError:
|
|
except AssertionError:
|
|
return response.json(378)
|
|
return response.json(378)
|
|
|
|
|
|
- UIDModel.objects.filter(uid=uid).update(status=0, mac='') # 重置uid的使用状态为未使用
|
|
|
|
|
|
+ UIDModel.objects.filter(uid=uid).update(status=0, mac='') # 重置uid的使用状态为未使用
|
|
uid_serial.delete()
|
|
uid_serial.delete()
|
|
|
|
|
|
# 记录操作日志
|
|
# 记录操作日志
|
|
@@ -382,11 +372,12 @@ class SerialNumberView(View):
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
def update_serial_status(serial, status):
|
|
def update_serial_status(serial, status):
|
|
- if SERVER_TYPE == 'Ansjer.cn_config.test_settings': # 测试服不处理
|
|
|
|
|
|
+ if CONFIG_INFO == CONFIG_TEST: # 测试服不处理
|
|
return True
|
|
return True
|
|
- if SERVER_TYPE == 'Ansjer.us_config.formal_settings':
|
|
|
|
|
|
+ server_domain = SERVER_DOMAIN_CN
|
|
|
|
+ if CONFIG_INFO == CONFIG_US:
|
|
server_domain = SERVER_DOMAIN_CN
|
|
server_domain = SERVER_DOMAIN_CN
|
|
- elif SERVER_TYPE == 'Ansjer.cn_config.formal_settings':
|
|
|
|
|
|
+ elif CONFIG_INFO == CONFIG_CN:
|
|
server_domain = SERVER_DOMAIN_US
|
|
server_domain = SERVER_DOMAIN_US
|
|
url = server_domain + 'serialNumber/changeSerialNumberStatus'
|
|
url = server_domain + 'serialNumber/changeSerialNumberStatus'
|
|
data = {'serial': serial, 'status': status}
|
|
data = {'serial': serial, 'status': status}
|
|
@@ -434,4 +425,3 @@ class SerialNumberView(View):
|
|
djangoLogger = logging.getLogger('django')
|
|
djangoLogger = logging.getLogger('django')
|
|
djangoLogger.exception(repr(e))
|
|
djangoLogger.exception(repr(e))
|
|
return response.json(500, str(e))
|
|
return response.json(500, str(e))
|
|
-
|
|
|