approve/launch/syncForm/delete/decision 全部 process.exit → ctx.fail. delete --yes 检查移入 ctx.fail (保留 BS-E13 排查提示). decision --list 分支保留. workflow/create.ts (9 exit, P2 高风险) 暂不动, 留专门 session 拆 sub-handler. Co-Authored-By: Claude <[email protected]>
125 lines
6.1 KiB
TypeScript
125 lines
6.1 KiB
TypeScript
/**
|
|
* commands/workflow/decision.ts — 决策流参数 (白皮书 5.6.5)
|
|
*
|
|
* 决策流不是独立实体, 是流程模板 (template) 的子配置:
|
|
* GET /api/workflow/template/{id}/DecisionParameter → FlowConfigModel
|
|
*
|
|
* 白皮书 5.6.5 提到的能力 (漏斗/覆盖/规则集/评分卡/交叉表/异常)
|
|
* 都打包在 FlowConfigModel 里, 由 web 端 decisionFlow 节点配置。
|
|
*
|
|
* v1 实现: 只读 (read-only), 因为更新要 PUT 整个 template, 复杂
|
|
* 写更新留 v0.10+ (需解析 FlowConfigModel + 跟现有 flowConfig 合并)
|
|
*/
|
|
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 DecisionOpts {
|
|
list?: boolean
|
|
json?: boolean
|
|
/** v2.1+ (2026-07-21): --verbose, addOutputOptions 注入 */
|
|
verbose?: boolean
|
|
}
|
|
|
|
export function buildWorkflowDecisionCommand(): Command {
|
|
const cmd = new Command('decision')
|
|
.description('决策流参数 (白皮书 5.6.5) — 流程模板的子配置 (漏斗/覆盖/规则集/评分卡/交叉表/异常)')
|
|
.argument('[templateId]', '模板 id, 不传且无 --list 则报错')
|
|
.option('--list', '列所有 template, 标记是否含决策流节点', false)
|
|
addOutputOptions(cmd)
|
|
.action(async (templateId: string | undefined, opts: DecisionOpts) => {
|
|
setupOutputFilter(opts)
|
|
const c = await JnpfClient.fromToken()
|
|
|
|
await wrapCommand({
|
|
command: 'workflow decision',
|
|
appCode: c.appCode,
|
|
startTime: Date.now(),
|
|
verbose: opts.verbose,
|
|
json: opts.json,
|
|
fixes: [],
|
|
}, async (ctx) => {
|
|
try {
|
|
if (opts.list) {
|
|
// 列所有 template, 调 DecisionParameter 探测 (会慢, 但准确)
|
|
const r = await c.get<{ list?: { id: string; fullName: string; enCode?: string; flowType?: number }[] }>(
|
|
'/workflow/template', { currentPage: 1, pageSize: 200 },
|
|
)
|
|
if (r.code !== 200) { return ctx.fail(`list 失败: ${r.msg}`, { code: r.code }) }
|
|
const list = r.data?.list || []
|
|
log.info(`共 ${list.length} 个 template, 逐个探测 DecisionParameter...`)
|
|
const rows: { id: string; fullName: string; hasDecision: boolean; summary: string }[] = []
|
|
for (const t of list) {
|
|
const r2 = await c.get<unknown>(`/workflow/template/${t.id}/DecisionParameter`)
|
|
const hasDecision = r2.code === 200 && r2.data != null && Object.keys(r2.data as object).length > 0
|
|
const summary = hasDecision
|
|
? Object.keys(r2.data as object).slice(0, 5).join(', ')
|
|
: ''
|
|
rows.push({ id: t.id, fullName: t.fullName, hasDecision, summary })
|
|
}
|
|
if (opts.json) { printJson(rows); return ctx.success({ total: rows.length }) }
|
|
console.log('ID FULL_NAME HAS-DECISION SUMMARY')
|
|
console.log('-'.repeat(100))
|
|
for (const r of rows) {
|
|
const id = r.id.padEnd(36)
|
|
const name = r.fullName.padEnd(22)
|
|
const has = (r.hasDecision ? '✓' : ' ').padEnd(13)
|
|
console.log(`${id}${name}${has}${r.summary}`)
|
|
}
|
|
const withDecision = rows.filter((r) => r.hasDecision).length
|
|
log.info(`共 ${rows.length} 个, 含决策流 ${withDecision} 个`)
|
|
return ctx.success({ total: rows.length, withDecision })
|
|
}
|
|
if (!templateId) {
|
|
return ctx.fail('必传 <templateId>, 或 --list 列所有')
|
|
}
|
|
log.info(`GET /workflow/template/${templateId}/DecisionParameter`)
|
|
const r = await c.get<unknown>(`/workflow/template/${templateId}/DecisionParameter`)
|
|
if (r.code !== 200) {
|
|
return ctx.fail(`失败 (code=${r.code}): ${r.msg}`, { templateId, code: r.code })
|
|
}
|
|
const data = r.data as Record<string, unknown> | null
|
|
if (!data || Object.keys(data).length === 0) {
|
|
log.warn(`template ${templateId} 没有决策流配置 (空 FlowConfigModel)`)
|
|
log.info('提示: web 端 flowDesign 拖入"决策"节点才会生成 DecisionParameter')
|
|
return ctx.success({ templateId, hasDecision: false })
|
|
}
|
|
if (opts.json) { printJson(data); return ctx.success({ templateId, hasDecision: true }) }
|
|
log.info(`template ${templateId} 决策流参数:`)
|
|
for (const [k, v] of Object.entries(data)) {
|
|
const vStr = typeof v === 'object' ? JSON.stringify(v) : String(v)
|
|
const vShort = vStr.length > 200 ? vStr.slice(0, 200) + '...' : vStr
|
|
console.log(` ${k.padEnd(20)} : ${vShort}`)
|
|
}
|
|
ctx.success({ templateId, hasDecision: true })
|
|
} catch (e) {
|
|
ctx.fail(`workflow decision 失败: ${(e as Error).message?.slice(0, 200)}`)
|
|
}
|
|
})
|
|
})
|
|
installHelpHook(cmd, {
|
|
purpose: '决策流参数 (白皮书 5.6.5) — 漏斗/覆盖/规则集/评分卡/交叉表/异常, 是 template 的子配置',
|
|
required: { '<templateId> | --list': '模板 id, 或 --list 列所有含决策流的' },
|
|
optional: { '--json': '原始 JSON' },
|
|
example: [
|
|
'dacli workflow decision 808986025610185477',
|
|
'dacli workflow decision --list',
|
|
'dacli workflow decision 808986025610185477 --json',
|
|
],
|
|
source: {
|
|
web: 'web/.../flowEngine/Form.vue + components/decisionFlow/*',
|
|
api: 'GET /api/workflow/template/{id}/DecisionParameter',
|
|
ref: '白皮书 5.6.5 决策流 (漏斗/覆盖/规则集/评分卡/交叉表/异常)',
|
|
},
|
|
notes: [
|
|
'决策流不是独立实体, 是 template 的子配置',
|
|
'更新需 PUT /workflow/template/{id} (整个 template 改写), v0.10+ 再做',
|
|
'web 端拖入"决策"节点才会生成 DecisionParameter (空模板查不到)',
|
|
'--list 会逐个探测, 模板多时慢, 计划加缓存',
|
|
],
|
|
})
|
|
return cmd
|
|
}
|