|
@@ -12,7 +12,7 @@ from django.db.models import Q, F, Sum
|
|
from django.forms.models import model_to_dict
|
|
from django.forms.models import model_to_dict
|
|
from django.views.generic.base import View
|
|
from django.views.generic.base import View
|
|
|
|
|
|
-from Ansjer.config import LOGGER
|
|
|
|
|
|
+from Ansjer.config import LOGGER, SERIAL_DOMAIN_NAME
|
|
from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, \
|
|
from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, \
|
|
AWS_SES_ACCESS_REGION
|
|
AWS_SES_ACCESS_REGION
|
|
from Ansjer.config import SERVER_DOMAIN_TEST, SERVER_DOMAIN_CN, SERVER_DOMAIN_US, SERVER_DOMAIN_EUR
|
|
from Ansjer.config import SERVER_DOMAIN_TEST, SERVER_DOMAIN_CN, SERVER_DOMAIN_US, SERVER_DOMAIN_EUR
|
|
@@ -1216,51 +1216,78 @@ class DeviceManagement(View):
|
|
try:
|
|
try:
|
|
# 从请求中检索文件
|
|
# 从请求中检索文件
|
|
file = request.FILES.get('deviceFile')
|
|
file = request.FILES.get('deviceFile')
|
|
- fileType = int(request_dict.get('type', 1))
|
|
|
|
|
|
+ file_type = int(request_dict.get('type', 1))
|
|
uid_list = []
|
|
uid_list = []
|
|
|
|
|
|
if not file:
|
|
if not file:
|
|
return response.json(444)
|
|
return response.json(444)
|
|
|
|
|
|
- # 处理文件内容并生成UID列表
|
|
|
|
- for item in file:
|
|
|
|
- id_val = item.decode().strip().replace(" ", "")
|
|
|
|
- if fileType == 2:
|
|
|
|
- uid = CommonService.get_uid_by_serial_number(id_val[:9])
|
|
|
|
- uid_list.append(uid)
|
|
|
|
- else:
|
|
|
|
- uid_list.append(id_val)
|
|
|
|
-
|
|
|
|
- if not uid_list:
|
|
|
|
- return response.json(0, {'userInfo': []})
|
|
|
|
-
|
|
|
|
- user_info = []
|
|
|
|
- batch_size = 50 # 为查询设置合理的批处理大小
|
|
|
|
-
|
|
|
|
- # 批量获取设备信息
|
|
|
|
- for i in range(0, len(uid_list), batch_size):
|
|
|
|
- batch_uids = uid_list[i:i + batch_size]
|
|
|
|
- device_info_qs = Device_Info.objects.filter(UID__in=batch_uids).values('UID', 'NickName', 'ip',
|
|
|
|
- 'userID__username')
|
|
|
|
- uid_to_device_info = {device_info['UID']: device_info for device_info in device_info_qs}
|
|
|
|
-
|
|
|
|
- # 将查询到的设备信息与当前批次进行匹配
|
|
|
|
- for uid in batch_uids:
|
|
|
|
- if uid in uid_to_device_info:
|
|
|
|
- device_info = uid_to_device_info[uid]
|
|
|
|
- user_info.append({
|
|
|
|
- 'uid': device_info['UID'],
|
|
|
|
- 'deviceName': device_info['NickName'],
|
|
|
|
- 'ip': device_info['ip'],
|
|
|
|
- 'uName': device_info['userID__username']
|
|
|
|
- })
|
|
|
|
|
|
+ device_info_list = []
|
|
|
|
+ # 处理文件内容并生成设备信息列表
|
|
|
|
+ # 序列号
|
|
|
|
+ if file_type == 2:
|
|
|
|
+ for item in file:
|
|
|
|
+ item = item.decode().strip().replace(" ", "")
|
|
|
|
+ # 请求序列号系统查询获取序列号记录
|
|
|
|
+ url = 'http://{}/serialNumber/checkSerialLog'.format(SERIAL_DOMAIN_NAME)
|
|
|
|
+ params = {'serial': item[:6]}
|
|
|
|
+ r = requests.get(url=url, params=params, timeout=5)
|
|
|
|
+ assert r.status_code == 200
|
|
|
|
+ result = eval(r.content)
|
|
|
|
+ is_reset = 0 if result['code'] == 0 else 1
|
|
|
|
+
|
|
|
|
+ uid = CommonService.get_uid_by_serial_number(item[:9])
|
|
|
|
+ # 根据uid查询设备信息
|
|
|
|
+ device_name, ip, username = cls.get_device_info(uid)
|
|
|
|
+
|
|
|
|
+ device_info_data = {
|
|
|
|
+ 'isReset': is_reset,
|
|
|
|
+ 'uid': uid,
|
|
|
|
+ 'serialNumber': item,
|
|
|
|
+ 'deviceName': device_name,
|
|
|
|
+ 'ip': ip,
|
|
|
|
+ 'uName': username
|
|
|
|
+ }
|
|
|
|
+ device_info_list.append(device_info_data)
|
|
|
|
+ # uid
|
|
|
|
+ else:
|
|
|
|
+ for item in file:
|
|
|
|
+ uid = item.decode().strip().replace(" ", "")
|
|
|
|
+ is_reset = 0
|
|
|
|
+ serial_number = CommonService.get_serial_number_by_uid(uid)
|
|
|
|
+ if serial_number == uid:
|
|
|
|
+ serial_number = ''
|
|
|
|
+ device_name, ip, username = cls.get_device_info(uid)
|
|
|
|
+ device_info_data = {
|
|
|
|
+ 'isReset': is_reset,
|
|
|
|
+ 'uid': uid,
|
|
|
|
+ 'serialNumber': serial_number,
|
|
|
|
+ 'deviceName': device_name,
|
|
|
|
+ 'ip': ip,
|
|
|
|
+ 'uName': username
|
|
|
|
+ }
|
|
|
|
+ device_info_list.append(device_info_data)
|
|
|
|
|
|
# 返回带有用户信息的响应
|
|
# 返回带有用户信息的响应
|
|
- return response.json(0, {'userInfo': user_info})
|
|
|
|
|
|
+ return response.json(0, {'userInfo': device_info_list})
|
|
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- LOGGER.error(f'查询设备信息异常: errLine: {e.__traceback__.tb_lineno}, errMsg: {repr(e)}')
|
|
|
|
- return response.json(5)
|
|
|
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def get_device_info(uid):
|
|
|
|
+ """
|
|
|
|
+ 根据uid查询设备信息
|
|
|
|
+ :param uid:
|
|
|
|
+ :return: device_name, ip, username
|
|
|
|
+ """
|
|
|
|
+ device_name, ip, username = '', '', ''
|
|
|
|
+ device_info_qs = Device_Info.objects.filter(UID=uid).values('NickName', 'ip', 'userID__username')
|
|
|
|
+ if device_info_qs.exists():
|
|
|
|
+ device_name = device_info_qs[0]['NickName']
|
|
|
|
+ ip = device_info_qs[0]['ip']
|
|
|
|
+ username = device_info_qs[0]['userID__username']
|
|
|
|
+ return device_name, ip, username
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
def get_customer_device_list(request_dict, response):
|
|
def get_customer_device_list(request_dict, response):
|