portal P1 Bug 5 fix + webapi migration (v3.0+)

- portal/{list,info,create,release} 切到 webapi/portal (loadPortal.*)
- 修复 Bug 5 (P1): portal category 必须从字典 businessType 拿真实 UUID
  - 后端 PortalServiceImpl.getModelList() 严格过滤 category 不在字典 → silently drop
  - create 命令加 resolvePortalCategory(): loadDict.getDictionaryAll()
    过滤 enCode='businessType' 取真实 id, 支持 explicit (id/enCode/fullName)
    + appCode-match + auto-first 兜底
  - 未传 --category 时自动派生 (类似 form autoDeriveCategoryFromBusinessType)
  - 显式 --category='1' 这类字符串被显式拒绝并列出合法项 (避免 silently drop)
- list/info 适配 webapi getPortalList/getInfo 已 unwrap 的响应形状 (无 .data 包裹)
- release 改走 webapi loadPortal.release(id, body), 兜底 JnpfClient 直调
  (pc=1 默认需要 pcModuleParentId, 不传走 --pc=0 --app=0 可跳过菜单父级)

Verification (testspace):
- list → 0 (empty)
- create → auto-derived category=e17e977fe98e43d0baabb327f70e6549 (车辆管理)
- list → 1 portal, category=车辆管理 (NOT silently dropped)
- release --pc=0 --app=0 → success, enabledMark=1, platformRelease 持久化
- explicit --category=CRM应用 → maps to fe72535365154b5f82fd7c2f984087f3
- negative --category=nonexistent → rejected with hint listing 合法项
This commit is contained in:
ssw committed 2026-07-01 16:25:58 +08:00
1 parent af1c6ea016
commit 9bbad1c198
4 files changed
+162 -57

No files matched your search

