|
@@ -17,8 +17,9 @@ from django.forms.models import model_to_dict
|
|
|
from django.utils import timezone
|
|
|
from django.views.generic.base import View
|
|
|
|
|
|
+from Ansjer.cn_config.config_test import CONFIG_INFO
|
|
|
from Ansjer.config import LOGGER, SERIAL_DOMAIN_NAME, HUAWEICLOUD_AK, HUAWEICLOUD_SK, HUAWEICLOUD_OBS_SERVER, \
|
|
|
- HUAWEICLOUD_BAIDU_BIG_MODEL_LICENSE_BUKET
|
|
|
+ HUAWEICLOUD_BAIDU_BIG_MODEL_LICENSE_BUKET, CONFIG_TEST, CONFIG_CN, CONFIG_US, CONFIG_EUR
|
|
|
from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, \
|
|
|
AWS_SES_ACCESS_REGION
|
|
|
from Ansjer.config import SERVER_DOMAIN_TEST, SERVER_DOMAIN_CN, SERVER_DOMAIN_US, SERVER_DOMAIN_EUR
|
|
@@ -124,7 +125,7 @@ class DeviceManagement(View):
|
|
|
return self.edit_device_ver_info(request_dict, response)
|
|
|
elif operation == 'delDeviceVerInfo': # 删除设备型号版本
|
|
|
return self.del_device_ver_info(request_dict, response)
|
|
|
- elif operation == 'syncDeviceVersion': # 删除设备型号版本
|
|
|
+ elif operation == 'syncDeviceVersion': # 一键同步
|
|
|
return self.sync_device_version(request_dict, response)
|
|
|
|
|
|
# 设备语音设置
|
|
@@ -1752,7 +1753,7 @@ class DeviceManagement(View):
|
|
|
version_config = version_config_qs.first()
|
|
|
|
|
|
# 将数据库字段映射为驼峰命名的响应数据
|
|
|
- response_data = {
|
|
|
+ req_data = {
|
|
|
'dCode': version_config.d_code,
|
|
|
'softwareVer': version_config.software_ver,
|
|
|
'firmwareVer': version_config.firmware_ver,
|
|
@@ -1778,7 +1779,8 @@ class DeviceManagement(View):
|
|
|
'electricityStatistics': version_config.electricity_statistics,
|
|
|
'supportsPetTracking': version_config.supports_pet_tracking
|
|
|
}
|
|
|
-
|
|
|
+ config_thread = threading.Thread(target=DeviceManagement.sync_device_version_config, kwargs=req_data)
|
|
|
+ config_thread.start()
|
|
|
# 返回成功响应,包含设备版本配置信息
|
|
|
return response.json(0)
|
|
|
|
|
@@ -1787,6 +1789,66 @@ class DeviceManagement(View):
|
|
|
LOGGER.exception("同步设备配置失败")
|
|
|
return response.json(500, f'Server error: {str(e)}')
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def sync_device_version_config(**req_data):
|
|
|
+ """
|
|
|
+ 同步设备版本信息到本地数据库及外部服务器(含异常跳过逻辑)
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ target_servers = []
|
|
|
+ if CONFIG_INFO == CONFIG_TEST:
|
|
|
+ target_servers = [
|
|
|
+ "https://www.zositechc.cn/open/device/configuration/syncVerConfig",
|
|
|
+ "https://www.dvema.com/open/device/configuration/syncVerConfig",
|
|
|
+ "https://api.zositeche.com/open/device/configuration/syncVerConfig"
|
|
|
+ ]
|
|
|
+ elif CONFIG_INFO == CONFIG_CN:
|
|
|
+ target_servers = [
|
|
|
+ "https://test.zositechc.cn/open/device/configuration/syncVerConfig",
|
|
|
+ "https://www.dvema.com/open/device/configuration/syncVerConfig",
|
|
|
+ "https://api.zositeche.com/open/device/configuration/syncVerConfig"
|
|
|
+ ]
|
|
|
+ elif CONFIG_INFO == CONFIG_US:
|
|
|
+ target_servers = [
|
|
|
+ "https://test.zositechc.cn/open/device/configuration/syncVerConfig",
|
|
|
+ "https://www.zositechc.cn/open/device/configuration/syncVerConfig",
|
|
|
+ "https://api.zositeche.com/open/device/configuration/syncVerConfig"
|
|
|
+ ]
|
|
|
+ elif CONFIG_INFO == CONFIG_EUR:
|
|
|
+ target_servers = [
|
|
|
+ "https://test.zositechc.cn/open/device/configuration/syncVerConfig",
|
|
|
+ "https://www.zositechc.cn/open/device/configuration/syncVerConfig",
|
|
|
+ "https://www.dvema.com/open/device/configuration/syncVerConfig"
|
|
|
+ ]
|
|
|
+
|
|
|
+ for server_url in target_servers:
|
|
|
+ try:
|
|
|
+ # 发送请求并设置超时(10秒)
|
|
|
+ headers = {'Content-Type': 'application/json'}
|
|
|
+ resp = requests.post(
|
|
|
+ server_url,
|
|
|
+ json=req_data,
|
|
|
+ headers=headers,
|
|
|
+ timeout=10 # 超时时间
|
|
|
+ )
|
|
|
+ resp.raise_for_status() # 抛出HTTP错误(如400/500)
|
|
|
+ LOGGER.info(f"[{server_url}] 同步成功,响应:{resp.json()}")
|
|
|
+
|
|
|
+ except requests.exceptions.ConnectTimeout:
|
|
|
+ LOGGER.error(f"[{server_url}] 连接超时,跳过")
|
|
|
+ continue
|
|
|
+ except requests.exceptions.ReadTimeout:
|
|
|
+ LOGGER.error(f"[{server_url}] 读取超时,跳过")
|
|
|
+ continue
|
|
|
+ except requests.exceptions.RequestException as e:
|
|
|
+ LOGGER.error(f"[{server_url}] 同步失败:{str(e)}")
|
|
|
+ continue # 跳过当前服务器
|
|
|
+ return True
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ LOGGER.exception("同步设备版本信息失败error{}".format(repr(e)))
|
|
|
+ return False
|
|
|
+
|
|
|
@staticmethod
|
|
|
def get_device_voice(request_dict, response):
|
|
|
"""
|