|
@@ -130,8 +130,19 @@ class SerialNumberView(View):
|
|
company_secret = 'ZsKWcxdD'
|
|
company_secret = 'ZsKWcxdD'
|
|
|
|
|
|
try:
|
|
try:
|
|
- # 判断序列号是否刚解绑,刚解绑1分钟内不能进行绑定
|
|
|
|
redisObj = RedisObject()
|
|
redisObj = RedisObject()
|
|
|
|
+ # 查询app是否已扫码,未扫码不能进行绑定
|
|
|
|
+ # 如果没扫码设置24小时的缓存,扫码后删除缓存
|
|
|
|
+ scanned_serial_key = serial + 'scanned_serial'
|
|
|
|
+ if redisObj.get_data(scanned_serial_key):
|
|
|
|
+ return response.json(5)
|
|
|
|
+ app_scanned_serial_qs = AppScannedSerial.objects.filter(serial=serial).values('region_country')
|
|
|
|
+ if not app_scanned_serial_qs.exists():
|
|
|
|
+ redisObj.set_data(scanned_serial_key, 1, 24*60*60)
|
|
|
|
+ LOGGER.info(f'{serial}当前序列号未进行APP扫码')
|
|
|
|
+ return response.json(5)
|
|
|
|
+
|
|
|
|
+ # 判断序列号是否刚解绑,刚解绑1分钟内不能进行绑定
|
|
unused_serial_redis_list = redisObj.lrange(UNUSED_SERIAL_REDIS_LIST, 0, -1)
|
|
unused_serial_redis_list = redisObj.lrange(UNUSED_SERIAL_REDIS_LIST, 0, -1)
|
|
unused_serial_redis_list = [str(i, 'utf-8') for i in unused_serial_redis_list]
|
|
unused_serial_redis_list = [str(i, 'utf-8') for i in unused_serial_redis_list]
|
|
if serial in unused_serial_redis_list:
|
|
if serial in unused_serial_redis_list:
|
|
@@ -142,6 +153,13 @@ class SerialNumberView(View):
|
|
if serial_unbind_uid_qs.exists():
|
|
if serial_unbind_uid_qs.exists():
|
|
return response.json(5)
|
|
return response.json(5)
|
|
|
|
|
|
|
|
+ # redis加锁,防止同一个序列号重复绑定
|
|
|
|
+ key = serial + 'do_attach_uid'
|
|
|
|
+ is_lock = redisObj.CONN.setnx(key, 1)
|
|
|
|
+ if not is_lock:
|
|
|
|
+ return response.json(5)
|
|
|
|
+ redisObj.CONN.expire(key, 60)
|
|
|
|
+
|
|
# 判断序列号是否已和企业关联
|
|
# 判断序列号是否已和企业关联
|
|
company_serial_qs = CompanySerialModel.objects.filter(company__secret=company_secret, serial_number=serial)
|
|
company_serial_qs = CompanySerialModel.objects.filter(company__secret=company_secret, serial_number=serial)
|
|
if not company_serial_qs.exists():
|
|
if not company_serial_qs.exists():
|
|
@@ -155,20 +173,8 @@ class SerialNumberView(View):
|
|
if is_verify == '1':
|
|
if is_verify == '1':
|
|
region_country = 0
|
|
region_country = 0
|
|
else:
|
|
else:
|
|
- # 查询app是否已扫码,未扫码不能进行绑定
|
|
|
|
- app_scanned_serial_qs = AppScannedSerial.objects.filter(serial=serial).values('region_country')
|
|
|
|
- if not app_scanned_serial_qs.exists():
|
|
|
|
- LOGGER.info(f'{serial}当前序列号未进行APP扫码')
|
|
|
|
- return response.json(5)
|
|
|
|
region_country = app_scanned_serial_qs[0]['region_country']
|
|
region_country = app_scanned_serial_qs[0]['region_country']
|
|
|
|
|
|
- # redis加锁,防止同一个序列号重复绑定
|
|
|
|
- key = serial + 'do_attach_uid'
|
|
|
|
- is_lock = redisObj.CONN.setnx(key, 1)
|
|
|
|
- if not is_lock:
|
|
|
|
- return response.json(5)
|
|
|
|
- redisObj.CONN.expire(key, 60)
|
|
|
|
-
|
|
|
|
# 获取并判断region_id
|
|
# 获取并判断region_id
|
|
region_id = CommonService.confirm_region_id(region_country)
|
|
region_id = CommonService.confirm_region_id(region_country)
|
|
if region_id not in REGION_ID_LIST:
|
|
if region_id not in REGION_ID_LIST:
|
|
@@ -216,10 +222,6 @@ class SerialNumberView(View):
|
|
company_serial.update_time = now_time
|
|
company_serial.update_time = now_time
|
|
company_serial.save()
|
|
company_serial.save()
|
|
|
|
|
|
- dev = Device_Info.objects.filter(UID=uid.uid)
|
|
|
|
- if dev.exists():
|
|
|
|
- dev.update(serial_number=full_serial)
|
|
|
|
-
|
|
|
|
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]
|
|
@@ -277,9 +279,7 @@ class SerialNumberView(View):
|
|
return response.json(10042)
|
|
return response.json(10042)
|
|
return response.json(0, self.get_uid_info_by_serial(company_serial.id))
|
|
return response.json(0, self.get_uid_info_by_serial(company_serial.id))
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- djangoLogger = logging.getLogger('django')
|
|
|
|
- djangoLogger.exception(repr(e))
|
|
|
|
- return response.json(176, str(e))
|
|
|
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def get_uid_info_by_serial(cls, company_serial_id):
|
|
def get_uid_info_by_serial(cls, company_serial_id):
|
|
@@ -660,6 +660,11 @@ class SerialNumberView(View):
|
|
data['add_time'] = now_time
|
|
data['add_time'] = now_time
|
|
AppScannedSerial.objects.create(**data)
|
|
AppScannedSerial.objects.create(**data)
|
|
|
|
|
|
|
|
+ # 扫码后删除缓存
|
|
|
|
+ redis_obj = RedisObject()
|
|
|
|
+ scanned_serial_key = serial + 'scanned_serial'
|
|
|
|
+ redis_obj.del_data(scanned_serial_key)
|
|
|
|
+
|
|
if company_serial.status == 0 or company_serial.status == 1: # 未使用
|
|
if company_serial.status == 0 or company_serial.status == 1: # 未使用
|
|
UnicomComboView().is_4g_device(serial_number, request_dict, request)
|
|
UnicomComboView().is_4g_device(serial_number, request_dict, request)
|
|
return response.json(173)
|
|
return response.json(173)
|