纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
4.4 KiB

3 years ago
  1. using NFine.Code;
  2. using NFine.Domain.Entity.SystemManage;
  3. using NFine.Domain.IRepository.SystemManage;
  4. using NFine.Domain.ViewModel;
  5. using NFine.Repository.SystemManage;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. namespace NFine.Application.SystemManage
  10. {
  11. public class RoleAuthorizeApp
  12. {
  13. private IRoleAuthorizeRepository service = new RoleAuthorizeRepository();
  14. private ModuleApp moduleApp = new ModuleApp();
  15. private ModuleButtonApp moduleButtonApp = new ModuleButtonApp();
  16. public List<RoleAuthorizeEntity> GetList(string ObjectId)
  17. {
  18. return service.IQueryable(t => t.F_ObjectId == ObjectId).ToList();
  19. }
  20. public List<ModuleEntity> GetMenuList(string roleId)
  21. {
  22. var data = new List<ModuleEntity>();
  23. if (OperatorProvider.Provider.GetCurrent().IsSystem)
  24. {
  25. data = moduleApp.GetList();
  26. }
  27. else
  28. {
  29. var moduledata = moduleApp.GetList();
  30. var authorizedata = service.IQueryable(t => t.F_ObjectId == roleId && t.F_ItemType == 1).ToList();
  31. foreach (var item in authorizedata)
  32. {
  33. ModuleEntity moduleEntity = moduledata.Find(t => t.F_Id == item.F_ItemId);
  34. if (moduleEntity != null)
  35. {
  36. data.Add(moduleEntity);
  37. }
  38. }
  39. }
  40. return data.OrderBy(t => t.F_SortCode).ToList();
  41. }
  42. public List<ModuleButtonEntity> GetButtonList(string roleId)
  43. {
  44. var data = new List<ModuleButtonEntity>();
  45. if (OperatorProvider.Provider.GetCurrent().IsSystem)
  46. {
  47. data = moduleButtonApp.GetList();
  48. }
  49. else
  50. {
  51. var buttondata = moduleButtonApp.GetList();
  52. var authorizedata = service.IQueryable(t => t.F_ObjectId == roleId && t.F_ItemType == 2).ToList();
  53. foreach (var item in authorizedata)
  54. {
  55. ModuleButtonEntity moduleButtonEntity = buttondata.Find(t => t.F_Id == item.F_ItemId);
  56. if (moduleButtonEntity != null)
  57. {
  58. data.Add(moduleButtonEntity);
  59. }
  60. }
  61. }
  62. return data.OrderBy(t => t.F_SortCode).ToList();
  63. }
  64. public bool ActionValidate(string roleId, string moduleId, string action)
  65. {
  66. var authorizeurldata = new List<AuthorizeActionModel>();
  67. var cachedata = CacheFactory.Cache().GetCache<List<AuthorizeActionModel>>("authorizeurldata_" + roleId);
  68. if (cachedata == null)
  69. {
  70. var moduledata = moduleApp.GetList();
  71. var buttondata = moduleButtonApp.GetList();
  72. var authorizedata = service.IQueryable(t => t.F_ObjectId == roleId).ToList();
  73. foreach (var item in authorizedata)
  74. {
  75. if (item.F_ItemType == 1)
  76. {
  77. ModuleEntity moduleEntity = moduledata.Find(t => t.F_Id == item.F_ItemId);
  78. authorizeurldata.Add(new AuthorizeActionModel { F_Id = moduleEntity.F_Id, F_UrlAddress = moduleEntity.F_UrlAddress });
  79. }
  80. else if (item.F_ItemType == 2)
  81. {
  82. ModuleButtonEntity moduleButtonEntity = buttondata.Find(t => t.F_Id == item.F_ItemId);
  83. authorizeurldata.Add(new AuthorizeActionModel { F_Id = moduleButtonEntity.F_ModuleId, F_UrlAddress = moduleButtonEntity.F_UrlAddress });
  84. }
  85. }
  86. CacheFactory.Cache().WriteCache(authorizeurldata, "authorizeurldata_" + roleId, DateTime.Now.AddMinutes(5));
  87. }
  88. else
  89. {
  90. authorizeurldata = cachedata;
  91. }
  92. authorizeurldata = authorizeurldata.FindAll(t => t.F_Id.Equals(moduleId));
  93. foreach (var item in authorizeurldata)
  94. {
  95. if (!string.IsNullOrEmpty(item.F_UrlAddress))
  96. {
  97. string[] url = item.F_UrlAddress.Split('?');
  98. if (item.F_Id == moduleId && url[0] == action)
  99. {
  100. return true;
  101. }
  102. }
  103. }
  104. return false;
  105. }
  106. }
  107. }