v1
This commit is contained in:
21
OrpaonVision.Core/Abstractions/IClock.cs
Normal file
21
OrpaonVision.Core/Abstractions/IClock.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace OrpaonVision.Core.Abstractions;
|
||||
|
||||
/// <summary>
|
||||
/// 时间服务抽象。
|
||||
///
|
||||
/// 用途:
|
||||
/// - 消除业务代码对 DateTime.Now 的直接依赖;
|
||||
/// - 提升可测试性,便于通过替身时间源复现时序问题。
|
||||
/// </summary>
|
||||
public interface IClock
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取当前本地时间。
|
||||
/// </summary>
|
||||
DateTime Now { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前 UTC 时间。
|
||||
/// </summary>
|
||||
DateTime UtcNow { get; }
|
||||
}
|
||||
26
OrpaonVision.Core/Abstractions/IUserContext.cs
Normal file
26
OrpaonVision.Core/Abstractions/IUserContext.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
namespace OrpaonVision.Core.Abstractions;
|
||||
|
||||
/// <summary>
|
||||
/// 当前用户上下文抽象。
|
||||
///
|
||||
/// 用途:
|
||||
/// - 为审计字段(CreatedBy/UpdatedBy)提供统一来源;
|
||||
/// - 在应用服务中统一获取当前登录人信息。
|
||||
/// </summary>
|
||||
public interface IUserContext
|
||||
{
|
||||
/// <summary>
|
||||
/// 当前用户 ID。
|
||||
/// </summary>
|
||||
string UserId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前用户名或工号。
|
||||
/// </summary>
|
||||
string UserName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前用户角色集合。
|
||||
/// </summary>
|
||||
IReadOnlyCollection<string> Roles { get; }
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using OrpaonVision.Core.Enums;
|
||||
|
||||
namespace OrpaonVision.Core.Annotation.Contracts;
|
||||
|
||||
/// <summary>
|
||||
/// 标注同步状态 DTO。
|
||||
/// </summary>
|
||||
public sealed class AnnotationSyncStatusDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 本地项目标识。
|
||||
/// </summary>
|
||||
public Guid ProjectId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 本地标注任务标识。
|
||||
/// </summary>
|
||||
public Guid AnnotationTaskId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 平台类型(当前固定为 Cvat)。
|
||||
/// </summary>
|
||||
public AnnotationPlatformEnum Platform { get; init; } = AnnotationPlatformEnum.Cvat;
|
||||
|
||||
/// <summary>
|
||||
/// 同步状态。
|
||||
/// </summary>
|
||||
public AnnotationSyncStatusEnum SyncStatus { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 同步进度(0~100)。
|
||||
/// </summary>
|
||||
public decimal ProgressPercent { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 最近一次同步时间(UTC)。
|
||||
/// </summary>
|
||||
public DateTime? LastSyncedAtUtc { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 最近错误信息。
|
||||
/// </summary>
|
||||
public string? LastErrorMessage { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using OrpaonVision.Core.Enums;
|
||||
|
||||
namespace OrpaonVision.Core.Annotation.Contracts;
|
||||
|
||||
/// <summary>
|
||||
/// 同步标注项目命令。
|
||||
///
|
||||
/// 当前版本约束:仅支持 CVAT。
|
||||
/// </summary>
|
||||
public sealed class SyncAnnotationProjectCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// 平台类型(当前固定为 Cvat)。
|
||||
/// </summary>
|
||||
public AnnotationPlatformEnum Platform { get; init; } = AnnotationPlatformEnum.Cvat;
|
||||
|
||||
/// <summary>
|
||||
/// 本地项目标识。
|
||||
/// </summary>
|
||||
public Guid ProjectId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 本地标注任务标识。
|
||||
/// </summary>
|
||||
public Guid AnnotationTaskId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// CVAT 服务地址,例如 http://127.0.0.1:8080。
|
||||
/// </summary>
|
||||
public string CvatServerEndpoint { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// CVAT 项目 ID。
|
||||
/// </summary>
|
||||
public long CvatProjectId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// CVAT 任务 ID。
|
||||
/// </summary>
|
||||
public long CvatTaskId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 发起同步的用户。
|
||||
/// </summary>
|
||||
public string RequestedBy { get; init; } = string.Empty;
|
||||
}
|
||||
24
OrpaonVision.Core/Annotation/IAnnotationSyncAppService.cs
Normal file
24
OrpaonVision.Core/Annotation/IAnnotationSyncAppService.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using OrpaonVision.Core.Annotation.Contracts;
|
||||
using OrpaonVision.Core.Results;
|
||||
|
||||
namespace OrpaonVision.Core.Annotation;
|
||||
|
||||
/// <summary>
|
||||
/// 标注同步应用服务接口。
|
||||
///
|
||||
/// 职责:
|
||||
/// - 发起本地标注任务与 CVAT 任务的同步;
|
||||
/// - 查询任务同步状态,供配置端界面展示。
|
||||
/// </summary>
|
||||
public interface IAnnotationSyncAppService
|
||||
{
|
||||
/// <summary>
|
||||
/// 发起同步。
|
||||
/// </summary>
|
||||
Task<Result> SyncProjectAsync(SyncAnnotationProjectCommand command, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// 查询同步状态。
|
||||
/// </summary>
|
||||
Task<Result<AnnotationSyncStatusDto>> GetSyncStatusAsync(Guid projectId, CancellationToken cancellationToken = default);
|
||||
}
|
||||
12
OrpaonVision.Core/Class1.cs
Normal file
12
OrpaonVision.Core/Class1.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace OrpaonVision.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Core 模块标记类型。
|
||||
///
|
||||
/// 该类型用于:
|
||||
/// 1) 提供统一的程序集锚点(反射扫描、依赖注入装配);
|
||||
/// 2) 替代模板生成的占位类,避免语义不明确的 Class1 命名。
|
||||
/// </summary>
|
||||
public sealed class CoreModuleMarker
|
||||
{
|
||||
}
|
||||
16
OrpaonVision.Core/Enums/AnnotationPlatformEnum.cs
Normal file
16
OrpaonVision.Core/Enums/AnnotationPlatformEnum.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace OrpaonVision.Core.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// 标注平台类型。
|
||||
///
|
||||
/// 说明:
|
||||
/// - 根据当前需求文档,系统当前版本仅支持 CVAT;
|
||||
/// - 后续若扩展其他平台,可在本枚举中追加,并由适配层实现差异化处理。
|
||||
/// </summary>
|
||||
public enum AnnotationPlatformEnum
|
||||
{
|
||||
/// <summary>
|
||||
/// CVAT 平台。
|
||||
/// </summary>
|
||||
Cvat = 1
|
||||
}
|
||||
27
OrpaonVision.Core/Enums/AnnotationSyncStatusEnum.cs
Normal file
27
OrpaonVision.Core/Enums/AnnotationSyncStatusEnum.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
namespace OrpaonVision.Core.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// 标注任务同步状态。
|
||||
/// </summary>
|
||||
public enum AnnotationSyncStatusEnum
|
||||
{
|
||||
/// <summary>
|
||||
/// 未同步。
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 同步中。
|
||||
/// </summary>
|
||||
Syncing = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 同步成功。
|
||||
/// </summary>
|
||||
Succeeded = 2,
|
||||
|
||||
/// <summary>
|
||||
/// 同步失败。
|
||||
/// </summary>
|
||||
Failed = 3
|
||||
}
|
||||
32
OrpaonVision.Core/Enums/AnnotationTaskStatusEnum.cs
Normal file
32
OrpaonVision.Core/Enums/AnnotationTaskStatusEnum.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
namespace OrpaonVision.Core.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// 标注任务状态。
|
||||
/// </summary>
|
||||
public enum AnnotationTaskStatusEnum
|
||||
{
|
||||
/// <summary>
|
||||
/// 待开始。
|
||||
/// </summary>
|
||||
Pending = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 进行中。
|
||||
/// </summary>
|
||||
InProgress = 2,
|
||||
|
||||
/// <summary>
|
||||
/// 已完成(外部平台已提交)。
|
||||
/// </summary>
|
||||
Completed = 3,
|
||||
|
||||
/// <summary>
|
||||
/// 已回收(业务系统已成功回收标注结果)。
|
||||
/// </summary>
|
||||
Recovered = 4,
|
||||
|
||||
/// <summary>
|
||||
/// 失败。
|
||||
/// </summary>
|
||||
Failed = 5
|
||||
}
|
||||
9
OrpaonVision.Core/OrpaonVision.Core.csproj
Normal file
9
OrpaonVision.Core/OrpaonVision.Core.csproj
Normal file
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
102
OrpaonVision.Core/Results/Result.cs
Normal file
102
OrpaonVision.Core/Results/Result.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
namespace OrpaonVision.Core.Results;
|
||||
|
||||
/// <summary>
|
||||
/// 非泛型统一返回结果。
|
||||
///
|
||||
/// 约束:
|
||||
/// - 普通业务失败使用 Result 返回,不建议抛异常;
|
||||
/// - 异常场景请由上层捕获后转换为统一错误码与消息。
|
||||
/// </summary>
|
||||
public class Result
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否成功。
|
||||
/// </summary>
|
||||
public bool Succeeded { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 业务编码(成功或失败编码)。
|
||||
/// </summary>
|
||||
public string Code { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 业务消息。
|
||||
/// </summary>
|
||||
public string Message { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 错误明细。
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<string> Errors { get; init; } = Array.Empty<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 跟踪 ID,用于日志链路关联。
|
||||
/// </summary>
|
||||
public string? TraceId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建成功结果。
|
||||
/// </summary>
|
||||
public static Result Success(string code = "OK", string message = "Success")
|
||||
{
|
||||
return new Result
|
||||
{
|
||||
Succeeded = true,
|
||||
Code = code,
|
||||
Message = message
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建失败结果。
|
||||
/// </summary>
|
||||
public static Result Fail(string code, string message, params string[] errors)
|
||||
{
|
||||
return new Result
|
||||
{
|
||||
Succeeded = false,
|
||||
Code = code,
|
||||
Message = message,
|
||||
Errors = errors
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 泛型统一返回结果。
|
||||
/// </summary>
|
||||
public sealed class Result<T> : Result
|
||||
{
|
||||
/// <summary>
|
||||
/// 业务数据。
|
||||
/// </summary>
|
||||
public T? Data { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建成功结果。
|
||||
/// </summary>
|
||||
public static Result<T> Success(T data, string code = "OK", string message = "Success")
|
||||
{
|
||||
return new Result<T>
|
||||
{
|
||||
Succeeded = true,
|
||||
Code = code,
|
||||
Message = message,
|
||||
Data = data
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建失败结果。
|
||||
/// </summary>
|
||||
public static new Result<T> Fail(string code, string message, params string[] errors)
|
||||
{
|
||||
return new Result<T>
|
||||
{
|
||||
Succeeded = false,
|
||||
Code = code,
|
||||
Message = message,
|
||||
Errors = errors
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user