|
@@ -231,9 +231,8 @@ class SerialNumberView(View):
|
|
|
|
|
|
return response.json(0, res)
|
|
|
return response.json(5)
|
|
|
- elif company_serial.status == 2: # 返回uid
|
|
|
- res = self.get_uid_info_by_serial(company_serial.id)
|
|
|
- return response.json(0, res)
|
|
|
+ elif company_serial.status == 2: # 不返回uid
|
|
|
+ return response.json(0)
|
|
|
elif company_serial.status == 3: # 已占用
|
|
|
sync_success = self.sync_serial_data_and_log(request, company_serial.id, serial_number, now_time)
|
|
|
if not sync_success:
|
|
@@ -366,98 +365,101 @@ class SerialNumberView(View):
|
|
|
@return : bool
|
|
|
"""
|
|
|
ip = CommonService.get_ip_address(request)
|
|
|
- operation = '{}序列号占用,'.format(serial)
|
|
|
+ operation = '{}序列号占用,APP扫码已停用同步UID'.format(serial)
|
|
|
log = {
|
|
|
'ip': ip,
|
|
|
'user_id': 1,
|
|
|
'status': 200,
|
|
|
'time': now_time,
|
|
|
'url': 'serialNumber/attachUID',
|
|
|
+ 'operation': operation
|
|
|
}
|
|
|
- sync_result = False
|
|
|
- # 测试服和国内服不同步
|
|
|
- if CONFIG_INFO == 'test' or CONFIG_INFO == 'cn':
|
|
|
- return sync_result
|
|
|
- try:
|
|
|
- # 判断当前序列号是否绑定UID
|
|
|
- uid_serial_qs = UIDCompanySerialModel.objects.filter(company_serial_id=company_serial_id)
|
|
|
- if uid_serial_qs.exists():
|
|
|
- operation += ',已绑定UID,不同步数据'
|
|
|
- log['operation'] = operation
|
|
|
- LogModel.objects.create(**log)
|
|
|
- return sync_result
|
|
|
-
|
|
|
- region = 'us'
|
|
|
- # 欧洲服同步美洲服,美洲服同步国内服数据
|
|
|
- if CONFIG_INFO == 'eur':
|
|
|
- domain_name = 'https://www.dvema.com/'
|
|
|
- else:
|
|
|
- region = 'cn'
|
|
|
- domain_name = 'https://www.zositechc.cn/'
|
|
|
-
|
|
|
- url = domain_name + 'serialNumber/get-status'
|
|
|
- response = requests.get(url=url, params={'serial_number': serial}, timeout=15)
|
|
|
-
|
|
|
- if response.status_code != 200:
|
|
|
- operation += '查询{}服UID数据响应状态码异常:{}'.format(region, response.status_code)
|
|
|
- log['operation'] = operation
|
|
|
- LogModel.objects.create(**log)
|
|
|
- return sync_result
|
|
|
-
|
|
|
- results = json.loads(response.text)
|
|
|
- if results['result_code'] != 0:
|
|
|
- operation += '查询{}服UID数据result_code异常:{}'.format(region, results['result_code'])
|
|
|
- log['operation'] = operation
|
|
|
- LogModel.objects.create(**log)
|
|
|
- return sync_result
|
|
|
-
|
|
|
- # 其它服没有绑定uid
|
|
|
- uid_info = results['result']['uidInfo']
|
|
|
- if not uid_info:
|
|
|
- operation += '{}服没有绑定UID'.format(region)
|
|
|
- log['operation'] = operation
|
|
|
- LogModel.objects.create(**log)
|
|
|
- return sync_result
|
|
|
- # 同步uid数据
|
|
|
- if uid_info['p2p_type'] == 1:
|
|
|
- operation += '尚云UID不同步数据'
|
|
|
- else:
|
|
|
- uid_qs = UIDModel.objects.filter(uid=uid_info['uid'])
|
|
|
- if not uid_qs.exists():
|
|
|
- uid_info['add_time'] = now_time
|
|
|
- uid_info['update_time'] = now_time
|
|
|
- uid_id = UIDModel.objects.create(**uid_info).id
|
|
|
- else:
|
|
|
- if uid_qs.first().status == 2: # 判断uid是否被使用
|
|
|
- operation += 'uid{}已被使用'.format(uid_info['uid'])
|
|
|
- log['operation'] = operation
|
|
|
- LogModel.objects.create(**log)
|
|
|
- return sync_result
|
|
|
- else:
|
|
|
- uid_qs.update(status=2, update_time=now_time)
|
|
|
- uid_id = uid_qs.first().id
|
|
|
-
|
|
|
- # 企业序列号关联 uid
|
|
|
- UIDCompanySerialModel.objects.create(
|
|
|
- uid_id=uid_id, company_serial_id=company_serial_id, add_time=now_time, update_time=now_time)
|
|
|
- # 修改企业序列号状态为2(绑定uid)
|
|
|
- CompanySerialModel.objects.filter(id=company_serial_id) \
|
|
|
- .update(status=2, update_time=now_time)
|
|
|
- sync_iot_result = SerialNumberView.sync_iot_core_data(domain_name, serial)
|
|
|
-
|
|
|
- operation += '同步{}服uid数据成功,同步iot数据结果:{}'.format(region, sync_iot_result)
|
|
|
- sync_result = True
|
|
|
-
|
|
|
- # 记录日志
|
|
|
- log['operation'] = operation
|
|
|
- LogModel.objects.create(**log)
|
|
|
- return sync_result
|
|
|
-
|
|
|
- except Exception as e:
|
|
|
- operation += '同步数据异常,error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e))
|
|
|
- log['operation'] = operation
|
|
|
- LogModel.objects.create(**log)
|
|
|
- return sync_result
|
|
|
+ LogModel.objects.create(**log)
|
|
|
+ return False
|
|
|
+ # sync_result = False
|
|
|
+ # # 测试服和国内服不同步
|
|
|
+ # if CONFIG_INFO == 'test' or CONFIG_INFO == 'cn':
|
|
|
+ # return sync_result
|
|
|
+ # try:
|
|
|
+ # # 判断当前序列号是否绑定UID
|
|
|
+ # uid_serial_qs = UIDCompanySerialModel.objects.filter(company_serial_id=company_serial_id)
|
|
|
+ # if uid_serial_qs.exists():
|
|
|
+ # operation += ',已绑定UID,不同步数据'
|
|
|
+ # log['operation'] = operation
|
|
|
+ # LogModel.objects.create(**log)
|
|
|
+ # return sync_result
|
|
|
+ #
|
|
|
+ # region = 'us'
|
|
|
+ # # 欧洲服同步美洲服,美洲服同步国内服数据
|
|
|
+ # if CONFIG_INFO == 'eur':
|
|
|
+ # domain_name = 'https://www.dvema.com/'
|
|
|
+ # else:
|
|
|
+ # region = 'cn'
|
|
|
+ # domain_name = 'https://www.zositechc.cn/'
|
|
|
+ #
|
|
|
+ # url = domain_name + 'serialNumber/get-status'
|
|
|
+ # response = requests.get(url=url, params={'serial_number': serial}, timeout=15)
|
|
|
+ #
|
|
|
+ # if response.status_code != 200:
|
|
|
+ # operation += '查询{}服UID数据响应状态码异常:{}'.format(region, response.status_code)
|
|
|
+ # log['operation'] = operation
|
|
|
+ # LogModel.objects.create(**log)
|
|
|
+ # return sync_result
|
|
|
+ #
|
|
|
+ # results = json.loads(response.text)
|
|
|
+ # if results['result_code'] != 0:
|
|
|
+ # operation += '查询{}服UID数据result_code异常:{}'.format(region, results['result_code'])
|
|
|
+ # log['operation'] = operation
|
|
|
+ # LogModel.objects.create(**log)
|
|
|
+ # return sync_result
|
|
|
+ #
|
|
|
+ # # 其它服没有绑定uid
|
|
|
+ # uid_info = results['result']['uidInfo']
|
|
|
+ # if not uid_info:
|
|
|
+ # operation += '{}服没有绑定UID'.format(region)
|
|
|
+ # log['operation'] = operation
|
|
|
+ # LogModel.objects.create(**log)
|
|
|
+ # return sync_result
|
|
|
+ # # 同步uid数据
|
|
|
+ # if uid_info['p2p_type'] == 1:
|
|
|
+ # operation += '尚云UID不同步数据'
|
|
|
+ # else:
|
|
|
+ # uid_qs = UIDModel.objects.filter(uid=uid_info['uid'])
|
|
|
+ # if not uid_qs.exists():
|
|
|
+ # uid_info['add_time'] = now_time
|
|
|
+ # uid_info['update_time'] = now_time
|
|
|
+ # uid_id = UIDModel.objects.create(**uid_info).id
|
|
|
+ # else:
|
|
|
+ # if uid_qs.first().status == 2: # 判断uid是否被使用
|
|
|
+ # operation += 'uid{}已被使用'.format(uid_info['uid'])
|
|
|
+ # log['operation'] = operation
|
|
|
+ # LogModel.objects.create(**log)
|
|
|
+ # return sync_result
|
|
|
+ # else:
|
|
|
+ # uid_qs.update(status=2, update_time=now_time)
|
|
|
+ # uid_id = uid_qs.first().id
|
|
|
+ #
|
|
|
+ # # 企业序列号关联 uid
|
|
|
+ # UIDCompanySerialModel.objects.create(
|
|
|
+ # uid_id=uid_id, company_serial_id=company_serial_id, add_time=now_time, update_time=now_time)
|
|
|
+ # # 修改企业序列号状态为2(绑定uid)
|
|
|
+ # CompanySerialModel.objects.filter(id=company_serial_id) \
|
|
|
+ # .update(status=2, update_time=now_time)
|
|
|
+ # sync_iot_result = SerialNumberView.sync_iot_core_data(domain_name, serial)
|
|
|
+ #
|
|
|
+ # operation += '同步{}服uid数据成功,同步iot数据结果:{}'.format(region, sync_iot_result)
|
|
|
+ # sync_result = True
|
|
|
+ #
|
|
|
+ # # 记录日志
|
|
|
+ # log['operation'] = operation
|
|
|
+ # LogModel.objects.create(**log)
|
|
|
+ # return sync_result
|
|
|
+ #
|
|
|
+ # except Exception as e:
|
|
|
+ # operation += '同步数据异常,error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e))
|
|
|
+ # log['operation'] = operation
|
|
|
+ # LogModel.objects.create(**log)
|
|
|
+ # return sync_result
|
|
|
|
|
|
def do_get_uid(self, request_dict, response):
|
|
|
serial_number = request_dict.get('serial_number', None)
|