|
@@ -6,12 +6,16 @@
|
|
|
@Email : zhangdongming@asj6.wecom.work
|
|
|
@Software: PyCharm
|
|
|
"""
|
|
|
+import logging
|
|
|
+
|
|
|
from django.db.models import Q
|
|
|
|
|
|
from Model.models import Device_Info, UID_Bucket, UID_Preview, UidSetModel, UidChannelSetModel, UnicomDeviceInfo, \
|
|
|
- UIDModel
|
|
|
+ UIDModel, DeviceChannelUserSet, DeviceChannelUserPermission, DeviceSharePermission
|
|
|
from Service.CommonService import CommonService
|
|
|
|
|
|
+LOGGER = logging.getLogger('info')
|
|
|
+
|
|
|
|
|
|
class UserDeviceService:
|
|
|
|
|
@@ -195,12 +199,13 @@ class UserDeviceService:
|
|
|
p_vo['initStringApp'] = uid_qs[0]['init_string_app']
|
|
|
|
|
|
@classmethod
|
|
|
- def get_device_info_dto(cls, p_vo, p_uid, uv_dict):
|
|
|
+ def get_device_info_dto(cls, p_vo, p_uid, uv_dict, user_id=None):
|
|
|
"""
|
|
|
获取设备信息DTO
|
|
|
- @param p_vo: 设备对象
|
|
|
+ @param user_id: 用户ID
|
|
|
+ @param p_vo: 设备信息
|
|
|
@param p_uid: 设备uid
|
|
|
- @param uv_dict: 设备通道字典
|
|
|
+ @param uv_dict: 设备通道信息
|
|
|
"""
|
|
|
uidversion = uv_dict[p_uid]['version']
|
|
|
if len(uidversion) > 6:
|
|
@@ -226,7 +231,8 @@ class UserDeviceService:
|
|
|
p_vo['is_human'] = uv_dict[p_uid]['is_human']
|
|
|
p_vo['is_custom_voice'] = uv_dict[p_uid]['is_custom_voice']
|
|
|
p_vo['is_ptz'] = uv_dict[p_uid]['is_ptz']
|
|
|
- p_vo['channels'] = uv_dict[p_uid]['channels']
|
|
|
+ p_vo['channels'] = cls.get_channel_permission_by_user(user_id, p_vo['isShare'], p_uid,
|
|
|
+ uv_dict[p_uid]['channels'])
|
|
|
p_vo['double_wifi'] = uv_dict[p_uid]['double_wifi']
|
|
|
p_vo['mobile4G'] = uv_dict[p_uid]['mobile4G']
|
|
|
p_vo['isCameraOpenCloud'] = 0 if uv_dict[p_uid]['mobile4G'] == 1 else p_vo['isCameraOpenCloud']
|
|
@@ -236,3 +242,35 @@ class UserDeviceService:
|
|
|
# 设备昵称 调用影子信息昵称,先阶段不可
|
|
|
if uv_dict[p_uid]['nickname']:
|
|
|
p_vo['NickName'] = uv_dict[p_uid]['nickname']
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def get_channel_permission_by_user(user_id, is_share, uid, channels):
|
|
|
+ """
|
|
|
+ 根据用户获取设备通道权限
|
|
|
+ @param user_id: 用户ID
|
|
|
+ @param is_share: 是否分享设备
|
|
|
+ @param uid: 设备UID
|
|
|
+ @param channels: 通道信息
|
|
|
+ @return: channels
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ if not is_share:
|
|
|
+ return channels
|
|
|
+ # 获取设备权限
|
|
|
+ channel_set_qs = DeviceChannelUserSet.objects.filter(user_id=user_id, uid=uid).values('id', 'channels')
|
|
|
+ if not channel_set_qs.exists() or not channels:
|
|
|
+ return channels
|
|
|
+ channel_list = [int(val) for val in channel_set_qs[0]['channels'].split(',')]
|
|
|
+ channel_permission_qs = DeviceChannelUserPermission.objects.filter(channel_user_id=channel_set_qs[0]['id']) \
|
|
|
+ .values('permission_id')
|
|
|
+ ids = [val['permission_id'] for val in channel_permission_qs]
|
|
|
+ channel_permission_list = list(DeviceSharePermission.objects.filter(id__in=ids)
|
|
|
+ .values('id', 'code').order_by('sort'))
|
|
|
+ for item in channels:
|
|
|
+ channel = item['channel']
|
|
|
+ if channel in channel_list:
|
|
|
+ item['channelPermissions'] = channel_permission_list
|
|
|
+ return channels
|
|
|
+ except Exception as e:
|
|
|
+ LOGGER.info('异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ return channels
|