namespace Admin.NET.Plugin.AiDOP.Rule; /// /// 全模块规则配置只读服务骨架。P21 阶段不访问数据库,仅提供默认值解析入口。 /// public class RuleConfigService : ITransient { private const string DefaultSource = "default"; private const string ConfiguredSource = "configured"; private readonly IRuleConfigRepository _repository; public RuleConfigService(IRuleConfigRepository? repository = null) { _repository = repository ?? new EmptyRuleConfigRepository(); } public async Task> ResolveOptionsAsync( string moduleCode, string scenarioCode, long tenantId, long? factoryId, TOptions defaults, CancellationToken cancellationToken = default) where TOptions : class, new() { cancellationToken.ThrowIfCancellationRequested(); var layers = await _repository.GetEffectiveLayersAsync(moduleCode, scenarioCode, tenantId, factoryId, cancellationToken); return RuleConfigResolver.Resolve(defaults, layers); } public Task> ResolveS3DeliveryGenerateOptionsAsync( long tenantId, long? factoryId, CancellationToken cancellationToken = default) { return ResolveOptionsAsync( "S3", "DELIVERY_GENERATE", tenantId, factoryId, new S3DeliveryGenerateRuleOptions(), cancellationToken); } public async Task> ResolveS3DeliveryGenerateSnapshotAsync( long tenantId, long? factoryId, DateTime? resolvedAt = null, CancellationToken cancellationToken = default) { var result = await ResolveS3DeliveryGenerateOptionsAsync(tenantId, factoryId, cancellationToken); if (!result.Success) { throw Oops.Oh($"S3交货单生成规则配置无效:{string.Join(";", result.Errors)}"); } return CreateSnapshot("S3", "DELIVERY_GENERATE", tenantId, factoryId, result, resolvedAt ?? DateTime.Now); } public RuleConfigSnapshot CreateSnapshot( string moduleCode, string scenarioCode, long tenantId, long? factoryId, RuleConfigResolveResult result, DateTime resolvedAt) where TOptions : class, new() { return new RuleConfigSnapshot { ModuleCode = moduleCode, ScenarioCode = scenarioCode, Source = result.AppliedItems.Count == 0 ? DefaultSource : ConfiguredSource, ResolvedAt = resolvedAt, TenantId = tenantId, FactoryId = factoryId, Options = result.Options, AppliedItems = result.AppliedItems, Warnings = result.Warnings }; } }