xiangning 8f85a2d3c8 refactor(file): 移除bucket参数并使用默认桶解析器
- 移除AbortMultipartCommand中的BucketName参数
- 移除CompleteMultipartCommand中的BucketName参数
- 移除DeleteFileCommand中的BucketName参数
- 移除DownloadFileQuery中的BucketName参数
- 移除GetFileContentQuery中的BucketName参数
- 移除GetFilePreviewQuery中的BucketName参数
- 移除GetOfficePreviewQuery中的BucketName参数
- 移除InitMultipartCommand中的BucketName参数
- 在各处理器中注入IBucketResolver并获取默认桶
- 更新所有相关端点和请求模型移除bucket参数
- 修改测试代码适配参数变更
- 添加IM离线消息到平台通知中心的跨模块集成实现
2026-07-03 13:32:08 +08:00

150 lines
4.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Text.Json;
using System.Text.Json.Serialization;
using Workflow.Domain.Enums;
namespace Workflow.Domain.Engine;
/// <summary>
/// X6 graph 的强类型模型,与 X6 toJSON/fromJSON 原生格式兼容。
/// 替代裸 JsonDocument,供 ProcessEngine / 校验器 / 迁移脚本统一读写。
/// 顶层结构为 { nodes: [], edges: [] }(X6 fromJSON 支持的两种等价格式之一)。
/// </summary>
public sealed class WorkflowGraph
{
[JsonPropertyName("nodes")]
public List<GraphNode> Nodes { get; set; } = new();
[JsonPropertyName("edges")]
public List<GraphEdge> Edges { get; set; } = new();
/// <summary>空图工厂(容错用)。</summary>
public static WorkflowGraph Empty() => new();
}
/// <summary>
/// X6 节点。shape 决定渲染器并反推 NodeType(见 <see cref="WorkflowShapeMap"/>);
/// 业务配置统一进 data;x/y/width/height/ports 为几何与渲染信息。
/// </summary>
public sealed class GraphNode
{
[JsonPropertyName("id")]
public string Id { get; set; } = string.Empty;
[JsonPropertyName("shape")]
public string Shape { get; set; } = string.Empty;
[JsonPropertyName("x")]
public double X { get; set; }
[JsonPropertyName("y")]
public double Y { get; set; }
[JsonPropertyName("width")]
public double? Width { get; set; }
[JsonPropertyName("height")]
public double? Height { get; set; }
[JsonPropertyName("angle")]
public double? Angle { get; set; }
[JsonPropertyName("visible")]
public bool? Visible { get; set; }
/// <summary>业务数据(节点配置)。替代旧 WorkflowNode.Config 字符串字段。</summary>
[JsonPropertyName("data")]
public JsonElement? Data { get; set; }
/// <summary>显示名(对应旧 WorkflowNode.Name)。</summary>
public string? GetTitle() => Data.TryGetString("title");
[JsonPropertyName("ports")]
public JsonElement? Ports { get; set; }
}
/// <summary>
/// X6 边。source/target 用 { cell, port } 结构;几何信息(vertices/router/connector)放顶层;
/// 业务字段(edgeType/condition/order)放 data。
/// </summary>
public sealed class GraphEdge
{
[JsonPropertyName("id")]
public string Id { get; set; } = string.Empty;
[JsonPropertyName("shape")]
public string? Shape { get; set; }
[JsonPropertyName("source")]
public GraphEndpoint Source { get; set; } = new();
[JsonPropertyName("target")]
public GraphEndpoint Target { get; set; } = new();
/// <summary>业务数据:edgeType / condition / order。</summary>
[JsonPropertyName("data")]
public JsonElement? Data { get; set; }
[JsonPropertyName("label")]
public JsonElement? Label { get; set; }
[JsonPropertyName("vertices")]
public List<GraphPoint>? Vertices { get; set; }
[JsonPropertyName("router")]
public JsonElement? Router { get; set; }
[JsonPropertyName("connector")]
public JsonElement? Connector { get; set; }
/// <summary>边类型(Normal=0/Approved=1/Rejected=2)。缺省为 Normal。</summary>
public EdgeType GetEdgeType() => Data.TryGetInt32("edgeType") is { } v ? (EdgeType)v : EdgeType.Normal;
/// <summary>条件表达式(Condition/ExclusiveGateway 出边)。</summary>
public string? GetCondition() => Data.TryGetString("condition");
/// <summary>分支评估顺序(值小优先)。</summary>
public int GetOrder() => Data.TryGetInt32("order") ?? 0;
}
public sealed class GraphEndpoint
{
/// <summary>节点 id(对应 GraphNode.Id)。</summary>
[JsonPropertyName("cell")]
public string? Cell { get; set; }
/// <summary>端口 id(top/right/bottom/left)。</summary>
[JsonPropertyName("port")]
public string? Port { get; set; }
}
public sealed class GraphPoint
{
[JsonPropertyName("x")]
public double X { get; set; }
[JsonPropertyName("y")]
public double Y { get; set; }
}
/// <summary>
/// JsonElement? 安全取值扩展:统一处理 Nullable 解构与 ValueKind 校验,
/// 避免 WorkflowGraph 各 getter 重复 null 检查。
/// </summary>
internal static class GraphJsonExtensions
{
public static string? TryGetString(this JsonElement? element, string name) =>
element is { ValueKind: JsonValueKind.Object } el
&& el.TryGetProperty(name, out var p)
&& p.ValueKind == JsonValueKind.String
? p.GetString()
: null;
public static int? TryGetInt32(this JsonElement? element, string name) =>
element is { ValueKind: JsonValueKind.Object } el
&& el.TryGetProperty(name, out var p)
&& (p.ValueKind == JsonValueKind.Number || p.ValueKind == JsonValueKind.String)
&& p.TryGetInt32(out var n)
? n
: null;
}