|
@@ -983,8 +983,8 @@ class SerialNumberView(View):
|
|
|
LOGGER.info('{}同步iot异常,errLine:{}, errMsg:{}'.format(serial_number, e.__traceback__.tb_lineno, repr(e)))
|
|
|
return False
|
|
|
|
|
|
- @staticmethod
|
|
|
- def save_user_net_info(request_dict, response):
|
|
|
+ @classmethod
|
|
|
+ def save_user_net_info(cls, request_dict, response):
|
|
|
"""
|
|
|
保存用户网络信息
|
|
|
@return:
|
|
@@ -1038,6 +1038,9 @@ class SerialNumberView(View):
|
|
|
device_net_info_qs = DeviceNetInfo.objects.filter(device_id=device_id)
|
|
|
if device_net_info_qs.exists():
|
|
|
device_net_info_qs.update(wifi_name=wifi_name, wifi_password=wifi_password)
|
|
|
+ else:
|
|
|
+ # 创建用户设备和设备网络数据
|
|
|
+ cls.creat_device_data(user_id, serial, uid, device_type, username, wifi_name, wifi_password)
|
|
|
else:
|
|
|
# 判断设备是否已被其他账号添加
|
|
|
device_info_qs = Device_Info.objects.filter(UID=uid).values('id')
|
|
@@ -1060,16 +1063,8 @@ class SerialNumberView(View):
|
|
|
return response.json(444)
|
|
|
Device_User.objects.create(**user_data)
|
|
|
|
|
|
- # 创建用户设备数据
|
|
|
- device_id = CommonService.getUserID(getUser=False)
|
|
|
- Device_Info.objects.create(
|
|
|
- id=device_id, userID_id=user_id, serial_number=serial_number, UID=uid, NickName=serial[:6],
|
|
|
- Type=device_type, View_Account='admin', View_Password='admin', vodPrimaryMaster=username,
|
|
|
- vodPrimaryUserID=user_id
|
|
|
- )
|
|
|
- DeviceNetInfo.objects.create(
|
|
|
- device_id=device_id, wifi_name=wifi_name, wifi_password=wifi_password
|
|
|
- )
|
|
|
+ # 创建用户设备和设备网络数据
|
|
|
+ cls.creat_device_data(user_id, serial, uid, device_type, username, wifi_name, wifi_password)
|
|
|
|
|
|
# 生成或更新扫码记录
|
|
|
serial = serial[:6]
|
|
@@ -1082,3 +1077,26 @@ class SerialNumberView(View):
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def creat_device_data(user_id, serial, uid, device_type, username, wifi_name, wifi_password):
|
|
|
+ """
|
|
|
+
|
|
|
+ @param user_id:
|
|
|
+ @param serial:
|
|
|
+ @param uid:
|
|
|
+ @param device_type:
|
|
|
+ @param username:
|
|
|
+ @param wifi_name:
|
|
|
+ @param wifi_password:
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ device_id = CommonService.getUserID(getUser=False)
|
|
|
+ Device_Info.objects.create(
|
|
|
+ id=device_id, userID_id=user_id, serial_number=serial[:9], UID=uid, NickName=serial[:6],
|
|
|
+ Type=device_type, View_Account='admin', View_Password='admin', vodPrimaryMaster=username,
|
|
|
+ vodPrimaryUserID=user_id
|
|
|
+ )
|
|
|
+ DeviceNetInfo.objects.create(
|
|
|
+ device_id=device_id, wifi_name=wifi_name, wifi_password=wifi_password
|
|
|
+ )
|