diff --git a/src/commands/form/_validate.ts b/src/commands/form/_validate.ts index 26e6494..3f62107 100644 --- a/src/commands/form/_validate.ts +++ b/src/commands/form/_validate.ts @@ -80,6 +80,25 @@ export function validateBasicInfo(opts: { } } } + // B-8 (2026-06-27 tds): 主表 primaryKey 字段禁止是业务字段 (PK 必须留给 JNPF f_id) + // 后端 FlowFormDataUtil.getKey() (L170-187) 选 primaryKey=1 字段作为 INSERT 列名 (排除 f_tenant_id). + // 用户在 tables[].fields 标业务字段 primaryKey=1 → getKey() 返该字段 → INSERT 重复拼列. + // 这是 dm create step machine 的镜像 (dm/_validate.ts PRIMARY_KEY_FIELDS), 在 form create 兜底拦截. + const RESERVED_PK_FIELDS = new Set(['f_id', 'f_tenant_id']) + for (const t of opts.tables) { + if (!t || t.typeId !== '1') continue // 只查主表 + if (!Array.isArray(t.fields)) continue + for (const f of t.fields) { + if (f && f.primaryKey === 1 && f.field && !RESERVED_PK_FIELDS.has(String(f.field).toLowerCase())) { + errors.push({ + field: `tables.${t.table}.fields[].primaryKey`, + message: `业务字段'${f.field}'禁止设为主键 (后端 FlowFormDataUtil.getKey() 选 PK → INSERT SQL 重复, 报 "specified twice"). ` + + `PK 必须留给 JNPF f_id, 业务唯一性请用 unique 约束或 billRule jnpfKey. (B-8)`, + code: 'B-8', + }) + } + } + } } return {