# VWED任务记录接口文档 本文档描述了VWED系统任务运行记录相关的API接口,主要用于查询任务执行过程中的块运行情况和详情。 ## 基础信息 - 基础路径:`/api/vwed-task-record` - 接口标签:`VWED任务运行记录` ## 接口清单 | 序号 | 接口名称 | 接口路径 | 请求方式 | 接口描述 | | --- | --- | --- | --- | --- | | 1 | 获取任务块运行记录 | `/blocks/{task_record_id}` | GET | 获取指定任务记录下的所有块运行情况 | | 2 | 获取块记录详情 | `/block/{block_record_id}` | GET | 获取指定块记录的详细信息 | | 3 | 终止任务 | `/stop/{task_record_id}` | POST | 停止指定任务记录下的所有运行任务实例 | | 4 | 获取任务执行结果 | `/execution/block/results/{task_record_id}` | GET | 获取指定任务记录的执行结果 | | 5 | 获取任务记录详情 | `/detail/{task_record_id}` | GET | 获取指定任务记录的详细信息 | | 6 | 重发失败任务 | `/retry/{task_record_id}` | POST | 重新执行失败状态的任务记录 | | 15 | 设置任务错误状态 | `/set-error/{task_record_id}` | POST | 将指定任务记录及其相关任务块状态设置为错误状态 | ## 接口详情 ### 1. 获取任务块运行记录 #### 接口说明 获取指定任务记录下的所有块运行情况,包括每个块的运行状态、执行时间、输入输出参数等信息。 #### 请求路径 ``` GET /api/vwed-task-record/blocks/{task_record_id} ``` #### 路径参数 | 参数名 | 类型 | 是否必须 | 描述 | | --- | --- | --- | --- | | task_record_id | string | 是 | 任务记录ID,由run_task接口返回的taskRecordId | #### 响应结果 成功响应: ```json { "code": 200, "message": "成功获取任务记录 {task_record_id} 的块运行情况", "data": [ { "id": "块记录ID", "block_name": "块名称", "block_id": "块ID", "status": 块执行状态码, "started_on": "开始时间", "ended_on": "结束时间", "ended_reason": "结束原因", "block_execute_name": "块执行名称", "block_input_params_value": { "参数名": "参数值" }, "block_out_params_value": { "参数名": "参数值" }, "remark": "备注" } ] } ``` 失败响应: ```json { "code": 500, "message": "获取任务块运行情况失败: {错误信息}" } ``` #### 响应字段说明 | 字段名 | 类型 | 描述 | | --- | --- | --- | | id | string | 块记录ID | | block_name | string | 块名称 | | block_id | string | 块ID | | status | integer | 块执行状态,1000:执行成功,1001:执行中,1002:未执行,2000:执行失败,2002:取消 | | started_on | string | 开始时间,ISO 8601格式 | | ended_on | string | 结束时间,ISO 8601格式 | | ended_reason | string | 结束原因 | | block_execute_name | string | 块执行名称 | | block_input_params_value | object | 块输入参数值 | | block_out_params_value | object | 块输出参数值 | | remark | string | 备注 | #### 示例 请求示例: ``` GET /api/vwed-task-record/blocks/7b84fd4d-e947-4ec7-8535-05ede5f8aa9d ``` 响应示例: ```json { "code": 200, "message": "成功获取任务记录 7b84fd4d-e947-4ec7-8535-05ede5f8aa9d 的块运行情况", "data": [ { "id": "b5410c81-99b3-4d61-bb79-e54292d012d4", "block_name": "-1", "block_id": "-1", "status": 1000, "started_on": "2025-04-30T17:28:19.105648", "ended_on": "2025-04-30T17:28:19.601597", "ended_reason": "执行成功", "block_execute_name": "RootBp", "block_input_params_value": {}, "block_out_params_value": null, "remark": "执行成功" }, { "id": "ee29eccd-11e8-490b-ac24-81f243771dda", "block_name": "b1", "block_id": "1", "status": 1000, "started_on": "2025-04-30T17:28:19.149185", "ended_on": "2025-04-30T17:28:19.576944", "ended_reason": "执行成功", "block_execute_name": "IterateListBp", "block_input_params_value": { "list": "[1,2,3,4,5]" }, "block_out_params_value": { "index": 4, "item": 5 }, "remark": "执行成功" }, { "id": "c944c7df-329c-468e-90ed-9e064ddccdbc", "block_name": "b2", "block_id": "2", "status": 1000, "started_on": "2025-04-30T17:28:19.457166", "ended_on": "2025-04-30T17:28:19.488009", "ended_reason": "执行成功", "block_execute_name": "PrintBp", "block_input_params_value": { "message": "blocks.b1.item" }, "block_out_params_value": null, "remark": "执行成功" } ] } ``` ### 2. 获取块记录详情 #### 接口说明 获取指定块记录的详细信息,包括完整的输入输出参数、内部变量等数据。 #### 请求路径 ``` GET /api/vwed-task-record/block/{block_record_id} ``` #### 路径参数 | 参数名 | 类型 | 是否必须 | 描述 | | --- | --- | --- | --- | | block_record_id | string | 是 | 块记录ID | #### 响应结果 成功响应: ```json { "code": 200, "message": "成功获取块记录详情", "data": { "id": "块记录ID", "block_name": "块名称", "block_id": "块ID", "block_config_id": "块配置ID", "block_input_params": { "参数名": { "type": "参数类型", "value": "参数默认值", "required": true/false } }, "block_input_params_value": { "参数名": "参数值" }, "block_out_params_value": { "参数名": "参数值" }, "block_internal_variables": { "变量名": "变量值" }, "block_execute_name": "块执行名称", "task_id": "任务定义ID", "task_record_id": "任务记录ID", "started_on": "开始时间", "ended_on": "结束时间", "ended_reason": "结束原因", "status": 块执行状态码, "ctrl_status": 控制状态码, "input_params": { "参数名": { "type": "参数类型", "value": "参数默认值", "required": true/false } }, "internal_variables": { "变量名": "变量值" }, "output_params": { "参数名": "参数值" }, "version": 版本号, "remark": "备注" } } ``` 失败响应: ```json { "code": 404, "message": "未找到ID为 {block_record_id} 的块记录" } ``` #### 响应字段说明 | 字段名 | 类型 | 描述 | | --- | --- | --- | | id | string | 块记录ID | | block_name | string | 块名称 | | block_id | string | 块ID | | block_config_id | string | 块配置ID | | block_input_params | object | 块输入参数定义 | | block_input_params_value | object | 块输入参数值 | | block_out_params_value | object | 块输出参数值 | | block_internal_variables | object | 块内部变量 | | block_execute_name | string | 块执行名称 | | task_id | string | 任务定义ID | | task_record_id | string | 任务记录ID | | started_on | string | 开始时间,ISO 8601格式 | | ended_on | string | 结束时间,ISO 8601格式 | | ended_reason | string | 结束原因 | | status | integer | 块执行状态,1000:执行成功,1001:执行中,1002:未执行,2000:执行失败,2002:取消 | | ctrl_status | integer | 控制状态 | | input_params | object | 输入参数 | | internal_variables | object | 内部变量 | | output_params | object | 输出参数 | | version | integer | 版本号 | | remark | string | 备注 | #### 示例 请求示例: ``` GET /api/vwed-task-record/block/00b7dc0d-7c23-4dce-ae95-3618f2cad202 ``` 响应示例: ```json { "code": 200, "message": "成功获取块记录详情", "data": { "id": "00b7dc0d-7c23-4dce-ae95-3618f2cad202", "block_name": "b1", "block_id": "1", "block_config_id": "", "block_input_params": { "keyRoute": { "type": "Simple", "value": "TK01", "required": true } }, "block_input_params_value": { "keyRoute": "TK01" }, "block_out_params_value": null, "block_internal_variables": {}, "block_execute_name": "CSelectAgvBp", "task_id": "3273c7cb-b4bb-47df-9d47-17f96bc401fc", "task_record_id": "5ce20794-2b45-4031-8de0-9df922f91bd1", "started_on": "2025-04-30T08:36:37.847431", "ended_on": "2025-04-30T08:36:37.959064", "ended_reason": "选择执行机器人失败: 执行数据库异常,违反了完整性例如:违反惟一约束、违反非空限制、字段内容超出长度等", "status": 2000, "ctrl_status": null, "input_params": { "keyRoute": { "type": "Simple", "value": "TK01", "required": true } }, "internal_variables": {}, "output_params": { "blocks": { "b1": null } }, "version": 1, "remark": "选择执行机器人失败: 执行数据库异常,违反了完整性例如:违反惟一约束、违反非空限制、字段内容超出长度等" } } ``` ### 3. 终止任务 #### 接口说明 停止指定任务记录下的所有运行任务实例,同时禁用定时任务。 #### 请求路径 ``` POST /api/vwed-task-record/stop/{task_record_id} ``` #### 路径参数 | 参数名 | 类型 | 是否必须 | 描述 | | --- | --- | --- | --- | | task_record_id | string | 是 | 任务记录ID | #### 响应结果 成功响应: ```json { "code": 200, "message": "任务终止成功", "data": { "task_record_id": "任务记录ID", "status": 任务状态码, "ended_on": "结束时间", "ended_reason": "结束原因" } } ``` 失败响应: ```json { "code": 400, "message": "任务终止失败: {错误信息}" } ``` 或 ```json { "code": 500, "message": "任务记录终止失败: {错误信息}" } ``` #### 响应字段说明 | 字段名 | 类型 | 描述 | | --- | --- | --- | | task_record_id | string | 任务记录ID | | status | integer | 任务状态码 | | ended_on | string | 结束时间,ISO 8601格式 | | ended_reason | string | 结束原因 | #### 示例 请求示例: ``` POST /api/vwed-task-record/stop/7b84fd4d-e947-4ec7-8535-05ede5f8aa9d ``` 响应示例: ```json { "code": 200, "message": "任务终止成功", "data": { "task_record_id": "7b84fd4d-e947-4ec7-8535-05ede5f8aa9d", "status": 2002, "ended_on": "2025-04-30T17:35:42.105648", "ended_reason": "任务终止" } } ``` ### 4. 获取任务执行结果 #### 接口说明 获取指定任务记录的执行结果,按照任务定义的嵌套结构组织,包括已执行和未执行的任务块信息。该接口会解析任务定义中的层级关系,展现真实的任务执行流程。 **重要更新 (v2.0)**:新版本支持基于数据库层级关系字段的查询,循环块(如IterateListBp、WhileBp等)的迭代日志和子块执行日志将按迭代次数自然嵌套在一起,便于前端展示。 #### 请求路径 ``` GET /api/vwed-task-record/execution/block/results/{task_record_id} ``` #### 路径参数 | 参数名 | 类型 | 是否必须 | 描述 | | --- | --- | --- | --- | | task_record_id | string | 是 | 任务记录ID | #### 查询参数 | 参数名 | 类型 | 是否必须 | 默认值 | 描述 | | --- | --- | --- | --- | --- | | use_new_version | boolean | 否 | true | 是否使用新版本查询(基于层级关系字段),默认true | #### 响应结果 成功响应(嵌套结构): ```json { "code": 200, "message": "成功获取任务记录嵌套执行结果", "data": { "blockId": "-1", "blockName": "-1", "blockType": "RootBp", "blockTypeName": "根节点", "level": 0, "inputParams": {}, "executionStatus": 1000, "executionRecord": { "recordId": "记录ID", "status": 1000, "startedOn": "2025-09-29T17:32:13.393204", "endedOn": "2025-09-29T17:32:55.880506", "endedReason": "执行成功", "inputParamsValue": {}, "outputParamsValue": null, "remark": "执行成功" }, "logs": [ { "logId": "日志ID", "level": 1, "createdAt": "2025-09-29T17:32:55.873390", "message": "分支 default 的所有子块执行完成", "output": { "executed": true, "branch": "default", "results": [] } } ], "children": [ { "blockId": "9", "blockName": "b5", "blockType": "CSelectAgvBp", "blockTypeName": "选择执行机器人块", "level": 1, "inputParams": { "keyRoute": { "type": "Simple", "value": "AP1", "required": true } }, "executionStatus": 1000, "executionRecord": { "recordId": "记录ID", "status": 1000, "startedOn": "2025-09-29T17:32:13.413588", "endedOn": "2025-09-29T17:32:55.867389", "endedReason": "执行成功", "inputParamsValue": { "keyRoute": "AP1" }, "outputParamsValue": { "selectedAgvId": "Fake-03" }, "remark": "执行成功" }, "logs": [ { "logId": "日志ID", "level": 1, "createdAt": "2025-09-29T17:32:55.708163", "message": "选择机器人块成功, 块id:b5", "output": { "selectedAgvId": "Fake-03" } } ], "children": [ { "blockId": "10", "blockName": "b6", "blockType": "PrintBp", "blockTypeName": "打印块", "level": 2, "inputParams": { "message": { "type": "Simple", "value": "test message", "required": false } }, "executionStatus": 1006, "executionRecord": { "recordId": null, "status": 1006, "startedOn": null, "endedOn": null, "endedReason": "任务块尚未执行", "inputParamsValue": null, "outputParamsValue": null, "remark": "任务块尚未执行" }, "logs": [], "children": [] } ] } ] } } ``` 失败响应: ```json { "code": 404, "message": "未找到任务记录 {task_record_id}" } ``` 或 ```json { "code": 500, "message": "获取任务记录执行结果失败: {错误信息}" } ``` #### 响应字段说明 **普通块字段**: | 字段名 | 类型 | 描述 | | --- | --- | --- | | blockId | string | 任务定义中的块ID | | blockName | string | 块名称(在执行记录中用于标识) | | blockType | string | 块类型(如CSelectAgvBp、PrintBp、IterateListBp等) | | blockTypeName | string | 块类型中文名称 | | level | integer | 嵌套层级,根节点为0,子块递增 | | inputParams | object | 任务定义中配置的输入参数 | | executionStatus | integer | 执行状态:1000-执行成功,1001-执行中,1006-未执行,2000-执行失败,2001-取消 | | executionRecord | object | 执行记录详情 | | executionRecord.recordId | string | 执行记录ID,未执行时为null | | executionRecord.status | integer | 执行状态码 | | executionRecord.startedOn | string | 开始时间,ISO 8601格式,未执行时为null | | executionRecord.endedOn | string | 结束时间,ISO 8601格式,未执行时为null | | executionRecord.endedReason | string | 结束原因 | | executionRecord.inputParamsValue | object | 实际输入参数值 | | executionRecord.outputParamsValue | object | 输出参数值 | | executionRecord.remark | string | 备注 | | logs | array | 执行日志列表 | | logs[].logId | string | 日志ID | | logs[].level | integer | 日志级别(1: 信息, 3: 错误) | | logs[].createdAt | string | 日志创建时间,ISO 8601格式 | | logs[].message | string | 日志消息 | | logs[].output | object/string | 日志输出内容 | | logs[].logType | string | 日志类型(iteration_start/iteration_end/block_execution/branch_execution) | | logs[].iterationIndex | integer | 迭代索引(循环中的第几次,从0开始) | | children | array | 子任务块列表,递归结构 | **循环块特有字段** (当blockType为IterateListBp、WhileBp、RepeatNumBp时): | 字段名 | 类型 | 描述 | | --- | --- | --- | | children[].iterationIndex | integer | 迭代索引(第几次循环,从0开始) | | children[].success | boolean | 该次迭代是否成功 | | children[].iterationLogs | array | 该次迭代的循环日志(如"第1次循环, item=1") | | children[].children | array | 该次迭代中执行的子块列表 | #### 功能特性 1. **嵌套结构展示**:按照任务定义的层级关系组织执行结果 2. **完整性展示**:显示已执行和未执行的任务块 3. **状态区分**: - 1000:执行成功 - 1001:执行中 - 1006:未执行(在任务定义中存在但尚未执行到) - 2000:执行失败 - 2001:取消 4. **详细信息**:每个块包含执行记录、日志和子块信息 5. **循环嵌套优化**(v2.0新增): - 循环块(IterateListBp等)按迭代次数组织子块 - 每次迭代包含循环日志和该次迭代的所有子块执行记录 - 支持多层嵌套循环 6. **回退兼容**:当无法解析任务定义时,自动回退到平铺模式 #### 示例 ##### 示例2: 循环嵌套结构 (v2.0新增) 请求示例: ``` GET /api/vwed-task-record/execution/block/results/402196b4-1afc-413b-a56f-c69d95c408e9 ``` 响应示例(包含循环块): ```json { "code": 200, "message": "成功获取任务记录嵌套执行结果", "data": { "blockId": "-1", "blockName": "-1", "blockType": "RootBp", "blockTypeName": "根节点", "level": 0, "executionStatus": 1000, "executionRecord": { "recordId": "402196b4-1afc-413b-a56f-c69d95c408e9", "status": 1000, "startedOn": "2025-10-10T10:09:45.161986", "endedOn": "2025-10-10T10:09:45.436580", "endedReason": "执行成功", "inputParamsValue": {}, "outputParamsValue": null, "remark": "执行成功" }, "logs": [], "children": [ { "blockId": "5", "blockName": "b3", "blockType": "IterateListBp", "blockTypeName": "迭代列表块", "level": 1, "executionStatus": 1000, "executionRecord": { "recordId": "f2c68ef4-f4ac-4ae1-9a50-b438ce133019", "status": 1000, "startedOn": "2025-10-10T10:09:45.182785", "endedOn": "2025-10-10T10:09:45.385973", "endedReason": "执行成功", "inputParamsValue": { "list": "[1, 2, 3, 4]" }, "outputParamsValue": { "index": 3, "item": 4 }, "remark": "执行成功" }, "logs": [], "children": [ { "iterationIndex": 0, "success": true, "iterationLogs": [ { "logId": "log-iter-0", "level": 1, "createdAt": "2025-10-10T10:09:45.231789", "message": "第1次循环, item=1", "output": "", "logType": "iteration_start", "iterationIndex": 0 } ], "children": [ { "blockId": "5", "blockName": "b4", "blockType": "PrintBp", "blockTypeName": "打印块", "level": 2, "iterationIndex": 0, "executionStatus": 1000, "executionRecord": { "recordId": "79fe7502-1cd5-4b23-a4ff-8d746a30e149", "status": 1000, "startedOn": "2025-10-10T10:09:45.325139", "endedOn": "2025-10-10T10:09:45.354310", "endedReason": "执行成功", "inputParamsValue": { "message": "blocks.b3.index" }, "outputParamsValue": null, "remark": "执行成功" }, "logs": [ { "logId": "log-print-0", "level": 1, "createdAt": "2025-10-10T10:09:45.354310", "message": "打印块执行成功", "output": { "message": 0 }, "logType": "block_execution", "iterationIndex": 0 } ], "children": [] } ] }, { "iterationIndex": 1, "success": true, "iterationLogs": [ { "logId": "log-iter-1", "level": 1, "createdAt": "2025-10-10T10:09:45.273859", "message": "第2次循环, item=2", "output": "", "logType": "iteration_start", "iterationIndex": 1 } ], "children": [ { "blockId": "5", "blockName": "b4", "blockType": "PrintBp", "blockTypeName": "打印块", "level": 2, "iterationIndex": 1, "executionStatus": 1000, "executionRecord": { "recordId": "79fe7502-1cd5-4b23-a4ff-8d746a30e149", "status": 1000, "startedOn": "2025-10-10T10:09:45.325139", "endedOn": "2025-10-10T10:09:45.354310", "endedReason": "执行成功", "inputParamsValue": { "message": "blocks.b3.index" }, "outputParamsValue": null, "remark": "执行成功" }, "logs": [ { "logId": "log-print-1", "level": 1, "createdAt": "2025-10-10T10:09:45.354310", "message": "打印块执行成功", "output": { "message": 1 }, "logType": "block_execution", "iterationIndex": 1 } ], "children": [] } ] } ] } ] } } ``` **循环嵌套结构说明**: 1. 循环块(IterateListBp)的 `children` 数组包含多个迭代项 2. 每个迭代项包含: - `iterationIndex`: 迭代索引(从0开始) - `success`: 该次迭代是否成功 - `iterationLogs`: 该次迭代的循环日志(如"第1次循环") - `children`: 该次迭代中执行的所有子块 3. 子块的 `logs` 包含该次迭代中该块的执行日志 4. 所有日志都带有 `logType` 和 `iterationIndex` 字段用于标识 ### 5. 获取任务记录详情 #### 接口说明 获取指定任务记录的详细信息,包括任务的基本信息、执行状态、开始结束时间等。 #### 请求路径 ``` GET /api/vwed-task-record/detail/{task_record_id} ``` #### 路径参数 | 参数名 | 类型 | 是否必须 | 描述 | | --- | --- | --- | --- | | task_record_id | string | 是 | 任务记录ID | #### 响应结果 成功响应: ```json { "code": 200, "message": "成功获取任务记录详情", "data": { "id": "任务记录ID", "task_id": "任务定义ID", "task_name": "任务名称", "task_version": 任务版本, "status": 任务状态码, "input_params": { "参数名": "参数值" }, "started_on": "开始时间", "ended_on": "结束时间", "ended_reason": "结束原因", "execution_time": 执行时长(毫秒), "created_at": "创建时间", "updated_at": "更新时间", "agv_id": "执行任务的AGV设备ID", "parent_task_record_id": "父任务记录ID", "root_task_record_id": "根任务记录ID", "state_description": "状态描述", "if_have_child_task": 是否有子任务, "periodic_task": 是否为周期任务, "priority": 优先级, "work_stations": "工作站", "work_types": "工作类型", "variables": { "变量名": "变量值" }, "source_type": 任务来源类型, "source_system": "来源系统标识", "source_user": "下达任务的用户ID或账号", "source_device": "下达任务的硬件设备标识", "source_ip": "下达任务的IP地址", "source_time": "任务下达时间", "source_client_info": "客户端设备信息", "source_remarks": "任务来源备注信息" } } ``` 失败响应: ```json { "code": 404, "message": "未找到ID为 {task_record_id} 的任务记录" } ``` 或 ```json { "code": 500, "message": "获取任务记录详情失败: {错误信息}" } ``` #### 响应字段说明 | 字段名 | 类型 | 描述 | | --- | --- | --- | | id | string | 任务记录ID | | task_id | string | 任务定义ID(对应def_id字段) | | task_name | string | 任务名称(对应def_label字段) | | task_version | integer | 任务定义版本(对应def_version字段) | | status | integer | 任务状态码,1000:执行成功,1001:执行中,1002:队列中,2000:失败,2001:取消,2002:暂停 | | input_params | object | 输入参数,JSON格式 | | started_on | string | 开始时间,对应first_executor_time字段,ISO 8601格式 | | ended_on | string | 结束时间,ISO 8601格式 | | ended_reason | string | 结束原因 | | execution_time | integer | 执行时长(毫秒),根据开始和结束时间计算或executor_time字段值 | | created_at | string | 创建时间,ISO 8601格式 | | updated_at | string | 更新时间,ISO 8601格式 | | agv_id | string | 执行任务的AGV设备ID | | parent_task_record_id | string | 父任务记录ID | | root_task_record_id | string | 根任务记录ID | | state_description | string | 状态描述 | | if_have_child_task | boolean | 是否有子任务 | | periodic_task | integer | 是否为周期任务,0:否,1:是 | | priority | integer | 优先级,数值越大优先级越高 | | work_stations | string | 工作站 | | work_types | string | 工作类型 | | variables | object | 变量信息,JSON格式 | | source_type | integer | 任务来源类型(1:系统调度,2:呼叫机,3:第三方系统,4:手持电脑) | | source_system | string | 来源系统标识(如:WMS、MES等系统编号) | | source_user | string | 下达任务的用户ID或账号 | | source_device | string | 下达任务的硬件设备标识(设备ID、MAC地址等) | | source_ip | string | 下达任务的IP地址 | | source_time | string | 任务下达时间,ISO 8601格式 | | source_client_info | string | 客户端设备信息(用户代理、浏览器、操作系统等) | | source_remarks | string | 任务来源备注信息 | #### 示例 请求示例: ``` GET /api/vwed-task-record/detail/7b84fd4d-e947-4ec7-8535-05ede5f8aa9d ``` 响应示例: ```json { "code": 200, "message": "成功获取任务记录详情", "data": { "id": "7b84fd4d-e947-4ec7-8535-05ede5f8aa9d", "task_id": "3273c7cb-b4bb-47df-9d47-17f96bc401fc", "task_name": "示例任务", "task_version": 2, "status": 1000, "input_params": { "from": "A", "to": "B" }, "started_on": "2025-04-30T17:28:19.105648", "ended_on": "2025-04-30T17:28:20.601597", "ended_reason": "执行成功", "execution_time": 1496, "created_at": "2025-04-30T17:28:19.100000", "updated_at": "2025-04-30T17:28:20.610000", "agv_id": "AGV001", "parent_task_record_id": null, "root_task_record_id": "7b84fd4d-e947-4ec7-8535-05ede5f8aa9d", "state_description": "任务已完成", "if_have_child_task": false, "periodic_task": 0, "priority": 1, "work_stations": "WS001", "work_types": "运输任务", "variables": { "position": {"x": 100, "y": 200} }, "source_type": 1, "source_system": "WMS", "source_user": "admin", "source_device": "PC-001", "source_ip": "192.168.1.100", "source_time": "2025-04-30T17:28:18.000000", "source_client_info": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)", "source_remarks": "测试任务" } } ``` ### 6. 重发失败任务 #### 接口说明 重新执行失败状态的任务记录。该接口用于重新执行状态为失败(status=2000)的任务记录,系统会使用原任务的输入参数重新启动任务。 #### 请求路径 ``` POST /api/vwed-task-record/retry/{task_record_id} ``` #### 路径参数 | 参数名 | 类型 | 是否必须 | 描述 | | --- | --- | --- | --- | | task_record_id | string | 是 | 失败的任务记录ID | #### 响应结果 成功响应: ```json { "code": 200, "message": "任务重发成功", "data": { "original_task_record_id": "原任务记录ID", "new_task_record_id": "新任务记录ID", "new_task_id": "任务定义ID", "retry_time": "重发时间", "original_task_name": "原任务名称", "original_input_params": { "参数名": "参数值" } } } ``` 失败响应: ```json { "code": 404, "message": "未找到任务记录 {task_record_id}" } ``` 或 ```json { "code": 400, "message": "任务状态为 {status},只能重发失败状态(2000)的任务" } ``` 或 ```json { "code": 500, "message": "重发任务失败: {错误信息}" } ``` #### 响应字段说明 | 字段名 | 类型 | 描述 | | --- | --- | --- | | original_task_record_id | string | 原始失败的任务记录ID | | new_task_record_id | string | 重发后生成的新任务记录ID | | new_task_id | string | 任务定义ID | | retry_time | string | 重发时间,ISO 8601格式 | | original_task_name | string | 原始任务名称 | | original_input_params | object | 原始任务的输入参数 | #### 功能说明 1. 检查任务记录是否存在 2. 验证任务状态必须为失败状态(2000) 3. 使用原任务的输入参数重新启动任务 4. 保持原有的来源系统信息 5. 在备注中标记为重发任务 6. 返回新生成的任务记录信息 #### 注意事项 - 只能重发失败状态(status=2000)的任务 - 重发时会使用原任务的所有输入参数 - 重发后会生成新的任务记录ID - 原任务记录状态不会改变 - 如果任务定义不存在,重发会失败 #### 示例 请求示例: ``` POST /api/vwed-task-record/retry/7b84fd4d-e947-4ec7-8535-05ede5f8aa9d ``` 响应示例: ```json { "code": 200, "message": "任务重发成功", "data": { "original_task_record_id": "7b84fd4d-e947-4ec7-8535-05ede5f8aa9d", "new_task_record_id": "8c95ge5e-f058-5fd8-9646-16fef6g9bb0e", "new_task_id": "3273c7cb-b4bb-47df-9d47-17f96bc401fc", "retry_time": "2025-09-19T10:30:15.123456", "original_task_name": "示例任务", "original_input_params": { "from": "A", "to": "B" } } } ``` ### 15. 设置任务错误状态 #### 接口说明 将指定任务记录及其相关任务块状态设置为错误状态 #### 请求信息 - **URL**: `/api/vwed-task-record/set-error/{task_record_id}` - **Method**: `POST` - **Content-Type**: `application/json` #### 路径参数 | 参数名 | 类型 | 必填 | 说明 | |--------|------|------|------| | task_record_id | string | 是 | 任务记录ID | #### 请求体参数 | 参数名 | 类型 | 必填 | 说明 | 示例 | |--------|------|------|------|------| | error_reason | string | 是 | 错误原因 | "系统异常导致任务失败" | #### 请求示例 ```json { "error_reason": "系统异常导致任务失败" } ``` #### 响应示例 ```json { "success": true, "message": "任务状态设置为错误成功", "data": { "task_record_id": "123456", "task_status": 2000, "error_reason": "系统异常导致任务失败", "ended_on": "2024-01-01T12:00:00", "updated_blocks_count": 5, "updated_blocks": [ { "block_id": "block_001", "block_name": "数据处理", "status": 2000 } ] } } ``` #### 状态码说明 - **200**: 成功 - **400**: 请求参数错误 - **404**: 任务记录不存在 - **500**: 服务器内部错误 #### 功能说明 1. 如果任务正在运行,会先尝试取消任务 2. 将任务状态设置为失败状态(2000) 3. 将所有未完成的任务块状态设置为失败状态(2000) 4. 记录错误原因和结束时间 5. 返回更新的任务块数量和详细信息 #### 注意事项 - 只有未完成的任务块(非成功或失败状态)才会被更新 - 已经完成或失败的任务块不会被重复更新 - 如果任务记录不存在,会返回404错误