using LeaRun.Application.Code; using LeaRun.Application.Entity.AuthorizeManage; using LeaRun.Application.Entity.AuthorizeManage.ViewModel; using LeaRun.Application.IService.AuthorizeManage; using LeaRun.Application.Service.AuthorizeManage; using LeaRun.Cache.Factory; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LeaRun.Application.Busines.AuthorizeManage { /// /// 版 本 /// Copyright (c) 2013-2016 上海力软信息技术有限公司 /// 创建人:佘赐雄 /// 日 期:2015.12.5 22:35 /// 描 述:授权认证 /// public class AuthorizeBLL { private IAuthorizeService service = new AuthorizeService(); private ModuleBLL moduleBLL = new ModuleBLL(); private ModuleButtonBLL moduleButtonBLL = new ModuleButtonBLL(); private ModuleColumnBLL moduleColumnBLL = new ModuleColumnBLL(); /// /// 获取授权功能 /// /// 用户Id /// public IEnumerable GetModuleList(string userId) { if (OperatorProvider.Provider.Current().IsSystem) { return moduleBLL.GetList().FindAll(t => t.EnabledMark.Equals(1)); } else { return service.GetModuleList(userId); } } /// /// 获取授权功能 /// /// 用户Id /// public IEnumerable GetModuleListN(string userId) { if (OperatorProvider.Provider.Current().IsSystem) { return moduleBLL.GetList().FindAll(t => t.EnabledMark.Equals(1)); } else { return service.GetModuleListN(userId); } } /// /// 获取授权功能按钮 /// /// 用户Id /// public IEnumerable GetModuleButtonList(string userId) { if (OperatorProvider.Provider.Current().IsSystem) { return moduleButtonBLL.GetList(); } else { return service.GetModuleButtonList(userId); } } /// /// 获取授权功能视图 /// /// 用户Id /// public IEnumerable GetModuleColumnList(string userId) { if (OperatorProvider.Provider.Current().IsSystem) { return moduleColumnBLL.GetList(); } else { return service.GetModuleColumnList(userId); } } /// /// 获取授权功能Url、操作Url /// /// 用户Id /// public IEnumerable GetUrlList(string userId) { return service.GetUrlList(userId); } /// /// Action执行权限认证 /// /// 用户Id /// 模块Id /// 请求地址 /// public bool ActionAuthorize(string userId, string moduleId, string action) { List authorizeUrlList = new List(); var cacheList = CacheFactory.Cache().GetCache>("AuthorizeUrl_" + userId); if (cacheList == null) { authorizeUrlList = this.GetUrlList(userId).ToList(); CacheFactory.Cache().WriteCache(authorizeUrlList, "AuthorizeUrl_" + userId, DateTime.Now.AddMinutes(1)); } else { authorizeUrlList = cacheList; } authorizeUrlList = authorizeUrlList.FindAll(t => t.ModuleId.Equals(moduleId)); foreach (AuthorizeUrlModel item in authorizeUrlList) { if (!string.IsNullOrEmpty(item.UrlAddress)) { string[] url = item.UrlAddress.Split('?'); if (item.ModuleId == moduleId && url[0] == action) { return true; } } } return false; } /// /// 获得权限范围用户ID /// /// 当前登陆用户信息 /// 可写入 /// public string GetDataAuthorUserId(Operator operators, bool isWrite = false) { return service.GetDataAuthorUserId(operators, isWrite); } /// /// 获得可读数据权限范围SQL /// /// 当前登陆用户信息 /// 可写入 /// public string GetDataAuthor(Operator operators, bool isWrite = false) { return service.GetDataAuthor(operators, isWrite); } } }