using System.Threading.Tasks; using Abp.Application.Services.Dto; using Abp.Authorization; using Abp.Domain.Entities; using Abp.Domain.Repositories; using WePlatform.Authorization.Users; using WePlatform.CommonManager.AppGuids; using WePlatform.CommonManager.AttachFiles; using WePlatform.CommonManager.Notifications; using WePlatform.CommonManager.States; using WePlatform.Configuration; using IwbZero.AppServiceBase; using IwbZero.Authorization.Base.Permissions; using IwbZero.Authorization.Base.Users; namespace WePlatform { public abstract class IwbAsyncCrudAppService : IwbZeroAsyncCrudAppService where TEntity : class, IEntity where TEntityDto : IEntityDto where TUpdateInput : IEntityDto where TGetInput : IEntityDto where TDeleteInput : IEntityDto { protected IwbAsyncCrudAppService(IRepository repository, string keyFiledName = null) : base(repository, keyFiledName) { AppGuidManager = NullAppGuidManager.Instance; AttachFileManager = NullAttachFileManager.Instance; StatesManager = NullStatesManager.Instance; NoticeManager = NullNotificationManager.Instance; } /// /// 系统字典管理 /// public IStatesManager StatesManager { get; set; } /// /// 系统附件管理 /// public IAttachFileManager AttachFileManager { get; set; } /// /// 系统GUID管理 /// public IAppGuidManager AppGuidManager { get; set; } /// /// 用户信息管理 /// public UserManager UserManager { get; set; } public INotificationManager NoticeManager { get; set; } #region DataPermission protected virtual async Task CheckDataPermission(string permissionName, string key, int operType) { if (string.IsNullOrEmpty(permissionName)) { ThrowError("DataPermissionNameIsNull"); return; } var useId = AbpSession.UserId ?? 0; if (useId == 0) { ThrowError("UserSessionTimeout"); return; } if (AbpSession.UserName != UserBase.AdminUserName && AbpSession.UserName != UserBase.SystemUserName) { if (!await UserManager.IsGrantedAsync(useId, key, operType, permissionName)) { throw new AbpAuthorizationException(L(IwbLanguageMessage.NoPermissionOperation)); } } } protected virtual async Task CheckDataQueryPermission(string permissionName, string key) { await CheckDataPermission(permissionName, key, (int)OperType.Query); } protected virtual async Task CheckDataUpdatePermission(string permissionName, string key) { await CheckDataPermission(permissionName, key, (int)OperType.Update); } protected virtual async Task CheckDataDeletePermission(string permissionName, string key) { await CheckDataPermission(permissionName, key, (int)OperType.Delete); } #endregion } #region AppService public abstract class IwbAsyncCrudAppService : IwbAsyncCrudAppService where TEntity : class, IEntity where TEntityDto : IEntityDto { protected IwbAsyncCrudAppService(IRepository repository, string keyFiledName = null) : base(repository) { KeyFiledName = keyFiledName; } } public abstract class IwbAsyncCrudAppService : IwbAsyncCrudAppService where TEntity : class, IEntity where TEntityDto : IEntityDto { protected IwbAsyncCrudAppService(IRepository repository, string keyFiledName = null) : base(repository) { KeyFiledName = keyFiledName; } } public abstract class IwbAsyncCrudAppService : IwbAsyncCrudAppService where TEntity : class, IEntity where TEntityDto : IEntityDto where TGetAllInput : IIwbPagedRequest { protected IwbAsyncCrudAppService(IRepository repository, string keyFiledName = null) : base(repository) { KeyFiledName = keyFiledName; } } public abstract class IwbAsyncCrudAppService : IwbAsyncCrudAppService where TGetAllInput : IIwbPagedRequest where TEntity : class, IEntity where TEntityDto : IEntityDto where TCreateInput : IEntityDto { protected IwbAsyncCrudAppService(IRepository repository, string keyFiledName = null) : base(repository) { KeyFiledName = keyFiledName; } } public abstract class IwbAsyncCrudAppService : IwbAsyncCrudAppService> where TEntity : class, IEntity where TEntityDto : IEntityDto where TUpdateInput : IEntityDto where TGetAllInput : IIwbPagedRequest { protected IwbAsyncCrudAppService(IRepository repository, string keyFiledName = null) : base(repository) { KeyFiledName = keyFiledName; } } public abstract class IwbAsyncCrudAppService : IwbAsyncCrudAppService> where TEntity : class, IEntity where TEntityDto : IEntityDto where TUpdateInput : IEntityDto where TGetInput : IEntityDto where TGetAllInput : IIwbPagedRequest { protected IwbAsyncCrudAppService(IRepository repository, string keyFiledName = null) : base(repository) { KeyFiledName = keyFiledName; } } #endregion }