|
@@ -1,748 +1,748 @@
|
|
|
-# -*- encoding: utf-8 -*-
|
|
|
-"""
|
|
|
-@File : EquipmentFamilyController.py
|
|
|
-@Time : 2022/5/13 15:50
|
|
|
-@Author : stephen
|
|
|
-@Email : zhangdongming@asj6.wecom.work
|
|
|
-@Software: PyCharm
|
|
|
-"""
|
|
|
-
|
|
|
-import time
|
|
|
-
|
|
|
-import oss2
|
|
|
-from django.db import connection
|
|
|
-from django.db import transaction
|
|
|
-from django.db.models import Q
|
|
|
-from django.views.generic.base import View
|
|
|
-
|
|
|
-from Ansjer.config import OSS_STS_ACCESS_SECRET, OSS_STS_ACCESS_KEY
|
|
|
-from Controller.DeviceConfirmRegion import Device_Region
|
|
|
-from Model.models import Device_Info, UID_Bucket, UID_Preview, UidSetModel, UidChannelSetModel, \
|
|
|
- iotdeviceInfoModel, UIDModel, Device_User, UserFamily, FamilyMember, FamilyMemberPermission, \
|
|
|
- FamilyRoomDevice, FamilyRoom
|
|
|
-from Object.ResponseObject import ResponseObject
|
|
|
-from Object.TokenObject import TokenObject
|
|
|
-from Service.CommonService import CommonService
|
|
|
-
|
|
|
-
|
|
|
-# 家庭设备管理
|
|
|
-class EquipmentFamilyView(View):
|
|
|
-
|
|
|
- def get(self, request, *args, **kwargs):
|
|
|
- request.encoding = 'utf-8'
|
|
|
- operation = kwargs.get('operation')
|
|
|
- return self.validation(request.GET, request, operation)
|
|
|
-
|
|
|
- def post(self, request, *args, **kwargs):
|
|
|
- request.encoding = 'utf-8'
|
|
|
-
|
|
|
- operation = kwargs.get('operation')
|
|
|
- return self.validation(request.POST, request, operation)
|
|
|
-
|
|
|
- def validation(self, request_dict, request, operation):
|
|
|
-
|
|
|
- token = TokenObject(request.META.get('HTTP_AUTHORIZATION'))
|
|
|
- lang = request_dict.get('lang', None)
|
|
|
- if lang:
|
|
|
- response = ResponseObject(lang)
|
|
|
- else:
|
|
|
- response = ResponseObject(token.lang) if token.lang else ResponseObject()
|
|
|
-
|
|
|
- if token.code != 0:
|
|
|
- return response.json(token.code)
|
|
|
- user_id = token.userID
|
|
|
-
|
|
|
- # 手机端添加设备,查询,修改
|
|
|
- if operation == 'add':
|
|
|
- return self.do_save(user_id, request_dict, response, request)
|
|
|
- # 分页获取设备
|
|
|
- if operation == 'page':
|
|
|
- return self.do_device_page(user_id, request_dict, response)
|
|
|
- # 条件查询设备列表
|
|
|
- if operation == 'query':
|
|
|
- return self.do_device_query(user_id, request_dict, response)
|
|
|
- # 获取家庭列表
|
|
|
- if operation == 'family-list':
|
|
|
- return self.get_family_list(user_id, request_dict, response)
|
|
|
- # 家庭保存
|
|
|
- if operation == 'family-save':
|
|
|
- return self.family_save(user_id, request_dict, response)
|
|
|
- # 获取房间列表
|
|
|
- if operation == 'room-list':
|
|
|
- return self.get_family_room_list(request_dict, response)
|
|
|
- # 房间保存
|
|
|
- if operation == 'room-save':
|
|
|
- return self.room_save(request_dict, response)
|
|
|
- if operation == 'room-sort':
|
|
|
- return self.room_sort_save(request_dict, response)
|
|
|
- if operation == 'permission-list':
|
|
|
- return self.get_member_permission_list(user_id, request_dict, response)
|
|
|
- else:
|
|
|
- return response.json(414)
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def do_save(cls, user_id, request_dict, response, request):
|
|
|
- """
|
|
|
- 添加设备
|
|
|
- @param request:
|
|
|
- @param user_id:
|
|
|
- @param request_dict:
|
|
|
- @param response:
|
|
|
- @return:
|
|
|
- """
|
|
|
- nick_name = request_dict.get('nickName', None)
|
|
|
- serial_number = request_dict.get('serialNumber', None)
|
|
|
- device_type = request_dict.get('deviceType', None)
|
|
|
- family_id = request_dict.get('familyId', None)
|
|
|
- room_id = request_dict.get('roomId', None)
|
|
|
- # type 可能为0
|
|
|
- if not all([nick_name, serial_number, device_type]):
|
|
|
- return response.json(444, {'param': 'nick_name, serial_number, device_type'})
|
|
|
- device_info_qs = Device_Info.objects.filter(serial_number=serial_number, userID_id=user_id)
|
|
|
- if device_info_qs:
|
|
|
- # 判断设备是否已存在
|
|
|
- if device_info_qs[0].isExist == 1:
|
|
|
- return response.json(174)
|
|
|
- else:
|
|
|
- device_info_qs.delete()
|
|
|
- try:
|
|
|
- with transaction.atomic():
|
|
|
- # 格式化后的日期时间
|
|
|
- now_time = CommonService.timestamp_to_str(int(time.time()))
|
|
|
- device_id = CommonService.getUserID(getUser=False)
|
|
|
- Device_Info.objects.create(id=device_id, userID_id=user_id, NickName=nick_name,
|
|
|
- Type=device_type,
|
|
|
- UID=serial_number,
|
|
|
- serial_number=serial_number, data_joined=now_time,
|
|
|
- update_time=now_time)
|
|
|
- boole = cls.family_room_device_save(family_id, room_id, device_id)
|
|
|
- if not boole:
|
|
|
- return response.json(15)
|
|
|
- # 判断是否有用户绑定
|
|
|
- us_qs = UidSetModel.objects.filter(uid=serial_number)
|
|
|
- if not us_qs:
|
|
|
- n_time = int(time.time())
|
|
|
- ip = CommonService.get_ip_address(request)
|
|
|
- region_id = Device_Region().get_device_region(ip)
|
|
|
- region_alexa = 'CN' if region_id == 1 else 'ALL'
|
|
|
- uid_set_create_dict = {
|
|
|
- 'uid': serial_number,
|
|
|
- 'addTime': n_time,
|
|
|
- 'updTime': n_time,
|
|
|
- 'ip': CommonService.get_ip_address(request_dict),
|
|
|
- 'nickname': nick_name,
|
|
|
- 'region_alexa': region_alexa,
|
|
|
- }
|
|
|
- UidSetModel.objects.create(**uid_set_create_dict)
|
|
|
- return response.json(0)
|
|
|
- except Exception as e:
|
|
|
- print(e)
|
|
|
- return response.json(177, repr(e))
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def do_device_page(cls, user_id, request_dict, response):
|
|
|
- """
|
|
|
- 查询设备列表
|
|
|
- @param user_id:
|
|
|
- @param request_dict:
|
|
|
- @param response:
|
|
|
- @return:
|
|
|
- """
|
|
|
- page_no = request_dict.get('pageNo', None)
|
|
|
- page_size = request_dict.get('pageSize', None)
|
|
|
- if not all([page_no, page_size]):
|
|
|
- return response.json(444)
|
|
|
-
|
|
|
- page = int(page_no)
|
|
|
- line = int(page_size)
|
|
|
- device_info_qs = Device_Info.objects.filter(userID=user_id)
|
|
|
- device_info_qs = device_info_qs.filter(~Q(isExist=0))
|
|
|
- total = device_info_qs.count()
|
|
|
- device_info_qs = device_info_qs.values("id", "userID_id", "NickName", "Type", "serial_number",
|
|
|
- "data_joined",
|
|
|
- "update_time")[(page - 1) * line: page * line]
|
|
|
- data = []
|
|
|
- for item in device_info_qs:
|
|
|
- data.append({
|
|
|
- 'id': item['id'],
|
|
|
- 'userId': item['userID_id'],
|
|
|
- 'nickName': item['NickName'],
|
|
|
- 'type': item['Type'],
|
|
|
- 'serialNumber': item['serial_number'],
|
|
|
- 'dataJoined': item['data_joined'].strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
- 'updateTime': item['update_time'].strftime("%Y-%m-%d %H:%M:%S")
|
|
|
- })
|
|
|
- return response.json(0, {'list': data, 'total': total})
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def do_device_query(cls, user_id, request_dict, response):
|
|
|
- """
|
|
|
- 查询用户设备信息
|
|
|
- @param user_id: 用户id
|
|
|
- @param request_dict: 请求参数
|
|
|
- @param response: 响应对象
|
|
|
- @return: response
|
|
|
- """
|
|
|
- page = request_dict.get('page', None)
|
|
|
- line = request_dict.get('line', None)
|
|
|
- nick_name = request_dict.get('NickName', None)
|
|
|
- family_id = request_dict.get('familyId', None)
|
|
|
- room_id = request_dict.get('roomId', None)
|
|
|
-
|
|
|
- page = int(page)
|
|
|
- line = int(line)
|
|
|
- uid = request_dict.get('uid', None)
|
|
|
- if family_id:
|
|
|
- permission = cls.get_member_permission_details(user_id, int(family_id))
|
|
|
- if not permission or permission == '003':
|
|
|
- return response.json(404)
|
|
|
- # 获取设备信息列表
|
|
|
- device_info_list = cls.get_device_info_list(user_id, nick_name, uid,
|
|
|
- page, line, family_id, room_id)
|
|
|
- uid_list = []
|
|
|
- # 判断是否是主用户 isPrimaryUser=0:否,1:是
|
|
|
- for dvl in device_info_list:
|
|
|
- if dvl['primaryUserID'] and dvl['id'] == dvl['primaryUserID']:
|
|
|
- dvl['isPrimaryUser'] = 1
|
|
|
- else:
|
|
|
- dvl['isPrimaryUser'] = 0
|
|
|
- uid_list.append(dvl['UID'])
|
|
|
- # 设备关联套餐,设备预览图
|
|
|
- uid_bucket_qs, uid_preview_qs = cls.get_bucket_and_preview_by_uid(uid_list)
|
|
|
- # 设备配置信息
|
|
|
- uid_set_dict = cls.get_uid_set_dict(uid_list)
|
|
|
- # 设备详情信息
|
|
|
- result = cls.get_device_details(device_info_list, uid_bucket_qs, uid_preview_qs, uid_set_dict)
|
|
|
- items = []
|
|
|
- for index, item in enumerate(result):
|
|
|
- # 加密
|
|
|
- if item['View_Password']:
|
|
|
- item['View_Password'] = CommonService.encode_data(item['View_Password'], 1, 4)
|
|
|
- items.append(item)
|
|
|
- return response.json(0, items)
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def get_device_info_list(cls, user_id, nick_name, uid, page, line, family_id, room_id):
|
|
|
- """
|
|
|
- 根据用户id获取设备信息
|
|
|
- @param room_id: 家庭id
|
|
|
- @param family_id: 房间id
|
|
|
- @param uid: uid
|
|
|
- @param nick_name: 设备名称
|
|
|
- @param line: 条数
|
|
|
- @param page: 页数
|
|
|
- @param user_id: 用户id
|
|
|
- @return: device_info_list 设备信息列表
|
|
|
- """
|
|
|
- # 获取用户设备信息
|
|
|
- device_info_qs = Device_Info.objects.filter(userID_id=user_id)
|
|
|
- # 过滤已重置的设备
|
|
|
- device_info_qs = device_info_qs.filter(~Q(isExist=2))
|
|
|
- if nick_name:
|
|
|
- device_info_qs = device_info_qs.filter(NickName__icontains=nick_name)
|
|
|
- if uid:
|
|
|
- device_info_qs.filter(UID=uid)
|
|
|
- if family_id or room_id:
|
|
|
- # 根据家庭id获取房间id关联查询设备
|
|
|
- return cls.get_family_device_list(user_id, page, line, family_id, room_id)
|
|
|
- device_info_values = device_info_qs.values('id', 'userID', 'NickName', 'UID', 'View_Account', 'View_Password',
|
|
|
- 'ChannelIndex',
|
|
|
- 'Type', 'isShare', 'primaryUserID', 'primaryMaster', 'data_joined',
|
|
|
- 'vodPrimaryUserID',
|
|
|
- 'vodPrimaryMaster', 'userID__userEmail', 'version', 'isVod',
|
|
|
- 'isExist', 'NotificationMode',
|
|
|
- 'isCameraOpenCloud', 'serial_number')
|
|
|
-
|
|
|
- device_info_values = device_info_values[(page - 1) * line:page * line]
|
|
|
- device_info_list = CommonService.qs_to_list(device_info_values)
|
|
|
- return device_info_list
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def get_family_device_list(cls, user_id, page_no, page_size, family_id, room_id):
|
|
|
- """
|
|
|
- 获取关联家庭设备列表
|
|
|
- @param user_id: 用户id
|
|
|
- @param page_no: 页数
|
|
|
- @param page_size: 分页大小
|
|
|
- @param family_id: 家庭id
|
|
|
- @param room_id: 房间id
|
|
|
- @return: result_list
|
|
|
- """
|
|
|
- cursor = connection.cursor()
|
|
|
- sql = 'SELECT d.id,d.userID_id as userID,d.NickName,d.UID,d.View_Account,d.View_Password,d.ChannelIndex,' \
|
|
|
- 'd.Type,d.isShare,d.primaryUserID,d.primaryMaster,d.data_joined,d.vodPrimaryUserID,d.vodPrimaryMaster, ' \
|
|
|
- 'd.version,d.isVod,d.isExist,d.NotificationMode,d.isCameraOpenCloud,d.serial_number '
|
|
|
- sql += 'FROM device_info d INNER JOIN loocam_family_room_device l ON d.id = l.device_id '
|
|
|
- sql += 'WHERE d.userID_id = %s AND d.isExist != %s '
|
|
|
- if family_id:
|
|
|
- sql += ' AND l.family_id = %s '
|
|
|
- if room_id:
|
|
|
- sql += ' AND l.room_id = %s '
|
|
|
- sql += ' order by d.data_joined DESC,d.id DESC LIMIT %s,%s '
|
|
|
- cursor.execute(sql, [user_id, 2, int(family_id) if family_id else int(room_id), ((page_no - 1) * page_size),
|
|
|
- page_size, ])
|
|
|
- data_obj = cursor.fetchall()
|
|
|
- cursor.close() # 执行完,关闭
|
|
|
- connection.close()
|
|
|
- result_list = []
|
|
|
- col_names = [desc[0] for desc in cursor.description]
|
|
|
- for item in data_obj:
|
|
|
- val = dict(zip(col_names, item))
|
|
|
- user_id = val['userID']
|
|
|
- device_user_qs = Device_User.objects.filter(userID=user_id)
|
|
|
- val['userID__userEmail'] = device_user_qs.first().userEmail
|
|
|
- val['isShare'] = False if val['isShare'] == 0 else True
|
|
|
- if 'data_joined' in val:
|
|
|
- if val['data_joined']:
|
|
|
- val['data_joined'] = val['data_joined'].strftime("%Y-%m-%d %H:%M:%S")
|
|
|
- else:
|
|
|
- val['data_joined'] = ''
|
|
|
- result_list.append(val)
|
|
|
- return result_list
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def get_bucket_and_preview_by_uid(cls, uid_list):
|
|
|
- """
|
|
|
- 根据uid列表查询套餐
|
|
|
- @param uid_list: uid列表
|
|
|
- @return: uid_bucket_qs
|
|
|
- """
|
|
|
- uid_bucket_qs = UID_Bucket.objects.filter(uid__in=uid_list).values('bucket__content', 'status', 'channel',
|
|
|
- 'endTime', 'uid')
|
|
|
- uid_preview_qs = UID_Preview.objects.filter(uid__in=uid_list).order_by('channel').values('id', 'uid', 'channel')
|
|
|
- return uid_bucket_qs, uid_preview_qs
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def get_uid_set_dict(cls, uid_list):
|
|
|
- """
|
|
|
- 获取uid配置信息
|
|
|
- @param uid_list: uid列表
|
|
|
- @return: uid_set_dict uid配置信息
|
|
|
- """
|
|
|
- uid_set_qs = UidSetModel.objects.filter(uid__in=uid_list) \
|
|
|
- .values('id', 'uid', 'version', 'nickname', 'ucode',
|
|
|
- 'detect_status', 'detect_group',
|
|
|
- 'detect_interval',
|
|
|
- 'region_alexa', 'is_alexa', 'deviceModel',
|
|
|
- 'TimeZone', 'TimeStatus', 'SpaceUsable',
|
|
|
- 'SpaceSum', 'MirrorType', 'RecordType',
|
|
|
- 'OutdoorModel', 'WIFIName', 'isDetector',
|
|
|
- 'DetectorRank', 'is_human', 'is_custom_voice',
|
|
|
- 'is_ptz', 'double_wifi', 'is_ai')
|
|
|
- uid_set_dict = {}
|
|
|
- for us in uid_set_qs:
|
|
|
- uid_set_dict[us['uid']] = {
|
|
|
- 'version': us['version'],
|
|
|
- 'nickname': us['nickname'],
|
|
|
- 'ucode': us['ucode'],
|
|
|
- 'detect_interval': us['detect_interval'],
|
|
|
- 'detect_group': us['detect_group'],
|
|
|
- 'detect_status': us['detect_status'],
|
|
|
- 'region_alexa': us['region_alexa'],
|
|
|
- 'is_alexa': us['is_alexa'],
|
|
|
- 'deviceModel': us['deviceModel'],
|
|
|
- 'TimeZone': us['TimeZone'],
|
|
|
- 'TimeStatus': us['TimeStatus'],
|
|
|
- 'SpaceUsable': us['SpaceUsable'],
|
|
|
- 'SpaceSum': us['SpaceSum'],
|
|
|
- 'MirrorType': us['MirrorType'],
|
|
|
- 'RecordType': us['RecordType'],
|
|
|
- 'OutdoorModel': us['OutdoorModel'],
|
|
|
- 'WIFIName': us['WIFIName'],
|
|
|
- 'isDetector': us['isDetector'],
|
|
|
- 'DetectorRank': us['DetectorRank'],
|
|
|
- 'is_human': us['is_human'],
|
|
|
- 'is_custom_voice': us['is_custom_voice'],
|
|
|
- 'is_ptz': us['is_ptz'],
|
|
|
- 'double_wifi': us['double_wifi'],
|
|
|
- 'is_ai': us['is_ai']
|
|
|
- }
|
|
|
- # 从uid_channel里面取出通道配置信息
|
|
|
- uid_channel_set_qs = UidChannelSetModel.objects.filter(uid__id=us['id']) \
|
|
|
- .values('channel', 'channel_name',
|
|
|
- 'pir_audio', 'mic_audio',
|
|
|
- 'battery_status',
|
|
|
- 'battery_level',
|
|
|
- 'sleep_status',
|
|
|
- 'sleep_time',
|
|
|
- 'light_night_model',
|
|
|
- 'light_alarm_type',
|
|
|
- 'light_alarm_level',
|
|
|
- 'light_alarm_man_en',
|
|
|
- 'light_alarm_vol',
|
|
|
- 'light_long_light'
|
|
|
- )
|
|
|
- channels_list = []
|
|
|
- for ucs in uid_channel_set_qs:
|
|
|
- channels_dict = {
|
|
|
- 'channel': ucs['channel'],
|
|
|
- 'channel_name': ucs['channel_name'],
|
|
|
- 'pir_audio': ucs['pir_audio'],
|
|
|
- 'mic_audio': ucs['mic_audio'],
|
|
|
- 'battery_status': ucs['battery_status'],
|
|
|
- 'battery_level': ucs['battery_level'],
|
|
|
- 'sleep_status': ucs['sleep_status'],
|
|
|
- 'sleep_time': ucs['sleep_time'],
|
|
|
- 'light_night_model': ucs['light_night_model'],
|
|
|
- 'light_alarm_type': ucs['light_alarm_type'],
|
|
|
- 'light_alarm_level': ucs['light_alarm_level'],
|
|
|
- 'light_alarm_man_en': ucs['light_alarm_man_en'],
|
|
|
- 'light_alarm_vol': ucs['light_alarm_vol'],
|
|
|
- 'light_long_light': ucs['light_long_light']
|
|
|
- }
|
|
|
- channels_list.append(channels_dict)
|
|
|
- uid_set_dict[us['uid']]['channels'] = channels_list
|
|
|
- return uid_set_dict
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def get_device_details(cls, device_info_list, uid_bucket_qs, uid_preview_qs, uid_set_dict):
|
|
|
- """
|
|
|
- 设备详情
|
|
|
- @param device_info_list: 设备信息列表
|
|
|
- @param uid_bucket_qs: 套餐对象
|
|
|
- @param uid_preview_qs:
|
|
|
- @param uid_set_dict:
|
|
|
- @return:
|
|
|
- """
|
|
|
- now_time = int(time.time())
|
|
|
- data = []
|
|
|
- for p in device_info_list:
|
|
|
- # 获取iotDeviceInfo表的endpoint和tokenIotNumber
|
|
|
- p['iot'] = []
|
|
|
- if p['serial_number']: # 存在序列号根据序列号查询
|
|
|
- iot_device_info_qs = iotdeviceInfoModel.objects.filter(serial_number=p['serial_number'][0:6])
|
|
|
- else: # 根据uid查询
|
|
|
- iot_device_info_qs = iotdeviceInfoModel.objects.filter(uid=p['UID'])
|
|
|
- if iot_device_info_qs.exists():
|
|
|
- iot_device_Info = iot_device_info_qs.values('endpoint', 'token_iot_number')
|
|
|
- p['iot'].append({
|
|
|
- 'endpoint': iot_device_Info[0]['endpoint'],
|
|
|
- 'token_iot_number': iot_device_Info[0]['token_iot_number']
|
|
|
- })
|
|
|
-
|
|
|
- p['vod'] = []
|
|
|
- for dm in uid_bucket_qs:
|
|
|
- if p['UID'] == dm['uid']:
|
|
|
- if dm['endTime'] > now_time:
|
|
|
- p['vod'].append(dm)
|
|
|
- p['preview'] = []
|
|
|
-
|
|
|
- auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
- bucket = oss2.Bucket(auth, 'oss-cn-hongkong.aliyuncs.com', 'statres')
|
|
|
-
|
|
|
- for up in uid_preview_qs:
|
|
|
- if p['UID'] == up['uid']:
|
|
|
- obj = 'uid_preview/{uid}/channel_{channel}.png'.format(uid=up['uid'], channel=up['channel'])
|
|
|
- img_sign = bucket.sign_url('GET', obj, 300)
|
|
|
- p['preview'].append(img_sign)
|
|
|
-
|
|
|
- p_uid = p['UID']
|
|
|
-
|
|
|
- # 返回设备初始化字符
|
|
|
- uid_qs = UIDModel.objects.filter(uid=p_uid).values('platform', 'init_string', 'init_string_app')
|
|
|
- if uid_qs.exists():
|
|
|
- p['platform'] = uid_qs[0]['platform']
|
|
|
- p['initString'] = uid_qs[0]['init_string']
|
|
|
- p['initStringApp'] = uid_qs[0]['init_string_app']
|
|
|
-
|
|
|
- if p_uid in uid_set_dict:
|
|
|
- # 设备版本号
|
|
|
- uidversion = uid_set_dict[p_uid]['version']
|
|
|
- if len(uidversion) > 6:
|
|
|
- uidversion = uidversion[0: uidversion.rfind('.')]
|
|
|
- p['uid_version'] = uidversion
|
|
|
- p['ucode'] = uid_set_dict[p_uid]['ucode']
|
|
|
- p['detect_interval'] = uid_set_dict[p_uid]['detect_interval']
|
|
|
- p['detect_status'] = uid_set_dict[p_uid]['detect_status']
|
|
|
- p['detect_group'] = uid_set_dict[p_uid]['detect_group']
|
|
|
- p['region_alexa'] = uid_set_dict[p_uid]['region_alexa']
|
|
|
- p['is_alexa'] = uid_set_dict[p_uid]['is_alexa']
|
|
|
- p['deviceModel'] = uid_set_dict[p_uid]['deviceModel']
|
|
|
- p['TimeZone'] = uid_set_dict[p_uid]['TimeZone']
|
|
|
- p['TimeStatus'] = uid_set_dict[p_uid]['TimeStatus']
|
|
|
- p['SpaceUsable'] = uid_set_dict[p_uid]['SpaceUsable']
|
|
|
- p['SpaceSum'] = uid_set_dict[p_uid]['SpaceSum']
|
|
|
- p['MirrorType'] = uid_set_dict[p_uid]['MirrorType']
|
|
|
- p['RecordType'] = uid_set_dict[p_uid]['RecordType']
|
|
|
- p['OutdoorModel'] = uid_set_dict[p_uid]['OutdoorModel']
|
|
|
- p['WIFIName'] = uid_set_dict[p_uid]['WIFIName']
|
|
|
- p['isDetector'] = uid_set_dict[p_uid]['isDetector']
|
|
|
- p['DetectorRank'] = uid_set_dict[p_uid]['DetectorRank']
|
|
|
- p['is_human'] = uid_set_dict[p_uid]['is_human']
|
|
|
- p['is_custom_voice'] = uid_set_dict[p_uid]['is_custom_voice']
|
|
|
- p['is_ptz'] = uid_set_dict[p_uid]['is_ptz']
|
|
|
- p['channels'] = uid_set_dict[p_uid]['channels']
|
|
|
- p['double_wifi'] = uid_set_dict[p_uid]['double_wifi']
|
|
|
- p['is_ai'] = uid_set_dict[p_uid]['is_ai']
|
|
|
- # 设备昵称 调用影子信息昵称,先阶段不可
|
|
|
- if uid_set_dict[p_uid]['nickname']:
|
|
|
- p['NickName'] = uid_set_dict[p_uid]['nickname']
|
|
|
- else:
|
|
|
- # 设备版本号
|
|
|
- p['uid_version'] = ''
|
|
|
- p['ucode'] = ''
|
|
|
- data.append(p)
|
|
|
- return data
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def get_family_list(cls, user_id, request_dict, response):
|
|
|
- """
|
|
|
- 查询家庭列表
|
|
|
- @param user_id: 用户id
|
|
|
- @param request_dict: 请求
|
|
|
- @param response: 响应
|
|
|
- @return: 家庭列表items
|
|
|
- """
|
|
|
- lang = request_dict.get('lang', 'cn')
|
|
|
- if user_id:
|
|
|
- with transaction.atomic():
|
|
|
- user_family_qs = UserFamily.objects.filter(user_id=user_id)
|
|
|
- if not user_family_qs.exists():
|
|
|
- n_time = int(time.time())
|
|
|
- device_user = Device_User.objects.get(userID=user_id)
|
|
|
- # 创建默认家庭使用用户名或者邮箱作为名称
|
|
|
- family_name = device_user.username if device_user.username else device_user.userEmail
|
|
|
- family_name = family_name + "的家" if lang == 'cn' else family_name + " home"
|
|
|
- user_family = UserFamily.objects.create(user_id=user_id, name=family_name,
|
|
|
- updated_time=n_time,
|
|
|
- created_time=n_time)
|
|
|
- if user_family.id:
|
|
|
- member_permission_qs = FamilyMemberPermission.objects.filter(no='001').values('id')
|
|
|
- permission_id = member_permission_qs.first()['id']
|
|
|
- FamilyMember.objects.create(family_id=user_family.id, user_id=user_id,
|
|
|
- user_name=device_user.username, identity=1,
|
|
|
- permission_id=int(permission_id), sort=1, updated_time=n_time,
|
|
|
- created_time=n_time)
|
|
|
- cls.family_device_binding(user_id, family_id=user_family.id)
|
|
|
-
|
|
|
- family_member_qs = FamilyMember.objects.filter(user_id=user_id) \
|
|
|
- .order_by('sort').values('identity', 'family_id', 'family__name', 'permission__no', 'family__location')
|
|
|
- items = []
|
|
|
- data = {}
|
|
|
- for item in family_member_qs:
|
|
|
- data['familyId'] = item['family_id']
|
|
|
- data['identity'] = item['identity']
|
|
|
- data['familyName'] = item['family__name']
|
|
|
- data['permissionId'] = item['permission_id']
|
|
|
- data['permissionNo'] = item['permission__no']
|
|
|
- data['familyLocation'] = item['family__location']
|
|
|
- items.append(data)
|
|
|
- return response.json(0, items)
|
|
|
- return response.json(309)
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def family_save(cls, user_id, request_dict, response):
|
|
|
- """
|
|
|
- 家庭保存
|
|
|
- @param user_id: 用户id
|
|
|
- @param request_dict: 参数
|
|
|
- @param response: 响应
|
|
|
- @return:
|
|
|
- """
|
|
|
- family_id = request_dict.get('familyId', None)
|
|
|
- family_name = request_dict.get('familyName', None)
|
|
|
- location = request_dict.get('location', None)
|
|
|
- with transaction.atomic():
|
|
|
- now_time = int(time.time())
|
|
|
- if family_id:
|
|
|
- family_member = FamilyMember.objects.filter(family_id=family_id, user_id=user_id)
|
|
|
- if family_member.exists():
|
|
|
- family_member = family_member.first()
|
|
|
- if family_member.identity == 0:
|
|
|
- return response.json(404)
|
|
|
- family_qs = UserFamily.objects.filter(id=family_id)
|
|
|
- if family_qs.exists():
|
|
|
- data = {
|
|
|
- 'updated_time': now_time
|
|
|
- }
|
|
|
- if family_name:
|
|
|
- data['name'] = family_name
|
|
|
- if location:
|
|
|
- data['location'] = location
|
|
|
- family_qs.update(**data)
|
|
|
- return response.json(0)
|
|
|
- data = {'user_id': user_id, 'updated_time': now_time, 'created_time': now_time}
|
|
|
- if family_name:
|
|
|
- data['name'] = family_name
|
|
|
- if location:
|
|
|
- data['location'] = location
|
|
|
- UserFamily.objects.create(**data)
|
|
|
- return response.json(0)
|
|
|
- return response.json(444)
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def family_room_device_save(cls, family_id, room_id, device_id):
|
|
|
- """
|
|
|
- 设备与家庭房间保存
|
|
|
- @param family_id: 家庭id
|
|
|
- @param room_id: 房间id
|
|
|
- @param device_id: 设备id
|
|
|
- @return: Boole
|
|
|
- """
|
|
|
- now_time = int(time.time())
|
|
|
- family_room_device = FamilyRoomDevice.objects.filter(device_id=device_id)
|
|
|
- if family_room_device.exists():
|
|
|
- return False
|
|
|
- data = {
|
|
|
- 'family_id': int(family_id),
|
|
|
- 'device_id': device_id,
|
|
|
- 'updated_time': now_time,
|
|
|
- 'created_time': now_time
|
|
|
- }
|
|
|
- if room_id:
|
|
|
- room_id = int(room_id)
|
|
|
- if FamilyRoom.objects.filter(id=room_id).exists():
|
|
|
- data['room_id'] = room_id
|
|
|
- FamilyRoomDevice.objects.create(**data)
|
|
|
- return True
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def family_device_binding(cls, user_id, family_id):
|
|
|
- """
|
|
|
- 用户旧设备与默认家庭进行绑定
|
|
|
- @param user_id:
|
|
|
- @param family_id:
|
|
|
- @return: True
|
|
|
- """
|
|
|
- device_info_qs = Device_Info.objects.filter(userID=user_id)
|
|
|
- device_info_qs = device_info_qs.filter(~Q(isExist=0)).values('id')
|
|
|
- if device_info_qs.exists():
|
|
|
- with transaction.atomic():
|
|
|
- not_time = time.time()
|
|
|
- device_list = []
|
|
|
- for item in device_info_qs:
|
|
|
- device_id = item['id']
|
|
|
- family_device_qs = FamilyRoomDevice.objects.filter(device_id=device_id)
|
|
|
- if not family_device_qs.exists():
|
|
|
- # 设备绑定家庭
|
|
|
- device_list.append(FamilyRoomDevice(family_id=family_id, device_id=device_id,
|
|
|
- created_time=not_time,
|
|
|
- updated_time=not_time))
|
|
|
- if device_list:
|
|
|
- FamilyRoomDevice.objects.bulk_create(device_list)
|
|
|
- return True
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def get_family_room_list(cls, request_dict, response):
|
|
|
- """
|
|
|
- 获取房间列表并统计该房间下有几台设备
|
|
|
- @param request_dict: 请求参数
|
|
|
- @param response: 响应参数
|
|
|
- @return: total;data
|
|
|
- """
|
|
|
- family_id = request_dict.get('familyId', None)
|
|
|
- if not family_id:
|
|
|
- return response.json(444)
|
|
|
- page_no = request_dict.get('pageNo', None)
|
|
|
- page_size = request_dict.get('pageSize', None)
|
|
|
- if not all([page_no, page_size]):
|
|
|
- return response.json(444)
|
|
|
- page_no = int(page_no)
|
|
|
- page_size = int(page_size)
|
|
|
- room_qs = FamilyRoom.objects.filter(family_id=family_id).order_by('sort')
|
|
|
- total = room_qs.count()
|
|
|
- room_qs = room_qs.values('id', 'name', 'sort')[(page_no - 1) * page_size: page_no * page_size]
|
|
|
- room_list = []
|
|
|
- if not room_qs.exists():
|
|
|
- return response.json(0, room_list)
|
|
|
- for item in room_qs:
|
|
|
- item['deviceCount'] = FamilyRoomDevice.objects.filter(family_id=family_id, room_id=item['id']).count()
|
|
|
- room_list.append(item)
|
|
|
- return response.json(0, {'total': total, 'data': room_list})
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def room_save(cls, request_dict, response):
|
|
|
- """
|
|
|
- 房间保存
|
|
|
- @param request_dict: 请求参数
|
|
|
- @param response: 响应参数
|
|
|
- @return:
|
|
|
- """
|
|
|
- family_id = request_dict.get('familyId', None)
|
|
|
- room_name = request_dict.get('roomName', None)
|
|
|
- room_id = request_dict.get('roomId', None)
|
|
|
- if not all([family_id, room_name]):
|
|
|
- return response.json(444)
|
|
|
- with transaction.atomic():
|
|
|
- now_time = int(time.time())
|
|
|
- if room_id:
|
|
|
- room_qs = FamilyRoom.objects.filter(id=int(room_id))
|
|
|
- if room_qs.exists():
|
|
|
- room_qs.update(name=room_name, updated_time=now_time)
|
|
|
- return response.json(0)
|
|
|
- room_qs = FamilyRoom.objects.filter(family_id=family_id, name=room_name)
|
|
|
-
|
|
|
- if room_qs.exists():
|
|
|
- room_dict = {'updated_time': now_time, 'name': room_name}
|
|
|
- room_qs.update(**room_dict)
|
|
|
- FamilyRoom.objects.create(family_id=family_id, name=room_name, updated_time=now_time,
|
|
|
- created_time=now_time)
|
|
|
- return response.json(0)
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def room_sort_save(cls, request_dict, response):
|
|
|
- """
|
|
|
- 房间排序
|
|
|
- @param request_dict: 请求参数
|
|
|
- @param response: 响应参数
|
|
|
- @return:
|
|
|
- """
|
|
|
- ids = request_dict.getlist('ids', None)
|
|
|
- if not ids:
|
|
|
- return response.json(444)
|
|
|
- for i, item in ids:
|
|
|
- id_sort = item[i]
|
|
|
- print(id_sort)
|
|
|
- return response.json(0)
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def get_member_permission_list(cls, user_id, request_dict, response):
|
|
|
- """
|
|
|
- 获取用户权限列表
|
|
|
- @param user_id:
|
|
|
- @param request_dict:
|
|
|
- @param response:
|
|
|
- @return:
|
|
|
- """
|
|
|
- family_id = request_dict.get('familyId')
|
|
|
- user_id = request_dict.get('userId', user_id)
|
|
|
- if not family_id:
|
|
|
- return response.json(404)
|
|
|
- result = cls.get_member_permission_by_family_id(user_id, family_id)
|
|
|
- return response.json(0, result)
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def get_member_permission_by_family_id(cls, user_id, family_id):
|
|
|
- """
|
|
|
- 获取权限列表并返回当前user_id所在家庭中权限
|
|
|
- @param user_id:
|
|
|
- @param family_id:
|
|
|
- @return:
|
|
|
- """
|
|
|
- member_qs = FamilyMember.objects.filter(family_id=family_id)
|
|
|
- if user_id:
|
|
|
- member_qs = member_qs.filter(user_id=user_id).values()
|
|
|
- if member_qs.exists():
|
|
|
- member_qs = member_qs.first()
|
|
|
- permission = FamilyMemberPermission.objects.all().values('id', 'no')
|
|
|
- data_list = []
|
|
|
- this_permission = {}
|
|
|
- result = {}
|
|
|
- for item in permission:
|
|
|
- if item['id'] == member_qs['permission_id']:
|
|
|
- this_permission['id'] = item['id']
|
|
|
- this_permission['no'] = item['no']
|
|
|
- data_list.append(item)
|
|
|
- result['memberPermission'] = this_permission
|
|
|
- result['permissionList'] = data_list
|
|
|
- return result
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def get_member_permission_details(cls, user_id, family_id):
|
|
|
- member_qs = FamilyMember.objects.filter(family_id=family_id, user_id=user_id).values()
|
|
|
- if member_qs.exists():
|
|
|
- member_qs = member_qs.first()
|
|
|
- permission_id = member_qs['permission_id']
|
|
|
- permission_qs = FamilyMemberPermission.objects.filter(id=permission_id).values('no')
|
|
|
- return permission_qs.first()['no']
|
|
|
- return ''
|
|
|
+# # -*- encoding: utf-8 -*-
|
|
|
+# """
|
|
|
+# @File : EquipmentFamilyController.py
|
|
|
+# @Time : 2022/5/13 15:50
|
|
|
+# @Author : stephen
|
|
|
+# @Email : zhangdongming@asj6.wecom.work
|
|
|
+# @Software: PyCharm
|
|
|
+# """
|
|
|
+#
|
|
|
+# import time
|
|
|
+#
|
|
|
+# import oss2
|
|
|
+# from django.db import connection
|
|
|
+# from django.db import transaction
|
|
|
+# from django.db.models import Q
|
|
|
+# from django.views.generic.base import View
|
|
|
+#
|
|
|
+# from Ansjer.config import OSS_STS_ACCESS_SECRET, OSS_STS_ACCESS_KEY
|
|
|
+# from Controller.DeviceConfirmRegion import Device_Region
|
|
|
+# from Model.models import Device_Info, UID_Bucket, UID_Preview, UidSetModel, UidChannelSetModel, \
|
|
|
+# iotdeviceInfoModel, UIDModel, Device_User, UserFamily, FamilyMember, FamilyMemberPermission, \
|
|
|
+# FamilyRoomDevice, FamilyRoom
|
|
|
+# from Object.ResponseObject import ResponseObject
|
|
|
+# from Object.TokenObject import TokenObject
|
|
|
+# from Service.CommonService import CommonService
|
|
|
+#
|
|
|
+#
|
|
|
+# # 家庭设备管理
|
|
|
+# class EquipmentFamilyView(View):
|
|
|
+#
|
|
|
+# def get(self, request, *args, **kwargs):
|
|
|
+# request.encoding = 'utf-8'
|
|
|
+# operation = kwargs.get('operation')
|
|
|
+# return self.validation(request.GET, request, operation)
|
|
|
+#
|
|
|
+# def post(self, request, *args, **kwargs):
|
|
|
+# request.encoding = 'utf-8'
|
|
|
+#
|
|
|
+# operation = kwargs.get('operation')
|
|
|
+# return self.validation(request.POST, request, operation)
|
|
|
+#
|
|
|
+# def validation(self, request_dict, request, operation):
|
|
|
+#
|
|
|
+# token = TokenObject(request.META.get('HTTP_AUTHORIZATION'))
|
|
|
+# lang = request_dict.get('lang', None)
|
|
|
+# if lang:
|
|
|
+# response = ResponseObject(lang)
|
|
|
+# else:
|
|
|
+# response = ResponseObject(token.lang) if token.lang else ResponseObject()
|
|
|
+#
|
|
|
+# if token.code != 0:
|
|
|
+# return response.json(token.code)
|
|
|
+# user_id = token.userID
|
|
|
+#
|
|
|
+# # 手机端添加设备,查询,修改
|
|
|
+# if operation == 'add':
|
|
|
+# return self.do_save(user_id, request_dict, response, request)
|
|
|
+# # 分页获取设备
|
|
|
+# if operation == 'page':
|
|
|
+# return self.do_device_page(user_id, request_dict, response)
|
|
|
+# # 条件查询设备列表
|
|
|
+# if operation == 'query':
|
|
|
+# return self.do_device_query(user_id, request_dict, response)
|
|
|
+# # 获取家庭列表
|
|
|
+# if operation == 'family-list':
|
|
|
+# return self.get_family_list(user_id, request_dict, response)
|
|
|
+# # 家庭保存
|
|
|
+# if operation == 'family-save':
|
|
|
+# return self.family_save(user_id, request_dict, response)
|
|
|
+# # 获取房间列表
|
|
|
+# if operation == 'room-list':
|
|
|
+# return self.get_family_room_list(request_dict, response)
|
|
|
+# # 房间保存
|
|
|
+# if operation == 'room-save':
|
|
|
+# return self.room_save(request_dict, response)
|
|
|
+# if operation == 'room-sort':
|
|
|
+# return self.room_sort_save(request_dict, response)
|
|
|
+# if operation == 'permission-list':
|
|
|
+# return self.get_member_permission_list(user_id, request_dict, response)
|
|
|
+# else:
|
|
|
+# return response.json(414)
|
|
|
+#
|
|
|
+# @classmethod
|
|
|
+# def do_save(cls, user_id, request_dict, response, request):
|
|
|
+# """
|
|
|
+# 添加设备
|
|
|
+# @param request:
|
|
|
+# @param user_id:
|
|
|
+# @param request_dict:
|
|
|
+# @param response:
|
|
|
+# @return:
|
|
|
+# """
|
|
|
+# nick_name = request_dict.get('nickName', None)
|
|
|
+# serial_number = request_dict.get('serialNumber', None)
|
|
|
+# device_type = request_dict.get('deviceType', None)
|
|
|
+# family_id = request_dict.get('familyId', None)
|
|
|
+# room_id = request_dict.get('roomId', None)
|
|
|
+# # type 可能为0
|
|
|
+# if not all([nick_name, serial_number, device_type]):
|
|
|
+# return response.json(444, {'param': 'nick_name, serial_number, device_type'})
|
|
|
+# device_info_qs = Device_Info.objects.filter(serial_number=serial_number, userID_id=user_id)
|
|
|
+# if device_info_qs:
|
|
|
+# # 判断设备是否已存在
|
|
|
+# if device_info_qs[0].isExist == 1:
|
|
|
+# return response.json(174)
|
|
|
+# else:
|
|
|
+# device_info_qs.delete()
|
|
|
+# try:
|
|
|
+# with transaction.atomic():
|
|
|
+# # 格式化后的日期时间
|
|
|
+# now_time = CommonService.timestamp_to_str(int(time.time()))
|
|
|
+# device_id = CommonService.getUserID(getUser=False)
|
|
|
+# Device_Info.objects.create(id=device_id, userID_id=user_id, NickName=nick_name,
|
|
|
+# Type=device_type,
|
|
|
+# UID=serial_number,
|
|
|
+# serial_number=serial_number, data_joined=now_time,
|
|
|
+# update_time=now_time)
|
|
|
+# boole = cls.family_room_device_save(family_id, room_id, device_id)
|
|
|
+# if not boole:
|
|
|
+# return response.json(15)
|
|
|
+# # 判断是否有用户绑定
|
|
|
+# us_qs = UidSetModel.objects.filter(uid=serial_number)
|
|
|
+# if not us_qs:
|
|
|
+# n_time = int(time.time())
|
|
|
+# ip = CommonService.get_ip_address(request)
|
|
|
+# region_id = Device_Region().get_device_region(ip)
|
|
|
+# region_alexa = 'CN' if region_id == 1 else 'ALL'
|
|
|
+# uid_set_create_dict = {
|
|
|
+# 'uid': serial_number,
|
|
|
+# 'addTime': n_time,
|
|
|
+# 'updTime': n_time,
|
|
|
+# 'ip': CommonService.get_ip_address(request_dict),
|
|
|
+# 'nickname': nick_name,
|
|
|
+# 'region_alexa': region_alexa,
|
|
|
+# }
|
|
|
+# UidSetModel.objects.create(**uid_set_create_dict)
|
|
|
+# return response.json(0)
|
|
|
+# except Exception as e:
|
|
|
+# print(e)
|
|
|
+# return response.json(177, repr(e))
|
|
|
+#
|
|
|
+# @classmethod
|
|
|
+# def do_device_page(cls, user_id, request_dict, response):
|
|
|
+# """
|
|
|
+# 查询设备列表
|
|
|
+# @param user_id:
|
|
|
+# @param request_dict:
|
|
|
+# @param response:
|
|
|
+# @return:
|
|
|
+# """
|
|
|
+# page_no = request_dict.get('pageNo', None)
|
|
|
+# page_size = request_dict.get('pageSize', None)
|
|
|
+# if not all([page_no, page_size]):
|
|
|
+# return response.json(444)
|
|
|
+#
|
|
|
+# page = int(page_no)
|
|
|
+# line = int(page_size)
|
|
|
+# device_info_qs = Device_Info.objects.filter(userID=user_id)
|
|
|
+# device_info_qs = device_info_qs.filter(~Q(isExist=0))
|
|
|
+# total = device_info_qs.count()
|
|
|
+# device_info_qs = device_info_qs.values("id", "userID_id", "NickName", "Type", "serial_number",
|
|
|
+# "data_joined",
|
|
|
+# "update_time")[(page - 1) * line: page * line]
|
|
|
+# data = []
|
|
|
+# for item in device_info_qs:
|
|
|
+# data.append({
|
|
|
+# 'id': item['id'],
|
|
|
+# 'userId': item['userID_id'],
|
|
|
+# 'nickName': item['NickName'],
|
|
|
+# 'type': item['Type'],
|
|
|
+# 'serialNumber': item['serial_number'],
|
|
|
+# 'dataJoined': item['data_joined'].strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
+# 'updateTime': item['update_time'].strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+# })
|
|
|
+# return response.json(0, {'list': data, 'total': total})
|
|
|
+#
|
|
|
+# @classmethod
|
|
|
+# def do_device_query(cls, user_id, request_dict, response):
|
|
|
+# """
|
|
|
+# 查询用户设备信息
|
|
|
+# @param user_id: 用户id
|
|
|
+# @param request_dict: 请求参数
|
|
|
+# @param response: 响应对象
|
|
|
+# @return: response
|
|
|
+# """
|
|
|
+# page = request_dict.get('page', None)
|
|
|
+# line = request_dict.get('line', None)
|
|
|
+# nick_name = request_dict.get('NickName', None)
|
|
|
+# family_id = request_dict.get('familyId', None)
|
|
|
+# room_id = request_dict.get('roomId', None)
|
|
|
+#
|
|
|
+# page = int(page)
|
|
|
+# line = int(line)
|
|
|
+# uid = request_dict.get('uid', None)
|
|
|
+# if family_id:
|
|
|
+# permission = cls.get_member_permission_details(user_id, int(family_id))
|
|
|
+# if not permission or permission == '003':
|
|
|
+# return response.json(404)
|
|
|
+# # 获取设备信息列表
|
|
|
+# device_info_list = cls.get_device_info_list(user_id, nick_name, uid,
|
|
|
+# page, line, family_id, room_id)
|
|
|
+# uid_list = []
|
|
|
+# # 判断是否是主用户 isPrimaryUser=0:否,1:是
|
|
|
+# for dvl in device_info_list:
|
|
|
+# if dvl['primaryUserID'] and dvl['id'] == dvl['primaryUserID']:
|
|
|
+# dvl['isPrimaryUser'] = 1
|
|
|
+# else:
|
|
|
+# dvl['isPrimaryUser'] = 0
|
|
|
+# uid_list.append(dvl['UID'])
|
|
|
+# # 设备关联套餐,设备预览图
|
|
|
+# uid_bucket_qs, uid_preview_qs = cls.get_bucket_and_preview_by_uid(uid_list)
|
|
|
+# # 设备配置信息
|
|
|
+# uid_set_dict = cls.get_uid_set_dict(uid_list)
|
|
|
+# # 设备详情信息
|
|
|
+# result = cls.get_device_details(device_info_list, uid_bucket_qs, uid_preview_qs, uid_set_dict)
|
|
|
+# items = []
|
|
|
+# for index, item in enumerate(result):
|
|
|
+# # 加密
|
|
|
+# if item['View_Password']:
|
|
|
+# item['View_Password'] = CommonService.encode_data(item['View_Password'], 1, 4)
|
|
|
+# items.append(item)
|
|
|
+# return response.json(0, items)
|
|
|
+#
|
|
|
+# @classmethod
|
|
|
+# def get_device_info_list(cls, user_id, nick_name, uid, page, line, family_id, room_id):
|
|
|
+# """
|
|
|
+# 根据用户id获取设备信息
|
|
|
+# @param room_id: 家庭id
|
|
|
+# @param family_id: 房间id
|
|
|
+# @param uid: uid
|
|
|
+# @param nick_name: 设备名称
|
|
|
+# @param line: 条数
|
|
|
+# @param page: 页数
|
|
|
+# @param user_id: 用户id
|
|
|
+# @return: device_info_list 设备信息列表
|
|
|
+# """
|
|
|
+# # 获取用户设备信息
|
|
|
+# device_info_qs = Device_Info.objects.filter(userID_id=user_id)
|
|
|
+# # 过滤已重置的设备
|
|
|
+# device_info_qs = device_info_qs.filter(~Q(isExist=2))
|
|
|
+# if nick_name:
|
|
|
+# device_info_qs = device_info_qs.filter(NickName__icontains=nick_name)
|
|
|
+# if uid:
|
|
|
+# device_info_qs.filter(UID=uid)
|
|
|
+# if family_id or room_id:
|
|
|
+# # 根据家庭id获取房间id关联查询设备
|
|
|
+# return cls.get_family_device_list(user_id, page, line, family_id, room_id)
|
|
|
+# device_info_values = device_info_qs.values('id', 'userID', 'NickName', 'UID', 'View_Account', 'View_Password',
|
|
|
+# 'ChannelIndex',
|
|
|
+# 'Type', 'isShare', 'primaryUserID', 'primaryMaster', 'data_joined',
|
|
|
+# 'vodPrimaryUserID',
|
|
|
+# 'vodPrimaryMaster', 'userID__userEmail', 'version', 'isVod',
|
|
|
+# 'isExist', 'NotificationMode',
|
|
|
+# 'isCameraOpenCloud', 'serial_number')
|
|
|
+#
|
|
|
+# device_info_values = device_info_values[(page - 1) * line:page * line]
|
|
|
+# device_info_list = CommonService.qs_to_list(device_info_values)
|
|
|
+# return device_info_list
|
|
|
+#
|
|
|
+# @classmethod
|
|
|
+# def get_family_device_list(cls, user_id, page_no, page_size, family_id, room_id):
|
|
|
+# """
|
|
|
+# 获取关联家庭设备列表
|
|
|
+# @param user_id: 用户id
|
|
|
+# @param page_no: 页数
|
|
|
+# @param page_size: 分页大小
|
|
|
+# @param family_id: 家庭id
|
|
|
+# @param room_id: 房间id
|
|
|
+# @return: result_list
|
|
|
+# """
|
|
|
+# cursor = connection.cursor()
|
|
|
+# sql = 'SELECT d.id,d.userID_id as userID,d.NickName,d.UID,d.View_Account,d.View_Password,d.ChannelIndex,' \
|
|
|
+# 'd.Type,d.isShare,d.primaryUserID,d.primaryMaster,d.data_joined,d.vodPrimaryUserID,d.vodPrimaryMaster, ' \
|
|
|
+# 'd.version,d.isVod,d.isExist,d.NotificationMode,d.isCameraOpenCloud,d.serial_number '
|
|
|
+# sql += 'FROM device_info d INNER JOIN loocam_family_room_device l ON d.id = l.device_id '
|
|
|
+# sql += 'WHERE d.userID_id = %s AND d.isExist != %s '
|
|
|
+# if family_id:
|
|
|
+# sql += ' AND l.family_id = %s '
|
|
|
+# if room_id:
|
|
|
+# sql += ' AND l.room_id = %s '
|
|
|
+# sql += ' order by d.data_joined DESC,d.id DESC LIMIT %s,%s '
|
|
|
+# cursor.execute(sql, [user_id, 2, int(family_id) if family_id else int(room_id), ((page_no - 1) * page_size),
|
|
|
+# page_size, ])
|
|
|
+# data_obj = cursor.fetchall()
|
|
|
+# cursor.close() # 执行完,关闭
|
|
|
+# connection.close()
|
|
|
+# result_list = []
|
|
|
+# col_names = [desc[0] for desc in cursor.description]
|
|
|
+# for item in data_obj:
|
|
|
+# val = dict(zip(col_names, item))
|
|
|
+# user_id = val['userID']
|
|
|
+# device_user_qs = Device_User.objects.filter(userID=user_id)
|
|
|
+# val['userID__userEmail'] = device_user_qs.first().userEmail
|
|
|
+# val['isShare'] = False if val['isShare'] == 0 else True
|
|
|
+# if 'data_joined' in val:
|
|
|
+# if val['data_joined']:
|
|
|
+# val['data_joined'] = val['data_joined'].strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+# else:
|
|
|
+# val['data_joined'] = ''
|
|
|
+# result_list.append(val)
|
|
|
+# return result_list
|
|
|
+#
|
|
|
+# @classmethod
|
|
|
+# def get_bucket_and_preview_by_uid(cls, uid_list):
|
|
|
+# """
|
|
|
+# 根据uid列表查询套餐
|
|
|
+# @param uid_list: uid列表
|
|
|
+# @return: uid_bucket_qs
|
|
|
+# """
|
|
|
+# uid_bucket_qs = UID_Bucket.objects.filter(uid__in=uid_list).values('bucket__content', 'status', 'channel',
|
|
|
+# 'endTime', 'uid')
|
|
|
+# uid_preview_qs = UID_Preview.objects.filter(uid__in=uid_list).order_by('channel').values('id', 'uid', 'channel')
|
|
|
+# return uid_bucket_qs, uid_preview_qs
|
|
|
+#
|
|
|
+# @classmethod
|
|
|
+# def get_uid_set_dict(cls, uid_list):
|
|
|
+# """
|
|
|
+# 获取uid配置信息
|
|
|
+# @param uid_list: uid列表
|
|
|
+# @return: uid_set_dict uid配置信息
|
|
|
+# """
|
|
|
+# uid_set_qs = UidSetModel.objects.filter(uid__in=uid_list) \
|
|
|
+# .values('id', 'uid', 'version', 'nickname', 'ucode',
|
|
|
+# 'detect_status', 'detect_group',
|
|
|
+# 'detect_interval',
|
|
|
+# 'region_alexa', 'is_alexa', 'deviceModel',
|
|
|
+# 'TimeZone', 'TimeStatus', 'SpaceUsable',
|
|
|
+# 'SpaceSum', 'MirrorType', 'RecordType',
|
|
|
+# 'OutdoorModel', 'WIFIName', 'isDetector',
|
|
|
+# 'DetectorRank', 'is_human', 'is_custom_voice',
|
|
|
+# 'is_ptz', 'double_wifi', 'is_ai')
|
|
|
+# uid_set_dict = {}
|
|
|
+# for us in uid_set_qs:
|
|
|
+# uid_set_dict[us['uid']] = {
|
|
|
+# 'version': us['version'],
|
|
|
+# 'nickname': us['nickname'],
|
|
|
+# 'ucode': us['ucode'],
|
|
|
+# 'detect_interval': us['detect_interval'],
|
|
|
+# 'detect_group': us['detect_group'],
|
|
|
+# 'detect_status': us['detect_status'],
|
|
|
+# 'region_alexa': us['region_alexa'],
|
|
|
+# 'is_alexa': us['is_alexa'],
|
|
|
+# 'deviceModel': us['deviceModel'],
|
|
|
+# 'TimeZone': us['TimeZone'],
|
|
|
+# 'TimeStatus': us['TimeStatus'],
|
|
|
+# 'SpaceUsable': us['SpaceUsable'],
|
|
|
+# 'SpaceSum': us['SpaceSum'],
|
|
|
+# 'MirrorType': us['MirrorType'],
|
|
|
+# 'RecordType': us['RecordType'],
|
|
|
+# 'OutdoorModel': us['OutdoorModel'],
|
|
|
+# 'WIFIName': us['WIFIName'],
|
|
|
+# 'isDetector': us['isDetector'],
|
|
|
+# 'DetectorRank': us['DetectorRank'],
|
|
|
+# 'is_human': us['is_human'],
|
|
|
+# 'is_custom_voice': us['is_custom_voice'],
|
|
|
+# 'is_ptz': us['is_ptz'],
|
|
|
+# 'double_wifi': us['double_wifi'],
|
|
|
+# 'is_ai': us['is_ai']
|
|
|
+# }
|
|
|
+# # 从uid_channel里面取出通道配置信息
|
|
|
+# uid_channel_set_qs = UidChannelSetModel.objects.filter(uid__id=us['id']) \
|
|
|
+# .values('channel', 'channel_name',
|
|
|
+# 'pir_audio', 'mic_audio',
|
|
|
+# 'battery_status',
|
|
|
+# 'battery_level',
|
|
|
+# 'sleep_status',
|
|
|
+# 'sleep_time',
|
|
|
+# 'light_night_model',
|
|
|
+# 'light_alarm_type',
|
|
|
+# 'light_alarm_level',
|
|
|
+# 'light_alarm_man_en',
|
|
|
+# 'light_alarm_vol',
|
|
|
+# 'light_long_light'
|
|
|
+# )
|
|
|
+# channels_list = []
|
|
|
+# for ucs in uid_channel_set_qs:
|
|
|
+# channels_dict = {
|
|
|
+# 'channel': ucs['channel'],
|
|
|
+# 'channel_name': ucs['channel_name'],
|
|
|
+# 'pir_audio': ucs['pir_audio'],
|
|
|
+# 'mic_audio': ucs['mic_audio'],
|
|
|
+# 'battery_status': ucs['battery_status'],
|
|
|
+# 'battery_level': ucs['battery_level'],
|
|
|
+# 'sleep_status': ucs['sleep_status'],
|
|
|
+# 'sleep_time': ucs['sleep_time'],
|
|
|
+# 'light_night_model': ucs['light_night_model'],
|
|
|
+# 'light_alarm_type': ucs['light_alarm_type'],
|
|
|
+# 'light_alarm_level': ucs['light_alarm_level'],
|
|
|
+# 'light_alarm_man_en': ucs['light_alarm_man_en'],
|
|
|
+# 'light_alarm_vol': ucs['light_alarm_vol'],
|
|
|
+# 'light_long_light': ucs['light_long_light']
|
|
|
+# }
|
|
|
+# channels_list.append(channels_dict)
|
|
|
+# uid_set_dict[us['uid']]['channels'] = channels_list
|
|
|
+# return uid_set_dict
|
|
|
+#
|
|
|
+# @classmethod
|
|
|
+# def get_device_details(cls, device_info_list, uid_bucket_qs, uid_preview_qs, uid_set_dict):
|
|
|
+# """
|
|
|
+# 设备详情
|
|
|
+# @param device_info_list: 设备信息列表
|
|
|
+# @param uid_bucket_qs: 套餐对象
|
|
|
+# @param uid_preview_qs:
|
|
|
+# @param uid_set_dict:
|
|
|
+# @return:
|
|
|
+# """
|
|
|
+# now_time = int(time.time())
|
|
|
+# data = []
|
|
|
+# for p in device_info_list:
|
|
|
+# # 获取iotDeviceInfo表的endpoint和tokenIotNumber
|
|
|
+# p['iot'] = []
|
|
|
+# if p['serial_number']: # 存在序列号根据序列号查询
|
|
|
+# iot_device_info_qs = iotdeviceInfoModel.objects.filter(serial_number=p['serial_number'][0:6])
|
|
|
+# else: # 根据uid查询
|
|
|
+# iot_device_info_qs = iotdeviceInfoModel.objects.filter(uid=p['UID'])
|
|
|
+# if iot_device_info_qs.exists():
|
|
|
+# iot_device_Info = iot_device_info_qs.values('endpoint', 'token_iot_number')
|
|
|
+# p['iot'].append({
|
|
|
+# 'endpoint': iot_device_Info[0]['endpoint'],
|
|
|
+# 'token_iot_number': iot_device_Info[0]['token_iot_number']
|
|
|
+# })
|
|
|
+#
|
|
|
+# p['vod'] = []
|
|
|
+# for dm in uid_bucket_qs:
|
|
|
+# if p['UID'] == dm['uid']:
|
|
|
+# if dm['endTime'] > now_time:
|
|
|
+# p['vod'].append(dm)
|
|
|
+# p['preview'] = []
|
|
|
+#
|
|
|
+# auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
+# bucket = oss2.Bucket(auth, 'oss-cn-hongkong.aliyuncs.com', 'statres')
|
|
|
+#
|
|
|
+# for up in uid_preview_qs:
|
|
|
+# if p['UID'] == up['uid']:
|
|
|
+# obj = 'uid_preview/{uid}/channel_{channel}.png'.format(uid=up['uid'], channel=up['channel'])
|
|
|
+# img_sign = bucket.sign_url('GET', obj, 300)
|
|
|
+# p['preview'].append(img_sign)
|
|
|
+#
|
|
|
+# p_uid = p['UID']
|
|
|
+#
|
|
|
+# # 返回设备初始化字符
|
|
|
+# uid_qs = UIDModel.objects.filter(uid=p_uid).values('platform', 'init_string', 'init_string_app')
|
|
|
+# if uid_qs.exists():
|
|
|
+# p['platform'] = uid_qs[0]['platform']
|
|
|
+# p['initString'] = uid_qs[0]['init_string']
|
|
|
+# p['initStringApp'] = uid_qs[0]['init_string_app']
|
|
|
+#
|
|
|
+# if p_uid in uid_set_dict:
|
|
|
+# # 设备版本号
|
|
|
+# uidversion = uid_set_dict[p_uid]['version']
|
|
|
+# if len(uidversion) > 6:
|
|
|
+# uidversion = uidversion[0: uidversion.rfind('.')]
|
|
|
+# p['uid_version'] = uidversion
|
|
|
+# p['ucode'] = uid_set_dict[p_uid]['ucode']
|
|
|
+# p['detect_interval'] = uid_set_dict[p_uid]['detect_interval']
|
|
|
+# p['detect_status'] = uid_set_dict[p_uid]['detect_status']
|
|
|
+# p['detect_group'] = uid_set_dict[p_uid]['detect_group']
|
|
|
+# p['region_alexa'] = uid_set_dict[p_uid]['region_alexa']
|
|
|
+# p['is_alexa'] = uid_set_dict[p_uid]['is_alexa']
|
|
|
+# p['deviceModel'] = uid_set_dict[p_uid]['deviceModel']
|
|
|
+# p['TimeZone'] = uid_set_dict[p_uid]['TimeZone']
|
|
|
+# p['TimeStatus'] = uid_set_dict[p_uid]['TimeStatus']
|
|
|
+# p['SpaceUsable'] = uid_set_dict[p_uid]['SpaceUsable']
|
|
|
+# p['SpaceSum'] = uid_set_dict[p_uid]['SpaceSum']
|
|
|
+# p['MirrorType'] = uid_set_dict[p_uid]['MirrorType']
|
|
|
+# p['RecordType'] = uid_set_dict[p_uid]['RecordType']
|
|
|
+# p['OutdoorModel'] = uid_set_dict[p_uid]['OutdoorModel']
|
|
|
+# p['WIFIName'] = uid_set_dict[p_uid]['WIFIName']
|
|
|
+# p['isDetector'] = uid_set_dict[p_uid]['isDetector']
|
|
|
+# p['DetectorRank'] = uid_set_dict[p_uid]['DetectorRank']
|
|
|
+# p['is_human'] = uid_set_dict[p_uid]['is_human']
|
|
|
+# p['is_custom_voice'] = uid_set_dict[p_uid]['is_custom_voice']
|
|
|
+# p['is_ptz'] = uid_set_dict[p_uid]['is_ptz']
|
|
|
+# p['channels'] = uid_set_dict[p_uid]['channels']
|
|
|
+# p['double_wifi'] = uid_set_dict[p_uid]['double_wifi']
|
|
|
+# p['is_ai'] = uid_set_dict[p_uid]['is_ai']
|
|
|
+# # 设备昵称 调用影子信息昵称,先阶段不可
|
|
|
+# if uid_set_dict[p_uid]['nickname']:
|
|
|
+# p['NickName'] = uid_set_dict[p_uid]['nickname']
|
|
|
+# else:
|
|
|
+# # 设备版本号
|
|
|
+# p['uid_version'] = ''
|
|
|
+# p['ucode'] = ''
|
|
|
+# data.append(p)
|
|
|
+# return data
|
|
|
+#
|
|
|
+# @classmethod
|
|
|
+# def get_family_list(cls, user_id, request_dict, response):
|
|
|
+# """
|
|
|
+# 查询家庭列表
|
|
|
+# @param user_id: 用户id
|
|
|
+# @param request_dict: 请求
|
|
|
+# @param response: 响应
|
|
|
+# @return: 家庭列表items
|
|
|
+# """
|
|
|
+# lang = request_dict.get('lang', 'cn')
|
|
|
+# if user_id:
|
|
|
+# with transaction.atomic():
|
|
|
+# user_family_qs = UserFamily.objects.filter(user_id=user_id)
|
|
|
+# if not user_family_qs.exists():
|
|
|
+# n_time = int(time.time())
|
|
|
+# device_user = Device_User.objects.get(userID=user_id)
|
|
|
+# # 创建默认家庭使用用户名或者邮箱作为名称
|
|
|
+# family_name = device_user.username if device_user.username else device_user.userEmail
|
|
|
+# family_name = family_name + "的家" if lang == 'cn' else family_name + " home"
|
|
|
+# user_family = UserFamily.objects.create(user_id=user_id, name=family_name,
|
|
|
+# updated_time=n_time,
|
|
|
+# created_time=n_time)
|
|
|
+# if user_family.id:
|
|
|
+# member_permission_qs = FamilyMemberPermission.objects.filter(no='001').values('id')
|
|
|
+# permission_id = member_permission_qs.first()['id']
|
|
|
+# FamilyMember.objects.create(family_id=user_family.id, user_id=user_id,
|
|
|
+# user_name=device_user.username, identity=1,
|
|
|
+# permission_id=int(permission_id), sort=1, updated_time=n_time,
|
|
|
+# created_time=n_time)
|
|
|
+# cls.family_device_binding(user_id, family_id=user_family.id)
|
|
|
+#
|
|
|
+# family_member_qs = FamilyMember.objects.filter(user_id=user_id) \
|
|
|
+# .order_by('sort').values('identity', 'family_id', 'family__name', 'permission__no', 'family__location')
|
|
|
+# items = []
|
|
|
+# data = {}
|
|
|
+# for item in family_member_qs:
|
|
|
+# data['familyId'] = item['family_id']
|
|
|
+# data['identity'] = item['identity']
|
|
|
+# data['familyName'] = item['family__name']
|
|
|
+# data['permissionId'] = item['permission_id']
|
|
|
+# data['permissionNo'] = item['permission__no']
|
|
|
+# data['familyLocation'] = item['family__location']
|
|
|
+# items.append(data)
|
|
|
+# return response.json(0, items)
|
|
|
+# return response.json(309)
|
|
|
+#
|
|
|
+# @classmethod
|
|
|
+# def family_save(cls, user_id, request_dict, response):
|
|
|
+# """
|
|
|
+# 家庭保存
|
|
|
+# @param user_id: 用户id
|
|
|
+# @param request_dict: 参数
|
|
|
+# @param response: 响应
|
|
|
+# @return:
|
|
|
+# """
|
|
|
+# family_id = request_dict.get('familyId', None)
|
|
|
+# family_name = request_dict.get('familyName', None)
|
|
|
+# location = request_dict.get('location', None)
|
|
|
+# with transaction.atomic():
|
|
|
+# now_time = int(time.time())
|
|
|
+# if family_id:
|
|
|
+# family_member = FamilyMember.objects.filter(family_id=family_id, user_id=user_id)
|
|
|
+# if family_member.exists():
|
|
|
+# family_member = family_member.first()
|
|
|
+# if family_member.identity == 0:
|
|
|
+# return response.json(404)
|
|
|
+# family_qs = UserFamily.objects.filter(id=family_id)
|
|
|
+# if family_qs.exists():
|
|
|
+# data = {
|
|
|
+# 'updated_time': now_time
|
|
|
+# }
|
|
|
+# if family_name:
|
|
|
+# data['name'] = family_name
|
|
|
+# if location:
|
|
|
+# data['location'] = location
|
|
|
+# family_qs.update(**data)
|
|
|
+# return response.json(0)
|
|
|
+# data = {'user_id': user_id, 'updated_time': now_time, 'created_time': now_time}
|
|
|
+# if family_name:
|
|
|
+# data['name'] = family_name
|
|
|
+# if location:
|
|
|
+# data['location'] = location
|
|
|
+# UserFamily.objects.create(**data)
|
|
|
+# return response.json(0)
|
|
|
+# return response.json(444)
|
|
|
+#
|
|
|
+# @classmethod
|
|
|
+# def family_room_device_save(cls, family_id, room_id, device_id):
|
|
|
+# """
|
|
|
+# 设备与家庭房间保存
|
|
|
+# @param family_id: 家庭id
|
|
|
+# @param room_id: 房间id
|
|
|
+# @param device_id: 设备id
|
|
|
+# @return: Boole
|
|
|
+# """
|
|
|
+# now_time = int(time.time())
|
|
|
+# family_room_device = FamilyRoomDevice.objects.filter(device_id=device_id)
|
|
|
+# if family_room_device.exists():
|
|
|
+# return False
|
|
|
+# data = {
|
|
|
+# 'family_id': int(family_id),
|
|
|
+# 'device_id': device_id,
|
|
|
+# 'updated_time': now_time,
|
|
|
+# 'created_time': now_time
|
|
|
+# }
|
|
|
+# if room_id:
|
|
|
+# room_id = int(room_id)
|
|
|
+# if FamilyRoom.objects.filter(id=room_id).exists():
|
|
|
+# data['room_id'] = room_id
|
|
|
+# FamilyRoomDevice.objects.create(**data)
|
|
|
+# return True
|
|
|
+#
|
|
|
+# @classmethod
|
|
|
+# def family_device_binding(cls, user_id, family_id):
|
|
|
+# """
|
|
|
+# 用户旧设备与默认家庭进行绑定
|
|
|
+# @param user_id:
|
|
|
+# @param family_id:
|
|
|
+# @return: True
|
|
|
+# """
|
|
|
+# device_info_qs = Device_Info.objects.filter(userID=user_id)
|
|
|
+# device_info_qs = device_info_qs.filter(~Q(isExist=0)).values('id')
|
|
|
+# if device_info_qs.exists():
|
|
|
+# with transaction.atomic():
|
|
|
+# not_time = time.time()
|
|
|
+# device_list = []
|
|
|
+# for item in device_info_qs:
|
|
|
+# device_id = item['id']
|
|
|
+# family_device_qs = FamilyRoomDevice.objects.filter(device_id=device_id)
|
|
|
+# if not family_device_qs.exists():
|
|
|
+# # 设备绑定家庭
|
|
|
+# device_list.append(FamilyRoomDevice(family_id=family_id, device_id=device_id,
|
|
|
+# created_time=not_time,
|
|
|
+# updated_time=not_time))
|
|
|
+# if device_list:
|
|
|
+# FamilyRoomDevice.objects.bulk_create(device_list)
|
|
|
+# return True
|
|
|
+#
|
|
|
+# @classmethod
|
|
|
+# def get_family_room_list(cls, request_dict, response):
|
|
|
+# """
|
|
|
+# 获取房间列表并统计该房间下有几台设备
|
|
|
+# @param request_dict: 请求参数
|
|
|
+# @param response: 响应参数
|
|
|
+# @return: total;data
|
|
|
+# """
|
|
|
+# family_id = request_dict.get('familyId', None)
|
|
|
+# if not family_id:
|
|
|
+# return response.json(444)
|
|
|
+# page_no = request_dict.get('pageNo', None)
|
|
|
+# page_size = request_dict.get('pageSize', None)
|
|
|
+# if not all([page_no, page_size]):
|
|
|
+# return response.json(444)
|
|
|
+# page_no = int(page_no)
|
|
|
+# page_size = int(page_size)
|
|
|
+# room_qs = FamilyRoom.objects.filter(family_id=family_id).order_by('sort')
|
|
|
+# total = room_qs.count()
|
|
|
+# room_qs = room_qs.values('id', 'name', 'sort')[(page_no - 1) * page_size: page_no * page_size]
|
|
|
+# room_list = []
|
|
|
+# if not room_qs.exists():
|
|
|
+# return response.json(0, room_list)
|
|
|
+# for item in room_qs:
|
|
|
+# item['deviceCount'] = FamilyRoomDevice.objects.filter(family_id=family_id, room_id=item['id']).count()
|
|
|
+# room_list.append(item)
|
|
|
+# return response.json(0, {'total': total, 'data': room_list})
|
|
|
+#
|
|
|
+# @classmethod
|
|
|
+# def room_save(cls, request_dict, response):
|
|
|
+# """
|
|
|
+# 房间保存
|
|
|
+# @param request_dict: 请求参数
|
|
|
+# @param response: 响应参数
|
|
|
+# @return:
|
|
|
+# """
|
|
|
+# family_id = request_dict.get('familyId', None)
|
|
|
+# room_name = request_dict.get('roomName', None)
|
|
|
+# room_id = request_dict.get('roomId', None)
|
|
|
+# if not all([family_id, room_name]):
|
|
|
+# return response.json(444)
|
|
|
+# with transaction.atomic():
|
|
|
+# now_time = int(time.time())
|
|
|
+# if room_id:
|
|
|
+# room_qs = FamilyRoom.objects.filter(id=int(room_id))
|
|
|
+# if room_qs.exists():
|
|
|
+# room_qs.update(name=room_name, updated_time=now_time)
|
|
|
+# return response.json(0)
|
|
|
+# room_qs = FamilyRoom.objects.filter(family_id=family_id, name=room_name)
|
|
|
+#
|
|
|
+# if room_qs.exists():
|
|
|
+# room_dict = {'updated_time': now_time, 'name': room_name}
|
|
|
+# room_qs.update(**room_dict)
|
|
|
+# FamilyRoom.objects.create(family_id=family_id, name=room_name, updated_time=now_time,
|
|
|
+# created_time=now_time)
|
|
|
+# return response.json(0)
|
|
|
+#
|
|
|
+# @classmethod
|
|
|
+# def room_sort_save(cls, request_dict, response):
|
|
|
+# """
|
|
|
+# 房间排序
|
|
|
+# @param request_dict: 请求参数
|
|
|
+# @param response: 响应参数
|
|
|
+# @return:
|
|
|
+# """
|
|
|
+# ids = request_dict.getlist('ids', None)
|
|
|
+# if not ids:
|
|
|
+# return response.json(444)
|
|
|
+# for i, item in ids:
|
|
|
+# id_sort = item[i]
|
|
|
+# print(id_sort)
|
|
|
+# return response.json(0)
|
|
|
+#
|
|
|
+# @classmethod
|
|
|
+# def get_member_permission_list(cls, user_id, request_dict, response):
|
|
|
+# """
|
|
|
+# 获取用户权限列表
|
|
|
+# @param user_id:
|
|
|
+# @param request_dict:
|
|
|
+# @param response:
|
|
|
+# @return:
|
|
|
+# """
|
|
|
+# family_id = request_dict.get('familyId')
|
|
|
+# user_id = request_dict.get('userId', user_id)
|
|
|
+# if not family_id:
|
|
|
+# return response.json(404)
|
|
|
+# result = cls.get_member_permission_by_family_id(user_id, family_id)
|
|
|
+# return response.json(0, result)
|
|
|
+#
|
|
|
+# @classmethod
|
|
|
+# def get_member_permission_by_family_id(cls, user_id, family_id):
|
|
|
+# """
|
|
|
+# 获取权限列表并返回当前user_id所在家庭中权限
|
|
|
+# @param user_id:
|
|
|
+# @param family_id:
|
|
|
+# @return:
|
|
|
+# """
|
|
|
+# member_qs = FamilyMember.objects.filter(family_id=family_id)
|
|
|
+# if user_id:
|
|
|
+# member_qs = member_qs.filter(user_id=user_id).values()
|
|
|
+# if member_qs.exists():
|
|
|
+# member_qs = member_qs.first()
|
|
|
+# permission = FamilyMemberPermission.objects.all().values('id', 'no')
|
|
|
+# data_list = []
|
|
|
+# this_permission = {}
|
|
|
+# result = {}
|
|
|
+# for item in permission:
|
|
|
+# if item['id'] == member_qs['permission_id']:
|
|
|
+# this_permission['id'] = item['id']
|
|
|
+# this_permission['no'] = item['no']
|
|
|
+# data_list.append(item)
|
|
|
+# result['memberPermission'] = this_permission
|
|
|
+# result['permissionList'] = data_list
|
|
|
+# return result
|
|
|
+#
|
|
|
+# @classmethod
|
|
|
+# def get_member_permission_details(cls, user_id, family_id):
|
|
|
+# member_qs = FamilyMember.objects.filter(family_id=family_id, user_id=user_id).values()
|
|
|
+# if member_qs.exists():
|
|
|
+# member_qs = member_qs.first()
|
|
|
+# permission_id = member_qs['permission_id']
|
|
|
+# permission_qs = FamilyMemberPermission.objects.filter(id=permission_id).values('no')
|
|
|
+# return permission_qs.first()['no']
|
|
|
+# return ''
|