From a9e42aa4478d92a5437f37183e2bb8850055d1f7 Mon Sep 17 00:00:00 2001 From: ssw Date: Thu, 2 Jul 2026 13:46:41 +0800 Subject: [PATCH] =?UTF-8?q?v0.15-1=20=E5=AE=9E=E6=96=BD:=20print=20CRUD=20?= =?UTF-8?q?=E5=8A=A0=20update=20+=20delete=20(3/15=20=E2=86=92=205/15,=202?= =?UTF-8?q?026-07-02)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit audit 2026-07-02 §role/print/di 报告 P2 #6: - print CRUD 3/15 (仅 list/info/create) - 缺 update/delete/copy/export/preview/version 等 12 命令 - v0.16+ 推大重构, 优先做最小 CRUD 闭环 (update + delete) v0.15-1 实施 (最小闭环): - 新建 print/update.ts (145 行) - 镜像 web updatePrintDev (PUT /api/system/printDev/{id}) - step machine 校验 fullName/enCode/category/commonUse/visibleType/icon/formId - spread orig 模式 (跟 form/workflow update 一致) - 新建 print/delete.ts (76 行) - 镜像 web delPrintDev (DELETE /api/system/printDev/{id}) - --yes TTY 确认 + id 数字校验 (P0-9 一致) - print/index.ts 注册 2 个新子命令 print webapi 引用覆盖: 3/15 → 5/15 (基础 CRUD 闭环) 剩余推 v0.16.1: copy/export/preview/version/batchData/getSelector 等 10 个 审计: dacli/docs/cmd-review/role-print-di-audit-2026-07-02.md §print 部分 --- src/commands/print/delete.ts | 85 ++++++++++++++++++ src/commands/print/index.ts | 9 ++ src/commands/print/update.ts | 162 +++++++++++++++++++++++++++++++++++ 3 files changed, 256 insertions(+) create mode 100644 src/commands/print/delete.ts create mode 100644 src/commands/print/update.ts diff --git a/src/commands/print/delete.ts b/src/commands/print/delete.ts new file mode 100644 index 0000000..0c00d51 --- /dev/null +++ b/src/commands/print/delete.ts @@ -0,0 +1,85 @@ +/** + * commands/print/delete.ts — 删除打印模板 + * + * v0.15+ (2026-07-02 v0.15-1): 镜像 web 端 delPrintDev + * 替代 v0.10 直接 c.delJson + * + * 镜像源: web/apps/jnpf-web-apps-main/src/api/system/printDev.ts:28 delPrintDev(id) + * web 端: defHttp.delete({ url: Api.Prefix + '/' + id }) + * 端点: DELETE /api/system/printDev/{id} (走 30000 jnpf-admin) + * + * 后端: PrintDevController @DeleteMapping("/{id}") + * + * v0.15+ 跟 report delete 一致: + * - --yes 跳过 TTY 确认 + * - id 数字校验 (跟 portal setDefault P2-4 / role assign P0-9 一致) + */ +import { Command } from 'commander' +import { JnpfClient } from '../../core/client.ts' +import { installAiHelpHook } from '../../core/help.ts' +import { log, printJson } from '../../core/log.ts' +import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' +import { initWebapi as initPrintDevWebapi, loadPrintDev } from '../../webapi/printDev.ts' + +interface DeleteOpts { + id: string + yes?: boolean + json?: boolean +} + +export function buildPrintDeleteCommand(): Command { + const cmd = new Command('delete') + .description('删除打印模板 (v0.15+ 镜像 web 端 delPrintDev, 走 /api/system/printDev/{id})') + .requiredOption('--id ', '打印模板 id') + .option('--yes', '跳过 TTY 确认 (强制删除)', false) + .option('--json', '原始 JSON 输出', false) + .action(async (opts: DeleteOpts) => { + // v0.15+ (P0-9): id 数字校验 (跟 portal/role 一致) + const idRegex = /^\d{10,30}$/ + if (!idRegex.test(opts.id)) { + log.error(`--id "${opts.id}" 不是合法 JNPF id (期望纯数字 10-30 位)`) + log.error('提示: 用 `dacli print list` 查 id, 别传 fullName/enCode') + process.exit(1) + } + + // v0.15+ TTY 确认 (跟 report delete 一致) + if (!opts.yes && process.stdin.isTTY) { + log.warn(`即将删除打印模板 id=${opts.id}, 此操作不可恢复`) + log.warn(' 提示: 加 --yes 跳过确认 (AI/脚本场景)') + process.exit(1) + } + + const c = await JnpfClient.fromToken() + await initPrintDevWebapi(c) + + // 镜像 web 端 delPrintDev(id) → defHttp.delete + const r = (await loadPrintDev.delPrintDev(opts.id)) as { code?: number; msg?: string } + if (r && r.code !== undefined && r.code !== 200) { + log.error(`print delete 失败 (code=${r.code}): ${r.msg}`) + const enhanced = enhanceFromBackend(r.msg || '', 'print', { entity: 'print' }) + log.error(` ${formatErrorLine(enhanced, { step: 0, stepName: '后端API' })}`) + process.exit(1) + } + log.ok(`✓ 打印模板已删除 id=${opts.id} (v0.15+ webapi 镜像)`) + if (opts.json) printJson({ id: opts.id, code: 200, msg: '删除成功' }) + }) + installAiHelpHook(cmd, { + purpose: '删除打印模板 (v0.15+ 镜像 web delPrintDev)', + required: { '--id': '打印模板 id' }, + optional: { '--yes': '跳过 TTY 确认 (强制删除)' }, + example: [ + 'dacli print delete --id=585817367276160133 --yes', + ], + source: { + web: 'web/apps/jnpf-web-apps-main/src/api/system/printDev.ts:28 delPrintDev(id)', + api: 'DELETE /api/system/printDev/{id} (走 webapi Proxy, 端口 30000 jnpf-admin)', + ref: 'jnpf/后端/jnpf-system/jnpf-system-controller/.../PrintDevController.java @DeleteMapping', + }, + notes: [ + 'v0.15+ 走 webapi 镜像 (loadPrintDev.delPrintDev), 替代旧版 c.delete', + '**v0.15+ (P0-9)**: --yes 跳过 TTY 确认 (跟 report/form delete 一致)', + '**v0.15+ (P0-9)**: id 数字校验, 输错字符串提前 exit 1', + ], + }) + return cmd +} diff --git a/src/commands/print/index.ts b/src/commands/print/index.ts index 0af9acf..29ed7ef 100644 --- a/src/commands/print/index.ts +++ b/src/commands/print/index.ts @@ -3,20 +3,29 @@ * * 打印模板 (onlineDev/printDev + teamwork/printTemplate) * + * v0.15+ (2026-07-02) 加 update + delete: 完整 CRUD 闭环 (3/15 → 5/15) + * 剩余 (推 v0.16): copy/export/preview/version/batchData 等 10 个 + * * 子命令: * list 列表 * info 详情 * create 新建 (绑 form 数据) + * update 修改 (v0.15+) + * delete 删除 (v0.15+) */ import { Command } from 'commander' import { buildPrintListCommand } from './list.ts' import { buildPrintInfoCommand } from './info.ts' import { buildPrintCreateCommand } from './create.ts' +import { buildPrintUpdateCommand } from './update.ts' // v0.15+ +import { buildPrintDeleteCommand } from './delete.ts' // v0.15+ export function buildPrintCommand(): Command { const cmd = new Command('print').description('打印模板 CRUD (绑 form 数据, 套打)') cmd.addCommand(buildPrintListCommand()) cmd.addCommand(buildPrintInfoCommand()) cmd.addCommand(buildPrintCreateCommand()) + cmd.addCommand(buildPrintUpdateCommand()) + cmd.addCommand(buildPrintDeleteCommand()) return cmd } diff --git a/src/commands/print/update.ts b/src/commands/print/update.ts new file mode 100644 index 0000000..417a160 --- /dev/null +++ b/src/commands/print/update.ts @@ -0,0 +1,162 @@ +/** + * commands/print/update.ts — 修改打印模板 + * + * v0.15+ (2026-07-02 v0.15-1): 镜像 web 端 updatePrintDev + * 替代 v0.10 直接 c.putJson + * + * 镜像源: web/apps/jnpf-web-apps-main/src/api/system/printDev.ts:24 updatePrintDev(data) + * web 端: defHttp.put({ url: Api.Prefix + '/' + data.id, data }) + * 端点: PUT /api/system/printDev/{id} (走 30000 jnpf-admin) + * + * 后端: PrintDevController @PutMapping("/{id}") + * PrintUpForm extends PrintCrForm + * + * 复用 print/_validate.ts (199 行, 9 字段含 commonUse/visibleType/icon/formId) + */ +import { Command } from 'commander' +import { JnpfClient } from '../../core/client.ts' +import { installAiHelpHook } from '../../core/help.ts' +import { log, printJson } from '../../core/log.ts' +import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' +import { + initWebapi as initPrintDevWebapi, + loadPrintDev, +} from '../../webapi/printDev.ts' +import { validatePrintCreate } from './_validate.ts' + +interface UpdateOpts { + id: string + fullName?: string + enCode?: string + category?: string + type?: string + sortCode?: string + enabledMark?: string + commonUse?: string + visibleType?: string + icon?: string + formId?: string + description?: string + json?: boolean +} + +/** PrintCrForm 字段 (跟 create 一致, 镜像 web 端 updatePrintDev body) */ +interface PrintForm { + id?: string + fullName?: string + enCode?: string + category?: string + type?: number + sortCode?: number + enabledMark?: number + commonUse?: number + visibleType?: number + icon?: string + formId?: string + description?: string +} + +export function buildPrintUpdateCommand(): Command { + const cmd = new Command('update') + .description('修改打印模板 (v0.15+ 镜像 web updatePrintDev, 走 /api/system/printDev/{id} 端口 30000)') + .requiredOption('--id ', '打印模板 id') + .option('--fullName ', '中文名') + .option('--enCode ', '英文编码') + .option('--category ', '分类 id') + .option('--type ', '类型 (1=简单打印 2=设计器打印 3=模板打印)') + .option('--sortCode ', '排序 0-999999', '0') + .option('--enabledMark <0|1>', '启用 (默认 1)', '1') + .option('--commonUse <0|1>', '常用 (默认 0, type=2 时必填)', '0') + .option('--visibleType <0|1|2>', '可见范围 (0=全部 1=本角色 2=本部门, 默认 0)', '0') + .option('--icon ', '图标 (commonUse=1 时必填)') + .option('--formId ', '绑定的表单 id (type=2 必填)') + .option('--description ', '说明') + .option('--json', '原始 JSON 输出', false) + .action(async (opts: UpdateOpts) => { + const c = await JnpfClient.fromToken() + await initPrintDevWebapi(c) + + // 1. 拉原 print 模板 (跟 web 一致: getPrintDevInfo 拿全字段) + const orig = (await loadPrintDev.getPrintDevInfo(opts.id)) as PrintForm + if (!orig || !orig.id) { + log.error(`print update 失败: 拉原模板 id=${opts.id} 失败`) + process.exit(1) + } + + // 2. step machine 校验 (校验 user-provided 字段, 跟 create 行为一致) + // 校验失败 exit 1, 跟其他 create/update 命令对齐 + const toValidate: Record = {} + if (opts.fullName !== undefined) toValidate.fullName = opts.fullName + if (opts.enCode !== undefined) toValidate.enCode = opts.enCode + if (opts.category !== undefined) toValidate.category = opts.category + if (opts.commonUse !== undefined) toValidate.commonUse = Number(opts.commonUse) + if (opts.visibleType !== undefined) toValidate.visibleType = Number(opts.visibleType) + if (opts.icon !== undefined) toValidate.icon = opts.icon + if (opts.formId !== undefined) toValidate.formId = opts.formId + if (Object.keys(toValidate).length > 0) { + const v = validatePrintCreate(toValidate as Parameters[0]) + if (!v.ok) { + for (const err of v.errors) log.error(` ${err.message}`) + process.exit(1) + } + } + + // 3. 构造 body (跟 web 端 handleSubmit 一致, spread orig 覆盖用户输入) + // 后端 PrintUpForm 必填所有字段, 跟 update 一致先 getPrintDevInfo 拿全字段 + const body: Record = { ...orig, id: opts.id } + if (opts.fullName !== undefined) body.fullName = opts.fullName + if (opts.enCode !== undefined) body.enCode = opts.enCode + if (opts.category !== undefined) body.category = opts.category + if (opts.type !== undefined) body.type = Number(opts.type) + if (opts.sortCode !== undefined) body.sortCode = Number(opts.sortCode) + if (opts.enabledMark !== undefined) body.enabledMark = Number(opts.enabledMark) + if (opts.commonUse !== undefined) body.commonUse = Number(opts.commonUse) + if (opts.visibleType !== undefined) body.visibleType = Number(opts.visibleType) + if (opts.icon !== undefined) body.icon = opts.icon + if (opts.formId !== undefined) body.formId = opts.formId + if (opts.description !== undefined) body.description = opts.description + + // 4. 调 webapi updatePrintDev (走 web 端镜像, 端点 /api/system/printDev/{id}) + const r = (await loadPrintDev.updatePrintDev(body)) as { code?: number; msg?: string } + if (r && r.code !== undefined && r.code !== 200) { + log.error(`print update 失败 (code=${r.code}): ${r.msg}`) + const enhanced = enhanceFromBackend(r.msg || '', 'print', { entity: 'print' }) + log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`) + process.exit(1) + } + log.ok(`✓ 打印模板修改成功 id=${opts.id} enCode=${body.enCode}`) + if (opts.json) printJson({ id: opts.id, code: 200, msg: '更新成功', raw: r }) + }) + installAiHelpHook(cmd, { + purpose: '修改打印模板 (v0.15+ 镜像 web 端 updatePrintDev)', + required: { '--id': '打印模板 id' }, + optional: { + '--fullName': '中文名', + '--enCode': '英文编码', + '--category': '分类 id', + '--type': '类型 (1=简单 2=设计器 3=模板)', + '--sortCode': '排序 0-999999', + '--enabledMark': '启用 (0/1)', + '--commonUse': '常用 (0/1, type=2 必填)', + '--visibleType': '可见范围 (0=全部 1=本角色 2=本部门)', + '--icon': '图标 (commonUse=1 必填)', + '--formId': '绑定的表单 id (type=2 必填)', + '--description': '说明', + }, + example: [ + 'dacli print update --id=585817367276160133 --fullName=新名称', + 'dacli print update --id=585817367276160133 --enabledMark=0', + ], + source: { + web: 'web/apps/jnpf-web-apps-main/src/api/system/printDev.ts:24 updatePrintDev', + api: 'PUT /api/system/printDev/{id} (走 webapi Proxy, 端口 30000 jnpf-admin)', + ref: 'jnpf/后端/jnpf-system/jnpf-system-controller/.../PrintDevController.java @PutMapping', + }, + notes: [ + 'v0.15+ 走 webapi 镜像 (loadPrintDev.updatePrintDev), 替代旧版 c.putJson', + '跟 create 一致, step machine 校验 fullName/enCode/category/commonUse/visibleType/icon/formId', + '后端 PrintUpForm 必填全字段, 走 spread orig 模式 (跟 form/workflow update 一致)', + ], + }) + return cmd +}