|
|
|
@ -1,5 +1,10 @@ |
|
|
|
|
package com.gyf.csams |
|
|
|
|
|
|
|
|
|
import org.jetbrains.exposed.dao.id.IntIdTable |
|
|
|
|
import org.jetbrains.exposed.sql.Column |
|
|
|
|
import org.jetbrains.exposed.sql.transactions.transaction |
|
|
|
|
import org.jetbrains.exposed.sql.vendors.MysqlDialect |
|
|
|
|
import org.jetbrains.exposed.sql.vendors.currentDialect |
|
|
|
|
import java.math.BigInteger |
|
|
|
|
import java.security.MessageDigest |
|
|
|
|
|
|
|
|
@ -19,3 +24,50 @@ fun String.md5(): String { |
|
|
|
|
return BigInteger(1, md.digest(toByteArray())).toString(16).padStart(32, '0') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Target(AnnotationTarget.CLASS,AnnotationTarget.FIELD) |
|
|
|
|
annotation class TableComment(val comment:String) |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 表、表字段添加注释 |
|
|
|
|
* |
|
|
|
|
* @param T |
|
|
|
|
* @param tables |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
fun <T : IntIdTable> updateComment(vararg tables:T){ |
|
|
|
|
transaction { |
|
|
|
|
if (currentDialect is MysqlDialect) { |
|
|
|
|
tables.forEach { |
|
|
|
|
val tableClass = it::class.java |
|
|
|
|
|
|
|
|
|
var statementList: List<String> = listOf<String>() |
|
|
|
|
.run { |
|
|
|
|
val comment = tableClass.getAnnotation(TableComment::class.java)?.comment ?: "" |
|
|
|
|
plus("ALTER TABLE ${it.tableName} COMMENT '$comment'") |
|
|
|
|
} |
|
|
|
|
tableClass.declaredFields.filter { it.name != "INSTANCE" } |
|
|
|
|
.forEach { |
|
|
|
|
it.isAccessible = true |
|
|
|
|
val column = it.get(null) |
|
|
|
|
if (column is Column<*>) { |
|
|
|
|
val ddl = column.ddl |
|
|
|
|
if (ddl.size == 1) { |
|
|
|
|
val comment = it.getAnnotation(TableComment::class.java)?.comment ?: "" |
|
|
|
|
statementList = statementList.plus( |
|
|
|
|
ddl[0].plus(" COMMENT '$comment'") |
|
|
|
|
.replace("ADD", "MODIFY") |
|
|
|
|
.replace("PRIMARY KEY", "") |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
statementList.forEach { |
|
|
|
|
exec(it) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|