From 680aa3f35813d13e14d5b0d388eedb3732ebc9c6 Mon Sep 17 00:00:00 2001 From: ssw Date: Sat, 27 Jun 2026 10:19:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(form+dm):=20B-8=20=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E7=A6=81=E6=AD=A2=20PK=20+=20form=20tables?= =?UTF-8?q?=20=E6=8F=90=E4=BA=A4=E5=89=8D=E8=BF=87=E6=BB=A4=20system=20?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 之前 form POST create 时 SQL 抛 'Column X specified twice'. 根因 (4 步流程定位): 1. 读源码: 后端 FlowFormDataUtil.createMast() getKey() L170-187 选 primaryKey=1 字段 (排除 f_tenant_id) 2. 理解意图: 用户 --tables 标 primaryKey=1 业务字段 (f_connector_code) → dm 建表标记 PK → 后端 getKey() 返 f_connector_code 作为 PK 名 3. createMast() L846-850 INSERT 先 set(f_connector_code=id).set(f_flow_task_id=id) 4. L857-875 遍历 mastForm 又 set(f_connector_code=value) → 重复 5. SQL: insert into connector (f_connector_code, f_flow_task_id, f_connector_code, ...) → ERROR 修复 (方案 D + C 组合, 防御深度): 1. dm create step machine 拒绝业务字段 primaryKey=1 (PRIMARY_KEY_FIELDS = {f_id}, PK 必须留给 JNPF f_id) 2. form create step machine 兜底拦截主表业务字段 PK=1 (RESERVED_PK_FIELDS = {f_id, f_tenant_id}, 镜像后端 getKey 排除规则) 3. form create 提交前过滤 tables[].fields 中与 system 字段重名的列 (SYSTEM_FIELDS: 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) 镜像 web formDesign + 后端 FlowFormDataUtil 行为, 避免 AI 在浏览器试错. tds B-8 复盘 2026-06-27. --- src/commands/form/_validate.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 {