using Edu.Common.Enum; using Edu.Model.Entity.System; using Edu.Model.ViewModel.System; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Edu.Repository.System { /// /// 菜单功能权限仓储层 /// public class RB_Menu_FunctionRepository : BaseRepository { /// /// 获取菜单功能权限分页列表 /// /// /// /// /// /// public List GetMenuFunctionPageListRepository(int pageIndex, int pageSize, out long rowsCount, RB_Menu_Function_ViewModel query) { rowsCount = 0; StringBuilder builder = new StringBuilder(); builder.AppendFormat(@" SELECT A.*,IFNULL(B.MenuName,'') AS MenuName FROM RB_Menu_Function AS A LEFT JOIN RB_Menu AS B ON A.MenuId=B.MenuId WHERE 1=1 "); if (query != null) { if (query.MenuId > 0) { builder.Append($" AND A.{nameof(RB_Menu_Function_ViewModel.MenuId)}={query.MenuId} "); } return GetPage(pageIndex, pageSize, out rowsCount, builder.ToString()).ToList(); } else { return new List(); } } /// /// 获取菜单功能权限列表 /// /// /// true-正常数据,false-全部数据 /// public List GetMenuFunctionListRepository(RB_Menu_Function_ViewModel query,bool isQueryNormal=false,int roleId=0) { StringBuilder builder = new StringBuilder(); builder.AppendFormat(@" SELECT A.* FROM RB_Menu_Function AS A WHERE 1=1 "); if (isQueryNormal) { builder.Append($" AND A.{nameof(RB_Menu_Function_ViewModel.Status)}={(int)DateStateEnum.Normal} "); } if (roleId > 0) { builder.AppendFormat(@" AND A.Id IN(SELECT Action_Id FROM rb_role_functionpermission WHERE Role_Id={0} )", roleId); } if (query != null) { if (query.MenuId > 0) { builder.Append($" AND A.{nameof(RB_Menu_Function_ViewModel.MenuId)}={query.MenuId} "); } return Get(builder.ToString()).ToList(); } else { return new List(); } } /// /// 根据岗位编号获取岗位角色菜单功能权限 /// /// 岗位编号 /// public List GetPostMenuFunctionListRepository(string postIds) { StringBuilder builder = new StringBuilder(); builder.AppendFormat(@" SELECT A.*,IFNULL(B.MenuName,'') AS MenuName,IFNULL(B.MenuUrl,'') AS MenuUrl FROM RB_Menu_Function AS A LEFT JOIN rb_menu AS B ON A.MenuId=B.MenuId WHERE 1=1 AND A.Status=0 AND A.Id IN(SELECT Action_Id FROM rb_role_functionpermission WHERE Role_Id IN (SELECT RoleId FROM rb_post_role WHERE PostId IN({0}))) ", postIds); return Get(builder.ToString()).ToList(); } /// /// 判断用户是否有某项功能权限 /// /// 权限编码 /// 岗位编号【可以多个】 /// public bool CheckUserFunctionRepository(string actionCode, string postIds) { int result = 0; StringBuilder builder = new StringBuilder(); builder.AppendFormat(@" SELECT 1 FROM RB_Menu_Function AS A WHERE 1=1 AND A.FunctionCode='{0}' AND A.Id IN(SELECT Action_Id FROM rb_role_functionpermission WHERE Role_Id IN (SELECT RoleId FROM rb_post_role WHERE PostId IN({1}))) ", actionCode.Trim(), postIds); var obj = base.ExecuteScalar(builder.ToString()); if (obj != null) { Int32.TryParse(obj.ToString(), out result); } return result > 0; } } }