diff --git a/src/commands/form/fix_entity.ts b/src/commands/form/fix_entity.ts index 709975f..3e4d60f 100644 --- a/src/commands/form/fix_entity.ts +++ b/src/commands/form/fix_entity.ts @@ -35,6 +35,7 @@ interface Opts { } const TARGET_ANNOTATION = '@TableId(value = "f_id", type = IdType.ASSIGN_ID)' +const TABLE_ID_PATTERN = /@TableId\s*\(/ /** 找 entity 目录(boot/ssw-{app}-entity/src/main/java/ssw/{app}/entity/) */ function findAppDirs(): { app: string; entityDir: string; bizDir: string | null }[] { @@ -62,7 +63,7 @@ function fixEntityFile(filePath: string, tableName?: string): { changed: boolean return { changed: false, reason: 'skip (not target table)' } } let content = readFileSync(filePath, 'utf-8') - if (content.includes(TARGET_ANNOTATION)) { + if (TABLE_ID_PATTERN.test(content)) { return { changed: false, reason: 'already fixed' } } const fIdMatch = content.match(/@JSONField\(name\s*=\s*"f_id"\)\s*\n\s*private\s+String\s+id\s*;/) @@ -131,7 +132,7 @@ export function buildFormFixEntityCommand(): Command { const full = join(dir, f) if (opts.dryRun) { const c = readFileSync(full, 'utf-8') - if (!c.includes(TARGET_ANNOTATION) && c.includes('@JSONField(name = "f_id")')) { + if (!TABLE_ID_PATTERN.test(c) && c.includes('@JSONField(name = "f_id")')) { log.ok(`[DRY] ${f}: 需要加 @TableId`) totalFixed++ } else { totalSkipped++ }