mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
代码生成支持机构索引
This commit is contained in:
43
script/addIndex.groovy
Normal file
43
script/addIndex.groovy
Normal file
@@ -0,0 +1,43 @@
|
||||
import groovy.io.FileType
|
||||
|
||||
|
||||
def camelToSnake(String str) {
|
||||
|
||||
str = str[0].toLowerCase() + str[1..-1]
|
||||
if (str.endsWith("Entity")) {
|
||||
str = str.substring(0, str.length() - 6)
|
||||
}
|
||||
|
||||
return str.replaceAll("([A-Z]+)", "_\$1").toLowerCase()
|
||||
}
|
||||
|
||||
|
||||
new File("../src/main/java").eachFileRecurse(FileType.FILES) {
|
||||
|
||||
if (it.name.endsWith(".java")) {
|
||||
def content = it.text
|
||||
|
||||
|
||||
if (content.contains("extends OrgCommonEntity")) {
|
||||
|
||||
if (content.contains("@Table")) {
|
||||
|
||||
println("文件名: ${it.name} 包含table注解, 跳过")
|
||||
} else {
|
||||
|
||||
|
||||
def lines = it.readLines()
|
||||
|
||||
|
||||
def lineNo = lines.findIndexOf { it.contains("extends OrgCommonEntity") }
|
||||
|
||||
lines.add(lineNo , """
|
||||
@jakarta.persistence.Table(indexes = @jakarta.persistence.Index(name ="idx_${camelToSnake(it.name.substring(0, it.name.indexOf(".java")))}_org_id", columnList = "organization_id"))
|
||||
""")
|
||||
it.text = lines.join("\n")
|
||||
|
||||
println("文件名: ${it.name} 添加索引成功")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user