using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using ClassNotify.Shared.Models; namespace ClassNotify.Server.Services; /// /// 批次升级创建结果 /// public sealed class DeviceUpdateBatchCreationResult { public int StatusCode { get; init; } public string? ErrorCode { get; init; } public string? ErrorMessage { get; init; } public UpdateBatchDto? Dto { get; init; } public static DeviceUpdateBatchCreationResult Accepted(UpdateBatchDto dto) => new() { StatusCode = 202, Dto = dto }; public static DeviceUpdateBatchCreationResult Conflict(string errorCode, string message) => new() { StatusCode = 409, ErrorCode = errorCode, ErrorMessage = message }; public static DeviceUpdateBatchCreationResult Forbidden(string message) => new() { StatusCode = 403, ErrorCode = UpdateErrorCodes.Forbidden, ErrorMessage = message }; public static DeviceUpdateBatchCreationResult BadRequest(string errorCode, string message) => new() { StatusCode = 400, ErrorCode = errorCode, ErrorMessage = message }; } /// /// 批次控制动作 (Continue / Stop) 结果 /// public sealed class DeviceUpdateBatchActionResult { public int StatusCode { get; init; } public string? ErrorCode { get; init; } public string? ErrorMessage { get; init; } public UpdateBatchDto? Dto { get; init; } public static DeviceUpdateBatchActionResult Ok(UpdateBatchDto dto) => new() { StatusCode = 200, Dto = dto }; public static DeviceUpdateBatchActionResult BadRequest(string errorCode, string message) => new() { StatusCode = 400, ErrorCode = errorCode, ErrorMessage = message }; public static DeviceUpdateBatchActionResult NotFound(string errorCode, string message) => new() { StatusCode = 404, ErrorCode = errorCode, ErrorMessage = message }; public static DeviceUpdateBatchActionResult Forbidden(string message) => new() { StatusCode = 403, ErrorCode = UpdateErrorCodes.Forbidden, ErrorMessage = message }; } /// /// 批次升级查询结果 /// public sealed class DeviceUpdateBatchQueryResult { public int StatusCode { get; init; } public string? ErrorCode { get; init; } public string? ErrorMessage { get; init; } public T? Data { get; init; } public static DeviceUpdateBatchQueryResult Ok(T data) => new() { StatusCode = 200, Data = data }; public static DeviceUpdateBatchQueryResult NotFound(string message) => new() { StatusCode = 404, ErrorCode = UpdateErrorCodes.BatchNotFound, ErrorMessage = message }; public static DeviceUpdateBatchQueryResult Forbidden(string message) => new() { StatusCode = 403, ErrorCode = UpdateErrorCodes.Forbidden, ErrorMessage = message }; } /// /// 小规模灰度升级管控服务接口 (P2.5 RC1-4 Phase 3) /// public interface IDeviceUpdateBatchService { /// /// SuperAdmin 创建小规模灰度升级批次 (1~5台设备,同校,单Canary) /// Task CreateBatchAsync( CreateUpdateBatchRequest request, string actorUser, string actorRole, string? actorTenantId, string clientIp, CancellationToken ct); /// /// SuperAdmin 查询灰度批次全量实时聚合视图 (严禁读取持久化汇总字段) /// Task> GetBatchAsync( string batchId, string actorRole, CancellationToken ct); /// /// SuperAdmin 人工放行灰度批次后续受控设备 (仅在 Canary 成功后生效) /// Task ContinueBatchAsync( string batchId, string actorUser, string actorRole, string clientIp, CancellationToken ct); /// /// SuperAdmin 人工紧急终止灰度批次 (Held 保持阻断,运行中安全终态化) /// Task StopBatchAsync( string batchId, string actorUser, string actorRole, string clientIp, CancellationToken ct); /// /// 获取可用于升级的 Release 清单 (供下拉框呈现) /// Task>> GetReleasesAsync( string actorRole, CancellationToken ct); }