using Learun.Application.Base.AuthorizeModule; using Learun.Cache.Base; using Learun.Cache.Factory; using Learun.Util; using System; using System.Collections.Generic; using System.Linq; namespace Learun.Application.Base.SystemModule { /// /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园 /// Copyright (c) 2013-2018 北京泉江科技有限公司 /// 创建人:陈彬彬 /// 日 期:2017.03.08 /// 描 述:功能模块(缓存在0号库) /// 功能模块缓存结构 /// public class ModuleBLL : ModuleIBLL { #region 属性 private ModuleService moduleService = new ModuleService(); private AuthorizeIBLL authorizeIBLL = new AuthorizeBLL(); #endregion #region 缓存定义 private ICache cache = CacheFactory.CaChe(); private string cacheKey = "learun_adms_modules"; private string cacheKeyBtn = "learun_adms_modules_Btn_"; // + 模块主键 private string cacheKeyColumn = "learun_adms_modules_Column_";// + 模块主键 private string cacheKeyForm = "learun_adms_modules_Form_";// + 模块主键 #endregion #region 功能模块 /// /// 功能列表 /// /// public List GetModuleList() { try { List list = cache.Read>(cacheKey, CacheId.module); if (list == null) { list = (List)moduleService.GetList(); cache.Write>(cacheKey, list, CacheId.module); } //导航版 var entity = list.FirstOrDefault(a => a.F_ModuleId == "be81bdde-8bbc-4080-b976-84faefc414d2"); UserInfo userInfo = LoginUserInfo.Get(); /*关联权限*/ if (!userInfo.isSystem) { string objectIds = userInfo.userId + (string.IsNullOrEmpty(userInfo.roleIds) ? "" : ("," + userInfo.roleIds)); List itemIdList = authorizeIBLL.GetItemIdListByobjectIds(objectIds, 1); list = list.FindAll(t => itemIdList.IndexOf(t.F_ModuleId) >= 0); } if (!list.Any(a => a.F_ModuleId == "be81bdde-8bbc-4080-b976-84faefc414d2") && entity != null) { list.Add(entity); } return list; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 功能列表 /// /// public ModuleEntity GetModuleByUrl(string url) { try { if (url.Contains("?")) { if (!url.Contains("/LR_FormModule/FormRelation/PreviewIndex")) { url = url.Substring(0, url.IndexOf('?')); } } List list = GetModuleList(); return list.Find(t => t.F_UrlAddress == url); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取功能列表的树形数据 /// /// public List GetModuleTree() { List modulelist = GetModuleList(); List treeList = new List(); foreach (var item in modulelist) { TreeModel node = new TreeModel(); node.id = item.F_ModuleId; node.text = item.F_FullName; node.value = item.F_EnCode; node.showcheck = false; node.checkstate = 0; node.isexpand = (item.F_AllowExpand == 1); node.icon = item.F_Icon; node.parentId = item.F_ParentId; treeList.Add(node); } return treeList.ToTree(); } /// /// 获取功能列表的树形数据(带勾选框) /// /// public List GetModuleCheckTree() { List modulelist = GetModuleList(); List treeList = new List(); foreach (var item in modulelist) { TreeModel node = new TreeModel(); node.id = item.F_ModuleId; node.text = item.F_FullName; node.value = item.F_EnCode; node.showcheck = true; node.checkstate = 0; node.isexpand = false; node.icon = item.F_Icon; node.parentId = item.F_ParentId; treeList.Add(node); } return treeList.ToTree(); } /// /// 获取功能列表的树形数据(只有展开项) /// /// public List GetExpendModuleTree() { List modulelist = GetModuleList(); List treeList = new List(); foreach (var item in modulelist) { if (item.F_Target == "expand") { TreeModel node = new TreeModel(); node.id = item.F_ModuleId; node.text = item.F_FullName; node.value = item.F_EnCode; node.showcheck = false; node.checkstate = 0; node.isexpand = true; node.icon = item.F_Icon; node.parentId = item.F_ParentId; treeList.Add(node); } } return treeList.ToTree(); } /// /// 根据父级主键获取数据 /// /// 关键字 /// 父级主键 /// public List GetModuleListByParentId(string keyword, string parentId) { try { List list = (List)GetModuleList(); list = list.FindAll(t => t.F_ParentId == parentId); if (!string.IsNullOrEmpty(keyword)) { list = list.FindAll(t => t.F_FullName.Contains(keyword) || t.F_EnCode.Contains(keyword)); } return list; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 功能实体 /// /// 主键值 /// public ModuleEntity GetModuleEntity(string keyValue) { try { return moduleService.GetEntity(keyValue); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } #endregion #region 模块按钮 /// /// 获取按钮列表数据 /// /// 模块Id /// public List GetButtonListNoAuthorize(string moduleId) { try { List list = cache.Read>(cacheKeyBtn + moduleId, CacheId.module); if (list == null) { list = (List)moduleService.GetButtonList(moduleId); cache.Write>(cacheKeyBtn + moduleId, list, CacheId.module); } return list; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取按钮列表数据 /// /// 模块Id /// public List GetButtonList(string moduleId) { try { List list = cache.Read>(cacheKeyBtn + moduleId, CacheId.module); if (list == null) { list = (List)moduleService.GetButtonList(moduleId); cache.Write>(cacheKeyBtn + moduleId, list, CacheId.module); } UserInfo userInfo = LoginUserInfo.Get(); /*关联权限*/ if (!userInfo.isSystem) { string objectIds = userInfo.userId + (string.IsNullOrEmpty(userInfo.roleIds) ? "" : ("," + userInfo.roleIds)); List itemIdList = authorizeIBLL.GetItemIdListByobjectIds(objectIds, 2); list = list.FindAll(t => itemIdList.IndexOf(t.F_ModuleButtonId) >= 0); } return list; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取按钮列表数据 /// /// 功能模块地址 /// public List GetButtonListByUrl(string url) { try { ModuleEntity moduleEntity = GetModuleByUrl(url); if (moduleEntity == null) { return new List(); } return GetButtonList(moduleEntity.F_ModuleId); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取按钮列表树形数据(基于功能模块) /// /// public List GetButtonCheckTree() { List modulelist = GetModuleList(); List treeList = new List(); foreach (var module in modulelist) { TreeModel node = new TreeModel(); node.id = module.F_ModuleId + "_learun_moduleId"; node.text = module.F_FullName; node.value = module.F_EnCode; node.showcheck = true; node.checkstate = 0; node.isexpand = false; node.icon = module.F_Icon; node.parentId = module.F_ParentId + "_learun_moduleId"; if (module.F_Target != "expand") { List buttonList = GetButtonList(module.F_ModuleId); if (buttonList.Count > 0) { treeList.Add(node); } foreach (var button in buttonList) { TreeModel buttonNode = new TreeModel(); buttonNode.id = button.F_ModuleButtonId; buttonNode.text = button.F_FullName; buttonNode.value = button.F_EnCode; buttonNode.showcheck = true; buttonNode.checkstate = 0; buttonNode.isexpand = true; buttonNode.icon = "fa fa-wrench"; buttonNode.parentId = (button.F_ParentId == "0" ? button.F_ModuleId + "_learun_moduleId" : button.F_ParentId); treeList.Add(buttonNode); }; } else { treeList.Add(node); } } return treeList.ToTree(); } #endregion #region 模块视图 /// /// 获取视图列表数据 /// /// 模块Id /// public List GetColumnList(string moduleId) { try { List list = cache.Read>(cacheKeyColumn + moduleId, CacheId.module); if (list == null) { list = (List)moduleService.GetColumnList(moduleId); cache.Write>(cacheKeyColumn + moduleId, list, CacheId.module); } UserInfo userInfo = LoginUserInfo.Get(); /*关联权限*/ if (!userInfo.isSystem) { string objectIds = userInfo.userId + (string.IsNullOrEmpty(userInfo.roleIds) ? "" : ("," + userInfo.roleIds)); List itemIdList = authorizeIBLL.GetItemIdListByobjectIds(objectIds, 3); list = list.FindAll(t => itemIdList.IndexOf(t.F_ModuleColumnId) >= 0); } return list; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取视图列表数据 /// /// 功能模块地址 /// public List GetColumnListByUrl(string url) { try { ModuleEntity moduleEntity = GetModuleByUrl(url); if (moduleEntity == null) { return new List(); } return GetColumnList(moduleEntity.F_ModuleId); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取按钮列表树形数据(基于功能模块) /// /// public List GetColumnCheckTree() { List modulelist = GetModuleList(); List treeList = new List(); foreach (var module in modulelist) { TreeModel node = new TreeModel(); node.id = module.F_ModuleId + "_learun_moduleId"; node.text = module.F_FullName; node.value = module.F_EnCode; node.showcheck = true; node.checkstate = 0; node.isexpand = false; node.icon = module.F_Icon; node.parentId = module.F_ParentId + "_learun_moduleId"; if (module.F_Target != "expand") { List columnList = GetColumnList(module.F_ModuleId); if (columnList.Count > 0) { treeList.Add(node); } foreach (var column in columnList) { TreeModel columnNode = new TreeModel(); columnNode.id = column.F_ModuleColumnId; columnNode.text = column.F_FullName; columnNode.value = column.F_EnCode; columnNode.showcheck = true; columnNode.checkstate = 0; columnNode.isexpand = true; columnNode.icon = "fa fa-filter"; columnNode.parentId = column.F_ModuleId + "_learun_moduleId"; treeList.Add(columnNode); }; } else { treeList.Add(node); } } return treeList.ToTree(); } #endregion #region 模块表单 /// /// 获取表单字段数据 /// /// 模块Id /// public List GetFormList(string moduleId) { try { List list = cache.Read>(cacheKeyForm + moduleId, CacheId.module); if (list == null) { list = (List)moduleService.GetFormList(moduleId); cache.Write>(cacheKeyForm + moduleId, list, CacheId.module); } UserInfo userInfo = LoginUserInfo.Get(); /*关联权限*/ if (!userInfo.isSystem) { string objectIds = userInfo.userId + (string.IsNullOrEmpty(userInfo.roleIds) ? "" : ("," + userInfo.roleIds)); List itemIdList = authorizeIBLL.GetItemIdListByobjectIds(objectIds, 3); list = list.FindAll(t => itemIdList.IndexOf(t.F_ModuleFormId) >= 0); } return list; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取表单字段数据 /// /// 功能模块地址 /// public List GetFormListByUrl(string url) { try { ModuleEntity moduleEntity = GetModuleByUrl(url); if (moduleEntity == null) { return new List(); } return GetFormList(moduleEntity.F_ModuleId); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取表单字段树形数据(基于功能模块) /// /// public List GetFormCheckTree() { List modulelist = GetModuleList(); List treeList = new List(); foreach (var module in modulelist) { TreeModel node = new TreeModel(); node.id = module.F_ModuleId + "_learun_moduleId"; node.text = module.F_FullName; node.value = module.F_EnCode; node.showcheck = true; node.checkstate = 0; node.isexpand = true; node.icon = module.F_Icon; node.parentId = module.F_ParentId + "_learun_moduleId"; if (module.F_Target != "expand") { List columnList = GetFormList(module.F_ModuleId); if (columnList.Count > 0) { treeList.Add(node); } foreach (var column in columnList) { TreeModel columnNode = new TreeModel(); columnNode.id = column.F_ModuleFormId; columnNode.text = column.F_FullName; columnNode.value = column.F_EnCode; columnNode.showcheck = true; columnNode.checkstate = 0; columnNode.isexpand = true; columnNode.icon = "fa fa-filter"; columnNode.parentId = column.F_ModuleId + "_learun_moduleId"; treeList.Add(columnNode); }; } else { treeList.Add(node); } } return treeList.ToTree(); } #endregion #region 提交数据 /// /// 虚拟删除模块功能 /// /// 主键值 public bool Delete(string keyValue) { try { List list = GetModuleListByParentId("", keyValue); if (list.Count > 0) { return false; } moduleService.Delete(keyValue); cache.Remove(cacheKey, CacheId.module); cache.Remove(cacheKeyBtn + keyValue, CacheId.module); cache.Remove(cacheKeyColumn + keyValue, CacheId.module); cache.Remove(cacheKeyForm + keyValue, CacheId.module); return true; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 保存模块功能实体(新增、修改) /// /// 主键值 /// 实体 /// 按钮列表 /// 视图列集合 /// 表单字段集合 public void SaveEntity(string keyValue, ModuleEntity moduleEntity, List moduleButtonEntitys, List moduleColumnEntitys, List moduleFormEntitys) { try { moduleService.SaveEntity(keyValue, moduleEntity, moduleButtonEntitys, moduleColumnEntitys, moduleFormEntitys); /*移除缓存信息*/ cache.Remove(cacheKey, CacheId.module); if (!string.IsNullOrEmpty(keyValue)) { cache.Remove(cacheKeyBtn + keyValue, CacheId.module); cache.Remove(cacheKeyColumn + keyValue, CacheId.module); cache.Remove(cacheKeyForm + keyValue, CacheId.module); } } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } #endregion #region 权限验证 /// /// 验证当前访问的地址是否有权限 /// /// 访问地址 /// public bool FilterAuthorize(string url) { try { List list = GetModuleList(); // 验证是否是功能页面 var modulelist = list.FindAll(t => t.F_UrlAddress == url); if (modulelist.Count > 0) { return true; } // 是否是功能按钮的 foreach (var item in list) { List buttonList = GetButtonList(item.F_ModuleId); var buttonList2 = buttonList.FindAll(t => t.F_ActionAddress == url); if (buttonList2.Count > 0) { return true; } } return false; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } #endregion } }