diff --git a/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Features/VoloFeatureAppService.cs b/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Features/VoloFeatureAppService.cs index 40e38228..a9cf40da 100644 --- a/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Features/VoloFeatureAppService.cs +++ b/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Features/VoloFeatureAppService.cs @@ -7,15 +7,103 @@ namespace Lion.AbpPro.BasicManagement.Features; public class VoloFeatureAppService : BasicManagementAppService, IVoloFeatureAppService { private readonly IFeatureAppService _featureAppService; + protected FeatureManagementOptions Options { get; } + protected IFeatureManager FeatureManager { get; } + protected IFeatureDefinitionManager FeatureDefinitionManager { get; } - public VoloFeatureAppService(IFeatureAppService featureAppService) + public VoloFeatureAppService(IFeatureManager featureManager, + IFeatureDefinitionManager featureDefinitionManager, + IOptions options, + IFeatureAppService featureAppService) { + FeatureManager = featureManager; + FeatureDefinitionManager = featureDefinitionManager; _featureAppService = featureAppService; + Options = options.Value; + } + + + private async Task GetAsync(string providerName, string providerKey) + { + var result = new GetFeatureListResultDto + { + Groups = new List() + }; + + foreach (var group in await FeatureDefinitionManager.GetGroupsAsync()) + { + var groupDto = CreateFeatureGroupDto(group); + + foreach (var featureDefinition in group.GetFeaturesWithChildren()) + { + if (providerName == TenantFeatureValueProvider.ProviderName && + CurrentTenant.Id == null && + providerKey == null && + !featureDefinition.IsAvailableToHost) + { + continue; + } + + var feature = await FeatureManager.GetOrNullWithProviderAsync(featureDefinition.Name, providerName, providerKey); + groupDto.Features.Add(CreateFeatureDto(feature, featureDefinition)); + } + + SetFeatureDepth(groupDto.Features, providerName, providerKey); + + if (groupDto.Features.Any()) + { + result.Groups.Add(groupDto); + } + } + + return result; + } + + private void SetFeatureDepth(List features, string providerName, string providerKey, FeatureDto parentFeature = null, int depth = 0) + { + foreach (var feature in features) + { + if ((parentFeature == null && feature.ParentName == null) || (parentFeature != null && parentFeature.Name == feature.ParentName)) + { + feature.Depth = depth; + SetFeatureDepth(features, providerName, providerKey, feature, depth + 1); + } + } + } + + private FeatureDto CreateFeatureDto(FeatureNameValueWithGrantedProvider featureNameValueWithGrantedProvider, FeatureDefinition featureDefinition) + { + return new FeatureDto + { + Name = featureDefinition.Name, + DisplayName = featureDefinition.DisplayName?.Localize(StringLocalizerFactory), + Description = featureDefinition.Description?.Localize(StringLocalizerFactory), + + ValueType = featureDefinition.ValueType, + + ParentName = featureDefinition.Parent?.Name, + Value = featureNameValueWithGrantedProvider.Value, + Provider = new FeatureProviderDto + { + Name = featureNameValueWithGrantedProvider.Provider?.Name, + Key = featureNameValueWithGrantedProvider.Provider?.Key + } + }; + } + + private FeatureGroupDto CreateFeatureGroupDto(FeatureGroupDefinition groupDefinition) + { + return new FeatureGroupDto + { + Name = groupDefinition.Name, + DisplayName = groupDefinition.DisplayName?.Localize(StringLocalizerFactory), + Features = new List() + }; } public virtual async Task GetAsync(GetFeatureListResultInput input) { - var result = await _featureAppService.GetAsync(input.ProviderName, input.ProviderKey); + var result = await GetAsync(input.ProviderName, input.ProviderKey); // 过滤自带的SettingManagement设置 result.Groups = result.Groups.Where(e => e.Name != "SettingManagement").ToList(); return result; @@ -23,11 +111,14 @@ public class VoloFeatureAppService : BasicManagementAppService, IVoloFeatureAppS public virtual async Task UpdateAsync(UpdateFeatureInput input) { - await _featureAppService.UpdateAsync(input.ProviderName, input.ProviderKey, input.UpdateFeaturesDto); + foreach (var feature in input.UpdateFeaturesDto.Features) + { + await FeatureManager.SetAsync(feature.Name, feature.Value, input.ProviderName, input.ProviderKey); + } } public virtual async Task DeleteAsync(DeleteFeatureInput input) { - await _featureAppService.DeleteAsync(input.ProviderName, input.ProviderKey); + await FeatureManager.DeleteAsync(input.ProviderName, input.ProviderKey); } } \ No newline at end of file