db.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package models
  2. import (
  3. "eta/eta_hub/models/data_manage"
  4. "eta/eta_hub/models/report"
  5. "eta/eta_hub/utils"
  6. "time"
  7. _ "github.com/go-sql-driver/mysql"
  8. "github.com/beego/beego/v2/client/orm"
  9. )
  10. func init() {
  11. // eta_master
  12. _ = orm.RegisterDataBase("default", "mysql", utils.MYSQL_URL)
  13. orm.SetMaxIdleConns("default", 50)
  14. orm.SetMaxOpenConns("default", 100)
  15. db, _ := orm.GetDB("default")
  16. db.SetConnMaxLifetime(10 * time.Minute)
  17. // eta_report
  18. _ = orm.RegisterDataBase("rddp", "mysql", utils.MYSQL_URL_RDDP)
  19. orm.SetMaxIdleConns("rddp", 50)
  20. orm.SetMaxOpenConns("rddp", 100)
  21. reportDb, _ := orm.GetDB("rddp")
  22. reportDb.SetConnMaxLifetime(10 * time.Minute)
  23. // eta_index
  24. _ = orm.RegisterDataBase("data", "mysql", utils.MYSQL_URL_DATA)
  25. orm.SetMaxIdleConns("data", 50)
  26. orm.SetMaxOpenConns("data", 100)
  27. indexDb, _ := orm.GetDB("data")
  28. indexDb.SetConnMaxLifetime(10 * time.Minute)
  29. orm.Debug = true
  30. orm.DebugLog = orm.NewLog(utils.Binlog)
  31. // 注册对象
  32. orm.RegisterModel(
  33. new(Report),
  34. new(EnglishReport),
  35. new(SmartReport),
  36. new(ReportStateRecord),
  37. new(data_manage.EdbSource),
  38. new(data_manage.EdbClassify),
  39. new(data_manage.EdbInfo),
  40. new(report.ReportChapterPermissionMapping), // 报告章节的权限关系表
  41. )
  42. afterInitTable()
  43. }
  44. // afterInitTable
  45. // @Description: 初始化表结构的的后置操作
  46. // @author: Roc
  47. // @datetime 2024-07-01 13:31:09
  48. func afterInitTable() {
  49. // 初始化指标来源配置
  50. data_manage.InitEdbSource()
  51. // 初始化是否启用mongo配置
  52. InitUseMongoConf()
  53. }