+143 -21
View File
@@ -1,11 +1,16 @@
/**
* commands/portal/create.ts — 新建门户 (v3.0+ 走 webapi/portal 镜像)
* commands/portal/create.ts — 新建门户 (v3.0+ 走 webapi/portal 镜像 + Bug 5 修复)
*
* 决策 6: 门户 webType=5-6, 不需要物理表, 走 dataInterfaceId 拉数据
*
* v3.0+ (2026-06-29 regression audit P0): 改用 webapi/portal.createPortal
* - 之前直接 c.postJson('/visualdev/Portal') — 经验复刻, 与 web 端 schema 漂移风险
* - 现在 webapi 镜像: 复用 web 端 createPortal
* v3.0+ (2026-07-01 regression audit P1):
* - 改用 webapi/portal.createPortal (复用 web 端同名函数)
* - **Bug 5 修复 (P1)**: portal category 必须从字典 businessType 派生真实 UUID.
* 后端 PortalServiceImpl.getModelList() (line 152-200) 严格过滤
* `entity.getCategory()` 必须在字典 BUSINESSTYPE 里, 不在则 silently drop.
* AI 用户传字符串 '1'/'2' → 后端接受 (写库) 但 list 时被过滤 → 看不到 portal.
* 修复: 用 loadDict.getDictionaryAll() 过滤 enCode='businessType',
* 取字典 *真实 UUID* 作为 category. 用户没传 --category 时按 appCode 自动派生.
*
* API: POST /api/visualdev/Portal (镜像 web createPortal)
*/
@@ -20,24 +25,101 @@ import {
createPortal,
getPortalList,
} from '../../webapi/portal.ts'
import { initWebapi as initDictWebapi, loadDict } from '../../webapi/dict.ts'
interface CreateOpts {
fullName: string
enCode: string
category: string
category?: string // 字典 businessType 真实 id 或 关键字 (门户/首页/工作台...)
platform?: string
type?: string
platformType?: string
link?: string
json?: boolean
description?: string
customUrl?: string
appCustomUrl?: string
linkType?: string
formData?: string
}
/**
* Bug 5 修复核心 (P1): 从字典 dict enCode='businessType' 拿 *真实* 分类 UUID.
* 真实 UUID 才是后端 PortalServiceImpl.getModelList() 不 silently drop 的唯一合法值.
*
* 顺序:
* 1. 显式传 opts.category → 必须在字典里 (否则 error 让 AI 知错)
* 2. 未传 → 自动从字典取首项 (13 项业务分类默认第 0 项)
*/
async function resolvePortalCategory(
c: JnpfClient,
opts: { category?: string; appCode?: string },
): Promise<{ id: string; name: string; matched: 'explicit' | 'auto-first' | 'appCode-match' }> {
await initDictWebapi(c)
const allResp = (await loadDict.getDictionaryAll()) as
| { data?: { list?: Array<any> } }
| { list?: Array<any> }
| Array<any>
const allList = Array.isArray(allResp)
? (allResp as Array<any>)
: (allResp as any)?.data?.list ||
(allResp as any)?.list ||
[]
const bizDict = allList.find((d: any) => d?.enCode === 'businessType')
const items: Array<{ id: string; enCode: string; fullName: string }> = (bizDict?.dictionaryList || []).map(
(it: any) => ({ id: it.id, enCode: it.enCode, fullName: it.fullName }),
)
if (items.length === 0) {
throw new Error(
'businessType 字典为空 (JNPF 平台至少应有 13 项业务分类). 检查 web 端表单设计器是否初始化.',
)
}
// 1. 显式 user-provided category → 校验必须在字典里
if (opts.category && String(opts.category).trim()) {
const byId = items.find((it) => it.id === String(opts.category))
if (byId) return { id: byId.id, name: byId.fullName, matched: 'explicit' }
// 允许按 enCode / fullName 匹配 (AI 友好)
const byCode = items.find(
(it) =>
it.enCode === opts.category ||
it.fullName === opts.category ||
String(it.fullName).includes(String(opts.category)),
)
if (byCode) return { id: byCode.id, name: byCode.fullName, matched: 'explicit' }
throw new Error(
`--category "${opts.category}" 在字典 businessType 里找不到. 合法项: ${items
.map((i) => `${i.fullName}(${i.id})`)
.join(', ').slice(0, 200)}`,
)
}
// 2. 未传 → 按 appCode 关键词 + 兜底首项
const app = String(opts.appCode || '').toLowerCase()
if (app) {
const fuzzy = items.find((it) => {
const f = String(it.fullName || '').toLowerCase()
const e = String(it.enCode || '').toLowerCase()
return app.includes(f) || app.includes(e) || f.includes(app)
})
if (fuzzy) return { id: fuzzy.id, name: fuzzy.fullName, matched: 'appCode-match' }
}
// 兜底: 字典首项 (默认第 0 项业务分类)
const fallback = items[0]
return { id: fallback.id, name: fallback.fullName, matched: 'auto-first' }
}
export function buildPortalCreateCommand(): Command {
const cmd = new Command('create')
.description('新建门户 (无物理表, 走 dataInterfaceId 拉数据)')
.description('新建门户 (无物理表, 走 dataInterfaceId 拉数据, Bug 5 已修: category 自动从字典派生 UUID)')
.requiredOption('--fullName <name>', '门户名称')
.requiredOption('--enCode <code>', '门户编码')
.requiredOption('--category <cat>', '分类: 1=经典门户 2=全屏门户')
// v3.0+ (P1 Bug 5 修): category 改为可选, 必从字典 businessType 取
// *真实 UUID*. 不传时按 appCode 自动派生.
.option(
'--category <cat>',
'分类: 字典 businessType 的 id/enCode/fullName (留空自动派生, 推荐留空)',
)
.option('--platform <p>', '平台: Web/App/PC', 'Web')
// v0.11e+ Phase B1: step machine 字段 (镜像 web visualPortal/Form.vue:55-105)
.option('--type <t>', '门户类型: 0=页面 1=外链 (镜像 Form.vue:55-67)')
@@ -48,17 +130,37 @@ export function buildPortalCreateCommand(): Command {
.option('--customUrl <url>', '配置路径 (镜像 PortalCrForm.customUrl, platformType=1)')
.option('--appCustomUrl <url>', '应用配置路径 (镜像 PortalCrForm.appCustomUrl)')
.option('--linkType <n>', '链接类型 (镜像 PortalCrForm.linkType, 0/1)', '0')
.option('--formData <json>', '门户布局 formData (JSON 字符串, 镜像 PortalCrForm.formData)')
.option(
'--formData <json>',
'门户布局 formData (JSON 字符串, 镜像 PortalCrForm.formData)',
)
.option('--json', '原始 JSON 输出', false)
.action(async (opts: CreateOpts) => {
const c = await JnpfClient.fromToken()
// v3.0+ Bug 5 修复 (P1): 先解析 category (从字典 businessType 拿真实 UUID)
// 在 step machine 之前, 拿到 id 才能让后续校验走到对的地方
let resolvedCategory: { id: string; name: string; matched: string }
try {
resolvedCategory = await resolvePortalCategory(c, {
category: opts.category,
appCode: (c as any).appCode,
})
log.info(
`✓ Bug 5: category 解析为真实 UUID (${resolvedCategory.matched}): ${resolvedCategory.name} (id=${resolvedCategory.id})`,
)
} catch (e) {
log.error(`Bug 5 修复 - category 解析失败: ${(e as Error).message?.slice(0, 300)}`)
process.exit(1)
}
const realCategoryId = resolvedCategory.id
// v0.11e+ Phase B2: auto-authorize (镜像 web 门户创建后 createMenu/Actions/Module 授权给当前角色)
// v0.11e+ Phase B1: step machine 校验 (2 step 镜像 web visualPortal/Form.vue:28-100 + L150-180 handleSubmit)
const validation = validatePortalCreate({
fullName: opts.fullName,
enCode: opts.enCode,
category: opts.category,
category: realCategoryId, // 字典真实 UUID (Bug 5 修复)
type: opts.type,
platformType: opts.platformType,
link: opts.link,
@@ -78,10 +180,11 @@ export function buildPortalCreateCommand(): Command {
// { fullName, enCode, enabledMark, description, formData (JSON 字符串), category, sortCode, type, customUrl, appCustomUrl, linkType, ... }
// web 端 visualPortal/Form.vue: const query = { ...values, id: state.dataForm.id }; createPortal(query)
// 关键: formData 必传 (JSON 字符串, 内嵌布局 schema), description 必传, type 必传
// **Bug 5 修复**: category 必为字典 businessType 真实 UUID (不是 '1' 字符串)
const portalCrForm = {
fullName: opts.fullName,
enCode: opts.enCode,
category: opts.category,
category: realCategoryId, // 真实 UUID, 不是字符串 '1'
type: opts.platformType ? Number(opts.platformType) : 0, // 0=门户设计, 1=配置路径 (镜像 web Form.vue:75-87)
platform: opts.platform,
formData: opts.formData || JSON.stringify({}), // JSON 字符串, web 端默认 '{}'
@@ -94,24 +197,35 @@ export function buildPortalCreateCommand(): Command {
}
// v3.0+ P0: 走 webapi/portal.createPortal (web 端同名函数)
await initPortalWebapi(c)
const r = (await createPortal(portalCrForm as any)) as { id?: string; code?: number; msg?: string }
const r = (await createPortal(portalCrForm as any)) as {
id?: string
code?: number
msg?: string
}
const rCode = r.code ?? 200
if (rCode !== 200) {
const enhanced = enhanceFromBackend(r.msg || '', 'portal', { entity: 'portal' })
log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`)
process.exit(1)
}
let id = r.id
let id: string | undefined = r.id
// BS-新12 v2 (jxcj 2026-07-01): jnpf portal 后端可能返纯字符串 id (而非 JSON 对象)
if (!id && typeof r === 'string' && /^\d+$/.test(r.trim())) id = r.trim()
if (!id && typeof (r as unknown) === 'string' && /^\d+$/.test((r as unknown as string).trim()))
id = (r as unknown as string).trim()
// 参考 datasource create 历史模式: 响应可能不返 id, 按 enCode 反查 list
if (!id) {
const listR = (await getPortalList({ keyword: opts.enCode, pageSize: 50 })) as
| { list?: { id: string; enCode: string; fullName: string }[] }
| {
data?: { list?: { id: string; enCode: string; fullName: string }[] }
list?: { id: string; enCode: string; fullName: string }[]
}
| { id: string; enCode: string; fullName: string }[]
const list = Array.isArray(listR) ? listR : listR.list || []
const list: Array<{ id: string; enCode: string; fullName: string }> = Array.isArray(listR)
? (listR as Array<{ id: string; enCode: string; fullName: string }>)
: (listR as any).data?.list || (listR as any).list || []
const found = list.find(
(d) => d.enCode === opts.enCode || d.fullName === opts.fullName,
(d: { id: string; enCode: string; fullName: string }) =>
d.enCode === opts.enCode || d.fullName === opts.fullName,
)
id = found?.id
}
@@ -123,19 +237,25 @@ export function buildPortalCreateCommand(): Command {
log.error('可能原因: 1) jnpf 响应格式变化 2) category/type 不被接受 3) systemId 没传')
process.exit(1)
}
log.info(`✓ 门户创建成功 id=${id}`)
if (opts.json) printJson({ ...(r as object), id })
log.info(
`✓ 门户创建成功 id=${id} category=${resolvedCategory.name}(${realCategoryId})`,
)
if (opts.json)
printJson({ ...(r as object), id, category: realCategoryId, categoryName: resolvedCategory.name })
})
installAiHelpHook(cmd, {
purpose: '新建门户 (首页/工作台设计器产物)',
required: {
'--fullName': '门户名称',
'--enCode': '门户编码',
'--category': '分类 1=经典门户 2=全屏门户',
},
optional: { '--platform': '平台 (Web/App/PC)', '--json': '原始 JSON 输出' },
optional: {
'--category': '分类 (字典 businessType 的 id/enCode/fullName, 留空自动派生 — Bug 5 推荐)',
'--platform': '平台 (Web/App/PC)',
'--json': '原始 JSON 输出',
},
example:
'dacli portal create --fullName=工作台 --enCode=workbench --category=1',
'dacli portal create --fullName=工作台 --enCode=workbench\ndacli portal create --fullName=CRM首页 --enCode=crm-home --category=CRM应用',
source: {
web: 'web/apps/jnpf-web-apps-main/src/views/onlineDev/visualPortal/Form.vue',
api: 'POST /api/visualdev/Portal',
@@ -144,6 +264,8 @@ export function buildPortalCreateCommand(): Command {
notes: [
'**决策 6**: 门户不需要物理表, 走 di 拉数据',
'**决策 6**: webType 5-6 (门户设计器)',
'**Bug 5 修复 (P1)**: category 自动从字典 businessType 派生真实 UUID, 避免后端 silently drop',
'**web 浏览器**: category 下拉框强制从字典选, 不会填无效值; 但 dacli 命令易传数字字符串, 修复后强制走字典 lookup',
],
})
return cmd
+6 -14
View File
@@ -10,7 +10,6 @@ import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
import { initWebapi as initPortalWebapi, loadPortal } from '../../webapi/portal.ts'
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
interface InfoOpts {
id: string
@@ -25,29 +24,22 @@ export function buildPortalInfoCommand(): Command {
.action(async (opts: InfoOpts) => {
const c = await JnpfClient.fromToken()
await initPortalWebapi(c)
// 镜像 web getInfo(id): 返回 { data: <portal> }
const r = (await loadPortal.getInfo(opts.id)) as {
code?: number
msg?: string
data?: Record<string, unknown>
}
const rCode = r.code ?? 200
if (rCode !== 200) {
const enhanced = enhanceFromBackend(r.msg || '', 'portal', { entity: 'portal' })
log.error(` ${formatErrorLine(enhanced, { step: 0, stepName: '后端API' })}`)
// webapi getInfo 已 unwrap: 返回 portal 对象直接 (含 fullName, enCode, category, formData...)
const d = (await loadPortal.getInfo(opts.id)) as Record<string, unknown>
if (!d || !d.id) {
log.error(`门户 id=${opts.id} 不存在或后端返空`)
process.exit(1)
}
if (opts.json) {
printJson(r.data)
printJson(d)
return
}
const d = r.data || ({} as Record<string, unknown>)
log.info(`门户 id=${opts.id} 名称=${d.fullName} 编码=${d.enCode}`)
console.log(`category: ${d.category}`)
console.log(`type: ${d.type}`)
console.log(`platform: ${d.platform || '-'}`)
console.log(`--- 完整 JSON (含 formData 布局) ---`)
printJson(r.data)
printJson(d)
})
installAiHelpHook(cmd, {
purpose: '查看门户的完整 schema (含布局/组件)',
+6 -9
View File
@@ -27,20 +27,17 @@ export function buildPortalListCommand(): Command {
const c = await JnpfClient.fromToken()
await initPortalWebapi(c)
// 镜像 web getPortalList(data): 返回 { data: list, total, ... }
// webapi getPortalList 已 unwrap: 返回 { pagination, list } 直接
const r = (await loadPortal.getPortalList({
keyword: opts.keyword,
})) as { code?: number; msg?: string; data?: { list?: Record<string, unknown>[] } }
const rCode = r.code ?? 200
if (rCode !== 200) {
log.error(`portal list 失败 (code=${rCode}): ${r.msg || ''}`)
process.exit(1)
}
const list = r.data?.list || []
})) as { pagination?: { total?: number }; list?: Record<string, unknown>[] }
const list = r.list || []
const total = r.pagination?.total ?? list.length
if (opts.json) {
printJson(r.data)
printJson(r)
return
}
log.info(`共 ${list.length} 个门户`)
log.info(`共 ${list.length} 个门户 (pagination.total=${total})`)
console.log('ID FULL_NAME ENCODE CATEGORY')
console.log('-'.repeat(90))
for (const d of list) {
+7 -13
View File
@@ -51,21 +51,15 @@ export function buildPortalReleaseCommand(): Command {
platformRelease,
}
// === step 2 PUT 后端API (/visualdev/Portal/Actions/release/{id}) ===
// 镜像 web ReleaseModal.vue 调 defHttp.put portal/{id}/Actions/release body
// loadPortal proxy 上取对应方法; webapi/portal.ts 没单独 export release
// 函数, 走 updatePortal 兜底 (id 走 portal.id)
let r: { code?: number; msg?: string; data?: unknown } = { code: 200 }
// 镜像 web ReleaseModal.vue: release(id, { ...formFields, platformRelease })
// webapi release 签名: (id, data) → PUT /visualdev/Portal/Actions/release/{id}
let r: { code?: number; msg?: string } = { code: 200 }
try {
const releaseFn = (loadPortal as any).releasePortal
const releaseFn = (loadPortal as any).release
if (typeof releaseFn === 'function') {
r = (await releaseFn(opts.id, body)) as typeof r
} else if (typeof (loadPortal as any).updatePortal === 'function') {
r = (await (loadPortal as any).updatePortal({
id: opts.id,
pc,
app,
platformRelease,
})) as typeof r
// webapi release 已 unwrap; 直接拿 resp (非 {code,data} 包装)
const resp = await releaseFn(opts.id, body)
r = resp || { code: 200 }
} else {
// 兜底: 直接用 JnpfClient 调 (保留既有行为)
r = (await c.putJson(