|
@@ -14,7 +14,9 @@ from django.db.models import Q, F, Sum, OuterRef, Min, Subquery
|
|
|
from django.forms.models import model_to_dict
|
|
|
from django.views.generic.base import View
|
|
|
|
|
|
-from Ansjer.config import LOGGER, SERIAL_DOMAIN_NAME
|
|
|
+from Ansjer.cn_config.config_test import CONFIG_INFO
|
|
|
+from Ansjer.config import LOGGER, SERIAL_DOMAIN_NAME, \
|
|
|
+ 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
|
|
@@ -117,6 +119,8 @@ 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': # 一键同步
|
|
|
+ return self.sync_device_version(request_dict, response)
|
|
|
|
|
|
# 设备语音设置
|
|
|
elif operation == 'getDeviceVoice': # 获取设备音频
|
|
@@ -1686,6 +1690,131 @@ class DeviceManagement(View):
|
|
|
device_version_info_qs.delete()
|
|
|
return response.json(0)
|
|
|
|
|
|
+ @classmethod
|
|
|
+ def sync_device_version(cls, request_dict, response):
|
|
|
+ """
|
|
|
+ 同步设备版本信息
|
|
|
+ @param user_id: 用户ID
|
|
|
+ @param request: 请求对象
|
|
|
+ @param request_dict: 请求参数
|
|
|
+ @param response: 响应对象
|
|
|
+ @return: 响应结果
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ # 从请求字典中获取设备码和版本号
|
|
|
+ version = request_dict.get('softwareVer')
|
|
|
+ d_code = request_dict.get('dCode')
|
|
|
+
|
|
|
+ # 查询设备版本配置
|
|
|
+ version_config_qs = DeviceVersionInfo.objects.filter(
|
|
|
+ d_code=d_code,
|
|
|
+ software_ver=version
|
|
|
+ )
|
|
|
+
|
|
|
+ # 检查是否存在匹配的配置
|
|
|
+ if not version_config_qs.exists():
|
|
|
+ return response.json(173) # 设备版本配置不存在
|
|
|
+
|
|
|
+ # 获取第一条匹配的记录(通常应该只有一条)
|
|
|
+ version_config = version_config_qs.first()
|
|
|
+
|
|
|
+ # 将数据库字段映射为驼峰命名的响应数据
|
|
|
+ req_data = {
|
|
|
+ 'dCode': version_config.d_code,
|
|
|
+ 'softwareVer': version_config.software_ver,
|
|
|
+ 'firmwareVer': version_config.firmware_ver,
|
|
|
+ 'videoCode': version_config.video_code,
|
|
|
+ 'regionAlexa': version_config.region_alexa,
|
|
|
+ 'supportsHumanTracking': version_config.supports_human_tracking,
|
|
|
+ 'supportsCustomVoice': version_config.supports_custom_voice,
|
|
|
+ 'supportsDualBandWifi': version_config.supports_dual_band_wifi,
|
|
|
+ 'supportsFourPoint': version_config.supports_four_point,
|
|
|
+ 'supports4g': version_config.supports_4g,
|
|
|
+ 'supportsPTZ': version_config.supports_ptz,
|
|
|
+ 'supportsAi': version_config.supports_ai,
|
|
|
+ 'supportsCloudStorage': version_config.supports_cloud_storage,
|
|
|
+ 'supportsAlexa': version_config.supports_alexa,
|
|
|
+ 'deviceType': version_config.device_type,
|
|
|
+ 'resolution': version_config.resolution,
|
|
|
+ 'aiType': version_config.ai_type,
|
|
|
+ 'supportsAlarm': version_config.supports_alarm,
|
|
|
+ 'supportsNightVision': version_config.supports_night_vision,
|
|
|
+ 'screenChannels': version_config.screen_channels,
|
|
|
+ 'networkType': version_config.network_type,
|
|
|
+ 'otherFeatures': version_config.other_features,
|
|
|
+ '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)
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ # 通用异常处理(建议替换为具体异常类型)
|
|
|
+ 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):
|
|
|
"""
|