/// <summary> /// 生成单位授权过的菜单的下拉列表数据 /// </summary> /// <param name="deptId">单位ID</param> /// <param name="platform">平台类型</param> /// <param name="keyword">关键字</param> /// <param name="columnId">栏目ID</param> /// <returns></returns> public ActionResult GetMenuAuthCheckBoxData(string deptId, int?platform, string keyword, string columnId, int themeType) { AppMenuSettingBLL settingBLL = new AppMenuSettingBLL(); AppSettingAssociationBLL associationBLL = new AppSettingAssociationBLL(); //AppMenuSettingEntity settingEntity = settingBLL.GetEntity(columnId); //找到当前栏目 List <DeptMenuAuthEntity> deptMenuAuthEntities = deptMenuAuthBLL.GetList(deptId); //找到所有的授权的菜单 List <MenuConfigEntity> menuConfigEntities = MenuConfigBLL.GetListByModuleIds(deptMenuAuthEntities.Select(p => p.ModuleId).ToList(), platform).ToList(); //获取当前单位下的菜单 List <AppSettingAssociationEntity> associationEntities = associationBLL.GetList(deptId, deptMenuAuthEntities.Select(x => x.ModuleId).ToList()).OrderBy(x => x.Sort).ToList(); //再找出所有的关系(排除掉非授权的菜单) //剔除已经被其他栏目选择了的菜单,但不包括当前选中的栏目 var columnIds = settingBLL.GetList(deptId, themeType, platform.Value).Where(p => p.Id != columnId).Select(x => x.Id).ToList(); List <string> setedIds = associationEntities.Where(x => columnIds.Contains(x.ColumnId)).Select(p => p.ModuleId).ToList(); var columnMenu = menuConfigEntities.Where(x => !setedIds.Contains(x.ModuleId)).ToList(); //当前栏目可选的菜单,即没有被其他栏目选择过的菜单 List <AppSettingAssociationEntity> checkMenus = associationBLL.GetListByColumnId(columnId, deptMenuAuthEntities.Select(x => x.ModuleId).ToList()).ToList().OrderBy(x => x.Sort).ToList(); //获取当前栏目下授权了的菜单 //var data = MenuTreeHelper.BuildMenuTree(menuList, true); var firstLevelMenus = columnMenu.Where(x => x.ParentId == platform.ToString()); List <MenuTreeModel> data = new List <MenuTreeModel>(); foreach (var firstmenu in firstLevelMenus) { data.Add(new MenuTreeModel(firstmenu, platform.ToString(), true)); } foreach (var firstLevel in data) { MenuTreeHelper.FomateTree(firstLevel, columnMenu, checkMenus.Select(p => p.ModuleId).ToList(), true); } return(Json(data, JsonRequestBehavior.AllowGet)); }
public ActionResult AssociationFrom(string DepartId, int platform, string ColumnId) { AppSettingAssociationBLL associationBLL = new AppSettingAssociationBLL(); List <DeptMenuAuthEntity> deptMenuAuthEntities = deptMenuAuthBLL.GetList(DepartId); //找到所有的授权的菜单 List <AppSettingAssociationEntity> associationEntities = associationBLL.GetListByColumnId(ColumnId, deptMenuAuthEntities.Select(x => x.ModuleId).ToList()).ToList().OrderBy(x => x.Sort).ToList(); //获取当前栏目下授权了的菜单 return(View(associationEntities.Select(p => p.ModuleId).ToList())); }
/// <summary> /// 批量保存栏目与菜单的关系 /// </summary> /// <param name="postData"></param> /// <returns></returns> public ActionResult BatchSaveAssociationSetting(BatchAssociationRequestModel postData) { try { AppSettingAssociationBLL associationBLL = new AppSettingAssociationBLL(); MenuConfigBLL menuConfigBLL = new MenuConfigBLL(); List <MenuConfigEntity> menuConfigEntities = MenuConfigBLL.GetList(null, postData.PaltformType).ToList();//所有的菜单,获取排序用 //先找出该栏目数据库里已存在的关联关系 List <AppSettingAssociationEntity> associationEntities = associationBLL.GetListByColumnId(postData.ColumnId); List <string> associationModuleIds = associationEntities.Select(x => x.ModuleId).ToList(); if (postData.ModuleIds != null && postData.ModuleIds.Count > 0) { //找出要新增的Id List <string> addIds = postData.ModuleIds.Where(x => !associationModuleIds.Contains(x)).ToList(); //数据库里面没有的,则是要新增的 //找出要删除的Id List <string> delIds = associationModuleIds.Where(p => !postData.ModuleIds.Contains(p)).ToList(); //数据库有 ,但是前台传入的ID集合里没有的,则是要删除的 //构建新增的实体 List <AppSettingAssociationEntity> inserEntities = new List <AppSettingAssociationEntity>(); addIds.ForEach(moduleId => { var module = menuConfigEntities.FirstOrDefault(x => x.ModuleId == moduleId); inserEntities.Add(new AppSettingAssociationEntity() { Id = Guid.NewGuid().ToString(), ColumnId = postData.ColumnId, ColumnName = postData.ColumnName, DeptId = postData.DeptId, ModuleId = moduleId, Sort = module == null ? null : module.Sort }); }); associationBLL.InsertList(inserEntities); associationBLL.Remove(postData.DeptId, delIds); } else { associationBLL.Remove(postData.DeptId, associationModuleIds); } //判断该菜单是不是安卓终端的,是的话就更新版本 if (postData.PaltformType == 1) { MenuAuthorizeEntity menuAuthorize = authorizeBLL.GetEntityByDeptId(postData.DeptId); if (menuAuthorize != null) { authorizeBLL.SaveForm(menuAuthorize.Id, menuAuthorize);//此处单纯的改变一下版本号 } } return(Success("保存成功")); } catch (Exception ex) { return(Error("保存失败:" + ex.Message)); } }