using IWareDataAccess.EF; using IWareDataAccess.Entity.Base; using IWareDataAccess.Entity.Summary; using IWareDataAccess.Entity.Sys; using IWareDataAccess.Helper; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IWareDataAccess.Sys.PERMISSION { public static class PermissionSqlFunc { /// /// 搜索全部(视图) /// /// /// /// public static List SearchView(PermissionWebEntity webEntity, out string msg) { msg = ""; using (Model edm = new Model()) { var f = PredicateBuilder.True(); //便利所有属性 Type type = webEntity.GetType(); foreach (var i in type.GetProperties()) { object v = Helper.Helper.GetFieldValueByName(webEntity, i.Name); if (i.PropertyType == typeof(String)) { string value; if (v != null) { value = v.ToString(); f = f.And(x => Helper.Helper.GetFieldValueByName(x, i.Name) != null ? Helper.Helper.GetFieldValueByName(x, i.Name).ToString().Contains(value) : false); } } else { if (v != null) { f = f.And(x => Object.Equals(Helper.Helper.GetFieldValueByName(x, i.Name), v)); } } } List list = edm.View_SYS_PERMISSION.Where(f.Compile()).ToList(); return list; } } /// /// 搜索全部(视图) /// /// /// /// public static int SearchViewNum(PermissionWebEntity webEntity) { using (Model edm = new Model()) { var f = PredicateBuilder.True(); //便利所有属性 Type type = webEntity.GetType(); foreach (var i in type.GetProperties()) { object v = Helper.Helper.GetFieldValueByName(webEntity, i.Name); if (i.PropertyType == typeof(String)) { string value; if (v != null) { value = v.ToString(); f = f.And(x => Helper.Helper.GetFieldValueByName(x, i.Name) != null ? Helper.Helper.GetFieldValueByName(x, i.Name).ToString().Contains(value) : false); } } else { if (v != null) { f = f.And(x => Object.Equals(Helper.Helper.GetFieldValueByName(x, i.Name), v)); } } } int num = edm.View_SYS_PERMISSION.Where(f.Compile()).Count(); return num; } } /// /// 搜索全部(表) /// /// /// /// public static List Search(PermissionWebEntity webEntity) { using (Model edm = new Model()) { var f = PredicateBuilder.True(); //便利所有属性 Type type = webEntity.GetType(); foreach (var i in type.GetProperties()) { object v = Helper.Helper.GetFieldValueByName(webEntity, i.Name); if (i.PropertyType == typeof(String)) { string value; if (v != null) { value = v.ToString(); f = f.And(x => Helper.Helper.GetFieldValueByName(x, i.Name) != null ? Helper.Helper.GetFieldValueByName(x, i.Name).ToString().Contains(value) : false); } } else { if (v != null) { f = f.And(x => Object.Equals(Helper.Helper.GetFieldValueByName(x, i.Name), v)); } } } List list = edm.SYS_PERMISSION.Where(f.Compile()).ToList(); return list; } } public static List urpvlst; /// /// 获取指定角色的菜单 /// /// /// /// public static List GetUserRoleAllPermission(string roleName, int type,out string msg) { try { msg = ""; using (Model edm = new Model()) { urpvlst = new List(); var rvplst = edm.SYS_ROLE_VS_PERMISSION.Where(x => x.SYS_ROLE.ROLENAME == roleName).ToList(); var prolst = edm.SYS_PERMISSION.Where(x => x.ENABLE == 1&&x.TYPE==type).ToList(); if (prolst != null && prolst.Count > 0) { foreach (var item in prolst.FindAll(c => c.FATHERPERMISSIONID == 0)) { UserRolePermissionViewEntity ure = new UserRolePermissionViewEntity(); ure.menu_Id = item.ID; ure.menuName = item.PERMISSION; ure.state = "open"; ure.parentId = (int)item.FATHERPERMISSIONID; urpvlst.Add(ure); FillMenu(ure, prolst, rvplst); } } else { msg = "查询异常"; return new List(); } return urpvlst; } } catch (Exception ex) { msg = "查询异常"; return new List(); } } private static void FillMenu(UserRolePermissionViewEntity node, List list, List rplst) { foreach (var i in list.FindAll(i => i.FATHERPERMISSIONID == node.menu_Id)) { UserRolePermissionViewEntity ure = new UserRolePermissionViewEntity(); ure.menu_Id = i.ID; ure.menuName = i.PERMISSION; ure.state = "open"; ure.parentId = (int)i.FATHERPERMISSIONID; int vl = 0; if (rplst != null && rplst.Count > 0) { var rp = rplst.FirstOrDefault(x => x.PERMISSIONID == i.ID); if (rp != null) { vl = 1; } else { vl = 0; } } else { vl = 0; } if (i.ISBUTTON == 1) { node.hasChild = "false"; if (node.auth == null) { node.auth = new List(); } node.auth.Add(new AuthEntity() { menu_Id=i.ID, label = i.PERMISSION, nodeName = i.BUTTONNAME, value = vl }); } else { var pd = list.FirstOrDefault(x => x.FATHERPERMISSIONID == i.ID); if (pd == null) { node.hasChild = "false"; if (node.auth == null) { node.auth = new List(); } node.auth.Add(new AuthEntity() { menu_Id = i.ID, label = i.PERMISSION, nodeName = i.BUTTONNAME, value = vl }); } else { if (node.children == null) { node.children = new List(); } node.children.Add(ure); if (node.children != null && node.children.Count > 0) { node.hasChild = "true"; } } } FillMenu(ure, list, rplst); } } public static List urmlst; public static List GetUserRolePermission(string roleName,int type, out string msg) { try { msg = ""; using (Model edm = new Model()) { List urplst = new List(); urmlst = new List(); var rvplst = edm.SYS_ROLE_VS_PERMISSION.Where(x => x.SYS_ROLE.ROLENAME==roleName).ToList(); var prolst = edm.SYS_PERMISSION.Where(x => x.ENABLE == 1&&x.TYPE==type).ToList(); if (prolst != null && prolst.Count > 0) { foreach (var item in prolst.FindAll(c => c.FATHERPERMISSIONID == 0)) { var rp = rvplst.FirstOrDefault(x => x.PERMISSIONID == item.ID); if (rp!=null) { UserRolePermissionViewEntity ure = new UserRolePermissionViewEntity(); ure.menu_Id = item.ID; ure.parentId = (int)item.FATHERPERMISSIONID; urplst.Add(ure); UserRoleMenuEntity urm = new UserRoleMenuEntity(); var titlels=item.PERMISSION.Split('-'); urm.path = item.PATH; if (!string.IsNullOrEmpty(item.PATH)) { var pn = item.PATH.Split('/'); urm.name = pn[pn.Length - 1]; } urm.meta = new Meta() { icon = item.ICON, title = titlels[titlels.Length - 1] }; urmlst.Add(urm); FillRoleMenu(ure,urm,prolst, rvplst); } } } else { msg = "查询异常"; return new List(); } return urmlst; } } catch (Exception ex) { msg = "查询异常"; return new List(); } } private static void FillRoleMenu(UserRolePermissionViewEntity node,UserRoleMenuEntity urm, List list, List rplst) { foreach (var i in list.FindAll(i => i.FATHERPERMISSIONID == node.menu_Id)) { int vl = 0; if (rplst != null && rplst.Count > 0) { var rp = rplst.FirstOrDefault(x => x.PERMISSIONID == i.ID); if (rp != null) { vl = 1; } else { vl = 0; } } else { vl = 0; } if (vl==1) { UserRolePermissionViewEntity ure = new UserRolePermissionViewEntity(); ure.menu_Id = i.ID; ure.parentId = (int)i.FATHERPERMISSIONID; UserRoleMenuEntity ur = new UserRoleMenuEntity(); var titlels = i.PERMISSION.Split('-'); ur.path = i.PATH; if (!string.IsNullOrEmpty(i.PATH) &&i.PATH.Contains('/')) { var pn = i.PATH.Split('/'); ur.name = pn[pn.Length - 1]; } else { ur.name = ""; } ur.meta = new Meta() { icon =i.ICON, title = titlels[titlels.Length-1] }; if (i.ISBUTTON != 1) { if (node.children == null) { node.children = new List(); } node.children.Add(ure); if (urm.children == null) { urm.children = new List(); } urm.children.Add(ur); } else //添加按钮级别的子功能 { } FillRoleMenu(ure, ur, list, rplst); } } } public static List GetPdaUserRolePermission(string roleName, out string msg) { try { msg = ""; using (Model edm = new Model()) { List meanlst = new List(); var pdalst = edm.SYS_PERMISSION.Where(x => x.TYPE == 2&&x.PERMISSIONLEVEL==2).ToList(); var rolevplst = edm.View_ROLE_VS_PERMISSION.Where(x => x.roleName == roleName); if (pdalst!=null) { pdalst.ForEach(x => { var ishave = rolevplst.FirstOrDefault(y => y.permission == x.PERMISSION); if (ishave!=null) { meanlst.Add(new PdaPermissionEntity() { title = x.PERMISSION, name = x.DEC,color=x.BUTTONNAME }); } }); } return meanlst; } } catch (Exception ex) { msg = "查询异常"; return new List(); } } } }