dacli: BS-55 form create 用 cleanTable + dm --no-strip-app-code

This commit is contained in:
ssw committed 2026-06-25 09:21:20 +08:00
1 parent ddd24b76dd
commit 32a5a566e2
3 files changed
+42 -7

No files matched your search

+6 -1
View File
@@ -19,6 +19,8 @@ interface CreateOpts {
tableName: string
dbLinkId?: string
fields: string
/** 2026-06-25 tdd9 BS-55: 显式不去 appCode 前缀 (默认 true = 去掉, 跟 form create 逻辑一致) */
stripAppCode?: boolean
json?: boolean
}
@@ -29,6 +31,7 @@ export function buildDmCreateCommand(): Command {
.requiredOption('--tableName <cn>', '表中文名')
.requiredOption('--fields <json>', '字段定义 JSON 数组')
.option('--dbLinkId <id>', '业务库 id (默认从 token.dbLinkId)')
.option('--strip-app-code [val]', '自动去 appCode 前缀 (默认 true; --no-strip-app-code 保留前缀, BS-55 修复)', v => v !== 'false')
.option('--json', '原始 JSON 输出', false)
.action(async (opts: CreateOpts) => {
const c = await JnpfClient.fromToken()
@@ -39,8 +42,10 @@ export function buildDmCreateCommand(): Command {
// CLAUDE.md §3: 表名 snake_case 无前缀 — 自动去 appCode 前缀 (jxcj_announcement → announcement)
// 已存在老表带前缀也允许 (向后兼容); 新建表推荐无前缀
// ⚠ 2026-06-25 tdd9 BS-55: form create 用 cleanTable 找物理表, dm 必须用同样的 cleanTable 名
const appCode = c.appCode
const cleanTable = opts.table.startsWith(`${appCode}_`)
const stripAppCode = opts.stripAppCode ?? true
const cleanTable = (stripAppCode && opts.table.startsWith(`${appCode}_`))
? opts.table.slice(appCode.length + 1)
: opts.table
if (cleanTable !== opts.table) {
+9 -1
View File
@@ -190,11 +190,18 @@ export function wrapSimplifiedFields(
return { wrapped, converted: wrapped.length, total: fields.length }
}
/** 2026-06-25 tdd9 BS-55: 表名去 appCode 前缀 (与 dm create 逻辑一致, 避免 form 与 dm 物理表不匹配) */
export function stripAppCodePrefix(table: string, appCode: string): string {
if (!appCode) return table
return table.startsWith(`${appCode}_`) ? table.slice(appCode.length + 1) : table
}
/** 从 fields 推导 tables 默认值 (D-2 自动推断) */
export function buildTablesFromFields(
enCode: string,
name: string,
fields: SimpleField[],
appCode?: string, // 2026-06-25 tdd9 BS-55: 可选, 传则去 appCode 前缀
): unknown[] {
// 排除系统列 (9 列) — 业务字段
const SYSTEM = 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'])
@@ -208,9 +215,10 @@ export function buildTablesFromFields(
dataLength: f.dataLength || (f.dataType === 'text' ? '0' : '200'),
allowNull: f.required ? 0 : 1,
}))
const logicalTable = appCode ? stripAppCodePrefix(enCode, appCode) : enCode
return [
{
table: enCode,
table: logicalTable, // BS-55: 与 dm 物理表名一致
tableName: name,
typeId: '1',
comment: '主表',
+27 -5
View File
@@ -254,9 +254,21 @@ export function buildFormCreateCommand(): Command {
fields: fieldsArr,
tableName: opts.enCode,
}
// v0.7.1 fix (盲点 23): 必须显式 4 个 use*Permission 字段, 否则后端 VisualUtil.setPcPermission
// 解开 Boolean (columnData.getUseBtnPermission().booleanValue()) NPE → 返 "System abnormality"
// 见 jnpf VisualUtil.java:139 + 后端 log_error.log
// 2026-06-25 tdd9 BS-55: 同步去 appCode 前缀 (与 dm 物理表名一致, 避免后端 "请在数据库中添加对应的数据表")
// formData 顶层 tableName 也用 cleanTable, 匹配物理表
const appCode55 = (c as any).appCode as string
const cleanTable55 = appCode55 && opts.enCode.startsWith(`${appCode55}_`)
? opts.enCode.slice(appCode55.length + 1)
: opts.enCode
formData.tableName = cleanTable55
// 同步 formData.fields[*].__config__.tableName (form 渲染时控件关联的物理表)
if (Array.isArray(formData.fields)) {
for (const fld of formData.fields as any[]) {
if (fld && fld.__config__ && fld.__config__.tableName === opts.enCode) {
fld.__config__.tableName = cleanTable55
}
}
}
//
// v0.7.4 (盲点 50): 必传 columnList + searchList, 否则 webType≠1 (有列表) 保存报
// "列表字段不允许为空" toast 2 次. 参考 e2eTest1 (id=836658473499370693) columnData 结构:
@@ -471,9 +483,16 @@ export function buildFormCreateCommand(): Command {
opts.enCode,
opts.fullName,
(fieldsArr as FullField[]).map(toSimpleField),
c.appCode, // BS-55: 传 appCode 让 logical table 去前缀
)
: opts.tables
? JSON.parse(opts.tables)
? // BS-55: 用户传 --tables 时, 也同步去前缀
JSON.parse(opts.tables).map((t: any) => {
if (t && t.table && c.appCode && t.table.startsWith(`${c.appCode}_`)) {
t.table = t.table.slice(c.appCode.length + 1)
}
return t
})
: type === 4
? []
: converted > 0
@@ -482,10 +501,13 @@ export function buildFormCreateCommand(): Command {
opts.enCode,
opts.fullName,
(fieldsArr as FullField[]).map(toSimpleField),
c.appCode, // BS-55
)
: [
{
table: opts.enCode,
table: c.appCode && opts.enCode.startsWith(`${c.appCode}_`)
? opts.enCode.slice(c.appCode.length + 1)
: opts.enCode,
typeId: '1',
comment: '主表',
fields: [