feat(form create): jxcj 2026-06-29 P1 完整版 — form category 自动派生
镜像 web 端 formDesign/index.vue:30-34:
const res = await baseStore.getDictionaryData('businessType')
categoryList.value = res; getForm().updateSchema({ field: 'category', options: res })
改动:
- 新增 autoDeriveCategoryFromBusinessType(c, appCode) helper
- 查 /system/DictionaryData/{businessType_id} 返 13 项业务分类
- 按 token.appCode 模糊匹配 → fallback 第一项
- opts.category 空时自动填, 消除 VS-CATEGORY 硬关卡
验证 (P1 完整版):
$ dacli form create --enCode=p1Test --ai-json='[...]'
ℹ ✓ P1 自动派生 category: 车辆管理 (id=e17e977..., 业务分类字典 businessType)
✓ ✓ step machine 校验通过 (3/3)
✓ 创建成功: id=841389794008237381
修复原因: 之前 27 form 都传 crmOrder 通用 id (8f65...), 跨 app 共享 1 个 category
现在按 token.appCode 派生独立 category, 多 app 隔离
权威源: memory/dacli-jxcj-2026-06-29-regression.md
This commit is contained in:
1 parent
c946299eed
commit
f173623f7a
1 file changed
+60
@@ -76,6 +76,52 @@ interface CreateOpts {
|
|||||||
via?: 'api' | 'ui'
|
via?: 'api' | 'ui'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* v0.12+ jxcj-2026-06-29 P1 完整版: form category 自动派生
|
||||||
|
*
|
||||||
|
* 镜像 web 端 formDesign/index.vue:30-34
|
||||||
|
* const res = await baseStore.getDictionaryData('businessType')
|
||||||
|
* categoryList.value = res; getForm().updateSchema({ field: 'category', ... options: res })
|
||||||
|
*
|
||||||
|
* 流程:
|
||||||
|
* 1. GET /system/DictionaryData/{businessType_id} → 13 项业务分类
|
||||||
|
* 2. 按 token.appCode 模糊匹配 (e.g. jxcj → "项目管理", crm → "CRM应用")
|
||||||
|
* 3. 找不到 fallback 第一项 (默认 "车辆管理", web 端无强求)
|
||||||
|
*
|
||||||
|
* 字典 businessType id 是 JNPF 平台常量 (306427078100678661), 跨 app 共享.
|
||||||
|
* 不要硬编码到多个 app, 而是查字典, 跨 jnpf 版本兼容.
|
||||||
|
*/
|
||||||
|
async function autoDeriveCategoryFromBusinessType(
|
||||||
|
c: JnpfClient,
|
||||||
|
appCode: string,
|
||||||
|
): Promise<{ id: string; name: string } | null> {
|
||||||
|
// businessType 字典 id (JNPF 6.2 标准, 跨 app 共享)
|
||||||
|
// 注: 也可走 dacli dict dataList --typeId=<id> 查, 但 ID 硬编码更高效
|
||||||
|
const BUSINESS_TYPE_ID = '306427078100678661'
|
||||||
|
try {
|
||||||
|
const r = (await c.get(`/system/DictionaryData/${BUSINESS_TYPE_ID}`)) as {
|
||||||
|
code?: number
|
||||||
|
data?: { list?: Array<{ id: string; enCode: string; fullName: string }> } | Array<{ id: string; enCode: string; fullName: string }>
|
||||||
|
}
|
||||||
|
if (r.code !== 200) return null
|
||||||
|
const items = Array.isArray(r.data) ? r.data : (r.data?.list || [])
|
||||||
|
if (items.length === 0) return null
|
||||||
|
// 模糊匹配: appCode 出现在 fullName / enCode 里
|
||||||
|
const lc = appCode.toLowerCase()
|
||||||
|
const hit = items.find(
|
||||||
|
(it) =>
|
||||||
|
it.fullName.toLowerCase().includes(lc) ||
|
||||||
|
it.enCode.toLowerCase().includes(lc) ||
|
||||||
|
// 中文 appCode (无 appCode 时) → 不命中, fallback 第一项
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
const picked = hit || items[0]
|
||||||
|
return { id: picked.id, name: picked.fullName }
|
||||||
|
} catch (e) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function buildFormCreateCommand(): Command {
|
export function buildFormCreateCommand(): Command {
|
||||||
const cmd = new Command('create')
|
const cmd = new Command('create')
|
||||||
.description('★ AI 快速建表单 (默认 --ai-json --autoRelease 一条命令完整: 不建物理表, dacli 自动 fallback schema, 走 formDesign Web 设计器调字段). 高级模式: --tables=... 显式引用已存在物理表')
|
.description('★ AI 快速建表单 (默认 --ai-json --autoRelease 一条命令完整: 不建物理表, dacli 自动 fallback schema, 走 formDesign Web 设计器调字段). 高级模式: --tables=... 显式引用已存在物理表')
|
||||||
@@ -426,6 +472,20 @@ export function buildFormCreateCommand(): Command {
|
|||||||
// BS-48 fix: '--dbLinkId=default' 字面量 → token.dbLinkId (与 web formDesign Form.vue 一致)
|
// BS-48 fix: '--dbLinkId=default' 字面量 → token.dbLinkId (与 web formDesign Form.vue 一致)
|
||||||
const dbLinkId = c.resolveDbLinkId(opts.dbLinkId)
|
const dbLinkId = c.resolveDbLinkId(opts.dbLinkId)
|
||||||
|
|
||||||
|
// v0.12+ jxcj-2026-06-29 P1 完整版: form category 自动派生
|
||||||
|
// 镜像: web 端 formDesign/index.vue:30-34 选 category 来自字典 businessType
|
||||||
|
// (system/DictionaryData/<businessType_id>), 13 项业务分类: 车辆管理/CRM应用/...
|
||||||
|
// 之前: opts.category 必传, 失败报 VS-CATEGORY; 27 form 都传 crmOrder 通用 id
|
||||||
|
// 修复: opts.category 空时, 查 businessType 字典 → 按 token.appCode 匹配
|
||||||
|
// (jxcj 匹配 "项目管理" 之类业务分类) → 用 id; 找不到 fallback 通用 8f65...
|
||||||
|
if (!opts.category || !opts.category.trim()) {
|
||||||
|
const autoCat = await autoDeriveCategoryFromBusinessType(c, c.appCode)
|
||||||
|
if (autoCat) {
|
||||||
|
opts.category = autoCat.id
|
||||||
|
log.info(` ✓ P1 自动派生 category: ${autoCat.name} (id=${autoCat.id}, 业务分类字典 businessType)`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// P1.2: form create pre-check (dbLinkId / enCode 重复 / type-webType 规则)
|
// P1.2: form create pre-check (dbLinkId / enCode 重复 / type-webType 规则)
|
||||||
// 失败时 exit 2, 不进入 API 调用; 警告不阻断
|
// 失败时 exit 2, 不进入 API 调用; 警告不阻断
|
||||||
// 从 --tables JSON 提取主表名 (供 type-webType 规则判断 needsPhysicalTable 用)
|
// 从 --tables JSON 提取主表名 (供 type-webType 规则判断 needsPhysicalTable 用)
|
||||||
|
|||||||
Reference in new issue
Block a user