手动阀

This commit is contained in:
2026-04-06 22:08:38 +08:00
parent 0b150470be
commit 71e099ca8e
9 changed files with 920 additions and 6 deletions

View File

@@ -42,19 +42,23 @@ public class ModelPackageAppService : IModelPackageAppService
private readonly ILogger<ModelPackageAppService> _logger;
private readonly ModelPackageOptions _options;
private readonly string _basePath;
private readonly IRuleValidationService _ruleValidationService;
/// <summary>
/// 初始化模型包应用服务。
/// </summary>
/// <param name="logger">日志记录器。</param>
/// <param name="options">模型包配置选项。</param>
/// <param name="options">配置选项。</param>
/// <param name="ruleValidationService">规则校验服务。</param>
public ModelPackageAppService(
ILogger<ModelPackageAppService> logger,
IOptions<ModelPackageOptions> options)
IOptions<ModelPackageOptions> options,
IRuleValidationService ruleValidationService)
{
_logger = logger;
_options = options.Value;
_basePath = _options.BasePath ?? "ModelPackages";
_ruleValidationService = ruleValidationService;
// 确保基础目录存在
if (!Directory.Exists(_basePath))
@@ -272,6 +276,31 @@ public class ModelPackageAppService : IModelPackageAppService
return Result<ModelPackageImportResultDto>.Fail(validationResult.Code, validationResult.Message);
}
// 校验规则快照包(如果存在)
var ruleSnapshotPath = Path.Combine(extractDir, "rules", "snapshot.ovpkg");
if (File.Exists(ruleSnapshotPath))
{
_logger.LogInformation("发现规则快照包,开始校验: {RuleSnapshotPath}", ruleSnapshotPath);
var ruleValidationResult = await _ruleValidationService.ValidateRuleSnapshotPackageAsync(ruleSnapshotPath, cancellationToken);
if (!ruleValidationResult.Succeeded)
{
// 清理失败的导入
if (Directory.Exists(extractDir))
{
Directory.Delete(extractDir, true);
}
return Result<ModelPackageImportResultDto>.Fail(ruleValidationResult.Code, $"规则快照包校验失败: {ruleValidationResult.Message}");
}
if (!ruleValidationResult.Data!.IsValid)
{
var errors = string.Join("; ", ruleValidationResult.Data.Errors);
_logger.LogWarning("规则快照包校验发现问题: {Errors}", errors);
// 可以选择是否将规则校验失败视为导入失败,这里仅记录警告
}
}
var importResult = new ModelPackageImportResultDto
{
ModelPackageId = packageId,