diff --git a/src/commands/workflow/index.ts b/src/commands/workflow/index.ts index 53a41c3..0688732 100644 --- a/src/commands/workflow/index.ts +++ b/src/commands/workflow/index.ts @@ -1,8 +1,8 @@ /** * commands/workflow/index.ts — workflow 父命令 * - * v0.11+ Phase 2: 9 子命令 (list/info/create/update/delete/launch/approve/decision/selector) - * 闭环 CRUD + 流程引擎 + * v0.11+ Phase 2: 10 子命令 (list/info/create/update/delete/launch/approve/decision/selector/tasks) + * 闭环 CRUD + 流程引擎 + 我的任务 (P1 NEW-CMD) */ import { Command } from 'commander' import { buildWorkflowListCommand } from './list.ts' @@ -14,9 +14,10 @@ import { buildWorkflowLaunchCommand } from './launch.ts' import { buildWorkflowApproveCommand } from './approve.ts' import { buildWorkflowDecisionCommand } from './decision.ts' import { buildWorkflowSelectorCommand } from './selector.ts' +import { buildWorkflowTasksCommand } from './tasks.ts' export function buildWorkflowCommand(): Command { - const cmd = new Command('workflow').description('流程引擎 (模板 CRUD + 发起/审批 + 决策流)') + const cmd = new Command('workflow').description('流程引擎 (模板 CRUD + 发起/审批 + 我的任务)') cmd.addCommand(buildWorkflowListCommand()) cmd.addCommand(buildWorkflowInfoCommand()) cmd.addCommand(buildWorkflowCreateCommand()) @@ -26,5 +27,6 @@ export function buildWorkflowCommand(): Command { cmd.addCommand(buildWorkflowApproveCommand()) cmd.addCommand(buildWorkflowDecisionCommand()) cmd.addCommand(buildWorkflowSelectorCommand()) + cmd.addCommand(buildWorkflowTasksCommand()) return cmd } diff --git a/src/commands/workflow/tasks.ts b/src/commands/workflow/tasks.ts new file mode 100644 index 0000000..9d79098 --- /dev/null +++ b/src/commands/workflow/tasks.ts @@ -0,0 +1,114 @@ +/** + * commands/workflow/tasks.ts — 查我的流程任务 (P1 NEW-CMD, v0.11+) + * + * API: GET /api/workflow/operator/List/{category}?keyword=&flowId=¤tPage=&pageSize= + * category: 1=待签 2=待办 3=已办 4=抄送 (默认 2 待办) + * + * 注意: web workFlow/task.ts 用了 @vben/stores (Pinia), 暂不镜像. + * 本命令直接调 JNPF REST API. + * + * v0.11+ Phase 2 P1 NEW-CMD (2026-06-25): AI 操作审批任务 + */ +import { Command } from 'commander' +import { JnpfClient } from '../../core/client.ts' +import { installAiHelpHook } from '../../core/help.ts' +import { log, printJson } from '../../core/log.ts' + +interface Opts { + category?: string + keyword?: string + flowId?: string + json?: boolean +} + +const CATEGORY_NAMES: Record = { + '1': '待签', + '2': '待办', + '3': '已办', + '4': '抄送', +} + +export function buildWorkflowTasksCommand(): Command { + const cmd = new Command('tasks') + .description('查我的流程任务 (P1 NEW-CMD, AI 审批任务管理)') + .option('--category <1|2|3|4>', '任务分类 1=待签 2=待办 3=已办 4=抄送 (默认 2)', '2') + .option('--flowId ', '按流程模板 id 过滤') + .option('--keyword ', '按关键字模糊搜索 (流程名/发起人/单号)') + .option('--json', '原始 JSON 输出', false) + .action(async (opts: Opts) => { + const c = await JnpfClient.fromToken() + const category = opts.category || '2' + const params: Record = { + currentPage: '1', + pageSize: '20', + } + if (opts.flowId) params.flowId = opts.flowId + if (opts.keyword) params.keyword = opts.keyword + + const r = (await c.get(`/workflow/operator/List/${category}`, params)) as { + code?: number + msg?: string + data?: { list?: TaskItem[]; pagination?: { total: number } } + } + + if (r?.code && r.code !== 200) { + log.error(`workflow tasks 失败: ${r.msg}`) + process.exit(1) + } + const list = r.data?.list || [] + const total = r.data?.pagination?.total ?? list.length + + if (opts.json) { + printJson(r) + return + } + const catName = CATEGORY_NAMES[category] || `category=${category}` + log.info(`共 ${total} 个${catName}任务`) + console.log('TASK_ID'.padEnd(20) + 'FLOW_NAME'.padEnd(30) + 'CREATOR'.padEnd(15) + 'TIME'.padEnd(20) + 'STATE') + console.log('-'.repeat(100)) + for (const t of list) { + const id = String(t.id || t.taskId || '').padEnd(20) + const flow = String(t.flowName || t.fullName || '').padEnd(30) + const creator = String(t.creatorUser || t.userName || '').padEnd(15) + const time = String(t.createTime || t.startTime || t.updateTime || '').padEnd(20) + const state = String(t.statusName || t.state || '') + console.log(`${id}${flow}${creator}${time}${state}`) + } + }) + + installAiHelpHook(cmd, { + purpose: '查我的流程任务 (待签/待办/已办/抄送 4 类)', + optional: { + '--category': '1=待签 2=待办 3=已办 4=抄送', + '--flowId': '按流程模板 id 过滤', + '--keyword': '按关键字模糊搜索', + }, + example: [ + 'dacli workflow tasks # 默认查待办', + 'dacli workflow tasks --category=1 # 待签', + 'dacli workflow tasks --keyword=请假', + 'dacli workflow tasks --json', + ], + source: { api: 'GET /api/workflow/operator/List/{category}?keyword=&flowId=¤tPage=&pageSize=' }, + notes: [ + '**web 镜像说明**: web workFlow/task.ts 用 @vben/stores (Pinia), v0.11+ 暂不镜像, 直接调 JNPF REST', + '**配合**: `workflow approve --taskId=X --status=0/1/2` 同意/不同意/退回', + ], + }) + return cmd +} + +interface TaskItem { + id?: string + taskId?: string + flowName?: string + fullName?: string + creatorUser?: string + userName?: string + createTime?: string + startTime?: string + updateTime?: string + statusName?: string + state?: string + [k: string]: unknown +} \ No newline at end of file