IwbAsyncCrudAppService.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using System.Threading.Tasks;
  2. using Abp.Application.Services.Dto;
  3. using Abp.Authorization;
  4. using Abp.Domain.Entities;
  5. using Abp.Domain.Repositories;
  6. using WePlatform.Authorization.Users;
  7. using WePlatform.CommonManager.AppGuids;
  8. using WePlatform.CommonManager.AttachFiles;
  9. using WePlatform.CommonManager.Notifications;
  10. using WePlatform.CommonManager.States;
  11. using WePlatform.Configuration;
  12. using IwbZero.AppServiceBase;
  13. using IwbZero.Authorization.Base.Permissions;
  14. using IwbZero.Authorization.Base.Users;
  15. namespace WePlatform
  16. {
  17. public abstract class IwbAsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput, TDeleteInput>
  18. : IwbZeroAsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput, TDeleteInput>
  19. where TEntity : class, IEntity<TPrimaryKey>
  20. where TEntityDto : IEntityDto<TPrimaryKey>
  21. where TUpdateInput : IEntityDto<TPrimaryKey>
  22. where TGetInput : IEntityDto<TPrimaryKey>
  23. where TDeleteInput : IEntityDto<TPrimaryKey>
  24. {
  25. protected IwbAsyncCrudAppService(IRepository<TEntity, TPrimaryKey> repository, string keyFiledName = null) : base(repository, keyFiledName)
  26. {
  27. AppGuidManager = NullAppGuidManager.Instance;
  28. AttachFileManager = NullAttachFileManager.Instance;
  29. StatesManager = NullStatesManager.Instance;
  30. NoticeManager = NullNotificationManager.Instance;
  31. }
  32. /// <summary>
  33. /// 系统字典管理
  34. /// </summary>
  35. public IStatesManager StatesManager { get; set; }
  36. /// <summary>
  37. /// 系统附件管理
  38. /// </summary>
  39. public IAttachFileManager AttachFileManager { get; set; }
  40. /// <summary>
  41. /// 系统GUID管理
  42. /// </summary>
  43. public IAppGuidManager AppGuidManager { get; set; }
  44. /// <summary>
  45. /// 用户信息管理
  46. /// </summary>
  47. public UserManager UserManager { get; set; }
  48. public INotificationManager NoticeManager { get; set; }
  49. #region DataPermission
  50. protected virtual async Task CheckDataPermission(string permissionName, string key, int operType)
  51. {
  52. if (string.IsNullOrEmpty(permissionName))
  53. {
  54. ThrowError("DataPermissionNameIsNull");
  55. return;
  56. }
  57. var useId = AbpSession.UserId ?? 0;
  58. if (useId == 0)
  59. {
  60. ThrowError("UserSessionTimeout");
  61. return;
  62. }
  63. if (AbpSession.UserName != UserBase.AdminUserName && AbpSession.UserName != UserBase.SystemUserName)
  64. {
  65. if (!await UserManager.IsGrantedAsync(useId, key, operType, permissionName))
  66. {
  67. throw new AbpAuthorizationException(L(IwbLanguageMessage.NoPermissionOperation));
  68. }
  69. }
  70. }
  71. protected virtual async Task CheckDataQueryPermission(string permissionName, string key)
  72. {
  73. await CheckDataPermission(permissionName, key, (int)OperType.Query);
  74. }
  75. protected virtual async Task CheckDataUpdatePermission(string permissionName, string key)
  76. {
  77. await CheckDataPermission(permissionName, key, (int)OperType.Update);
  78. }
  79. protected virtual async Task CheckDataDeletePermission(string permissionName, string key)
  80. {
  81. await CheckDataPermission(permissionName, key, (int)OperType.Delete);
  82. }
  83. #endregion
  84. }
  85. #region AppService
  86. public abstract class IwbAsyncCrudAppService<TEntity, TEntityDto>
  87. : IwbAsyncCrudAppService<TEntity, TEntityDto, int>
  88. where TEntity : class, IEntity<int>
  89. where TEntityDto : IEntityDto<int>
  90. {
  91. protected IwbAsyncCrudAppService(IRepository<TEntity, int> repository, string keyFiledName = null)
  92. : base(repository)
  93. {
  94. KeyFiledName = keyFiledName;
  95. }
  96. }
  97. public abstract class IwbAsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey>
  98. : IwbAsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, IIwbPagedRequest>
  99. where TEntity : class, IEntity<TPrimaryKey>
  100. where TEntityDto : IEntityDto<TPrimaryKey>
  101. {
  102. protected IwbAsyncCrudAppService(IRepository<TEntity, TPrimaryKey> repository, string keyFiledName = null)
  103. : base(repository)
  104. {
  105. KeyFiledName = keyFiledName;
  106. }
  107. }
  108. public abstract class IwbAsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput>
  109. : IwbAsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TEntityDto, TEntityDto>
  110. where TEntity : class, IEntity<TPrimaryKey>
  111. where TEntityDto : IEntityDto<TPrimaryKey>
  112. where TGetAllInput : IIwbPagedRequest
  113. {
  114. protected IwbAsyncCrudAppService(IRepository<TEntity, TPrimaryKey> repository, string keyFiledName = null)
  115. : base(repository)
  116. {
  117. KeyFiledName = keyFiledName;
  118. }
  119. }
  120. public abstract class IwbAsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput>
  121. : IwbAsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TCreateInput>
  122. where TGetAllInput : IIwbPagedRequest
  123. where TEntity : class, IEntity<TPrimaryKey>
  124. where TEntityDto : IEntityDto<TPrimaryKey>
  125. where TCreateInput : IEntityDto<TPrimaryKey>
  126. {
  127. protected IwbAsyncCrudAppService(IRepository<TEntity, TPrimaryKey> repository, string keyFiledName = null)
  128. : base(repository)
  129. {
  130. KeyFiledName = keyFiledName;
  131. }
  132. }
  133. public abstract class IwbAsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput>
  134. : IwbAsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, EntityDto<TPrimaryKey>>
  135. where TEntity : class, IEntity<TPrimaryKey>
  136. where TEntityDto : IEntityDto<TPrimaryKey>
  137. where TUpdateInput : IEntityDto<TPrimaryKey>
  138. where TGetAllInput : IIwbPagedRequest
  139. {
  140. protected IwbAsyncCrudAppService(IRepository<TEntity, TPrimaryKey> repository, string keyFiledName = null)
  141. : base(repository)
  142. {
  143. KeyFiledName = keyFiledName;
  144. }
  145. }
  146. public abstract class IwbAsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput>
  147. : IwbAsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput, EntityDto<TPrimaryKey>>
  148. where TEntity : class, IEntity<TPrimaryKey>
  149. where TEntityDto : IEntityDto<TPrimaryKey>
  150. where TUpdateInput : IEntityDto<TPrimaryKey>
  151. where TGetInput : IEntityDto<TPrimaryKey>
  152. where TGetAllInput : IIwbPagedRequest
  153. {
  154. protected IwbAsyncCrudAppService(IRepository<TEntity, TPrimaryKey> repository, string keyFiledName = null)
  155. : base(repository)
  156. {
  157. KeyFiledName = keyFiledName;
  158. }
  159. }
  160. #endregion
  161. }