diff --git a/src/commands/workflow/delete.ts b/src/commands/workflow/delete.ts new file mode 100644 index 0000000..90f5607 --- /dev/null +++ b/src/commands/workflow/delete.ts @@ -0,0 +1,41 @@ +/** + * commands/workflow/delete.ts — 流程模板删除 + * + * v0.11+ Phase 2 新增: 流程模板 CRUD 闭环 + * + * API: DELETE /api/workflow/template/{id} + */ +import { Command } from 'commander' +import { JnpfClient } from '../../core/client.ts' +import { installAiHelpHook } from '../../core/help.ts' +import { log } from '../../core/log.ts' + +interface Opts { id: string; yes?: boolean } + +export function buildWorkflowDeleteCommand(): Command { + const cmd = new Command('delete') + .description('流程模板删除 (硬删, 无回收)') + .requiredOption('--id ', '流程模板 id') + .option('--yes', '跳过确认', false) + .action(async (opts: Opts) => { + if (!opts.yes) { + log.warn(`即将删除流程模板 id=${opts.id}, 加 --yes 跳过确认`) + process.exit(2) + } + const c = await JnpfClient.fromToken() + const r = await c.del(`/workflow/template/${opts.id}`) + if (r.code !== 200) { + log.error(`workflow delete 失败: ${r.msg}`) + process.exit(1) + } + log.ok(`✓ 流程模板已删除 (id=${opts.id})`) + }) + installAiHelpHook(cmd, { + purpose: '流程模板删除. 引用该流程的 form 会失效.', + required: { '--id': '流程模板 id', '--yes': '跳过确认' }, + example: 'dacli workflow delete --id=1234567890 --yes', + source: { api: 'DELETE /api/workflow/template/{id}' }, + notes: ['v0.11+ P0 新增', '引用该流程的 form 会失效', '谨慎操作'], + }) + return cmd +} diff --git a/src/commands/workflow/index.ts b/src/commands/workflow/index.ts index f14079d..53a41c3 100644 --- a/src/commands/workflow/index.ts +++ b/src/commands/workflow/index.ts @@ -1,18 +1,27 @@ /** * commands/workflow/index.ts — workflow 父命令 + * + * v0.11+ Phase 2: 9 子命令 (list/info/create/update/delete/launch/approve/decision/selector) + * 闭环 CRUD + 流程引擎 */ import { Command } from 'commander' import { buildWorkflowListCommand } from './list.ts' +import { buildWorkflowInfoCommand } from './info.ts' +import { buildWorkflowCreateCommand } from './create.ts' +import { buildWorkflowUpdateCommand } from './update.ts' +import { buildWorkflowDeleteCommand } from './delete.ts' import { buildWorkflowLaunchCommand } from './launch.ts' import { buildWorkflowApproveCommand } from './approve.ts' -import { buildWorkflowCreateCommand } from './create.ts' import { buildWorkflowDecisionCommand } from './decision.ts' import { buildWorkflowSelectorCommand } from './selector.ts' export function buildWorkflowCommand(): Command { - const cmd = new Command('workflow').description('流程引擎 (模板/发起/审批 + 5.6.5 决策流参数)') + const cmd = new Command('workflow').description('流程引擎 (模板 CRUD + 发起/审批 + 决策流)') cmd.addCommand(buildWorkflowListCommand()) + cmd.addCommand(buildWorkflowInfoCommand()) cmd.addCommand(buildWorkflowCreateCommand()) + cmd.addCommand(buildWorkflowUpdateCommand()) + cmd.addCommand(buildWorkflowDeleteCommand()) cmd.addCommand(buildWorkflowLaunchCommand()) cmd.addCommand(buildWorkflowApproveCommand()) cmd.addCommand(buildWorkflowDecisionCommand()) diff --git a/src/commands/workflow/info.ts b/src/commands/workflow/info.ts new file mode 100644 index 0000000..045b4ba --- /dev/null +++ b/src/commands/workflow/info.ts @@ -0,0 +1,50 @@ +/** + * commands/workflow/info.ts — 流程模板详情 + * + * v0.11+ Phase 2 新增: 流程模板 CRUD 闭环 (P0) + * + * API: GET /api/workflow/template/{id} + */ +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 { id: string; json?: boolean } + +export function buildWorkflowInfoCommand(): Command { + const cmd = new Command('info') + .description('流程模板详情 (含 category/enabledMark/version/关联 form)') + .requiredOption('--id ', '流程模板 id') + .option('--json', '原始 JSON 输出', false) + .action(async (opts: Opts) => { + const c = await JnpfClient.fromToken() + const r = await c.get>(`/workflow/template/${opts.id}`) + if (r.code !== 200 || !r.data) { + log.error(`workflow info 失败: ${r.msg || 'id 不存在'}`) + process.exit(1) + } + if (opts.json) { + printJson(r.data) + return + } + const d = r.data + log.info(`流程模板详情 (id=${opts.id})`) + console.log(` fullName : ${d.fullName}`) + console.log(` enCode : ${d.enCode}`) + console.log(` category : ${d.category}`) + console.log(` enabledMark : ${d.enabledMark === 1 ? '启用' : '禁用'}`) + console.log(` version : ${d.version || '1'}`) + console.log(` formId : ${d.formId || '-'}`) + console.log(` description : ${d.description || '-'}`) + }) + installAiHelpHook(cmd, { + purpose: '流程模板详情. AI 引用 workflow id 验证 (P0 闭环, 之前只有 list/launch/approve/decision).', + required: { '--id': '流程模板 id' }, + optional: { '--json': '原始 JSON 输出' }, + example: 'dacli workflow info --id=1234567890', + source: { api: 'GET /api/workflow/template/{id}' }, + notes: ['v0.11+ P0 新增, 闭环 CRUD 必需'], + }) + return cmd +} diff --git a/src/commands/workflow/update.ts b/src/commands/workflow/update.ts new file mode 100644 index 0000000..52db7a3 --- /dev/null +++ b/src/commands/workflow/update.ts @@ -0,0 +1,66 @@ +/** + * commands/workflow/update.ts — 流程模板修改 + * + * v0.11+ Phase 2 新增: 流程模板 CRUD 闭环 + * + * API: PUT /api/workflow/template/{id} + */ +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 { + id: string + fullName?: string + enCode?: string + category?: string + enabledMark?: string + description?: string + json?: boolean +} + +export function buildWorkflowUpdateCommand(): Command { + const cmd = new Command('update') + .description('流程模板修改 (改 fullName/enCode/category/enabledMark, PUT 语义)') + .requiredOption('--id ', '流程模板 id') + .option('--fullName ', '中文名') + .option('--enCode ', '英文编码') + .option('--category ', '分类 id') + .option('--enabledMark <0|1>', '启用/禁用') + .option('--description ', '描述') + .option('--json', '原始 JSON 输出', false) + .action(async (opts: Opts) => { + const c = await JnpfClient.fromToken() + // 拉原模板 + const orig = (await c.get>(`/workflow/template/${opts.id}`)).data + if (!orig) { + log.error(`workflow update 失败: 拉原模板 id=${opts.id} 失败`) + process.exit(1) + } + const body: Record = { ...orig, id: opts.id } + if (opts.fullName) body.fullName = opts.fullName + if (opts.enCode) body.enCode = opts.enCode + if (opts.category) body.category = opts.category + if (opts.enabledMark !== undefined) body.enabledMark = parseInt(opts.enabledMark, 10) + if (opts.description) body.description = opts.description + log.info(`PUT /workflow/template/${opts.id}`) + const r = await c.putJson(`/workflow/template/${opts.id}`, body) + if (r.code !== 200) { + log.error(`workflow update 失败 (code=${r.code}): ${r.msg}`) + if (opts.json) printJson(r) + process.exit(1) + } + log.ok(`✓ 流程模板更新成功 (id=${opts.id})`) + if (opts.json) printJson(r.data) + }) + installAiHelpHook(cmd, { + purpose: '流程模板修改 (改 fullName/enCode/category/enabledMark/description). PUT 语义, 未传保留.', + required: { '--id': '流程模板 id' }, + optional: { '--fullName': '中文名', '--enCode': '英文编码', '--category': '分类 id', '--enabledMark': '启用/禁用 0|1', '--description': '描述' }, + example: 'dacli workflow update --id=123 --enabledMark=0', + source: { api: 'PUT /api/workflow/template/{id}' }, + notes: ['v0.11+ P0 新增', '未传字段保留 (PUT 语义)'], + }) + return cmd +}