|
@@ -17,6 +17,12 @@ import (
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
+var (
|
|
|
+ tableMap = map[string]int{
|
|
|
+ "base_from_mysteel_chemical_data": 1,
|
|
|
+ }
|
|
|
+)
|
|
|
+
|
|
|
type LocalTime time.Time
|
|
|
|
|
|
// InitDb
|
|
@@ -57,7 +63,27 @@ func InitDb() {
|
|
|
if utils.MYSQL_WEEKLY_URL != `` && (utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox || utils.BusinessCode == utils.BusinessCodeDebug) {
|
|
|
connectDb(utils.MYSQL_WEEKLY_URL, utils.DbNameWeekly, newLogger, dbMap, false)
|
|
|
}
|
|
|
-
|
|
|
+ for _, db := range dbMap {
|
|
|
+ _ = db.Callback().Query().Before("gorm:query").Register("before_query", func(tx *gorm.DB) {
|
|
|
+ orgSql := tx.Statement.SQL.String()
|
|
|
+ if _, ok := tableMap[tx.Statement.Table]; ok && strings.Contains(strings.ToLower(orgSql), "select") {
|
|
|
+ newSql := utils.ReplaceDriverKeywords(utils.DbDriverName, orgSql)
|
|
|
+ tx.Statement.SQL.Reset()
|
|
|
+ tx.Statement.SQL.WriteString(newSql)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ _ = db.Callback().Raw().Before("gorm:raw").Register("before_raw", func(tx *gorm.DB) {
|
|
|
+ orgSql := tx.Statement.SQL.String()
|
|
|
+ if _, ok := tableMap[tx.Statement.Table]; ok &&
|
|
|
+ (strings.Contains(strings.ToLower(orgSql), "delete") ||
|
|
|
+ strings.Contains(strings.ToLower(orgSql), "update") ||
|
|
|
+ strings.Contains(strings.ToLower(orgSql), "insert")) {
|
|
|
+ newSql := utils.ReplaceDriverKeywords(utils.DbDriverName, orgSql)
|
|
|
+ tx.Statement.SQL.Reset()
|
|
|
+ tx.Statement.SQL.WriteString(newSql)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
//全局赋值数据库链接
|
|
|
DbMap = dbMap
|
|
|
|