diff --git a/src/commands/form/codegen.ts b/src/commands/form/codegen.ts index 117f02e..19f966a 100644 --- a/src/commands/form/codegen.ts +++ b/src/commands/form/codegen.ts @@ -88,6 +88,17 @@ interface CodegenOpts { * 默认开启多模块归类 (v0.10+ 推荐, 对齐 aibridge docs/code-rule.md §POM 依赖规则) */ flat?: boolean + /** + * P1-3 fix (2026-07-16): 默认把 Controller 输出到 biz 模块 (对齐 ssw-dos 模式) + * + * 根因: 旧版默认输出到独立 ${moduleArtifactId}-controller/ 子目录, + * 用户需手动 cp Controller 到 ssw-{app}-biz/controller/ 才能对齐 ssw-dos 模块结构. + * jxcj M1 11 form codegen 后, 9 controller 需手动 cp (announcement + auditrecord 缺失) + * 镜像: ssw-dos 模块结构只分 entity + biz (controller 在 biz 里), 业务代码不需要单独 controller 模块 + * 修: 默认 mode='biz', Controller 直接写到 ${moduleArtifactId}-biz/controller/ + * --separate-controller (旧版行为): 输出到独立 ${moduleArtifactId}-controller/ + */ + separateController?: boolean /** * 生成 4 个 pom.xml 占位 (parent + entity/biz/controller), 严格按 aibridge POM 模板 * 与 --flat 互斥 (pom 必须配合多模块结构才有意义) @@ -359,10 +370,14 @@ function fixUnresolvedVelocityVars(content: string): { fixed: string; count: num * 兜底: classifyFile 的 kind → 映射模块名 * 前端 vue/ts/js → null (不归 Maven 模块, 写到 outDir/web/ 或根) */ -function pathToModule(filePath: string, kind: string, moduleArtifactId: string): string | null { +function pathToModule(filePath: string, kind: string, moduleArtifactId: string, separateController = false): string | null { const lower = filePath.toLowerCase() + // P1-3 fix (2026-07-16): Controller 默认归 biz 模块 (对齐 ssw-dos 模式) + // 默认 mode='biz': Controller 写到 ${moduleArtifactId}-biz/controller/ (与 service/mapper 同一模块) + // --separate-controller: 输出到独立 ${moduleArtifactId}-controller/ (旧版行为兼容) + const controllerModule = separateController ? `${moduleArtifactId}-controller` : `${moduleArtifactId}-biz` // 1. 路径含 controller/service/entity/model/mapper → 解析 (最准确) - if (lower.includes('/controller/') || /controller\.java$/.test(lower)) return `${moduleArtifactId}-controller` + if (lower.includes('/controller/') || /controller\.java$/.test(lower)) return controllerModule if (lower.includes('/service/') || /serviceimpl?\.java$/.test(lower)) return `${moduleArtifactId}-biz` if (lower.includes('/mapper/') || /mapper\.(java|xml)$/.test(lower)) return `${moduleArtifactId}-biz` if (lower.includes('/entity/') || /entity\.java$/.test(lower)) return `${moduleArtifactId}-entity` @@ -372,7 +387,7 @@ function pathToModule(filePath: string, kind: string, moduleArtifactId: string): // 3. 其他 .xml 资源 (非 mapper) → 归 biz (与 mapper.xml 同目录) if (lower.endsWith('.xml')) return `${moduleArtifactId}-biz` // 4. 兜底用 kind 映射 - if (kind === 'controller') return `${moduleArtifactId}-controller` + if (kind === 'controller') return controllerModule if (kind === 'service' || kind === 'mapper') return `${moduleArtifactId}-biz` if (kind === 'entity' || kind === 'model') return `${moduleArtifactId}-entity` return null @@ -614,6 +629,8 @@ export function buildFormCodegenCommand(): Command { .option('--out ', '输出目录 (默认 ./generated/${company}-${module}/)') // ⭐ 多模块归类 (v0.10+ 默认开启, 对齐 aibridge ssw-{appCode} 多模块 POM 结构) .option('--flat', '关闭多模块归类 (旧版兼容: 文件直接写到 outDir 根, 不分 entity/biz/controller)', false) + // P1-3 fix (2026-07-16): Controller 默认归 biz 模块 (对齐 ssw-dos 模式) + .option('--separate-controller', 'Controller 输出到独立 ${moduleArtifactId}-controller/ 子目录 (旧版行为, 默认合并到 biz)', false) .option('--multi-module-pom', '生成 4 个 pom.xml 占位 (parent + entity/biz/controller, 严格按 aibridge §POM 依赖规则; 与 --flat 互斥)', false) // 选择性导出 (只生成指定模块, 用于单模块编译验证) // 值: all | entity | biz | controller | 任意逗号分隔组合 (如 entity,biz) @@ -794,7 +811,11 @@ export function buildFormCodegenCommand(): Command { mkdirSync(outDir, { recursive: true }) log.info(`输出目录: ${outDir}`) if (!opts.flat) { - log.info(` ssw-{appCode} 多模块归类 (entity/biz/controller), 用 --flat 关闭`) + if (opts.separateController) { + log.info(` ssw-{appCode} 多模块归类 (entity/biz/controller), --separate-controller 模式 (Controller 独立模块)`) + } else { + log.info(` ssw-{appCode} 多模块归类 (entity/biz, P1-3 默认: Controller 合并到 biz 模块, 对齐 ssw-dos)`) + } } else { log.info(` --flat 模式: 不分模块, 全部文件写到 outDir 根`) } @@ -821,7 +842,7 @@ export function buildFormCodegenCommand(): Command { } for (const f of files) { // 决定 Maven 子模块 (--flat 时为 null, 文件直接写到 outDir 根) - const targetModule = opts.flat ? null : pathToModule(f.path, f.kind, moduleArtifactId) + const targetModule = opts.flat ? null : pathToModule(f.path, f.kind, moduleArtifactId, opts.separateController) // === 前端 web/uniapp 重定向 === // JNPF 把 web/* 和 app/* 都放进 ssw-jxcj 包内, 但应该写到 web/uniapp 目标位置