基于json的工作流构建包,支持从json文件或json字符串构建工作流。
$ dotnet add package Easy.WorkFlow.JsonBuilderEasy.WorkFlow.JsonBuilder 是一个基于JSON的工作流构建包,为 Easy.WorkFlow.Core 提供从JSON文件或JSON字符串构建工作流定义的能力。本库支持 .NET 6、.NET 7、.NET 8、 .NET 9、.NET10。
dotnet add package Easy.WorkFlow.JsonBuilder在 Program.cs 或 Startup.cs 中注册 JsonBuilder 服务:
// 首先注册工作流核心服务
services.AddWorkFlow();
// 注册JSON构建器服务
services.AddJsonBuilder(options =>
{
// 配置JSON文件的基础路径(可选)
options.BasePath = Path.Combine(Directory.GetCurrentDirectory(), "WorkFlowDefinitions");
});// 创建工作流构建上下文
var context = new WorkFlowBuilderContext<string>
{
SourceType = "json",
Source = "workflow-definition.json" // 相对于BasePath的文件路径
};
// 使用工作流服务构建
await _workflowService.BuildAsync(context);// JSON工作流定义字符串
string jsonWorkflow = @"{
""id"": 1001,
""name"": ""请假工作流"",
""description"": ""请假审批"",
""version"": 1,
""steps"": [
{
""id"": 1,
""wfId"": 1001,
""number"": 0,
""name"": ""请假申请"",
// ...其他步骤属性
},
// ...更多步骤
],
""formName"": ""请假表单.json"",
""createdTime"": ""2023-06-18"",
""createdUserName"": ""Admin"",
""createdUserId"": 10001
}";
// 创建工作流构建上下文
var context = new WorkFlowBuilderContext<string>
{
SourceType = "json",
Data = jsonWorkflow
};
// 使用工作流服务构建
await _workflowService.BuildAsync(context);以下是一个完整的工作流JSON定义示例:
{
"id": 1001,
"name": "请假工作流",
"description": "请假审批",
"version": 1,
"steps": [
{
"id": 1,
"wfId": 1001,
"number": 0,
"name": "请假申请",
"description": "请假申请",
"when": null,
"processor": "api/text",
"processorType": 3,
"processorContext": "{\"method\":\"post\",\"content\":\"userid=[user.userid]&username=[user.username]\"}",
"actors": null,
"actorNames": null,
"actorsExpression": null,
"actorType": 1,
"actionBtns": [
{
"name": "提交",
"type": 1,
"callback": null
}
],
"next": [
2
]
},
{
"id": 2,
"wfId": 1001,
"number": 1,
"name": "审批",
"description": "请假审批",
"when": null,
"processor": "INSERT INTO WF_Text (Name,date) VALUES (@name,@date)",
"processorType": 1,
"processorContext": "name=[user.username]&date=[date]",
"actors": null,
"actorNames": null,
"actorsExpression": "[user]",
"actorType": 2,
"actionBtns": [
{
"name": "同意",
"type": 1,
"callback": null
},
{
"name": "拒绝",
"type": 2,
"callback": null
}
],
"next": null
}
],
"formName": "请假表单.json",
"createdTime": "2023-06-18",
"createdUserName": "Admin",
"createdUserId": 10001
}| 字段 | 类型 | 描述 |
|---|---|---|
| id | long | 工作流唯一标识符 |
| name | string | 工作流名称 |
| description | string | 工作流描述 |
| version | int | 工作流版本号 |
| steps | array | 工作流步骤集合 |
| formName | string | 关联的表单名称 |
| createdTime | string | 创建时间 |
| createdUserName | string | 创建人名称 |
| createdUserId | long | 创建人ID |
| 字段 | 类型 | 描述 |
|---|---|---|
| id | long | 步骤唯一标识符 |
| wfId | long | 所属工作流ID |
| number | int | 步骤级别编号 |
| name | string | 步骤名称 |
| description | string | 步骤描述 |
| when | string | 执行条件表达式 |
| processor | string | 处理器内容(SQL语句、远程URL或方法名) |
| processorType | int | 处理器类型(1=SQL, 2=Action, 3=URL) |
| processorContext | string | 处理器上下文数据 |
| actors | array | 固定处理人ID列表 |
| actorNames | array | 固定处理人名称列表 |
| actorsExpression | string | 动态处理人表达式 |
| actorType | int | 处理人类型(1=用户, 2=表达式) |
| actionBtns | array | 步骤操作按钮 |
| next | array | 下一步骤ID列表 |
Easy.WorkFlow.JsonBuilder 可以与 Easy.WorkFlow 生态系统中的其他包一起使用:
BasePath 的相对路径Easy.WorkFlow.JsonBuilder 使用 MIT 许可证。