/// <summary> /// 查询用户权限 /// </summary> /// <param name="personId"></param> public void QueryPersonPurview(int personId, ActionExecutingContext e) { try { //根据人员id查询人员所有用的园区权限 List <ServRolePurviewModel> rolePruList = servPersonInfoBLL.GetRegionPurByPersonId(personId); if (rolePruList.Count == 0)//没有园区权限则直接跳转到没有权限页面 { Response.Redirect("/NotPurview.html"); e.Result = new EmptyResult(); } else { int regionId = 0; //园区id //根据人员id获取人员信息 ServPersonInfoModel personModel = servPersonInfoBLL.GetPersonInfoByPersonId(personId); //判断人员是否有默认主控园区 if (personModel.ext1 != "" && personModel.ext1 != null) {//没有设置主控园区则使用有权限的第一条数据 ServRolePurviewModel purModel = rolePruList.FirstOrDefault(n => n.region_id == Convert.ToInt32(personModel.ext1)); //判断用户设置的主控园区是否存在 if (purModel != null) { regionId = Convert.ToInt32(personModel.ext1); } } else { regionId = rolePruList[0].region_id; } //用园区id和人员角色id查询权限 List <ServPurviewInfoModel> purviewList = servPersonInfoBLL.GetPurviewInfoByRoleIdAndRegionId(personModel.role_id, regionId); if (regionId == 0)//超级管理员拥有所有的园区切换权限 { //获取当前配置的园区 ViewData["MasterRegion"] = baseRegionConfigBll.GetAllRegionConfig(); } else { //根据园区id集合获取园区 ViewData["MasterRegion"] = baseRegionConfigBll.GetRegionConfig(rolePruList); } //当前用户的权限 ViewData["personPurviewList"] = purviewList; ViewData["personPurviewListJson"] = json.Serialize(purviewList); //用户信息 ViewData["UserInfoModel"] = personModel; ViewData["UserInfoJson"] = json.Serialize(personModel); ReadingConfig(); //读取配置 SetRegionCookie(regionId); //设置主控园区cookie //读取视频平台配置 ReadVideoConfig(); //ViewData["AllRegion"] = json.Serialize(baseRegionConfigBll.GetAllRegionConfig()); } } catch (Exception ex) { throw ex; } }
/// <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> /// 添加超级管理员信息 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool AddSuperAdmin(ApiPersonInfoModel model) { try { bool result = false; string parStr = JsonHelper.ObjectToString <ApiPersonInfoModel>(model); string str = HttpHelper.PostWebRequestBandError("http://" + personIp + "/ApiPersonInfo/AddPersonInfoAndAccount", parStr, "application/json;charset=utf-8", Encoding.UTF8); int personId = JsonHelper.StringToObject <int>(str); if (personId == 0) { return(false); } //创建角色 ServRoleInfoModel roleModel = new ServRoleInfoModel(); roleModel.role_name = "超级管理员"; roleModel.role_code = "SCJGLY"; roleModel.role_describe = ""; roleModel.ext1 = "-1"; int roleId = servRoleInfoDAL.AddEntity(roleModel); if (roleId == 0) { return(false); } //创建角色权限关联(拥有所有权限) List <EnumModel> purviewList = EnumClass.GetEnumModelList <EnumClass.PurviewEnum>(); ServRolePurviewModel purviewModel; for (int i = 0; i < purviewList.Count; i++) { purviewModel = new ServRolePurviewModel(); purviewModel.purview_id = Convert.ToInt32(purviewList[i].key); purviewModel.role_id = roleId; purviewModel.region_id = 0; int purviewId = servRolePurviewDAL.AddEntity(purviewModel); if (purviewId == 0) { return(false); } } //创建用户 ServPersonInfoModel personModel = new ServPersonInfoModel(); personModel.status = 1; personModel.ssoid = personId; personModel.alias = "超级管理员"; personModel.role_id = roleId; int personinfoId = AddPersonInfo(personModel); if (personinfoId == 0) { return(false); } result = true; return(result); } catch (Exception ex) { throw ex; } }
/// <summary> /// 根据角色id和权限id获取角色权限绑定 /// </summary> /// <param name="query"></param> /// <returns></returns> public ServRolePurviewModel GetRolePurviewByRoleIdAndPurviewId(ServRolePurviewModel query) { try { return(mapContext.QueryForObject <ServRolePurviewModel>("GetRolePurviewByRoleIdAndPurviewId", query)); } catch (Exception ex) { throw ex; } }
public int AddEntity(ServRolePurviewModel entity) { try { return((int)mapContext.Insert("InsertRolePuriview", entity)); } catch (Exception ex) { throw ex; } }
/// <summary> /// 根据角色id和权限id删除角色权限绑定 /// </summary> /// <param name="query"></param> /// <returns></returns> public int DeleteRolePurviewByRoleIdAndPurviewId(ServRolePurviewModel query) { try { return(mapContext.Delete("DeleteRolePurviewByRoleIdAndPurviewId", query)); } catch (Exception ex) { throw ex; } }
/// <summary> /// 根据角色id和权限id删除或新增角色权限绑定 /// </summary> /// <param name="roleId"></param> /// <param name="purviewId"></param> /// <param name="checkFlag">true:新增。false:删除</param> /// <returns></returns> public bool RolePurviewBindByCheck(int roleId, int regionId, string purviewCode, bool checkFlag) { try { bool result = false; string[] codeArray = purviewCode.Split(','); for (int i = 0; i < codeArray.Length; i++) { ServRolePurviewModel model = new ServRolePurviewModel(); model.role_id = roleId; model.purview_id = Convert.ToInt32(codeArray[i]); model.region_id = regionId; //根据角色id和权限id查看数据库中是否已有绑定 ServRolePurviewModel rolePurview = servRolePurviewDAL.GetRolePurviewByRoleIdAndPurviewId(model); if (checkFlag)//被勾选上,添加 { //判断数据库中没有绑定才添加如有绑定则不添加 if (rolePurview == null) { int id = servRolePurviewDAL.AddEntity(model); } result = true; } else//取消勾选,删除 { //有绑定才删除 if (rolePurview != null) { int num = servRolePurviewDAL.DeleteRolePurviewByRoleIdAndPurviewId(model); } result = true; } } return(result); } catch (Exception ex) { throw ex; } }
public bool UpdateEntity(int id, ServRolePurviewModel newentity) { throw new NotImplementedException(); }