|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728 |
- 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
- {
- /// <summary>
- /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
- /// Copyright (c) 2013-2018 北京泉江科技有限公司
- /// 创建人:陈彬彬
- /// 日 期:2017.03.08
- /// 描 述:功能模块(缓存在0号库)
- /// 功能模块缓存结构
- /// </summary>
- 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 功能模块
- /// <summary>
- /// 功能列表
- /// </summary>
- /// <returns></returns>
- public List<ModuleEntity> GetModuleList()
- {
- try
- {
- List<ModuleEntity> list = cache.Read<List<ModuleEntity>>(cacheKey, CacheId.module);
- if (list == null)
- {
- list = (List<ModuleEntity>)moduleService.GetList();
- cache.Write<List<ModuleEntity>>(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<string> 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);
- }
- }
- }
- /// <summary>
- /// 功能列表
- /// </summary>
- /// <returns></returns>
- public ModuleEntity GetModuleByUrl(string url)
- {
- try
- {
- if (url.Contains("?"))
- {
- if (!url.Contains("/LR_FormModule/FormRelation/PreviewIndex"))
- {
- url = url.Substring(0, url.IndexOf('?'));
- }
- }
- List<ModuleEntity> list = GetModuleList();
- return list.Find(t => t.F_UrlAddress == url);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 获取功能列表的树形数据
- /// </summary>
- /// <returns></returns>
- public List<TreeModel> GetModuleTree()
- {
- List<ModuleEntity> modulelist = GetModuleList();
- List<TreeModel> treeList = new List<TreeModel>();
- 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();
- }
- /// <summary>
- /// 获取功能列表的树形数据(带勾选框)
- /// </summary>
- /// <returns></returns>
- public List<TreeModel> GetModuleCheckTree()
- {
- List<ModuleEntity> modulelist = GetModuleList();
- List<TreeModel> treeList = new List<TreeModel>();
- 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();
- }
- /// <summary>
- /// 获取功能列表的树形数据(只有展开项)
- /// </summary>
- /// <returns></returns>
- public List<TreeModel> GetExpendModuleTree()
- {
- List<ModuleEntity> modulelist = GetModuleList();
- List<TreeModel> treeList = new List<TreeModel>();
- 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();
- }
- /// <summary>
- /// 根据父级主键获取数据
- /// </summary>
- /// <param name="keyword">关键字</param>
- /// <param name="parentId">父级主键</param>
- /// <returns></returns>
- public List<ModuleEntity> GetModuleListByParentId(string keyword, string parentId)
- {
- try
- {
- List<ModuleEntity> list = (List<ModuleEntity>)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);
- }
- }
- }
- /// <summary>
- /// 功能实体
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <returns></returns>
- 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 模块按钮
- /// <summary>
- /// 获取按钮列表数据
- /// </summary>
- /// <param name="moduleId">模块Id</param>
- /// <returns></returns>
- public List<ModuleButtonEntity> GetButtonListNoAuthorize(string moduleId)
- {
- try
- {
- List<ModuleButtonEntity> list = cache.Read<List<ModuleButtonEntity>>(cacheKeyBtn + moduleId, CacheId.module);
- if (list == null)
- {
- list = (List<ModuleButtonEntity>)moduleService.GetButtonList(moduleId);
- cache.Write<List<ModuleButtonEntity>>(cacheKeyBtn + moduleId, list, CacheId.module);
- }
- return list;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 获取按钮列表数据
- /// </summary>
- /// <param name="moduleId">模块Id</param>
- /// <returns></returns>
- public List<ModuleButtonEntity> GetButtonList(string moduleId)
- {
- try
- {
- List<ModuleButtonEntity> list = cache.Read<List<ModuleButtonEntity>>(cacheKeyBtn + moduleId, CacheId.module);
- if (list == null)
- {
- list = (List<ModuleButtonEntity>)moduleService.GetButtonList(moduleId);
- cache.Write<List<ModuleButtonEntity>>(cacheKeyBtn + moduleId, list, CacheId.module);
- }
- UserInfo userInfo = LoginUserInfo.Get();
- /*关联权限*/
- if (!userInfo.isSystem)
- {
- string objectIds = userInfo.userId + (string.IsNullOrEmpty(userInfo.roleIds) ? "" : ("," + userInfo.roleIds));
- List<string> 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);
- }
- }
- }
- /// <summary>
- /// 获取按钮列表数据
- /// </summary>
- /// <param name="url">功能模块地址</param>
- /// <returns></returns>
- public List<ModuleButtonEntity> GetButtonListByUrl(string url)
- {
- try
- {
- ModuleEntity moduleEntity = GetModuleByUrl(url);
- if (moduleEntity == null)
- {
- return new List<ModuleButtonEntity>();
- }
- return GetButtonList(moduleEntity.F_ModuleId);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 获取按钮列表树形数据(基于功能模块)
- /// </summary>
- /// <returns></returns>
- public List<TreeModel> GetButtonCheckTree()
- {
- List<ModuleEntity> modulelist = GetModuleList();
- List<TreeModel> treeList = new List<TreeModel>();
- 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<ModuleButtonEntity> 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 模块视图
- /// <summary>
- /// 获取视图列表数据
- /// </summary>
- /// <param name="moduleId">模块Id</param>
- /// <returns></returns>
- public List<ModuleColumnEntity> GetColumnList(string moduleId)
- {
- try
- {
- List<ModuleColumnEntity> list = cache.Read<List<ModuleColumnEntity>>(cacheKeyColumn + moduleId, CacheId.module);
- if (list == null)
- {
- list = (List<ModuleColumnEntity>)moduleService.GetColumnList(moduleId);
- cache.Write<List<ModuleColumnEntity>>(cacheKeyColumn + moduleId, list, CacheId.module);
- }
- UserInfo userInfo = LoginUserInfo.Get();
- /*关联权限*/
- if (!userInfo.isSystem)
- {
- string objectIds = userInfo.userId + (string.IsNullOrEmpty(userInfo.roleIds) ? "" : ("," + userInfo.roleIds));
- List<string> 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);
- }
- }
- }
- /// <summary>
- /// 获取视图列表数据
- /// </summary>
- /// <param name="url">功能模块地址</param>
- /// <returns></returns>
- public List<ModuleColumnEntity> GetColumnListByUrl(string url)
- {
- try
- {
- ModuleEntity moduleEntity = GetModuleByUrl(url);
- if (moduleEntity == null)
- {
- return new List<ModuleColumnEntity>();
- }
- return GetColumnList(moduleEntity.F_ModuleId);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 获取按钮列表树形数据(基于功能模块)
- /// </summary>
- /// <returns></returns>
- public List<TreeModel> GetColumnCheckTree()
- {
- List<ModuleEntity> modulelist = GetModuleList();
- List<TreeModel> treeList = new List<TreeModel>();
- 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<ModuleColumnEntity> 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 模块表单
- /// <summary>
- /// 获取表单字段数据
- /// </summary>
- /// <param name="moduleId">模块Id</param>
- /// <returns></returns>
- public List<ModuleFormEntity> GetFormList(string moduleId)
- {
- try
- {
- List<ModuleFormEntity> list = cache.Read<List<ModuleFormEntity>>(cacheKeyForm + moduleId, CacheId.module);
- if (list == null)
- {
- list = (List<ModuleFormEntity>)moduleService.GetFormList(moduleId);
- cache.Write<List<ModuleFormEntity>>(cacheKeyForm + moduleId, list, CacheId.module);
- }
- UserInfo userInfo = LoginUserInfo.Get();
- /*关联权限*/
- if (!userInfo.isSystem)
- {
- string objectIds = userInfo.userId + (string.IsNullOrEmpty(userInfo.roleIds) ? "" : ("," + userInfo.roleIds));
- List<string> 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);
- }
- }
- }
- /// <summary>
- /// 获取表单字段数据
- /// </summary>
- /// <param name="url">功能模块地址</param>
- /// <returns></returns>
- public List<ModuleFormEntity> GetFormListByUrl(string url)
- {
- try
- {
- ModuleEntity moduleEntity = GetModuleByUrl(url);
- if (moduleEntity == null)
- {
- return new List<ModuleFormEntity>();
- }
- return GetFormList(moduleEntity.F_ModuleId);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 获取表单字段树形数据(基于功能模块)
- /// </summary>
- /// <returns></returns>
- public List<TreeModel> GetFormCheckTree()
- {
- List<ModuleEntity> modulelist = GetModuleList();
- List<TreeModel> treeList = new List<TreeModel>();
- 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<ModuleFormEntity> 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 提交数据
- /// <summary>
- /// 虚拟删除模块功能
- /// </summary>
- /// <param name="keyValue">主键值</param>
- public bool Delete(string keyValue)
- {
- try
- {
- List<ModuleEntity> 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);
- }
- }
- }
- /// <summary>
- /// 保存模块功能实体(新增、修改)
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <param name="moduleEntity">实体</param>
- /// <param name="moduleButtonEntitys">按钮列表</param>
- /// <param name="moduleColumnEntitys">视图列集合</param>
- /// <param name="moduleFormEntitys">表单字段集合</param>
- public void SaveEntity(string keyValue, ModuleEntity moduleEntity, List<ModuleButtonEntity> moduleButtonEntitys, List<ModuleColumnEntity> moduleColumnEntitys, List<ModuleFormEntity> 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 权限验证
- /// <summary>
- /// 验证当前访问的地址是否有权限
- /// </summary>
- /// <param name="url">访问地址</param>
- /// <returns></returns>
- public bool FilterAuthorize(string url)
- {
- try
- {
- List<ModuleEntity> list = GetModuleList();
- // 验证是否是功能页面
- var modulelist = list.FindAll(t => t.F_UrlAddress == url);
- if (modulelist.Count > 0)
- {
- return true;
- }
- // 是否是功能按钮的
- foreach (var item in list)
- {
- List<ModuleButtonEntity> 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
- }
- }
|