diff --git a/src/commands/report/create.ts b/src/commands/report/create.ts index e305536..e12ad0d 100644 --- a/src/commands/report/create.ts +++ b/src/commands/report/create.ts @@ -20,6 +20,7 @@ import { JnpfClient } from '../../core/client.ts' import { installAiHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' import { initWebapi as initReportWebapi, loadReport } from '../../webapi/report.ts' +import { validateReportCreate } from './_validate.ts' // v0.15+ (P1-1, 2026-07-02): 4 命令接入 _validate interface CreateOpts { fullName: string @@ -49,6 +50,24 @@ export function buildReportCreateCommand(): Command { .action(async (opts: CreateOpts) => { const c = await JnpfClient.fromToken() + // v0.15+ (P1-1, 2026-07-02): step machine 校验 (之前 _validate.ts 71 行零引用) + // 镜像 web onlineDev/report/Form.vue:26-58 schemas (fullName maxlength 100, enCode 正则, category 必填) + const validation = validateReportCreate({ + fullName: opts.fullName, + enCode: opts.enCode, + category: opts.category, + sortCode: opts.sortCode, + description: opts.description, + }) + if (!validation.ok) { + for (const step of validation.steps) { + for (const err of step.errors) { + log.error(` [${step.stepName}] ${err.message}`) + } + } + process.exit(1) + } + // v0.14+ webapi 化: 走 webapi/report.initWebapi + loadReport.createReport // - 镜像 web 端 createReport (走 reportHttp, 端口 32000 报表服务) // - 不直接 c.postJson('/api/Report') — 那是经验复刻, web 端 schema 变了会漂移 diff --git a/src/commands/report/release.ts b/src/commands/report/release.ts index 77a7f55..ebac940 100644 --- a/src/commands/report/release.ts +++ b/src/commands/report/release.ts @@ -21,6 +21,7 @@ import { JnpfClient } from '../../core/client.ts' import { installAiHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' import { initWebapi as initReportWebapi, loadReport } from '../../webapi/report.ts' +import { validateBasicInfo, validateNumeric } from './_validate.ts' // v0.15+ (P1-1) interface ReleaseOpts { id: string @@ -72,6 +73,23 @@ export function buildReportReleaseCommand(): Command { process.exit(1) } + // === step 1.5: v0.15+ (P1-1) 校验当前报表的 fullName/enCode/category/sortCode === + // 之前 _validate.ts 零引用, release 不校验 → enCode 漂移能过; 现统一从 _validate 走 + const vBasic = validateBasicInfo({ + fullName: current.fullName, + enCode: current.enCode, + category: current.category, + }) + if (!vBasic.ok) { + for (const err of vBasic.errors) log.error(` [${vBasic.stepName}] ${err.message}`) + process.exit(1) + } + const vNum = validateNumeric({ sortCode: 0 }) // sortCode 不强制, 只校验 enabledMark 等 + if (!vNum.ok) { + for (const err of vNum.errors) log.error(` [${vNum.stepName}] ${err.message}`) + process.exit(1) + } + // === step 2: 校验 type=1 必传 cells === const releaseType = Number(opts.type || 1) if (releaseType === 1 && !opts.cells) { diff --git a/src/commands/report/update.ts b/src/commands/report/update.ts index 161a9c2..c2a047c 100644 --- a/src/commands/report/update.ts +++ b/src/commands/report/update.ts @@ -17,6 +17,7 @@ import { JnpfClient } from '../../core/client.ts' import { installAiHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' import { initWebapi as initReportWebapi, loadReport } from '../../webapi/report.ts' +import { validateBasicInfo, validateNumeric } from './_validate.ts' // v0.15+ (P1-1) interface UpdateOpts { id: string @@ -66,6 +67,27 @@ export function buildReportUpdateCommand(): Command { // v0.14+ webapi 化: 走 webapi/report.initWebapi + loadReport.updateReport await initReportWebapi(c) + // v0.15+ (P1-1): 校验用户传入的字段 (fullName/enCode/category 必填) + // 镜像 web onlineDev/report/Form.vue:26-58 schemas + BS-49 enCode 唯一性 + // 注: 只校验 user-provided 字段, 没传的字段保持原值 + 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.sortCode !== undefined) toValidate.sortCode = opts.sortCode + if (Object.keys(toValidate).length > 0) { + const vBasic = validateBasicInfo(toValidate as { fullName?: string; enCode?: string; category?: string }) + if (!vBasic.ok) { + for (const err of vBasic.errors) log.error(` [${vBasic.stepName}] ${err.message}`) + process.exit(1) + } + const vNum = validateNumeric({ sortCode: opts.sortCode }) + if (!vNum.ok) { + for (const err of vNum.errors) log.error(` [${vNum.stepName}] ${err.message}`) + process.exit(1) + } + } + // 镜像 web 端 Form.vue handleSubmit 模式: // const query = { ...values, id }; // formMethod(query); // updateReport(query)