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 {