101 lines
4.2 KiB
TypeScript
101 lines
4.2 KiB
TypeScript
/**
|
|
* commands/workflow/list.ts — 流程模板/任务 列表
|
|
*
|
|
* API:
|
|
* GET /api/workflow/template[?category=X] 模板
|
|
* GET /api/workflow/operator/List/{type} 我的待办 (type=1 待审批, 2 已审批, 3 抄送)
|
|
*/
|
|
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, printCommandEnd } from './_output.ts'
|
|
|
|
interface ListOpts {
|
|
category?: string
|
|
todo?: string
|
|
pageSize?: string
|
|
json?: boolean
|
|
verbose?: boolean
|
|
}
|
|
|
|
export function buildWorkflowListCommand(): Command {
|
|
const cmd = new Command('list')
|
|
.description('流程模板 / 我的待办 列表')
|
|
.option('--category <c>', '模板分类')
|
|
.option('--todo <type>', '我的待办 (1=待审批 2=已审批 3=抄送), 启用此模式时 category 忽略', '0')
|
|
.option('--pageSize <s>', '每页', '50')
|
|
.option('--verbose', '完整输出 (含 step machine、API 调用等过程日志)', false)
|
|
.option('--json', '原始 JSON 输出', false)
|
|
.action(async (opts: ListOpts) => {
|
|
setupOutputFilter(opts)
|
|
const c = await JnpfClient.fromToken()
|
|
const startTime = Date.now()
|
|
let cmdError: string | undefined
|
|
let cmdSummary: Record<string, unknown> = {}
|
|
|
|
try {
|
|
const todo = Number(opts.todo || '0')
|
|
const path = todo > 0
|
|
? `/workflow/operator/List/${todo}`
|
|
: `/workflow/template${opts.category ? `?category=${opts.category}` : ''}`
|
|
const r = await c.get<{ list?: { id: string; fullName: string; enCode?: string; category?: string; flowId?: string; enabledMark?: number; status?: number }[]; msg?: string }>(path, {
|
|
currentPage: 1,
|
|
pageSize: opts.pageSize,
|
|
})
|
|
if (r.code !== 200) {
|
|
cmdError = r.msg || `code=${r.code}`
|
|
log.error(`workflow list 失败: ${cmdError}`)
|
|
// v2.1+ (2026-07-21): 错误路径落 CommandLog
|
|
printCommandEnd({
|
|
command: 'workflow list',
|
|
appCode: c.appCode,
|
|
result: 'failure',
|
|
error: cmdError,
|
|
summary: { path, category: opts.category, todo },
|
|
duration_ms: Date.now() - startTime,
|
|
verbose: opts.verbose,
|
|
json: opts.json,
|
|
})
|
|
process.exit(1)
|
|
}
|
|
const list = r.data?.list || []
|
|
cmdSummary = { path, total: list.length, category: opts.category, todo }
|
|
if (opts.json) { printJson(r.data); return }
|
|
log.info(`${path} 共 ${list.length} 条`)
|
|
// v0.12+ jxcj-2026-06-29 fix: 多输出一列 FLOW_ID (TemplateJsonEntity.id = 最新 version id)
|
|
// 作用: launchFlow / actionLaunchFlow 用 template=FLOW_ID, 不要用 ID (TemplateEntity.id)
|
|
console.log('ID FLOW_ID FULL_NAME ENCODE CATEGORY')
|
|
console.log('-'.repeat(120))
|
|
for (const t of list) {
|
|
console.log(`${String(t.id || '').padEnd(36)}${String(t.flowId || '').padEnd(36)}${String(t.fullName || '').padEnd(22)}${String(t.enCode || '').padEnd(22)}${t.category || ''}`)
|
|
}
|
|
if (list.some((t) => t.id !== t.flowId)) {
|
|
log.info(` 💡 launchFlow / actionLaunchFlow 需用 FLOW_ID (≠ ID):`)
|
|
log.info(` dacli workflow launch --id=<FLOW_ID> ...`)
|
|
}
|
|
} finally {
|
|
// v2.1+ (2026-07-21): 落 CommandLog (L3) — list 类查询历史可追溯
|
|
printCommandEnd({
|
|
command: 'workflow list',
|
|
appCode: c.appCode,
|
|
result: cmdError ? 'failure' : 'success',
|
|
error: cmdError,
|
|
summary: cmdSummary,
|
|
duration_ms: Date.now() - startTime,
|
|
verbose: opts.verbose,
|
|
json: opts.json,
|
|
})
|
|
}
|
|
})
|
|
|
|
installHelpHook(cmd, {
|
|
purpose: '看流程模板 (--category) 或 我的待办 (--todo 1/2/3).',
|
|
required: {},
|
|
optional: { '--category': '模板分类', '--todo': '1=待审批 2=已审批 3=抄送', '--pageSize': '每页' },
|
|
example: ['dacli workflow list', 'dacli workflow list --todo=1'],
|
|
source: { api: 'GET /api/workflow/template 或 /api/workflow/operator/List/{type}' },
|
|
})
|
|
return cmd
|
|
}
|