diff --git a/src/commands/bigscreen/delete.ts b/src/commands/bigscreen/delete.ts index e576cc4..42eb73a 100644 --- a/src/commands/bigscreen/delete.ts +++ b/src/commands/bigscreen/delete.ts @@ -1,20 +1,21 @@ /** * commands/bigscreen/delete.ts — 大屏删除 * - * v0.11+ Phase 2 新增: 大屏 CRUD 闭环 - * - * API: DELETE /api/extend/BigData/{id} + * v0.11+ Phase 2: webapi 化 (loadVisualData.removeVisualData) + * 替代 v0.10 直接 c.del + * 注: 大屏 web 端在 jnpf-web-datascreen-vue3 (v2 审计已修正) */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installAiHelpHook } from '../../core/help.ts' import { log } from '../../core/log.ts' +import { initWebapi, loadVisualData } from '../../webapi/visualdata.ts' interface Opts { id: string; yes?: boolean } export function buildBigscreenDeleteCommand(): Command { const cmd = new Command('delete') - .description('大屏删除 (硬删)') + .description('大屏删除 (硬删, v0.11+ webapi)') .requiredOption('--id ', '大屏 id') .option('--yes', '跳过确认', false) .action(async (opts: Opts) => { @@ -23,8 +24,12 @@ export function buildBigscreenDeleteCommand(): Command { process.exit(2) } const c = await JnpfClient.fromToken() - const r = await c.del(`/extend/BigData/${opts.id}`) - if (r.code !== 200) { + await initWebapi(c) + log.info(`loadVisualData.removeVisualData (id=${opts.id})`) + const r = (await ( + loadVisualData.removeVisualData?.(opts.id) || loadVisualData.remove?.(opts.id) + )) as { code?: number; msg?: string } + if (r.code !== 200 && r.code !== undefined) { log.error(`bigscreen delete 失败: ${r.msg}`) process.exit(1) } @@ -34,8 +39,8 @@ export function buildBigscreenDeleteCommand(): Command { purpose: '大屏删除', required: { '--id': '大屏 id', '--yes': '跳过确认' }, example: 'dacli bigscreen delete --id=123 --yes', - source: { api: 'DELETE /api/extend/BigData/{id}' }, - notes: ['v0.11+ P0 新增, 谨慎操作'], + source: { api: 'DELETE /api/visualdata/remove (jnpf-web-datascreen-vue3)', ref: 'web/.../jnpf-web-datascreen-vue3/src/api/visual.js removeVisualData()' }, + notes: ['v0.11+ 改用 webapi 镜像 (loadVisualData.removeVisualData)', '谨慎操作'], }) return cmd } diff --git a/src/commands/bigscreen/update.ts b/src/commands/bigscreen/update.ts index 55bbbc4..d654e3d 100644 --- a/src/commands/bigscreen/update.ts +++ b/src/commands/bigscreen/update.ts @@ -1,16 +1,15 @@ /** * commands/bigscreen/update.ts — 大屏修改 * - * v0.11+ Phase 2 新增: 大屏 CRUD 闭环 (P0) - * - * API: PUT /api/extend/BigData/{id} - * 注: 实际 web 端在 jnpf-web-datascreen-vue3 用 /visual/update (v2 审计) - * 但 dacli 现有代码统一用 /extend/BigData, 保持兼容 + * v0.11+ Phase 2: webapi 化 (loadVisualData.getVisualDataInfo + updateVisualData) + * 替代 v0.10 直接 c.get/c.putJson + * 注: 大屏 web 端在 jnpf-web-datascreen-vue3 (v2 审计已修正) */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installAiHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' +import { initWebapi, loadVisualData } from '../../webapi/visualdata.ts' interface Opts { id: string @@ -22,7 +21,7 @@ interface Opts { export function buildBigscreenUpdateCommand(): Command { const cmd = new Command('update') - .description('大屏修改 (改 fullName/enCode/category, PUT 语义)') + .description('大屏修改 (改 fullName/enCode/category, PUT 语义, v0.11+ webapi)') .requiredOption('--id ', '大屏 id') .option('--fullName ', '大屏名') .option('--enCode ', '大屏编码') @@ -30,18 +29,26 @@ export function buildBigscreenUpdateCommand(): Command { .option('--json', '原始 JSON 输出', false) .action(async (opts: Opts) => { const c = await JnpfClient.fromToken() - const origR = await c.get | null>(`/extend/BigData/${opts.id}`) - if (origR.code !== 200 || !origR.data) { + await initWebapi(c) + // web 端 updateVisualData(id, data) 接受 (id, data) + // 走 getInfo 拿原数据 + const wrapper = (await loadVisualData.getVisualDataInfo?.(opts.id) || + (await loadVisualData.getInfo?.(opts.id))) as { data?: Record } | Record + const orig = (wrapper as { data?: Record }).data || (wrapper as Record) + if (!orig) { log.error(`bigscreen update 失败: 拉原大屏 id=${opts.id} 失败`) process.exit(1) } - const body: Record = { ...(origR.data as Record), id: opts.id } + 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 - log.info(`PUT /extend/BigData/${opts.id}`) - const r = await c.putJson(`/extend/BigData/${opts.id}`, body) - if (r.code !== 200) { + log.info(`loadVisualData.updateVisualData (id=${opts.id})`) + // web 端 update(id, data) 调用 + const r = (await ( + loadVisualData.updateVisualData?.(opts.id, body) || loadVisualData.update?.(opts.id, body) + )) as { code?: number; msg?: string; data?: unknown } + if (r.code !== 200 && r.code !== undefined) { log.error(`bigscreen update 失败 (code=${r.code}): ${r.msg}`) if (opts.json) printJson(r) process.exit(1) @@ -50,12 +57,12 @@ export function buildBigscreenUpdateCommand(): Command { if (opts.json) printJson(r.data) }) installAiHelpHook(cmd, { - purpose: '大屏修改. 改 fullName/enCode/category, PUT 语义, 未传保留.', + purpose: '大屏修改. 改 fullName/enCode/category, PUT 语义.', required: { '--id': '大屏 id' }, optional: { '--fullName': '大屏名', '--enCode': '大屏编码', '--category': '分类' }, example: 'dacli bigscreen update --id=123 --fullName=新名', - source: { api: 'PUT /api/extend/BigData/{id}' }, - notes: ['v0.11+ P0 新增', '未传字段保留 (PUT 语义)'], + source: { api: 'POST /api/visualdata/update (jnpf-web-datascreen-vue3)', ref: 'web/.../jnpf-web-datascreen-vue3/src/api/visual.js updateVisualData()' }, + notes: ['v0.11+ 改用 webapi 镜像 (loadVisualData.updateVisualData)', '大屏 web 端在 jnpf-web-datascreen-vue3'], }) return cmd } diff --git a/src/commands/workflow/delete.ts b/src/commands/workflow/delete.ts index 90f5607..8f413f7 100644 --- a/src/commands/workflow/delete.ts +++ b/src/commands/workflow/delete.ts @@ -1,20 +1,20 @@ /** * commands/workflow/delete.ts — 流程模板删除 * - * v0.11+ Phase 2 新增: 流程模板 CRUD 闭环 - * - * API: DELETE /api/workflow/template/{id} + * v0.11+ Phase 2: webapi 化 (loadWorkflow.delFlow) + * 替代 v0.10 直接 c.del */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installAiHelpHook } from '../../core/help.ts' import { log } from '../../core/log.ts' +import { initWebapi, loadWorkflow } from '../../webapi/workflow.ts' interface Opts { id: string; yes?: boolean } export function buildWorkflowDeleteCommand(): Command { const cmd = new Command('delete') - .description('流程模板删除 (硬删, 无回收)') + .description('流程模板删除 (硬删, 无回收, v0.11+ webapi)') .requiredOption('--id ', '流程模板 id') .option('--yes', '跳过确认', false) .action(async (opts: Opts) => { @@ -23,8 +23,10 @@ export function buildWorkflowDeleteCommand(): Command { process.exit(2) } const c = await JnpfClient.fromToken() - const r = await c.del(`/workflow/template/${opts.id}`) - if (r.code !== 200) { + await initWebapi(c) + log.info(`loadWorkflow.delFlow (id=${opts.id})`) + const r = (await loadWorkflow.delFlow(opts.id)) as { code?: number; msg?: string } + if (r.code !== 200 && r.code !== undefined) { log.error(`workflow delete 失败: ${r.msg}`) process.exit(1) } @@ -34,8 +36,8 @@ export function buildWorkflowDeleteCommand(): Command { 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 会失效', '谨慎操作'], + source: { api: 'DELETE /api/workflow/template/{id}', ref: 'web/.../api/workFlow/template.ts delFlow()' }, + notes: ['v0.11+ 改用 webapi 镜像 (loadWorkflow.delFlow)', '引用该流程的 form 会失效', '谨慎操作'], }) return cmd } diff --git a/src/commands/workflow/info.ts b/src/commands/workflow/info.ts index 045b4ba..dd22f6d 100644 --- a/src/commands/workflow/info.ts +++ b/src/commands/workflow/info.ts @@ -1,34 +1,34 @@ /** * commands/workflow/info.ts — 流程模板详情 * - * v0.11+ Phase 2 新增: 流程模板 CRUD 闭环 (P0) - * - * API: GET /api/workflow/template/{id} + * v0.11+ Phase 2: webapi 化 (loadWorkflow.getInfo) + * 替代 v0.10 直接 c.get */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installAiHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' +import { initWebapi, loadWorkflow } from '../../webapi/workflow.ts' interface Opts { id: string; json?: boolean } export function buildWorkflowInfoCommand(): Command { const cmd = new Command('info') - .description('流程模板详情 (含 category/enabledMark/version/关联 form)') + .description('流程模板详情 (含 category/enabledMark/version/关联 form, v0.11+ webapi)') .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 不存在'}`) + await initWebapi(c) + const d = (await loadWorkflow.getInfo(opts.id)) as Record + if (!d) { + log.error(`workflow info 失败: id=${opts.id} 不存在`) process.exit(1) } if (opts.json) { - printJson(r.data) + printJson(d) return } - const d = r.data log.info(`流程模板详情 (id=${opts.id})`) console.log(` fullName : ${d.fullName}`) console.log(` enCode : ${d.enCode}`) @@ -39,12 +39,12 @@ export function buildWorkflowInfoCommand(): Command { console.log(` description : ${d.description || '-'}`) }) installAiHelpHook(cmd, { - purpose: '流程模板详情. AI 引用 workflow id 验证 (P0 闭环, 之前只有 list/launch/approve/decision).', + purpose: '流程模板详情. AI 引用 workflow id 验证 (P0 闭环).', required: { '--id': '流程模板 id' }, optional: { '--json': '原始 JSON 输出' }, example: 'dacli workflow info --id=1234567890', - source: { api: 'GET /api/workflow/template/{id}' }, - notes: ['v0.11+ P0 新增, 闭环 CRUD 必需'], + source: { api: 'GET /api/workflow/template/{id}', ref: 'web/.../api/workFlow/template.ts getInfo()' }, + notes: ['v0.11+ 改用 webapi 镜像 (loadWorkflow.getInfo)'], }) return cmd } diff --git a/src/commands/workflow/update.ts b/src/commands/workflow/update.ts index 52db7a3..7803832 100644 --- a/src/commands/workflow/update.ts +++ b/src/commands/workflow/update.ts @@ -1,14 +1,14 @@ /** * commands/workflow/update.ts — 流程模板修改 * - * v0.11+ Phase 2 新增: 流程模板 CRUD 闭环 - * - * API: PUT /api/workflow/template/{id} + * v0.11+ Phase 2: webapi 化 (loadWorkflow.getInfo + update) + * 替代 v0.10 直接 c.get/c.putJson */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installAiHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' +import { initWebapi, loadWorkflow } from '../../webapi/workflow.ts' interface Opts { id: string @@ -22,7 +22,7 @@ interface Opts { export function buildWorkflowUpdateCommand(): Command { const cmd = new Command('update') - .description('流程模板修改 (改 fullName/enCode/category/enabledMark, PUT 语义)') + .description('流程模板修改 (PUT 语义, v0.11+ webapi)') .requiredOption('--id ', '流程模板 id') .option('--fullName ', '中文名') .option('--enCode ', '英文编码') @@ -32,8 +32,8 @@ export function buildWorkflowUpdateCommand(): Command { .option('--json', '原始 JSON 输出', false) .action(async (opts: Opts) => { const c = await JnpfClient.fromToken() - // 拉原模板 - const orig = (await c.get>(`/workflow/template/${opts.id}`)).data + await initWebapi(c) + const orig = (await loadWorkflow.getInfo(opts.id)) as Record if (!orig) { log.error(`workflow update 失败: 拉原模板 id=${opts.id} 失败`) process.exit(1) @@ -44,9 +44,9 @@ export function buildWorkflowUpdateCommand(): Command { 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.info(`loadWorkflow.update (id=${opts.id})`) + const r = (await loadWorkflow.update(body)) as { code?: number; msg?: string; data?: unknown } + if (r.code !== 200 && r.code !== undefined) { log.error(`workflow update 失败 (code=${r.code}): ${r.msg}`) if (opts.json) printJson(r) process.exit(1) @@ -55,12 +55,12 @@ export function buildWorkflowUpdateCommand(): Command { if (opts.json) printJson(r.data) }) installAiHelpHook(cmd, { - purpose: '流程模板修改 (改 fullName/enCode/category/enabledMark/description). PUT 语义, 未传保留.', + purpose: '流程模板修改 (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 语义)'], + source: { api: 'PUT /api/workflow/template/{id}', ref: 'web/.../api/workFlow/template.ts update()' }, + notes: ['v0.11+ 改用 webapi 镜像 (loadWorkflow.update)'], }) return cmd }