|
@@ -55,7 +55,7 @@ class SerialView(View):
|
|
|
if operation == 'number/page':
|
|
|
return self.serial_page(request_dict, response)
|
|
|
if operation == 'syncSerial': # 同步序列号数据
|
|
|
- return self.sync_serial(request_dict, response)
|
|
|
+ return self.sync_serial(request, request_dict, response)
|
|
|
if operation == 'vpg-info/page':
|
|
|
return self.vpg_page(request_dict, response)
|
|
|
if operation == 'uid-info/page':
|
|
@@ -196,7 +196,7 @@ class SerialView(View):
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
@staticmethod
|
|
|
- def sync_serial(request_dict, response):
|
|
|
+ def sync_serial(request, request_dict, response):
|
|
|
serial = request_dict.get('serial', None)
|
|
|
sync_region = request_dict.get('syncRegion', None)
|
|
|
if not all([serial, sync_region]):
|
|
@@ -236,7 +236,7 @@ class SerialView(View):
|
|
|
with transaction.atomic():
|
|
|
if uid_qs.exists():
|
|
|
uid_qs.update(status=2)
|
|
|
- uid_id = uid_qs['id']
|
|
|
+ uid_id = uid_qs[0]['id']
|
|
|
else:
|
|
|
uid_data = {
|
|
|
'uid': uid,
|
|
@@ -267,7 +267,7 @@ class SerialView(View):
|
|
|
company_serial_qs.update(status=2)
|
|
|
|
|
|
# 同步iot数据
|
|
|
- if res_data['certificate_id']:
|
|
|
+ if res_data.get('certificate_id'):
|
|
|
iot_device_info_qs = iotdeviceInfoModel.objects.filter(serial_number=serial).\
|
|
|
values('certificate_id')
|
|
|
iot_data = {
|
|
@@ -286,6 +286,20 @@ class SerialView(View):
|
|
|
else:
|
|
|
iot_data['serial_number'] = serial
|
|
|
iotdeviceInfoModel.objects.create(**iot_data)
|
|
|
+
|
|
|
+ # 记录操作日志
|
|
|
+ ip = CommonService.get_ip_address(request)
|
|
|
+ content = json.loads(json.dumps(request_dict))
|
|
|
+ log = {
|
|
|
+ 'ip': ip,
|
|
|
+ 'user_id': 1,
|
|
|
+ 'status': 200,
|
|
|
+ 'time': now_time,
|
|
|
+ 'url': 'serial/syncSerial',
|
|
|
+ 'content': json.dumps(content),
|
|
|
+ 'operation': '序列号{}同步{}服数据'.format(serial, sync_region)
|
|
|
+ }
|
|
|
+ LogModel.objects.create(**log)
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|