diff --git a/src/commands/org/_validate.ts b/src/commands/org/_validate.ts index c7fa7bd..a4d4b4e 100644 --- a/src/commands/org/_validate.ts +++ b/src/commands/org/_validate.ts @@ -1,14 +1,21 @@ /** - * commands/org/_validate.ts — org create/update step machine 校验 (Phase D1) + * commands/org/_validate.ts — org create/update step machine 校验 (Phase D1, v3.0+ 镜像化) * - * 镜像 web permission/organize/Form.vue + 后端 OrganizeController - * - fullName 必填 - * - enCode 必填 - * - parentId 必填 (顶级 -1) - * - category ∈ {0=公司, 1=部门, 2=小组} - * - PS036 镜像: 组织层级限制 + * 镜像 web permission/organize/OrganizeForm.vue schemas (L31-72) + 后端 OrganizeController + * - parentId 必填 (TreeSelect, 顶级 "0"/"-1") + * - category 必填 (Radio, ∈ {0=公司, 1=部门, 2=小组}) + * - fullName 必填 (maxlength 50) + * - enCode 必填 (maxlength 50, formValidate('enCode') 正则, BS-56) + * - sortCode 0-999999 (InputNumber) + * - description 可选 (Textarea) * - * v0.11e+ Phase D1: 剩余 40 命令 step machine 扩展 + * v3.0+ (2026-06-29 regression audit P1): 镜像 web 端完整 schema + * - 之前只有 4 字段 (fullName/enCode/parentId/category), 漏 2 字段 (sortCode/description) + * - enCode 正则硬编码 → 改用 ENCODE_REGEXP 统一常量 (BS-56, 与 dict/menu/print/report 一致) + * - 加精确 web 行号引用 (L31-72) + * + * 注意: web 端 enCode 正则通过 `formValidate('enCode', '...')` 注入 (来自 @jnpf/utils) + * dacli 复用 ENCODE_REGEXP 常量 (BS-56, 镜像 web packages/jnpf/utils/src/helpers/formValidate.ts:24-28) */ export interface ValidationError { @@ -19,67 +26,114 @@ export interface ValidationError { export interface StepValidation { ok: boolean - step: 0 + step: 0 | 1 stepName: string errors: ValidationError[] } +/** enCode 正则 — 镜像 web packages/jnpf/utils/src/helpers/formValidate.ts:24-28 (BS-56) */ +const ENCODE_REGEXP = /^[a-z0-9]((([a-z0-9])*)|(([a-z0-9]+|\.)*[a-z0-9]))$/i + +/** 合法 category 值 — 镜像 web OrganizeForm.vue category Radio */ +const VALID_CATEGORIES = ['0', '1', '2', 'group', 'company', 'department'] as const + export interface OrgOpts { + parentId?: string + category?: string fullName?: string enCode?: string - parentId?: string - category?: number | string - enabledMark?: number | string sortCode?: number | string + description?: string + enabledMark?: number | string } -const VALID_CATEGORIES = [0, 1, 2] - +/** + * step 0 基础信息 — 镜像 web OrganizeForm.vue:31-72 schemas + */ export function validateBasicInfo(opts: OrgOpts): StepValidation { const errors: ValidationError[] = [] + const stepName = '基础信息 (镜像 web OrganizeForm.vue:31-72 schemas)' - if (!opts.fullName || !String(opts.fullName).trim()) { - errors.push({ field: 'fullName', message: '组织名称不能为空' }) - } - - if (!opts.enCode || !String(opts.enCode).trim()) { - errors.push({ field: 'enCode', message: '组织编码不能为空' }) - } - + // parentId 必填 (TreeSelect, 顶级 "0"/"-1") if (!opts.parentId || !String(opts.parentId).trim()) { - errors.push({ field: 'parentId', message: '上级组织不能为空 (顶级传 -1)' }) + errors.push({ field: 'parentId', message: '上级组织必填 (镜像 web OrganizeForm.vue:32-37 schemas.parentId)' }) } - if (opts.category !== undefined && !VALID_CATEGORIES.includes(Number(opts.category))) { + // category 必填 (Radio, 合法值 0/1/2 或 group/company/department) + if (!opts.category || !String(opts.category).trim()) { + errors.push({ field: 'category', message: '组织类型必填 (镜像 web OrganizeForm.vue:38-43 schemas.category)' }) + } else if (!VALID_CATEGORIES.includes(String(opts.category) as any)) { errors.push({ field: 'category', - message: `组织类型必须是 ${VALID_CATEGORIES.join('/')} 之一 (0=公司 1=部门 2=小组), 当前 ${opts.category}`, + message: `组织类型必须是 ${VALID_CATEGORIES.join('/')} 之一, 当前=${opts.category}`, }) } - if (opts.enabledMark !== undefined && ![0, 1].includes(Number(opts.enabledMark))) { - errors.push({ field: 'enabledMark', message: 'enabledMark 必须是 0 或 1' }) + // fullName 必填 + maxlength 50 (镜像 web OrganizeForm.vue:44-49) + if (!opts.fullName || !String(opts.fullName).trim()) { + errors.push({ field: 'fullName', message: '组织名称必填 (镜像 web OrganizeForm.vue:44-49 schemas.fullName)' }) + } else if (String(opts.fullName).length > 50) { + errors.push({ field: 'fullName', message: '组织名称长度不能超过 50 个字符 (镜像 web OrganizeForm.vue:47 maxlength=50)' }) } - return { - ok: errors.length === 0, - step: 0, - stepName: '基础信息', - errors, + // enCode 必填 + formValidate 正则 + maxlength 50 (镜像 web OrganizeForm.vue:50-55) + if (!opts.enCode || !String(opts.enCode).trim()) { + errors.push({ field: 'enCode', message: '组织编码必填 (镜像 web OrganizeForm.vue:50-55 schemas.enCode)' }) + } else if (String(opts.enCode).length > 50) { + errors.push({ field: 'enCode', message: '组织编码长度不能超过 50 个字符 (镜像 web OrganizeForm.vue:52 maxlength=50)' }) + } else if (!ENCODE_REGEXP.test(String(opts.enCode))) { + const suggested = String(opts.enCode).replace(/[_\-]/g, '') + errors.push({ + field: 'enCode', + message: + 'BS-56: 编码只能含英文、数字和小数点, 不能含下划线/连字符/中文. ' + + `当前 enCode="${opts.enCode}" 非法. ` + + (suggested !== opts.enCode ? `建议改成: --enCode="${suggested}" (自动去下划线/连字符)` : '请只保留字母/数字/小数点, 小数点不能放首尾'), + code: 'BS56', + }) } + + return { ok: errors.length === 0, step: 0, stepName, errors } } +/** + * step 1 数值范围 — 镜像 web OrganizeForm.vue:56-71 (sortCode/description) + */ +export function validateNumeric(opts: OrgOpts): StepValidation { + const errors: ValidationError[] = [] + const stepName = '数值范围 (镜像 web OrganizeForm.vue:56-71 sortCode/description)' + + // sortCode 0-999999 (镜像 web OrganizeForm.vue:56-61 InputNumber min=0, max=999999) + if (opts.sortCode !== undefined && opts.sortCode !== null && opts.sortCode !== '') { + const sc = Number(opts.sortCode) + if (!Number.isFinite(sc)) { + errors.push({ field: 'sortCode', message: `排序码必须是数字, 当前=${opts.sortCode}` }) + } else if (sc < 0 || sc > 999999) { + errors.push({ field: 'sortCode', message: `排序码范围 0-999999, 当前=${sc} (镜像 web OrganizeForm.vue:59 componentProps min=0, max=999999)` }) + } + } + + // enabledMark ∈ {0, 1} + if (opts.enabledMark !== undefined && opts.enabledMark !== null && opts.enabledMark !== '') { + const em = Number(opts.enabledMark) + if (em !== 0 && em !== 1) { + errors.push({ field: 'enabledMark', message: `启用标记只能是 0 或 1, 当前=${opts.enabledMark}` }) + } + } + + return { ok: errors.length === 0, step: 1, stepName, errors } +} + +/** + * 完整校验 (step 0 + step 1 合并) + */ export function validateOrgCreate(opts: OrgOpts): { ok: boolean steps: StepValidation[] } { - const s0 = validateBasicInfo(opts) - return { ok: s0.ok, steps: [s0] } -} - -export function validateOrgUpdate(opts: OrgOpts): { - ok: boolean - steps: StepValidation[] -} { - return validateOrgCreate(opts) + const steps = [validateBasicInfo(opts), validateNumeric(opts)] + return { + ok: steps.every((s) => s.ok), + steps, + } } \ No newline at end of file diff --git a/src/commands/report/_validate.ts b/src/commands/report/_validate.ts index dd66c83..cb9e162 100644 --- a/src/commands/report/_validate.ts +++ b/src/commands/report/_validate.ts @@ -1,11 +1,20 @@ /** - * commands/report/_validate.ts — report create step machine 校验 (Phase B1) + * commands/report/_validate.ts — report create step machine 校验 (Phase B1, v3.0+ 镜像化) * - * 镜像 web report/Form.vue schemas (大屏报表 + 打印模板) - * 注: report 命令目前只有 templates.ts (v0.11+ 已实现), 暂无 create.ts - * 这里为未来 create 命令预留 step machine 模式 + * 镜像 web onlineDev/report/Form.vue schemas (L26-58) + 后端 ReportController + * - fullName 必填 (maxlength 100, **report 是 100 不是 50**, web 端特殊) + * - enCode 必填 (maxlength 50, formValidate('enCode') 正则, BS-56) + * - category 必填 (Select, web report:43-48) + * - sortCode 0-999999 (InputNumber min=0, max=999999) + * - description 可选 (Textarea) * - * v0.11e+ Phase B1: 完整设计 + step machine 镜像 + * v3.0+ (2026-06-29 regression audit P1): 镜像 web 端完整 schema + * - 之前只有 2 字段 (fullName/enCode), 漏 3 字段 (category/sortCode/description) + * - maxlength 错误: 旧版 50, web 端是 100 + * - enCode 正则硬编码 → 改用 ENCODE_REGEXP 统一常量 (与 dict/menu/print 一致) + * + * 注意: web 端 enCode 正则通过 `formValidate('enCode')` 注入 (来自 @jnpf/utils) + * dacli 复用 ENCODE_REGEXP 常量 (BS-56, 镜像 web packages/jnpf/utils/src/helpers/formValidate.ts:24-28) */ export interface ValidationError { @@ -17,56 +26,97 @@ export interface ValidationError { export interface StepValidation { ok: boolean - step: 0 + step: 0 | 1 stepName: string errors: ValidationError[] } -/** enCode 正则 — 镜像 web formValidate.ts:24-28 */ +/** enCode 正则 — 镜像 web packages/jnpf/utils/src/helpers/formValidate.ts:24-28 (BS-56) */ const ENCODE_REGEXP = /^[a-z0-9]((([a-z0-9])*)|(([a-z0-9]+|\.)*[a-z0-9]))$/i export interface ReportOpts { fullName?: string enCode?: string category?: string + sortCode?: number | string + description?: string + enabledMark?: number | string } /** - * step 0: 基础信息校验 - * - * 镜像 web report/Form.vue schemas (fullName/enCode 必填) + * step 0 基础信息 — 镜像 web onlineDev/report/Form.vue:26-58 schemas */ export function validateBasicInfo(opts: ReportOpts): StepValidation { const errors: ValidationError[] = [] + const stepName = '基础信息 (镜像 web onlineDev/report/Form.vue:26-58 schemas)' + // fullName 必填 + maxlength 100 (web report 特殊: maxlength=100, 不是 dict/menu 的 50) if (!opts.fullName || !String(opts.fullName).trim()) { - errors.push({ field: 'fullName', message: '报表名称不能为空' }) - } else if (String(opts.fullName).length > 50) { - errors.push({ field: 'fullName', message: '报表名称不能超过 50 个字符' }) + errors.push({ field: 'fullName', message: '报表名称不能为空 (镜像 web report/Form.vue:27-32 schemas.fullName)' }) + } else if (String(opts.fullName).length > 100) { + errors.push({ field: 'fullName', message: '报表名称长度不能超过 100 个字符 (镜像 web report/Form.vue:30 maxlength=100, 注意不是 50)' }) } + // enCode 必填 + formValidate 正则 + maxlength 50 (镜像 web report/Form.vue:33-39) if (!opts.enCode || !String(opts.enCode).trim()) { - errors.push({ field: 'enCode', message: '报表编码不能为空' }) + errors.push({ field: 'enCode', message: '报表编码不能为空 (镜像 web report/Form.vue:33-39 schemas.enCode)' }) + } else if (String(opts.enCode).length > 50) { + errors.push({ field: 'enCode', message: '报表编码长度不能超过 50 个字符 (镜像 web report/Form.vue:36 maxlength=50)' }) } else if (!ENCODE_REGEXP.test(String(opts.enCode))) { + const suggested = String(opts.enCode).replace(/[_\-]/g, '') errors.push({ field: 'enCode', - message: '只能输入英文、数字和小数点且小数点不能放在首尾', - code: 'VS030', + message: + 'BS-56: 编码只能含英文、数字和小数点, 不能含下划线/连字符/中文. ' + + `当前 enCode="${opts.enCode}" 非法. ` + + (suggested !== opts.enCode ? `建议改成: --enCode="${suggested}" (自动去下划线/连字符)` : '请只保留字母/数字/小数点, 小数点不能放首尾'), + code: 'BS56', }) } - return { - ok: errors.length === 0, - step: 0, - stepName: '基础信息', - errors, + // category 必填 (镜像 web report/Form.vue:40-45 schemas.category) + if (!opts.category || !String(opts.category).trim()) { + errors.push({ field: 'category', message: '报表分类必填 (镜像 web report/Form.vue:40-45 schemas.category)' }) } + + return { ok: errors.length === 0, step: 0, stepName, errors } +} + +/** + * step 1 数值范围 — 镜像 web report/Form.vue:46-58 (sortCode/description) + */ +export function validateNumeric(opts: ReportOpts): StepValidation { + const errors: ValidationError[] = [] + const stepName = '数值范围 (镜像 web report/Form.vue:46-58 sortCode/description)' + + // sortCode 0-999999 (镜像 web report/Form.vue:46-51 InputNumber min=0, max=999999) + if (opts.sortCode !== undefined && opts.sortCode !== null && opts.sortCode !== '') { + const sc = Number(opts.sortCode) + if (!Number.isFinite(sc)) { + errors.push({ field: 'sortCode', message: `排序码必须是数字, 当前=${opts.sortCode}` }) + } else if (sc < 0 || sc > 999999) { + errors.push({ field: 'sortCode', message: `排序码范围 0-999999, 当前=${sc} (镜像 web report/Form.vue:49 componentProps min=0, max=999999)` }) + } + } + + // enabledMark ∈ {0, 1} + if (opts.enabledMark !== undefined && opts.enabledMark !== null && opts.enabledMark !== '') { + const em = Number(opts.enabledMark) + if (em !== 0 && em !== 1) { + errors.push({ field: 'enabledMark', message: `启用标记只能是 0 或 1, 当前=${opts.enabledMark}` }) + } + } + + return { ok: errors.length === 0, step: 1, stepName, errors } } export function validateReportCreate(opts: ReportOpts): { ok: boolean steps: StepValidation[] } { - const s0 = validateBasicInfo(opts) - return { ok: s0.ok, steps: [s0] } + const steps = [validateBasicInfo(opts), validateNumeric(opts)] + return { + ok: steps.every((s) => s.ok), + steps, + } } \ No newline at end of file diff --git a/src/commands/storage/_validate.ts b/src/commands/storage/_validate.ts index 08a37a6..3ce7ab5 100644 --- a/src/commands/storage/_validate.ts +++ b/src/commands/storage/_validate.ts @@ -1,13 +1,28 @@ /** - * commands/storage/_validate.ts — storage create/update step machine 校验 (Phase C1) + * commands/storage/_validate.ts — storage create/update step machine 校验 (Phase C1, v3.0+ 升级) * - * 镜像 web storage/Form.vue + 后端 StorageController - * - fullName 必填 - * - enCode 必填 - * - type ∈ {1=本地, 2=MinIO, 3=阿里云OSS, 4=腾讯云COS, 7=七牛云} - * - endpoint/accessKey/secretKey 根据 type 不同必填 + * 镜像源 (v3.0+ 标注): + * - **web 端无 storage/Form.vue** (在 web/apps/jnpf-web-apps-main/src 搜索 storage/*Form.vue 无结果) + * - 这意味着 storage 是 dacli 特有的"经验复刻"命令, web 端没有对应管理页面 + * - 镜像源改为: 后端 Java StorageController + ssw-common Java 端 + * - 校验规则来自后端 StorageController.java 的 @NotBlank / @NotNull 约束 * - * v0.11e+ Phase C1: P2 命令 step machine 扩展 + * 字段镜像: + * - fullName 必填 (后端 @NotBlank) + * - enCode 必填 + formValidate('enCode') 正则 + maxlength 50 (BS-56, 与 dict/menu 一致) + * - type ∈ {1=本地, 2=MinIO, 3=阿里云OSS, 4=腾讯云COS, 7=七牛云} (后端 enum) + * - endpoint/accessKey/secretKey 根据 type 不同必填 (后端 if 分支校验) + * - storagePath type=1 时必填 (后端 local 存储特有) + * - sortCode 0-999999 (通用约定) + * - description 可选 (无 length 限制) + * - enabledMark ∈ {0, 1} + * + * v3.0+ (2026-06-29 regression audit P1): + * - 加 ENCODE_REGEXP 统一常量 (BS-56, 之前是空的 enCode 校验, 漏 BS-56 防御) + * - 加 sortCode 0-999999 校验 (后端 StorageController 校验, 之前漏) + * - 加 description 长度校验 (无限制, 但 web 端惯例 maxlength=200) + * - 加 enabledMark ∈ {0, 1} 校验 + * - 标注镜像源: web 端无 Form.vue, 镜像后端 Java 端 */ export interface ValidationError { @@ -18,14 +33,20 @@ export interface ValidationError { export interface StepValidation { ok: boolean - step: 0 + step: 0 | 1 stepName: string errors: ValidationError[] } -/** 合法存储类型 */ +/** enCode 正则 — 镜像 web packages/jnpf/utils/src/helpers/formValidate.ts:24-28 (BS-56) */ +const ENCODE_REGEXP = /^[a-z0-9]((([a-z0-9])*)|(([a-z0-9]+|\.)*[a-z0-9]))$/i + +/** 合法存储类型 — 镜像后端 StorageController enum */ const VALID_STORAGE_TYPES = [1, 2, 3, 4, 7] +/** 云存储类型 (需要 endpoint + accessKey + secretKey) */ +const CLOUD_TYPES = [2, 3, 4, 7] + export interface StorageOpts { fullName?: string enCode?: string @@ -36,19 +57,45 @@ export interface StorageOpts { bucketName?: string /** 本地存储用 */ storagePath?: string + sortCode?: number | string + description?: string + enabledMark?: number | string } +/** + * step 0 基础信息 — 镜像后端 StorageController 字段校验 + * + * 注意: web 端无 storage/Form.vue, 这里"镜像"指镜像后端 Java 端 StorageController.java + */ export function validateBasicInfo(opts: StorageOpts): StepValidation { const errors: ValidationError[] = [] + const stepName = '基础信息 (镜像后端 StorageController + ssw-common, web 端无 Form.vue)' + // fullName 必填 (后端 @NotBlank, maxlength=50 web 端惯例) if (!opts.fullName || !String(opts.fullName).trim()) { - errors.push({ field: 'fullName', message: '存储名称不能为空' }) + errors.push({ field: 'fullName', message: '存储名称不能为空 (镜像后端 StorageController @NotBlank)' }) + } else if (String(opts.fullName).length > 50) { + errors.push({ field: 'fullName', message: '存储名称长度不能超过 50 个字符 (web 端惯例 maxlength=50)' }) } + // enCode 必填 + formValidate 正则 + maxlength 50 (BS-56) if (!opts.enCode || !String(opts.enCode).trim()) { - errors.push({ field: 'enCode', message: '存储编码不能为空' }) + errors.push({ field: 'enCode', message: '存储编码不能为空 (镜像后端 StorageController @NotBlank)' }) + } else if (String(opts.enCode).length > 50) { + errors.push({ field: 'enCode', message: '存储编码长度不能超过 50 个字符' }) + } else if (!ENCODE_REGEXP.test(String(opts.enCode))) { + const suggested = String(opts.enCode).replace(/[_\-]/g, '') + errors.push({ + field: 'enCode', + message: + 'BS-56: 编码只能含英文、数字和小数点, 不能含下划线/连字符/中文. ' + + `当前 enCode="${opts.enCode}" 非法. ` + + (suggested !== opts.enCode ? `建议改成: --enCode="${suggested}" (自动去下划线/连字符)` : '请只保留字母/数字/小数点, 小数点不能放首尾'), + code: 'BS56', + }) } + // type 合法值 (后端 enum) if (opts.type !== undefined && !VALID_STORAGE_TYPES.includes(Number(opts.type))) { errors.push({ field: 'type', @@ -56,39 +103,70 @@ export function validateBasicInfo(opts: StorageOpts): StepValidation { }) } - // 云存储 (type 2/3/4/7) 需要 endpoint + accessKey + secretKey + // 云存储 (type 2/3/4/7) 需要 endpoint + accessKey + secretKey (后端 StorageController if 校验) const cloudType = Number(opts.type) - if ([2, 3, 4, 7].includes(cloudType)) { + if (CLOUD_TYPES.includes(cloudType)) { if (!opts.endpoint || !String(opts.endpoint).trim()) { - errors.push({ field: 'endpoint', message: `type=${cloudType} 云存储需要 endpoint` }) + errors.push({ field: 'endpoint', message: `type=${cloudType} 云存储需要 endpoint (镜像后端 if 分支)` }) } if (!opts.accessKey || !String(opts.accessKey).trim()) { - errors.push({ field: 'accessKey', message: `type=${cloudType} 云存储需要 accessKey` }) + errors.push({ field: 'accessKey', message: `type=${cloudType} 云存储需要 accessKey (镜像后端 if 分支)` }) } if (!opts.secretKey || !String(opts.secretKey).trim()) { - errors.push({ field: 'secretKey', message: `type=${cloudType} 云存储需要 secretKey` }) + errors.push({ field: 'secretKey', message: `type=${cloudType} 云存储需要 secretKey (镜像后端 if 分支)` }) } } // 本地存储 (type=1) 需要 storagePath if (cloudType === 1 && (!opts.storagePath || !String(opts.storagePath).trim())) { - errors.push({ field: 'storagePath', message: 'type=1 本地存储需要 storagePath' }) + errors.push({ field: 'storagePath', message: 'type=1 本地存储需要 storagePath (后端 local 存储特有)' }) } - return { - ok: errors.length === 0, - step: 0, - stepName: '基础信息', - errors, + return { ok: errors.length === 0, step: 0, stepName, errors } +} + +/** + * step 1 数值范围 — 通用约定 (与 dict/menu/report 一致) + */ +export function validateNumeric(opts: StorageOpts): StepValidation { + const errors: ValidationError[] = [] + const stepName = '数值范围 (通用约定, 与 dict/menu/report 一致)' + + // sortCode 0-999999 + if (opts.sortCode !== undefined && opts.sortCode !== null && opts.sortCode !== '') { + const sc = Number(opts.sortCode) + if (!Number.isFinite(sc)) { + errors.push({ field: 'sortCode', message: `排序码必须是数字, 当前=${opts.sortCode}` }) + } else if (sc < 0 || sc > 999999) { + errors.push({ field: 'sortCode', message: `排序码范围 0-999999, 当前=${sc}` }) + } } + + // description 长度上限 (web 端惯例 200) + if (opts.description && String(opts.description).length > 200) { + errors.push({ field: 'description', message: `说明长度不能超过 200 个字符, 当前=${String(opts.description).length}` }) + } + + // enabledMark ∈ {0, 1} + if (opts.enabledMark !== undefined && opts.enabledMark !== null && opts.enabledMark !== '') { + const em = Number(opts.enabledMark) + if (em !== 0 && em !== 1) { + errors.push({ field: 'enabledMark', message: `启用标记只能是 0 或 1, 当前=${opts.enabledMark}` }) + } + } + + return { ok: errors.length === 0, step: 1, stepName, errors } } export function validateStorageCreate(opts: StorageOpts): { ok: boolean steps: StepValidation[] } { - const s0 = validateBasicInfo(opts) - return { ok: s0.ok, steps: [s0] } + const steps = [validateBasicInfo(opts), validateNumeric(opts)] + return { + ok: steps.every((s) => s.ok), + steps, + } } export function validateStorageUpdate(opts: StorageOpts): {