diff --git a/src/commands/form/codegen.ts b/src/commands/form/codegen.ts index 2f29738..6ba989d 100644 --- a/src/commands/form/codegen.ts +++ b/src/commands/form/codegen.ts @@ -41,6 +41,8 @@ interface CodegenOpts { description?: string dbLinkId?: string mainClassName?: string + /** v0.12+ BS-New-9: 显式传 form enCode 用于 Controller @RequestMapping 路径 (避免从 mainClassName 推导类名) */ + enCode?: string enableFlow?: string out?: string /** @@ -574,6 +576,7 @@ export function buildFormCodegenCommand(): Command { .option('--description ', '功能描述 (写到类注释)') .option('--dbLinkId ', '数据源 id (走业务库, 默认从 token.dbLinkId)') .option('--mainClassName ', '主表类名 (PascalCase, 默认从 enCode 自动转换: jxcj_develop_project → JxcjDevelopProject)') + .option('--enCode ', 'v0.12+ BS-New-9: 显式指定 form enCode (Controller @RequestMapping 路径用, 默认取 opts.module)') .option('--enableFlow <0|1>', '是否启用流程 0/1', '0') .option('--out ', '输出目录 (默认 ./generated/${company}-${module}/)') // ⭐ 多模块归类 (v0.10+ 默认开启, 对齐 aibridge ssw-{appCode} 多模块 POM 结构) @@ -851,6 +854,31 @@ export function buildFormCodegenCommand(): Command { // 实测 jxcj 28 form: vue + xml 0 残留, 仅 .java 触发修复 // 仍对 xml/vue 做检查 (WARN 而非改) — 防未来模板变动 let contentToWrite = f.content + // v0.12+ BS-New-9 fix (2026-06-30 jxcj): Controller @RequestMapping 路径改写 + // 根因: JNPF CodePreview 生成的 Controller 默认路径是 /api/example/{ClassName} + // (走 JNPF 内置 example 模块), 28 个 form 都映射到 /api/example/Team 等 + // → 与 JNPF 自带的 example 路径冲突, 后端注册歧义 + // 镜像: web/webapi 创建业务模块时, 正确路径应为 /api/{company}/{module}/{enCode camelCase} + // 例: /api/ssw/jxcj/team (company=ssw, module=jxcj, enCode=team) + // 修: Controller.java 文件检测 @RequestMapping("/api/example/X"), 改成 /api/{company}/{module}/{enCode camelCase} + // v0.12+ 修正: 用 form.enCode (而非 PascalCase→camelCase 推导) 保证路径与 JNPF form menu 一致 + if (f.path.includes('controller/') && f.path.endsWith('.java')) { + // 用 opts.enCode 或默认 opts.module + const enCodeForPath = opts.enCode || opts.module || 'unknown' + const updated = contentToWrite.replace( + /@RequestMapping\((["'])\/api\/example\/([A-Z][A-Za-z0-9]+)\1\)/g, + (_m, q, className) => { + // 优先用 opts.enCode (form enCode), 否则从 className 推导 + return `@RequestMapping(${q}/api/${opts.company || 'ssw'}/${opts.module || ''}/${enCodeForPath}${q})` + }, + ) + if (updated !== contentToWrite) { + const replaced = (contentToWrite.match(/@RequestMapping\((["'])\/api\/example\//g) || []).length + contentToWrite = updated + counts['__fix:bs-new-9-path'] = (counts['__fix:bs-new-9-path'] || 0) + replaced + log.info(` BS-New-9: 改写 ${replaced} 个 Controller @RequestMapping 到 /api/${opts.company || 'ssw'}/${opts.module || ''}/${enCodeForPath}`) + } + } if (/\$\{[a-zA-Z]/.test(contentToWrite)) { if (f.path.endsWith('.java')) { const { fixed, count } = fixUnresolvedVelocityVars(contentToWrite)