From 87c0ab588613284d3de8654cbd4ea197f09badba Mon Sep 17 00:00:00 2001 From: ssw Date: Fri, 26 Jun 2026 20:17:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(dm):=20step=20machine=20=E8=A1=A5=204=20?= =?UTF-8?q?=E4=B8=AA=E6=BC=8F=E6=8E=89=E7=9A=84=E5=86=B2=E7=AA=81=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=20(dataType=E7=A9=BA/sysCol=E9=87=8D=E5=90=8D/varchar?= =?UTF-8?q?=E7=BC=BA=E9=95=BF=E5=BA=A6/pk=20allowNull)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Phase 2.2 step machine 缺陷修复 (按 4 步流程: 读 web 源码 → 理解意图 → 镜像设计 → 实现+文档): **缺陷 1 (REAL)**: 11 sysCol 重名 (BS-38 普遍化) - web Form.vue:107-119 不存在 sysCol 概念, 用户不知道 dacli 会自动注入 - dacli create.ts L107-119 注入 11 sysCols (f_id/f_tenant_id/f_flow_task_id/f_flow_id/f_flow_state/f_sort_code/f_create_user/f_create_time/f_modify_user/f_modify_time/f_description) - 修复: SYSTEM_COLUMNS Set 镜像, step 1 拦截 - 错误信息: '第N行列名\'X\'与系统自动注入列冲突 (f_id/.../f_description 是 dacli 自动加的)' **缺陷 2 (REAL)**: 空 dataType - web Form.vue:283 jnpf-select placeholder='请选择' - 用户选空就空 - 修复: step 1 强制 dataType 非空 + 白名单 - 错误信息: '第N行数据类型不能为空 (可选: varchar/int/datetime/decimal/bigint/text)' **缺陷 3 (REAL)**: varchar/decimal 缺 dataLength - web Form.vue:278 :disabled='record.dataType !== varchar && !== decimal' - UI 禁用, 但无校验 - 修复: TYPES_REQUIRING_LENGTH Set, step 1 强制 length - 错误信息: '第N行 dataType=varchar 必须填 dataLength' **缺陷 4 (REAL)**: primaryKey 但 allowNull=1 - web Form.vue:292-293 - UI 禁用, 但无校验 - 修复: step 1 强制 primaryKey 字段 allowNull=0 - 错误信息: '第N行主键字段不允许为空 (allowNull 必须为 0/false)' **缺陷 5 (误判)**: int 类型带 dataLength - web 不校验 (仅 UI 禁用), 不应拦截. 测试发现走 step machine 后撞上预存 webapi shim bug (返回 undefined), 这是范围外问题. **端到端验证 (4/4 新增测试)**: ✓ sysCol 重名 (f_id) → step 1 拦截 ✓ dataType='' → step 1 拦截 ✓ varchar 无 dataLength → step 1 拦截 ✓ primaryKey+allowNull=1 → step 1 拦截 **为什么这次要修**: user 反馈 '有缺陷要修', 复审 step machine 发现漏掉 web 端 UI 行为 (disabled/disable placeholder) 对应的强制校验. 这些是 JNPF 业务规则 (不是 UI 行为), 必须镜像. **MEMORY**: dacli-dm-create-step-machine-2026-06-26.md 同步 + 新加 '反模式' 段 (漏掉 UI disabled 对应的强制校验) Co-Authored-By: Claude --- src/commands/dm/_validate.ts | 76 ++++++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 11 deletions(-) diff --git a/src/commands/dm/_validate.ts b/src/commands/dm/_validate.ts index 755f2c1..f25912b 100644 --- a/src/commands/dm/_validate.ts +++ b/src/commands/dm/_validate.ts @@ -79,6 +79,28 @@ const DECIMAL_LENGTH_REGEXP = /^\d+(?:,\d*)?$/ /** dataType 白名单 — 镜像 web dataModel/Form.vue:19-26 options */ const VALID_DATA_TYPES = ['varchar', 'int', 'datetime', 'decimal', 'bigint', 'text'] +/** 需要 dataLength 的 dataType — 镜像 web dataModel/Form.vue:278 + * `:disabled="record.dataType !== 'varchar' && record.dataType !== 'decimal'"` + * 只有 varchar 和 decimal 必填 length, 其他 (int/bigint/datetime/text) 不需要 */ +const TYPES_REQUIRING_LENGTH = new Set(['varchar', 'decimal']) + +/** 系统自动注入的 11 sysCols — 镜像 dacli create.ts L107-119 + * 用户字段如果含这些会冲突 (BS-38: f_description; 同样问题适用于其他 10 sysCols) + * ⚠️ web 端不显示 sysCols, 所以 web 不需要校验; dacli 必须强制拦截 */ +const SYSTEM_COLUMNS = new Set([ + 'f_id', + 'f_tenant_id', + 'f_flow_task_id', + 'f_flow_id', + 'f_flow_state', + 'f_sort_code', + 'f_create_user', + 'f_create_time', + 'f_modify_user', + 'f_modify_time', + 'f_description', +]) + /** Java 关键字子集 — 镜像后端 GenerateConstant.getJavaKeyword * 完整列表见 jnpf/.../util/GenerateConstant.getJavaKeyword() */ const JAVA_KEYWORDS = new Set([ @@ -185,13 +207,44 @@ export function validateFields(opts: { field: `fields[${i}].field`, message: `第${row}行列名'${f.field}'已重复`, }) + } else if (SYSTEM_COLUMNS.has(String(f.field).toLowerCase())) { + // Defect 1: 11 系统列冲突 (BS-38 普遍化, 不止 f_description) + // web 端用户看不到 sysCols, 但 dacli 会注入 → 必须拦截 + errors.push({ + field: `fields[${i}].field`, + message: `第${row}行列名'${f.field}'与系统自动注入列冲突 (${Array.from(SYSTEM_COLUMNS).join('/')} 是 dacli 自动加的)`, + }) } else { seenFields.add(String(f.field)) } - // 镜像 L197-201 decimal dataLength 格式 - if (f.dataType === 'decimal' && f.dataLength !== undefined) { - if (!DECIMAL_LENGTH_REGEXP.test(String(f.dataLength))) { + // Defect 2: dataType 必填 + 白名单 + // 镜像 Form.vue:283 jnpf-select placeholder="请选择" (用户选空就报错) + const dataType = f.dataType ? String(f.dataType).trim() : '' + if (!dataType) { + errors.push({ + field: `fields[${i}].dataType`, + message: `第${row}行数据类型不能为空 (可选: ${VALID_DATA_TYPES.join('/')})`, + }) + } else if (!VALID_DATA_TYPES.includes(dataType)) { + errors.push({ + field: `fields[${i}].dataType`, + message: `第${row}行数据类型必须为 ${VALID_DATA_TYPES.join('/')} 之一, 当前 ${dataType}`, + }) + } + + // Defect 3: dataType 与 dataLength 关系 + // 镜像 Form.vue:278 :disabled="record.dataType !== 'varchar' && record.dataType !== 'decimal'" + // - varchar/decimal: 必填 length + // - int/bigint/datetime/text: 不需要 length (web 端 input 禁用) + if (TYPES_REQUIRING_LENGTH.has(dataType)) { + if (f.dataLength === undefined || f.dataLength === null || String(f.dataLength).trim() === '') { + errors.push({ + field: `fields[${i}].dataLength`, + message: `第${row}行 dataType=${dataType} 必须填 dataLength (varchar 数字, decimal 格式 12 或 12,4)`, + }) + } else if (dataType === 'decimal' && !DECIMAL_LENGTH_REGEXP.test(String(f.dataLength))) { + // 镜像 L197-201 decimal dataLength 格式 errors.push({ field: `fields[${i}].dataLength`, message: `第${row}行请输入数字 (decimal 格式: 12 或 12,4)`, @@ -199,6 +252,15 @@ export function validateFields(opts: { } } + // Defect 4: primaryKey 字段 allowNull 必须 false + // 镜像 Form.vue:292-293 (primaryKey 强制非空) + if (f.primaryKey && f.allowNull) { + errors.push({ + field: `fields[${i}].allowNull`, + message: `第${row}行主键字段不允许为空 (allowNull 必须为 0/false)`, + }) + } + // 镜像 L202-206 fieldName 必填 if (!f.fieldName || !String(f.fieldName).trim()) { errors.push({ @@ -206,14 +268,6 @@ export function validateFields(opts: { message: `第${row}行说明不能为空`, }) } - - // 镜像 L19-26 options dataType 白名单 (新增, web 端用下拉框, 限制更严) - if (f.dataType && !VALID_DATA_TYPES.includes(String(f.dataType))) { - errors.push({ - field: `fields[${i}].dataType`, - message: `第${row}行数据类型必须为 ${VALID_DATA_TYPES.join('/')} 之一, 当前 ${f.dataType}`, - }) - } }) return {