/// <summary> /// 根据角色id获取角色权限绑定Ztree展示 /// </summary> /// <param name="roleId"></param> /// <returns></returns> public List <ServPurviewInfoCustom> GetPurviewInfoByRoleId(int roleId) { try { //查询角色权限绑定 List <ServRolePurviewModel> rolePurviewList = servRolePurviewDAL.GetRolePurviewByRoleId(roleId); //查询所有的园区 List <BaseRegionConfigModel> regionList = baseRegionConfigDAL.GetAllRegionConfig(); //查询所有的权限 ServPurviewInfoQuery query = new ServPurviewInfoQuery(); List <ServPurviewInfoModel> purviewList = servPurviewInfoDAL.GetEntities(query); //List<EnumModel> purviewList = EnumClass.GetEnumModelList<EnumClass.PurviewEnum>(); ServPurviewInfoCustom purviewCustom; List <ServPurviewInfoCustom> purviewCustomList = new List <ServPurviewInfoCustom>(); for (int j = 0; j < regionList.Count; j++) { purviewCustom = new ServPurviewInfoCustom(); purviewCustom.id = regionList[j].id; purviewCustom.pid = -1; purviewCustom.sid = regionList[j].id; purviewCustom.purview_code = 0; purviewCustom.purview_name = regionList[j].region_name; purviewCustomList.Add(purviewCustom); for (int i = 0; i < purviewList.Count; i++) { purviewCustom = new ServPurviewInfoCustom(); purviewCustom.id = purviewList[i].id; //如果权限的pid=-1则pid绑定为园区id if (purviewList[i].pid == -1) { purviewCustom.pid = regionList[j].id; } else { purviewCustom.pid = Convert.ToInt32(purviewList[i].pid + "" + regionList[j].id);; } purviewCustom.sid = Convert.ToInt32(purviewList[i].purview_code + "" + regionList[j].id); purviewCustom.purview_code = purviewList[i].purview_code; purviewCustom.purview_name = purviewList[i].purview_name; ServRolePurviewModel rolePurviewModel = rolePurviewList.FirstOrDefault(n => n.purview_id == purviewList[i].purview_code && n.region_id == regionList[j].id); if (rolePurviewModel != null) { purviewCustom.@checked = true; } else { purviewCustom.@checked = false; } purviewCustomList.Add(purviewCustom); } } return(purviewCustomList); } catch (Exception ex) { throw ex; } }
/// <summary> /// 根据角色id获取角色下的权限 /// </summary> /// <param name="roleId"></param> /// <returns></returns> public List <ServPurviewInfoCustom> GetPurviewInfoByRoleId(int roleId) { try { List <ServPurviewInfoCustom> purviewList = new List <ServPurviewInfoCustom>(); //根据角色id获取角色所包含的园区权限 List <ServRolePurviewModel> rolePurList = servPurviewInfoDAL.GetRoleRegionIdByRoleId(roleId); for (int i = 0; i < rolePurList.Count; i++) { ServRolePurviewQuery query = new ServRolePurviewQuery(); query.role_id = roleId; query.region_id = rolePurList[i].region_id; List <ServPurviewInfoModel> purviewList1 = servPurviewInfoDAL.GetPurviewInfoByRoleId(query); for (int j = 0; j < purviewList1.Count; j++) { ServPurviewInfoCustom purCus = new ServPurviewInfoCustom(); purCus.id = purviewList1[j].id; purCus.purview_code = purviewList1[j].purview_code; purCus.purview_name = purviewList1[j].purview_name; purCus.sid = Convert.ToInt32(purviewList1[j].purview_code + "" + rolePurList[i].region_id); if (purviewList1[j].pid == -1) { purCus.pid = rolePurList[i].region_id; } else { purCus.pid = Convert.ToInt32(purviewList1[j].pid + "" + rolePurList[i].region_id); } purCus.region_id = rolePurList[i].region_id; purviewList.Add(purCus); } //根据园区id获取园区信息 BaseRegionConfigModel regionModel = baseRegionConfigDAL.GetEntity(rolePurList[i].region_id); ServPurviewInfoCustom purCus1 = new ServPurviewInfoCustom(); if (regionModel != null) { purCus1.id = regionModel.id; purCus1.purview_name = regionModel.region_name; purCus1.purview_code = regionModel.id; purCus1.pid = -1; purCus1.sid = regionModel.id; } else { purCus1.purview_name = "超级管理员"; } purCus1.region_id = rolePurList[i].region_id; purviewList.Add(purCus1); } return(purviewList); } catch (Exception ex) { throw ex; } }