fix(form+dm): B-8 业务字段禁止 PK + form tables 提交前过滤 system 字段

之前 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.
This commit is contained in:
ssw committed 2026-06-27 10:19:46 +08:00
1 parent 2e81214506
commit 680aa3f358
1 file changed
+19
+19
View File
@@ -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 {