/** * commands/workflow/tasks.ts — 查我的流程任务 (P1 NEW-CMD, v0.11+) * * API: GET /api/workflow/operator/List/{category}?keyword=&flowId=¤tPage=&pageSize= * category: 0=待签 1=待办 2=在办 3=已办 4=抄送 (默认 1 待办) * * 注意: 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 { installHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' import { setupOutputFilter, addOutputOptions, wrapCommand } from '../_output_filter.ts' // v2.1+ 输出过滤; v2.2+ wrapCommand 收口 5c interface Opts { category?: string keyword?: string flowId?: string json?: boolean /** v2.1+ (2026-07-21): --verbose, addOutputOptions 注入 */ verbose?: boolean } const CATEGORY_NAMES: Record = { '0': '待签', '1': '待办', '2': '在办', '3': '已办', '4': '抄送', } export function buildWorkflowTasksCommand(): Command { const cmd = new Command('tasks') .description('查我的流程任务 (P1 NEW-CMD, AI 审批任务管理)') .option('--category <0|1|2|3|4>', '任务分类 0=待签 1=待办 2=在办 3=已办 4=抄送 (默认 1)', '1') .option('--flowId ', '按流程模板 id 过滤') .option('--keyword ', '按关键字模糊搜索 (流程名/发起人/单号)') addOutputOptions(cmd) .action(async (opts: Opts) => { setupOutputFilter(opts) const c = await JnpfClient.fromToken() await wrapCommand({ command: 'workflow tasks', appCode: c.appCode, startTime: Date.now(), verbose: opts.verbose, json: opts.json, fixes: [], }, async (ctx) => { try { const category = opts.category || '1' 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) { return ctx.fail(`workflow tasks 失败: ${r.msg}`, { category, code: r.code }) } const list = r.data?.list || [] const total = r.data?.pagination?.total ?? list.length const summary = { category, total, returned: list.length } if (opts.json) { printJson(r) return ctx.success(summary) } const catName = CATEGORY_NAMES[category] || `category=${category}` log.info(`共 ${total} 个${catName}任务`) log.printRawTable( ['TASK_ID', 'FLOW_NAME', 'CREATOR', 'TIME', 'STATE'], list.map((t) => [ String(t.id || t.taskId || ''), String(t.flowName || t.fullName || ''), String(t.creatorUser || t.userName || ''), String(t.createTime || t.startTime || t.updateTime || ''), String(t.statusName || t.state || ''), ]), ) ctx.success(summary) } catch (e) { ctx.fail(`workflow tasks 失败: ${(e as Error).message?.slice(0, 200)}`) } }) }) installHelpHook(cmd, { purpose: '查我的流程任务 (待签/待办/已办/抄送 4 类)', optional: { '--category': '0=待签 1=待办 2=在办 3=已办 4=抄送', '--flowId': '按流程模板 id 过滤', '--keyword': '按关键字模糊搜索', }, example: [ 'dacli workflow tasks # 默认查待办', 'dacli workflow tasks --category=0 # 待签', '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 }