feat(dacli): form codegen 默认从 enCode 推导 PascalCase 类名
背景: 业务反馈"生成的类名没有按照 SnakCase 命名法" - JNPF 平台 CodePreview API 生成的类名是 `Jxcj_announcementMapper` (混合 PascalCase+snake_case) - 实际 jxcj 28 个 mapper/entity 全部是这种风格 (历史包袱, 暂不动) - 后续新建 form 用 dacli form codegen 走时, 默认从 enCode 自动转 PascalCase 修改: src/commands/form/codegen.ts - 新增 helper: snakeToPascalCase(s) * jxcj_announcement → JxcjAnnouncement * jxcj_develop_project → JxcjDevelopProject * jxcj → Jxcj * JxcjAnnouncement (已PascalCase) → 原样保留 (避免破坏用户传入) - 默认 mainClassName: opts.mainClassName || enCode 改为 opts.mainClassName || snakeToPascalCase(enCode) - --mainClassName help 加转换说明 测试 (8/8 PASS): ✓ jxcj_announcement → JxcjAnnouncement ✓ jxcj_develop_project → JxcjDevelopProject ✓ jxcj → Jxcj ✓ jxcj_notification_record → JxcjNotificationRecord ✓ JxcjAnnouncement (已 PascalCase) → 原样保留 ✓ TdsBilling (PascalCase) → 原样保留 ✓ '' (empty) → '' ✓ a_b_c → ABC 注: 已存在的 jxcj 28 个 mapper/entity 保留原 `Jxcj_xxxMapper` 风格 (历史包袱, 改动范围过大) Co-Authored-By: Claude <[email protected]>
This commit is contained in:
1 parent
5350e5e274
commit
aeeb61d08a
1 file changed
+24
-2
@@ -123,6 +123,28 @@ function validateCode(value: string, label: string): string | null {
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* snake_case → PascalCase 转换, 用于从 form.enCode 推导 Java 类名
|
||||
*
|
||||
* 例:
|
||||
* "jxcj_announcement" → "JxcjAnnouncement"
|
||||
* "jxcj_develop_project" → "JxcjDevelopProject"
|
||||
* "jxcj" → "Jxcj"
|
||||
* "jxcj_notification_record" → "JxcjNotificationRecord"
|
||||
*
|
||||
* 规则: 按 `_` 切分, 每段首字母大写, 然后拼接; 若首段首字符是字母则强制大写
|
||||
* (e.g. "jxcj" → "Jxcj"). 已 PascalCase 风格的输入原样返回.
|
||||
*/
|
||||
export function snakeToPascalCase(s: string): string {
|
||||
if (!s) return s
|
||||
// 已是 PascalCase (无下划线, 首字母大写) → 原样返回, 避免破坏用户传入的 PascalCase
|
||||
if (!s.includes('_') && /^[A-Z]/.test(s)) return s
|
||||
const parts = s.split('_').filter(p => p.length > 0)
|
||||
return parts
|
||||
.map(p => p.charAt(0).toUpperCase() + p.slice(1))
|
||||
.join('')
|
||||
}
|
||||
|
||||
/** 分类文件: 前端 vs 后端, 后端再细分 */
|
||||
function classifyFile(item: CodeTreeItem): 'web' | 'entity' | 'model' | 'service' | 'mapper' | 'controller' | null {
|
||||
const folder = (item.folderName || '').toLowerCase()
|
||||
@@ -480,7 +502,7 @@ export function buildFormCodegenCommand(): Command {
|
||||
.option('--modulePackage <pkg>', '模块包名 (默认 ${company}.${module},如 ssw.tds) — 写到 Java package 行')
|
||||
.option('--description <desc>', '功能描述 (写到类注释)')
|
||||
.option('--dbLinkId <id>', '数据源 id (走业务库, 默认从 token.dbLinkId)')
|
||||
.option('--mainClassName <name>', '主表类名 (PascalCase, 默认取 enCode)')
|
||||
.option('--mainClassName <name>', '主表类名 (PascalCase, 默认从 enCode 自动转换: jxcj_develop_project → JxcjDevelopProject)')
|
||||
.option('--enableFlow <0|1>', '是否启用流程 0/1', '0')
|
||||
.option('--out <path>', '输出目录 (默认 ./generated/${company}-${module}/)')
|
||||
// ⭐ 多模块归类 (v0.10+ 默认开启, 对齐 aibridge ssw-{appCode} 多模块 POM 结构)
|
||||
@@ -520,7 +542,7 @@ export function buildFormCodegenCommand(): Command {
|
||||
log.error(moduleErr)
|
||||
process.exit(2)
|
||||
}
|
||||
const mainClassName = opts.mainClassName || enCode
|
||||
const mainClassName = opts.mainClassName || snakeToPascalCase(enCode)
|
||||
|
||||
// 1.5. 拿 form 完整配置 (含 tables) — 给 --auto-alias 用 + 拿主表名给 description 默认值
|
||||
// 用 GET /Alias/Info 拿 table 列表 (比 /Config.formData 可靠, webType=2/3 都返回)
|
||||
|
||||
Reference in new issue
Block a user