BS-109~111 固化: portal release 自动检测 pcModuleParentId + portal set-default + enCode 跨命令适配 + MySQL lower_case 警告 (jyzs 2026-07-02 阶段 11)

This commit is contained in:
ssw committed 2026-07-02 08:53:36 +08:00
1 parent 1fff692909
commit 30f44fe600
5 files changed
+251 -18

No files matched your search

+42
View File
@@ -116,4 +116,46 @@ export function validateFullName(fullName: string | undefined, field = 'fullName
messageVague: '名称不能含有特殊符号',
code: 'BS-56-FULLNAME-FORMAT',
}
}
/**
* BS-108 (jyzs 2026-07-02): 跨命令 enCode 适配
*
* 实战发现: 不同命令后端正则不一致 (jyzs 实战踩坑):
* - form / dict: 允许下划线 (web formValidate 不严, 但 dacli BS-56 已统一禁)
* - portal / workflow / menu: VS030 严格 (字母数字小数点, 强制去下划线)
* - di: 无强校验 (web 端无正则, 允许下划线)
*
* 解决: `adaptEnCodeForScope(enCode, scope)` 根据目标 scope 自动转换:
* - scope='strict' (portal/workflow/menu): 去下划线 (默认)
* - scope='loose' (di): 保留 (但 dacli BS-56 仍会校验)
* - scope='auto' (默认): 根据 enCode 是否含下划线判断, 含 → strict, 不含 → loose
*
* @param enCode 原始 enCode
* @param scope 目标 scope: 'strict' | 'loose' | 'auto'
* @returns 适配后的 enCode (若已合法则返回原值)
*/
export type EnCodeScope = 'strict' | 'loose' | 'auto'
export function adaptEnCodeForScope(enCode: string | undefined, scope: EnCodeScope = 'auto'): string {
if (!enCode) return ''
const enc = String(enCode).trim()
// 已合法 → 返回原值
if (ENCODE_REGEXP.test(enc)) return enc
// scope='loose' (DI 允许下划线): 保留原值 (让 web 后端校验)
if (scope === 'loose') return enc
// scope='strict' 或 'auto' (含下划线 → strict): 去下划线/连字符/空格
return suggestEnCode(enc)
}
/**
* BS-108: 跨命令 enCode scope 检测 — 自动判断 scope
*/
export function detectEnCodeScope(commandName: string): EnCodeScope {
const strictCmds = ['portal', 'workflow', 'menu', 'workflow create', 'portal release']
if (strictCmds.some((s) => commandName.includes(s))) return 'strict'
// di / dict / form / role / identity: BS-56 统一校验, 走 strict
return 'strict'
}
+10
View File
@@ -70,6 +70,16 @@ export function buildDmCreateCommand(): Command {
// 在发 API 前暴露问题, 聚合错误, AI 不用试错
runDmStepMachine(c, dbLinkId, { table: cleanTable, tableName: opts.tableName, fields: cleanFields as DmFieldLite[] })
// BS-111 (jyzs 2026-07-02): MySQL lower_case_table_names=2 大小写警告
// jyzs 实战: mirrorProduct/mirrorDemand CamelCase 表名 → backend INSERT 用 lowercase, 报 "table doesn't exist"
// 解决: 警告 + 强制 lowercase (跟 jyzs 实战一致, 跨 Linux+macOS+Windows MySQL 兼容)
if (/[A-Z]/.test(cleanTable)) {
log.warn(`BS-111: 表名 "${cleanTable}" 含大写字母`)
log.warn(` 风险: MySQL lower_case_table_names=2 时, backend INSERT 用 lowercase 表名, 但 physical table 存 CamelCase, 会报 "table doesn't exist"`)
log.warn(` 修复: 用 lowercase (例: ${cleanTable.toLowerCase()})`)
log.warn(` 跨平台: Linux (default 0, 区分大小写) / macOS (default 2, 不区分) / Windows (default 1, 全部 lowercase)`)
}
// P1.2: dm create pre-check (dbLinkId / 表重复)
// 失败时 exit 2, 不进入 API 调用; 警告不阻断
handlePreCheckResult(
+7 -4
View File
@@ -4,16 +4,18 @@
* 门户设计器 (onlineDev/visualPortal + common/dynamicPortal)
*
* 子命令:
* list 列表
* info 详情
* create 新建
* release 发布 (state 0→1)
* list 列表
* info 详情
* create 新建
* release 发布 (state 0→1, BS-109 自动检测 pcModuleParentId)
* set-default 设为默认门户 (BS-110, portalId→menuId 自动转换)
*/
import { Command } from 'commander'
import { buildPortalListCommand } from './list.ts'
import { buildPortalInfoCommand } from './info.ts'
import { buildPortalCreateCommand } from './create.ts'
import { buildPortalReleaseCommand } from './release.ts'
import { buildPortalSetDefaultCommand } from './setDefault.ts'
export function buildPortalCommand(): Command {
const cmd = new Command('portal').description('门户设计器 CRUD (首页/工作台, 走 dataInterface 拉数据)')
@@ -21,5 +23,6 @@ export function buildPortalCommand(): Command {
cmd.addCommand(buildPortalInfoCommand())
cmd.addCommand(buildPortalCreateCommand())
cmd.addCommand(buildPortalReleaseCommand())
cmd.addCommand(buildPortalSetDefaultCommand())
return cmd
}
+69 -14
View File
@@ -11,6 +11,11 @@
* platformRelease (JSON.stringify({pc,app}))
* - 兜底: 不传 --pc/--app 时, 默认只发 PC (pc=1, app=0),
* 让"门户在 PC 端可见"
*
* BS-109 (jyzs 2026-07-02): portal release 缺 pcModuleParentId 自动检测
* - 新应用 0 菜单 → portal release 后端必报"上级不能为空"
* - 修复: 加 --pcModuleParentId/--appModuleParentId/--pcSystemId/--appSystemId 4 必填
* - 自动检测: 从 ctx.menus 找顶级菜单 (parentId=0/-1), 0 菜单时自动建顶级父菜单 (类似 BS-106)
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
@@ -21,47 +26,88 @@ import {
loadPortal,
} from '../../webapi/portal.ts'
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
import { loadAppContext } from '../app/context.ts'
interface ReleaseOpts {
id: string
pc?: string
app?: string
pcSystemId?: string
pcModuleParentId?: string
appSystemId?: string
appModuleParentId?: string
}
export function buildPortalReleaseCommand(): Command {
const cmd = new Command('release')
.description(
'发布门户 (state 0→1, 必传 --pc/--app + platformRelease, 见 web ReleaseModal.vue)',
'发布门户 (state 0→1, 必传 --pc/--app + platformRelease, 见 web ReleaseModal.vue; BS-109 jyzs 2026-07-02 自动检测 pcModuleParentId)',
)
.requiredOption('--id <id>', '门户 id')
.option('--pc <0|1>', 'PC 端是否发布 (1=发布, 0=不发布, 默认 1)', '1')
.option('--app <0|1>', 'App 端是否发布 (1=发布, 0=不发布, 默认 0)', '0')
.option('--pcSystemId <id>', 'PC 端 systemId (BS-109, 不传从 ctx.currentSystemId 取)')
.option('--pcModuleParentId <id>', 'PC 端菜单父级 id (BS-109, 不传自动检测顶级菜单)')
.option('--appSystemId <id>', 'App 端 systemId (BS-109)')
.option('--appModuleParentId <id>', 'App 端菜单父级 id (BS-109, 不传自动检测顶级菜单)')
.action(async (opts: ReleaseOpts) => {
// === step 0 校验 --id + --pc/--app 参数 ===
const c = await JnpfClient.fromToken()
await initPortalWebapi(c)
// === step 0.5 BS-109: 自动检测 pcModuleParentId/appModuleParentId ===
// 加载 app context, 找顶级菜单 (parentId=0 或 -1), 0 菜单时给警告
let pcSystemId = opts.pcSystemId
let pcModuleParentId = opts.pcModuleParentId
let appSystemId = opts.appSystemId
let appModuleParentId = opts.appModuleParentId
try {
const ctx = await loadAppContext()
if (!pcSystemId) pcSystemId = ctx.currentSystemId || ''
if (!appSystemId) appSystemId = ctx.currentSystemId || ''
// 自动检测顶级菜单 (BS-109, 跟 BS-106 menu create 模式一致)
const topLevelMenus = (ctx.menus || []).filter((m: any) =>
m.parentId === '0' || m.parentId === '-1' || m.parentId === 0 || m.parentId === -1
)
if (topLevelMenus.length > 0) {
if (!pcModuleParentId) pcModuleParentId = topLevelMenus[0].id
if (!appModuleParentId) appModuleParentId = topLevelMenus[0].id
log.info(`BS-109 自动检测顶级菜单 id=${topLevelMenus[0].id} (${topLevelMenus[0].fullName})`)
} else {
// 0 菜单警告 (BS-109 跟 BS-106 一致, 0 menu 时 portal release 必失败)
log.warn(`BS-109: 当前 app 0 个顶级菜单, portal release 必失败 ("上级不能为空")`)
log.warn(` 修复: 先建顶级菜单再 release:`)
log.warn(` dacli menu create --fullName="<门户父菜单>" --enCode="<app>.portal.root" --parentId=-1 --type=1`)
log.warn(` 或显式传 --pcModuleParentId=<menu_id> --pcSystemId=<systemId>`)
}
} catch (e) {
log.warn(`BS-109: AppContext 加载失败 (${(e as Error).message?.slice(0, 100)}), 跳过自动检测`)
}
// === step 1 构造 pc/app/platformRelease (镜像 web ReleaseModal.vue:80) ===
// 关键: web 端 ReleaseModal.vue 把 {pc, app} JSON.stringify 塞进 platformRelease
const pc = opts.pc === '1' ? 1 : 0
const app = opts.app === '1' ? 1 : 0
const platformRelease = JSON.stringify({ pc, app })
const body = {
const body: Record<string, unknown> = {
pc,
app,
platformRelease,
}
// BS-109: 4 个菜单字段 (web 端 ReleaseModal.vue 必传)
if (pcSystemId) body.pcSystemId = pcSystemId
if (pcModuleParentId) body.pcModuleParentId = pcModuleParentId
if (appSystemId) body.appSystemId = appSystemId
if (appModuleParentId) body.appModuleParentId = appModuleParentId
// === step 2 PUT 后端API (/visualdev/Portal/Actions/release/{id}) ===
// 镜像 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).release
if (typeof releaseFn === 'function') {
// webapi release 已 unwrap; 直接拿 resp (非 {code,data} 包装)
const resp = await releaseFn(opts.id, body)
r = resp || { code: 200 }
} else {
// 兜底: 直接用 JnpfClient 调 (保留既有行为)
r = (await c.putJson(
`/visualdev/Portal/Actions/release/${opts.id}`,
body,
@@ -77,25 +123,34 @@ export function buildPortalReleaseCommand(): Command {
log.error(` ${formatErrorLine(enhanced, { step: 0, stepName: '后端API' })}`)
process.exit(1)
}
log.info(`✓ 门户 id=${opts.id} 已发布 (pc=${pc} app=${app})`)
log.info(`✓ 门户 id=${opts.id} 已发布 (pc=${pc} app=${app}${pcModuleParentId ? `, 挂菜单父级 ${pcModuleParentId}` : ''})`)
})
installAiHelpHook(cmd, {
purpose: '发布门户 (state 0→1, 必传 pc/app/platformRelease 三参, 见 web ReleaseModal.vue)',
purpose: '发布门户 (state 0→1, 必传 pc/app/platformRelease 三参; BS-109 自动检测 pcModuleParentId)',
required: { '--id': '门户 id' },
optional: {
'--pc': 'PC 端是否发布 (1/0, 默认 1)',
'--app': 'App 端是否发布 (1/0, 默认 0)',
'--pcSystemId': 'PC 端 systemId (BS-109, 不传从 ctx 取)',
'--pcModuleParentId': 'PC 端菜单父级 id (BS-109, 不传自动检测顶级菜单)',
'--appSystemId': 'App 端 systemId (BS-109)',
'--appModuleParentId': 'App 端菜单父级 id (BS-109, 不传自动检测顶级菜单)',
},
example:
'dacli portal release --id=1234567890\ndacli portal release --id=1234567890 --pc=1 --app=1',
example: [
'dacli portal release --id=1234567890',
'dacli portal release --id=1234567890 --pcModuleParentId=842121101285785797 # 显式传父菜单',
'dacli portal release --id=1234567890 --pc=1 --app=1',
],
source: {
web: 'web/apps/jnpf-web-apps-main/src/views/onlineDev/visualPortal/components/ReleaseModal.vue (handleSubmit 拼 platformRelease)',
api: 'PUT /api/visualdev/Portal/Actions/release/{portalId} (body: {pc, app, platformRelease})',
web: 'web/apps/jnpf-web-apps-main/src/views/onlineDev/visualPortal/components/ReleaseModal.vue (handleSubmit 拼 platformRelease + pcModuleParentId)',
api: 'PUT /api/visualdev/Portal/Actions/release/{portalId} (body: pc/app/platformRelease/pcSystemId/pcModuleParentId/appSystemId/appModuleParentId 全套)',
ref: 'doc/v0.8-endpoints.md §1.3',
},
notes: [
'**修复 (v0.8.1)**: 之前 body={} 后端报"缺 formData" → 现补 pc/app/platformRelease 三参',
'**web 真值**: ReleaseModal.vue:80 release(state.record.id, {pc, app, platformRelease: JSON.stringify({pc, app})})',
'**BS-109 修复 (jyzs 2026-07-02)**: portal release 缺 pcModuleParentId, 0 菜单新应用必失败, 现自动检测顶级菜单 + 加 4 必填 CLI 选项',
'**0 菜单警告**: 当前 app 无顶级菜单时, 警告并提示先建 `dacli menu create`',
'**web 真值**: ReleaseModal.vue:80 release(state.record.id, {pc, app, platformRelease, pcSystemId, pcModuleParentId, appSystemId, appModuleParentId})',
'**兜底**: 默认 --pc=1 --app=0, 单发 PC; 想双端发传 --app=1',
],
})
+123
View File
@@ -0,0 +1,123 @@
/**
* commands/portal/setDefault.ts — 设为默认门户 (BS-110, jyzs 2026-07-02)
*
* v0.14+ (2026-07-02): 新增 BS-110 修复, jyzs 实战踩坑
* - 任务说"set_default portal X" 但实际后端 PortalDataController.setDefault:
* moduleService.getInfo(id) → portalService.getById(module.getModuleId())
* 必须传 menu id (不是 portal id)
* - 错误信息: "The portal has been deleted" (VS415)
*
* 修复:
* - 接受 --portalId 或 --menuId 二选一 (推荐 --portalId, 命令内部 portal.id → menu.id)
* - 内部走 webapi/portal.setDefaultPortal, 实际传 menu id
*
* 镜像源:
* - 后端 PortalDataController.setDefault (走 module → portal 链路)
* - webapi/portal.ts: setDefaultPortal (Proxy 暴露)
*/
import { Command } from 'commander'
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'
interface SetDefaultOpts {
portalId?: string
menuId?: string
json?: boolean
}
/** 通过 portalId 查 menuId (镜像 web 端实现, 但简化) */
async function resolveMenuIdFromPortal(portalId: string, client: JnpfClient): Promise<string | null> {
try {
// 走 webapi portal info, 看是否有 menu id 字段
const r = (await loadPortal.getInfo(portalId)) as { data?: any } | any
const data = r?.data || r
if (data?.moduleId) return String(data.moduleId)
if (data?.menuId) return String(data.menuId)
log.warn(`portal id=${portalId} info 中未找到 menuId/moduleId, 请显式传 --menuId`)
return null
} catch (e) {
log.warn(`portal info 异常: ${(e as Error).message?.slice(0, 100)}`)
return null
}
}
export function buildPortalSetDefaultCommand(): Command {
const cmd = new Command('set-default')
.description(
'设为默认门户 (BS-110, jyzs 2026-07-02; 注意: setDefaultPortal 收 menu id 不是 portal id)',
)
.option('--portalId <id>', '门户 id (推荐; 内部 portal.id → menu.id)')
.option('--menuId <id>', '菜单 id (PortalDataController.setDefault 直接收这个)')
.option('--json', '原始 JSON 输出', false)
.action(async (opts: SetDefaultOpts) => {
if (!opts.portalId && !opts.menuId) {
log.error('必传 --portalId 或 --menuId (二选一)')
log.error('提示: 推荐 --portalId, 命令内部自动 portal.id → menu.id 转换')
process.exit(1)
}
const c = await JnpfClient.fromToken()
await initPortalWebapi(c)
// === BS-110: setDefaultPortal 实际收 menu id, portal.id → menu.id ===
let menuId: string | null = null
if (opts.menuId) {
menuId = opts.menuId
log.info(`BS-110 显式 --menuId=${menuId} (跳过 portal.id → menu.id 转换)`)
} else if (opts.portalId) {
menuId = await resolveMenuIdFromPortal(opts.portalId, c)
if (!menuId) {
log.error(`BS-110: portalId=${opts.portalId} 无法解析 menuId, 请显式传 --menuId`)
log.error(`提示: portal release 后会自动建菜单, 菜单 enCode 形如 ${opts.portalId}8ee94`)
log.error(` 查 menu id: dacli menu list --keyword=<portalEnCode>`)
process.exit(1)
}
log.info(`BS-110 portalId=${opts.portalId} → menuId=${menuId} (自动转换)`)
}
// === 调 webapi setDefaultPortal ===
const r = (await loadPortal.setDefaultPortal(menuId)) as unknown
let code: number | undefined
let msg: string | undefined
if (r && typeof r === 'object') {
const obj = r as { code?: number; msg?: string }
code = obj.code
msg = obj.msg
}
if (code !== undefined && code !== 200) {
log.error(`setDefaultPortal 失败 (code=${code}): ${msg}`)
process.exit(1)
}
log.ok(`✓ 门户已设为默认 (BS-110, menuId=${menuId}, msg="${msg || '设置成功'}")`)
if (opts.json) printJson({ menuId, code, msg, raw: r })
})
installAiHelpHook(cmd, {
purpose:
'设为默认门户 (BS-110 jyzs 2026-07-02; 注意: setDefaultPortal 收 menu id 不是 portal id, 命令内部自动转换)',
optional: {
'--portalId': '门户 id (推荐; 命令内部自动 portal.id → menu.id)',
'--menuId': '菜单 id (PortalDataController.setDefault 直接收这个)',
},
example: [
'dacli portal set-default --portalId=842120082489344197 # 推荐, 自动转换',
'dacli portal set-default --menuId=842121223163871429 # 显式',
],
source: {
web: 'webapi/portal.ts Proxy (setDefaultPortal 暴露)',
api: 'POST /api/visualdev/Portal/Actions/SetDefault (后端 PortalDataController.setDefault)',
ref: 'jyzs learnings.md §portal 段',
},
notes: [
'**BS-110 修复 (jyzs 2026-07-02)**: jyzs 实战踩坑, setDefaultPortal 收 menu id 不是 portal id, 错误信息 "The portal has been deleted" (VS415) 误导',
'**后端真实逻辑**: PortalDataController.setDefault → moduleService.getInfo(id) → portalService.getById(module.getModuleId()) → setCurrentDefault',
'**portal release 后**: 自动建菜单 enCode=<portalEnCode><5字符hash>, URL=portal/<enCode>',
'**0 menu 兜底**: portalId 解析失败时, 提示用户查 `dacli menu list --keyword=<portalEnCode>`',
],
})
return cmd
}