| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 | 
							- from Model.models import *
 
- from Service.CommonService import CommonService
 
- # 针对模型封装的复用性代码
 
- class ModelService:
 
-     # 获取当前用户角色名
 
-     @staticmethod
 
-     def getRole(rid):
 
-         Roles = Role.objects.get(rid=rid)
 
-         return Roles.roleName
 
-     @staticmethod
 
-     def getValidateMember(userID):
 
-         device_user_query_set = Device_User.objects.get(userID=userID)
 
-         role_query_set = device_user_query_set.role.all()
 
-         role_dict = CommonService.query_set_to_dict(role_query_set)
 
-         permission = role_dict["datas"][0]["fields"]["permission"]
 
-         if len(permission):
 
-             if 92 in permission:
 
-                 return True
 
-         return False
 
-     # 获取用户所有权限
 
-     @staticmethod
 
-     def own_permission(userID):
 
-         device_user_query_set = Device_User.objects.get(userID=userID)
 
-         role_query_set = device_user_query_set.role.all()
 
-         if role_query_set.exists():
 
-             role_dict = CommonService.query_set_to_dict(role_query_set)
 
-             permission = role_dict["datas"][0]["fields"]["permission"]
 
-             if len(permission):
 
-                 return permission
 
-         return []
 
-     # 获取用户角色相关
 
-     @staticmethod
 
-     def own_role(userID):
 
-         device_user_query_set = Device_User.objects.get(userID=userID)
 
-         role_query_set = device_user_query_set.role.all()
 
-         if role_query_set.exists():
 
-             return {'rid': role_query_set[0].rid, 'roleName': role_query_set[0].roleName}
 
-         return {'rid': '', 'roleName': ''}
 
-     # 检测权限有无
 
-     @staticmethod
 
-     def check_permission(userID, permID):
 
-         try:
 
-             device_user_query_set = Device_User.objects.get(userID=userID)
 
-             if device_user_query_set:
 
-                 role_query_set = device_user_query_set.role.all()
 
-                 if role_query_set:
 
-                     role_dict = CommonService.query_set_to_dict(role_query_set)
 
-                     permission = role_dict["datas"][0]["fields"]["permission"]
 
-                     print(permission)
 
-                     if len(permission) > 0:
 
-                         if permID in permission:
 
-                             return True
 
-         except Exception as e:
 
-             return False
 
-         return False
 
-     # 根据设备主键ID判断是否拥有该设备
 
-     @staticmethod
 
-     def check_user_own_device(userID, deviceID):
 
-         try:
 
-             device_user = Device_User.objects.get(userID=userID)
 
-             device_info_queryset = device_user.device_info_set.all().values('id')
 
-             id_list = []
 
-             for id_dict in list(device_info_queryset):
 
-                 id_list.append(id_dict['id'])
 
-             if deviceID in id_list:
 
-                 return True
 
-         except Exception as e:
 
-             return False
 
-         return False
 
-     # 根据设设备唯一名称UID判断是否拥有该设备
 
-     @staticmethod
 
-     def check_own_device(userID, UID):
 
-         device_info_queryset = Device_Info.objects.filter(userID_id=userID, UID=UID)
 
-         if device_info_queryset.exists():
 
-             return True
 
-         return False
 
-     # 根据userID获取用户名
 
-     @staticmethod
 
-     def get_user_name(userID):
 
-         try:
 
-             device_user = Device_User.objects.get(userID=userID)
 
-         except Exception as e:
 
-             return None
 
-         else:
 
-             return device_user.username
 
-     # 根据username获取userID
 
-     @staticmethod
 
-     def get_userID_byname(username):
 
-         try:
 
-             device_user = Device_User.objects.get(username=username)
 
-         except Exception as e:
 
-             return None
 
-         else:
 
-             return device_user.userID
 
-     # 访问日志添加
 
-     @staticmethod
 
-     def addAccessLog(data):
 
-         try:
 
-             access_log = Access_Log.objects.create(**data)
 
-         except Exception as e:
 
-             return False
 
-         else:
 
-             if access_log.id:
 
-                 return True
 
-             else:
 
-                 return False
 
-     # 判断设备账户信息是否正确
 
-     @staticmethod
 
-     def device_auth(UID, View_Account, View_Password, ChannelIndex):
 
-         device_info_queryset = Device_Info.objects.filter(UID=UID, View_Account=View_Account,
 
-                                                           View_Password=View_Password, ChannelIndex=ChannelIndex)
 
-         if device_info_queryset.exists():
 
-             return True
 
-         return False
 
 
  |