|
@@ -6,24 +6,26 @@ import operator
|
|
|
import os
|
|
|
import threading
|
|
|
import time
|
|
|
-
|
|
|
+import csv
|
|
|
import oss2
|
|
|
import requests
|
|
|
+from obs import ObsClient
|
|
|
from django.core.paginator import Paginator
|
|
|
from django.db import transaction
|
|
|
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, \
|
|
|
- CONFIG_INFO, CONFIG_TEST, CONFIG_CN, CONFIG_US, CONFIG_EUR
|
|
|
+from Ansjer.config import LOGGER, SERIAL_DOMAIN_NAME, HUAWEICLOUD_AK, HUAWEICLOUD_SK, HUAWEICLOUD_OBS_SERVER, \
|
|
|
+ HUAWEICLOUD_BAIDU_BIG_MODEL_LICENSE_BUKET,CONFIG_INFO, 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
|
|
|
from Model.models import Device_Info, UidSetModel, LogModel, UID_Bucket, Unused_Uid_Meal, StsCrdModel, \
|
|
|
VodHlsModel, ExperienceContextModel, DeviceTypeModel, UidUserModel, ExperienceAiModel, AiService, \
|
|
|
AppBundle, App_Info, AppDeviceType, DeviceNameLanguage, UIDCompanySerialModel, UidPushModel, \
|
|
|
- CustomCustomerOrderInfo, CustomCustomerDevice, DeviceVersionInfo, VoicePromptModel, DeviceAlgorithmExplain
|
|
|
+ CustomCustomerOrderInfo, CustomCustomerDevice, DeviceVersionInfo, VoicePromptModel, DeviceAlgorithmExplain, BaiduBigModelLicense, \
|
|
|
+ Instavision
|
|
|
from Object.AWS.AmazonS3Util import AmazonS3Util
|
|
|
from Object.Enums.RedisKeyConstant import RedisKeyConstant
|
|
|
from Object.RedisObject import RedisObject
|
|
@@ -137,6 +139,29 @@ class DeviceManagement(View):
|
|
|
return self.del_device_voice(request_dict, response)
|
|
|
elif operation == 'deviceTypeList':
|
|
|
return self.device_type_list(response)
|
|
|
+
|
|
|
+ # 百度大模型
|
|
|
+ elif operation == 'getBaiduBigModelLicense': # 查询大模型许可证
|
|
|
+ return self.get_baidu_big_model_license(request_dict, response)
|
|
|
+ elif operation == 'addBaiduBigModelLicense': # 添加大模型许可证
|
|
|
+ return self.add_baidu_big_model_license(request, response)
|
|
|
+ elif operation == 'editBaiduBigModelLicense': # 编辑大模型许可证
|
|
|
+ return self.edit_baidu_big_model_license(request, request_dict, response)
|
|
|
+ elif operation == 'delBaiduBigModelLicense': # 删除大模型许可证
|
|
|
+ return self.del_baidu_big_model_license(request_dict, response)
|
|
|
+
|
|
|
+ # Instavision即时视觉
|
|
|
+ elif operation == 'getInstavision': # 查询即时视觉列表
|
|
|
+ return self.get_instavision(request_dict, response)
|
|
|
+ elif operation == 'addInstavision': # 添加即时视觉
|
|
|
+ return self.add_instavision(request, response)
|
|
|
+ elif operation == 'editInstavision': # 编辑即时视觉
|
|
|
+ return self.edit_instavision(request_dict, response)
|
|
|
+ elif operation == 'delInstavision': # 删除即时视觉
|
|
|
+ return self.del_instavision(request_dict, response)
|
|
|
+
|
|
|
+ elif operation == 'devicePowerDisplay':
|
|
|
+ return self.device_power_display(request_dict, response)
|
|
|
else:
|
|
|
return response.json(444, 'operation')
|
|
|
|
|
@@ -2079,4 +2104,269 @@ class DeviceManagement(View):
|
|
|
return response.json(0, list(device_type_qs))
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
|
- return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def get_baidu_big_model_license(request_dict, response):
|
|
|
+ """查询百度大模型许可证列表"""
|
|
|
+ page_no = request_dict.get('pageNo')
|
|
|
+ page_size = request_dict.get('pageSize')
|
|
|
+ serial = request_dict.get('serial', '')
|
|
|
+ license_name = request_dict.get('licenseName', '')
|
|
|
+ use_status = request_dict.get('useStatus')
|
|
|
+
|
|
|
+ if not all([page_no, page_size]):
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ try:
|
|
|
+ query = BaiduBigModelLicense.objects.all()
|
|
|
+ if serial:
|
|
|
+ query = query.filter(serial__contains=serial)
|
|
|
+ if license_name:
|
|
|
+ query = query.filter(license_name__contains=license_name)
|
|
|
+ if use_status:
|
|
|
+ query = query.filter(use_status=use_status)
|
|
|
+
|
|
|
+ total = query.count()
|
|
|
+ licenses = query.order_by('-id')[
|
|
|
+ (int(page_no)-1)*int(page_size):int(page_no)*int(page_size)
|
|
|
+ ].values('id', 'serial', 'license_name', 'use_status', 'created_time', 'updated_time')
|
|
|
+
|
|
|
+ return response.json(0, {
|
|
|
+ 'list': list(licenses),
|
|
|
+ 'total': total
|
|
|
+ })
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def add_baidu_big_model_license(request, response):
|
|
|
+ """添加百度大模型许可证"""
|
|
|
+ file = request.FILES.get('file', None)
|
|
|
+ if not file:
|
|
|
+ return response.json(444)
|
|
|
+ try:
|
|
|
+ license_name = str(file)
|
|
|
+ now_time = int(time.time())
|
|
|
+
|
|
|
+ # 上传文件到华为云OBS
|
|
|
+ obs_client = ObsClient(
|
|
|
+ access_key_id=HUAWEICLOUD_AK,
|
|
|
+ secret_access_key=HUAWEICLOUD_SK,
|
|
|
+ server=HUAWEICLOUD_OBS_SERVER
|
|
|
+ )
|
|
|
+ resp = obs_client.putObject(
|
|
|
+ bucketName=HUAWEICLOUD_BAIDU_BIG_MODEL_LICENSE_BUKET,
|
|
|
+ objectKey=license_name,
|
|
|
+ content=file
|
|
|
+ )
|
|
|
+ assert resp.status < 300
|
|
|
+
|
|
|
+ # 更新或创建数据
|
|
|
+ license_qs = BaiduBigModelLicense.objects.filter(license_name=license_name)
|
|
|
+ if license_qs.exists():
|
|
|
+ license_qs.update(updated_time=now_time)
|
|
|
+ else:
|
|
|
+ BaiduBigModelLicense.objects.create(
|
|
|
+ license_name=license_name,
|
|
|
+ created_time=now_time,
|
|
|
+ updated_time=now_time
|
|
|
+ )
|
|
|
+ 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 edit_baidu_big_model_license(request, request_dict, response):
|
|
|
+ """编辑百度大模型许可证"""
|
|
|
+ license_id = request_dict.get('id')
|
|
|
+ serial = request_dict.get('serial')
|
|
|
+ use_status = request_dict.get('useStatus')
|
|
|
+
|
|
|
+ if not license_id:
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ try:
|
|
|
+ update_data = {
|
|
|
+ 'updated_time': int(time.time())
|
|
|
+ }
|
|
|
+ if serial:
|
|
|
+ update_data['serial'] = serial
|
|
|
+ if use_status is not None:
|
|
|
+ update_data['use_status'] = int(use_status)
|
|
|
+
|
|
|
+ BaiduBigModelLicense.objects.filter(id=license_id).update(**update_data)
|
|
|
+ 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 del_baidu_big_model_license(request_dict, response):
|
|
|
+ """删除百度大模型许可证"""
|
|
|
+ license_id = request_dict.get('id')
|
|
|
+
|
|
|
+ if not license_id:
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ try:
|
|
|
+ # 先查询出license_name
|
|
|
+ baidu_license = BaiduBigModelLicense.objects.filter(id=license_id).first()
|
|
|
+ if not baidu_license:
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ license_name = baidu_license.license_name
|
|
|
+
|
|
|
+ # 删除数据库记录
|
|
|
+ BaiduBigModelLicense.objects.filter(id=license_id).delete()
|
|
|
+
|
|
|
+ # 删除华为云上的文件
|
|
|
+ obs_client = ObsClient(
|
|
|
+ access_key_id=HUAWEICLOUD_AK,
|
|
|
+ secret_access_key=HUAWEICLOUD_SK,
|
|
|
+ server=HUAWEICLOUD_OBS_SERVER
|
|
|
+ )
|
|
|
+ obs_client.deleteObject(
|
|
|
+ bucketName=HUAWEICLOUD_BAIDU_BIG_MODEL_LICENSE_BUKET,
|
|
|
+ objectKey=license_name
|
|
|
+ )
|
|
|
+
|
|
|
+ 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 get_instavision(request_dict, response):
|
|
|
+ """查询即时视觉列表"""
|
|
|
+ page_no = request_dict.get('pageNo')
|
|
|
+ page_size = request_dict.get('pageSize')
|
|
|
+ device_id = request_dict.get('deviceId', '')
|
|
|
+ mac = request_dict.get('mac', '')
|
|
|
+ access_key = request_dict.get('accessKey', '')
|
|
|
+ use_status = request_dict.get('useStatus')
|
|
|
+
|
|
|
+ if not all([page_no, page_size]):
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ try:
|
|
|
+ query = Instavision.objects.all()
|
|
|
+ if device_id:
|
|
|
+ query = query.filter(device_id__contains=device_id)
|
|
|
+ if mac:
|
|
|
+ query = query.filter(mac__contains=mac)
|
|
|
+ if access_key:
|
|
|
+ query = query.filter(access_key__contains=access_key)
|
|
|
+ if use_status is not None:
|
|
|
+ query = query.filter(use_status=use_status)
|
|
|
+
|
|
|
+ total = query.count()
|
|
|
+ instavisions = query.order_by('-id')[
|
|
|
+ (int(page_no)-1)*int(page_size):int(page_no)*int(page_size)
|
|
|
+ ].values('id', 'mac', 'device_id', 'access_key', 'use_status', 'created_time', 'updated_time')
|
|
|
+
|
|
|
+ return response.json(0, {
|
|
|
+ 'list': list(instavisions),
|
|
|
+ 'total': total
|
|
|
+ })
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def add_instavision(request, response):
|
|
|
+ """添加即时视觉
|
|
|
+ 仅支持CSV批量导入
|
|
|
+ """
|
|
|
+ file = request.FILES.get('file', None)
|
|
|
+ if not file:
|
|
|
+ return response.json(444, '请上传CSV文件')
|
|
|
+
|
|
|
+ try:
|
|
|
+ # 读取CSV文件内容
|
|
|
+ csv_content = io.StringIO(file.read().decode('utf-8'))
|
|
|
+ csv_reader = csv.DictReader(csv_content)
|
|
|
+
|
|
|
+ now_time = int(time.time())
|
|
|
+
|
|
|
+ # 获取所有已存在的device_id
|
|
|
+ existing_device_ids = set(Instavision.objects.values_list('device_id', flat=True))
|
|
|
+
|
|
|
+ # 准备批量创建的对象列表
|
|
|
+ instavision_objects = []
|
|
|
+
|
|
|
+ for row in csv_reader:
|
|
|
+ # 获取Device Id和Access Key列的数据
|
|
|
+ device_id = row.get('Device Id', '')
|
|
|
+ access_key = row.get('Access Key', '')
|
|
|
+
|
|
|
+ if not device_id or not access_key:
|
|
|
+ continue
|
|
|
+
|
|
|
+ # 检查是否已存在相同的device_id
|
|
|
+ if device_id in existing_device_ids:
|
|
|
+ continue
|
|
|
+
|
|
|
+ # 添加到待创建列表
|
|
|
+ instavision_objects.append(Instavision(
|
|
|
+ device_id=device_id,
|
|
|
+ access_key=access_key,
|
|
|
+ created_time=now_time,
|
|
|
+ updated_time=now_time
|
|
|
+ ))
|
|
|
+
|
|
|
+ # 将此device_id添加到已存在集合中,防止CSV中有重复
|
|
|
+ existing_device_ids.add(device_id)
|
|
|
+
|
|
|
+ # 使用bulk_create批量创建记录
|
|
|
+ if instavision_objects:
|
|
|
+ Instavision.objects.bulk_create(instavision_objects)
|
|
|
+
|
|
|
+ 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 edit_instavision(request_dict, response):
|
|
|
+ """编辑即时视觉"""
|
|
|
+ instavision_id = request_dict.get('id')
|
|
|
+ device_id = request_dict.get('deviceId')
|
|
|
+ access_key = request_dict.get('accessKey')
|
|
|
+ mac = request_dict.get('mac')
|
|
|
+ use_status = request_dict.get('useStatus')
|
|
|
+
|
|
|
+ if not instavision_id:
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ try:
|
|
|
+ update_data = {
|
|
|
+ 'updated_time': int(time.time())
|
|
|
+ }
|
|
|
+ if device_id:
|
|
|
+ # 检查是否与其他记录的device_id冲突
|
|
|
+ if Instavision.objects.exclude(id=instavision_id).filter(device_id=device_id).exists():
|
|
|
+ return response.json(444, '设备ID已存在')
|
|
|
+ update_data['device_id'] = device_id
|
|
|
+ if access_key:
|
|
|
+ update_data['access_key'] = access_key
|
|
|
+ if mac:
|
|
|
+ update_data['mac'] = mac
|
|
|
+ if use_status is not None:
|
|
|
+ update_data['use_status'] = int(use_status)
|
|
|
+
|
|
|
+ Instavision.objects.filter(id=instavision_id).update(**update_data)
|
|
|
+ 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 del_instavision(request_dict, response):
|
|
|
+ """删除即时视觉"""
|
|
|
+ instavision_id = request_dict.get('id')
|
|
|
+
|
|
|
+ if not instavision_id:
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ try:
|
|
|
+ # 删除数据库记录
|
|
|
+ Instavision.objects.filter(id=instavision_id).delete()
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|