auto(bfc0cfa2c3a4): session end @ 2026-07-21T12:59:18 (+1f)
This commit is contained in:
1 parent
a104101a8a
commit
dfeb935ac8
1 file changed
+49
-2
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* commands/print/create.ts — 新建打印模板 (v0.11e+ Phase D1 wire up, v3.0+ 重构)
|
||||
* commands/print/create.ts — 新建打印模板 (v0.11e+ Phase D1 wire up, v3.0+ 重构, v2.1+ 三层接入)
|
||||
*
|
||||
* 决策 6: 打印模板 webType=1-2 (printDev), 不需要物理表, 绑 form 数据
|
||||
*
|
||||
@@ -17,6 +17,13 @@
|
||||
* - 改用独立 _validate.ts (不再复用 report/_validate.ts)
|
||||
* - 回归审计发现 print 有 8 字段, report 只有 2-4 字段, 借用导致校验不全
|
||||
* - 详见 dacli/docs/cmd-review/regression-2026-06-29.md
|
||||
*
|
||||
* v2.1+ (2026-07-21) 三层接入 (跨命令 auto-fix 模式, 参照 dict/typecreate.ts):
|
||||
* L1: --verbose / --json 三模式 (commands/_output_filter.ts:setupOutputFilter)
|
||||
* L2: 跨命令 auto-fix pipeline, enCode 含 `-`/`_` 自动 strip (S-X1 silent, BS-新38)
|
||||
* fullName 含 space/parens 自动 soften (S-X2 silent, BS-新52)
|
||||
* 已有 printDev 重名 → suggest 加 `<appCode>` 前缀 (G-X1 suggest)
|
||||
* L3: 完成后落 CommandLog, `dacli log last --detail` 可查 (含回滚命令)
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
@@ -29,6 +36,8 @@ import {
|
||||
createPrintDev,
|
||||
getPrintDevList,
|
||||
} from '../../webapi/printDev.ts'
|
||||
import { runCommandAutoFix, fetchExistingLists } from '../_auto_fix.ts' // v2.1+ (2026-07-21): 跨命令 auto-fix (S-X1/S-X2 silent + G-X1 suggest)
|
||||
import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): stdout 三模式 + CommandLog 落盘
|
||||
|
||||
interface CreateOpts {
|
||||
fullName: string
|
||||
@@ -41,6 +50,7 @@ interface CreateOpts {
|
||||
description?: string
|
||||
sortCode?: string
|
||||
json?: boolean
|
||||
verbose?: boolean
|
||||
}
|
||||
|
||||
export function buildPrintCreateCommand(): Command {
|
||||
@@ -55,9 +65,23 @@ export function buildPrintCreateCommand(): Command {
|
||||
.option('--visibleType <1|2>', '发布范围 (1=公开 2=权限设置, 仅 commonUse=1 时校验)', '1')
|
||||
.option('--description <desc>', '说明 (Textarea)')
|
||||
.option('--sortCode <n>', '排序码 (0-999999)', '0')
|
||||
.option('--verbose', '完整输出 (含 step machine、API 调用等过程日志)', false)
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
.action(async (opts: CreateOpts) => {
|
||||
// v2.1+ L1: stdout 三模式 — 默认 quiet, --verbose 全部输出, --json 原始 JSON
|
||||
setupOutputFilter(opts)
|
||||
const c = await JnpfClient.fromToken()
|
||||
const startTime = Date.now()
|
||||
|
||||
// v2.1+ L2 silent+assertive+suggest: 跨命令 auto-fix pipeline (S-X1/S-X2/G-X1)
|
||||
// - enCode 含 `-`/`_` 自动 strip (BS-新38 silent)
|
||||
// - fullName 含 space/parens 自动 soften (BS-新52 silent)
|
||||
// - 已有 printDev 重名 → suggest 加 `<appCode>` 前缀 (BS-47, 启用需 fetchExistingLists)
|
||||
const fixCtx = await fetchExistingLists(c, c.appCode)
|
||||
const cmdFix = runCommandAutoFix(opts as unknown as Record<string, unknown>, fixCtx)
|
||||
if (cmdFix.silent.length > 0) {
|
||||
Object.assign(opts, cmdFix.opts)
|
||||
}
|
||||
|
||||
// v3.0+ step machine 校验 (3 step: 基础信息 + 数值范围 + 条件校验)
|
||||
// 镜像 web printDev/Form.vue:29-92 schemas + ifShow 规则 (L65-77)
|
||||
@@ -102,6 +126,18 @@ export function buildPrintCreateCommand(): Command {
|
||||
if (rCode !== 200) {
|
||||
const enhanced = enhanceFromBackend(r.msg || '', 'print', { entity: 'print' })
|
||||
log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`)
|
||||
// v2.1+ L3: 失败也落 CommandLog (供 AI 查 dacli log last 看回滚建议)
|
||||
printCommandEnd({
|
||||
command: 'print create',
|
||||
appCode: c.appCode,
|
||||
result: 'failure',
|
||||
summary: { enCode: opts.enCode, fullName: opts.fullName },
|
||||
fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
|
||||
error: r.msg || `code=${rCode}`,
|
||||
duration_ms: Date.now() - startTime,
|
||||
verbose: opts.verbose,
|
||||
json: opts.json,
|
||||
})
|
||||
process.exit(1)
|
||||
}
|
||||
let id = r.id
|
||||
@@ -116,8 +152,19 @@ export function buildPrintCreateCommand(): Command {
|
||||
)
|
||||
id = found?.id
|
||||
}
|
||||
log.info(`✓ 打印模板创建成功 id=${id}`)
|
||||
log.ok(`✓ 打印模板创建成功 id=${id}`)
|
||||
if (opts.json) printJson({ ...(r as object), id })
|
||||
|
||||
// v2.1+ L3: 落 CommandLog + 打印摘要 + "详情: dacli log last" 提示
|
||||
printCommandEnd({
|
||||
command: 'print create',
|
||||
appCode: c.appCode,
|
||||
summary: { id, enCode: opts.enCode, category: opts.category, formId: opts.formId },
|
||||
fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
|
||||
duration_ms: Date.now() - startTime,
|
||||
verbose: opts.verbose,
|
||||
json: opts.json,
|
||||
})
|
||||
})
|
||||
installHelpHook(cmd, {
|
||||
purpose: '新建打印模板 (绑 form 数据, 套打)',
|
||||
|
||||
Reference in new issue
Block a user