AuthorizeBLL.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using LeaRun.Application.Code;
  2. using LeaRun.Application.Entity.AuthorizeManage;
  3. using LeaRun.Application.Entity.AuthorizeManage.ViewModel;
  4. using LeaRun.Application.IService.AuthorizeManage;
  5. using LeaRun.Application.Service.AuthorizeManage;
  6. using LeaRun.Cache.Factory;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace LeaRun.Application.Busines.AuthorizeManage
  13. {
  14. /// <summary>
  15. /// 版 本
  16. /// Copyright (c) 2013-2016 上海力软信息技术有限公司
  17. /// 创建人:佘赐雄
  18. /// 日 期:2015.12.5 22:35
  19. /// 描 述:授权认证
  20. /// </summary>
  21. public class AuthorizeBLL
  22. {
  23. private IAuthorizeService service = new AuthorizeService();
  24. private ModuleBLL moduleBLL = new ModuleBLL();
  25. private ModuleButtonBLL moduleButtonBLL = new ModuleButtonBLL();
  26. private ModuleColumnBLL moduleColumnBLL = new ModuleColumnBLL();
  27. /// <summary>
  28. /// 获取授权功能
  29. /// </summary>
  30. /// <param name="userId">用户Id</param>
  31. /// <returns></returns>
  32. public IEnumerable<ModuleEntity> GetModuleList(string userId)
  33. {
  34. if (OperatorProvider.Provider.Current().IsSystem)
  35. {
  36. return moduleBLL.GetList().FindAll(t => t.EnabledMark.Equals(1));
  37. }
  38. else
  39. {
  40. return service.GetModuleList(userId);
  41. }
  42. }
  43. /// <summary>
  44. /// 获取授权功能
  45. /// </summary>
  46. /// <param name="userId">用户Id</param>
  47. /// <returns></returns>
  48. public IEnumerable<ModuleEntity> GetModuleListN(string userId)
  49. {
  50. if (OperatorProvider.Provider.Current().IsSystem)
  51. {
  52. return moduleBLL.GetList().FindAll(t => t.EnabledMark.Equals(1));
  53. }
  54. else
  55. {
  56. return service.GetModuleListN(userId);
  57. }
  58. }
  59. /// <summary>
  60. /// 获取授权功能按钮
  61. /// </summary>
  62. /// <param name="userId">用户Id</param>
  63. /// <returns></returns>
  64. public IEnumerable<ModuleButtonEntity> GetModuleButtonList(string userId)
  65. {
  66. if (OperatorProvider.Provider.Current().IsSystem)
  67. {
  68. return moduleButtonBLL.GetList();
  69. }
  70. else
  71. {
  72. return service.GetModuleButtonList(userId);
  73. }
  74. }
  75. /// <summary>
  76. /// 获取授权功能视图
  77. /// </summary>
  78. /// <param name="userId">用户Id</param>
  79. /// <returns></returns>
  80. public IEnumerable<ModuleColumnEntity> GetModuleColumnList(string userId)
  81. {
  82. if (OperatorProvider.Provider.Current().IsSystem)
  83. {
  84. return moduleColumnBLL.GetList();
  85. }
  86. else
  87. {
  88. return service.GetModuleColumnList(userId);
  89. }
  90. }
  91. /// <summary>
  92. /// 获取授权功能Url、操作Url
  93. /// </summary>
  94. /// <param name="userId">用户Id</param>
  95. /// <returns></returns>
  96. public IEnumerable<AuthorizeUrlModel> GetUrlList(string userId)
  97. {
  98. return service.GetUrlList(userId);
  99. }
  100. /// <summary>
  101. /// Action执行权限认证
  102. /// </summary>
  103. /// <param name="userId">用户Id</param>
  104. /// <param name="moduleId">模块Id</param>
  105. /// <param name="action">请求地址</param>
  106. /// <returns></returns>
  107. public bool ActionAuthorize(string userId, string moduleId, string action)
  108. {
  109. List<AuthorizeUrlModel> authorizeUrlList = new List<AuthorizeUrlModel>();
  110. var cacheList = CacheFactory.Cache().GetCache<List<AuthorizeUrlModel>>("AuthorizeUrl_" + userId);
  111. if (cacheList == null)
  112. {
  113. authorizeUrlList = this.GetUrlList(userId).ToList();
  114. CacheFactory.Cache().WriteCache(authorizeUrlList, "AuthorizeUrl_" + userId, DateTime.Now.AddMinutes(1));
  115. }
  116. else
  117. {
  118. authorizeUrlList = cacheList;
  119. }
  120. authorizeUrlList = authorizeUrlList.FindAll(t => t.ModuleId.Equals(moduleId));
  121. foreach (AuthorizeUrlModel item in authorizeUrlList)
  122. {
  123. if (!string.IsNullOrEmpty(item.UrlAddress))
  124. {
  125. string[] url = item.UrlAddress.Split('?');
  126. if (item.ModuleId == moduleId && url[0] == action)
  127. {
  128. return true;
  129. }
  130. }
  131. }
  132. return false;
  133. }
  134. /// <summary>
  135. /// 获得权限范围用户ID
  136. /// </summary>
  137. /// <param name="operators">当前登陆用户信息</param>
  138. /// <param name="isWrite">可写入</param>
  139. /// <returns></returns>
  140. public string GetDataAuthorUserId(Operator operators, bool isWrite = false)
  141. {
  142. return service.GetDataAuthorUserId(operators, isWrite);
  143. }
  144. /// <summary>
  145. /// 获得可读数据权限范围SQL
  146. /// </summary>
  147. /// <param name="operators">当前登陆用户信息</param>
  148. /// <param name="isWrite">可写入</param>
  149. /// <returns></returns>
  150. public string GetDataAuthor(Operator operators, bool isWrite = false)
  151. {
  152. return service.GetDataAuthor(operators, isWrite);
  153. }
  154. }
  155. }