db.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package models
  2. import (
  3. "eta_gn/eta_task/models/data_manage"
  4. "eta_gn/eta_task/models/data_manage/edb_refresh"
  5. "eta_gn/eta_task/models/data_manage/future_good"
  6. "eta_gn/eta_task/models/report"
  7. "eta_gn/eta_task/utils"
  8. "time"
  9. _ "github.com/go-sql-driver/mysql"
  10. "github.com/beego/beego/v2/client/orm"
  11. )
  12. func initback() {
  13. _ = orm.RegisterDataBase("default", "mysql", utils.MYSQL_URL)
  14. orm.SetMaxIdleConns("default", 50)
  15. orm.SetMaxOpenConns("default", 100)
  16. db, _ := orm.GetDB("default")
  17. db.SetConnMaxLifetime(10 * time.Minute)
  18. if utils.MYSQL_URL_RDDP != "" {
  19. _ = orm.RegisterDataBase("rddp", "mysql", utils.MYSQL_URL_RDDP)
  20. orm.SetMaxIdleConns("rddp", 50)
  21. orm.SetMaxOpenConns("rddp", 100)
  22. report_db, _ := orm.GetDB("rddp")
  23. report_db.SetConnMaxLifetime(10 * time.Minute)
  24. }
  25. if utils.MYSQL_URL_EDB != "" {
  26. _ = orm.RegisterDataBase("edb", "mysql", utils.MYSQL_URL_EDB)
  27. orm.SetMaxIdleConns("edb", 50)
  28. orm.SetMaxOpenConns("edb", 100)
  29. edb_db, _ := orm.GetDB("edb")
  30. edb_db.SetConnMaxLifetime(10 * time.Minute)
  31. }
  32. if utils.MYSQL_URL_DATA != "" {
  33. _ = orm.RegisterDataBase("data", "mysql", utils.MYSQL_URL_DATA)
  34. orm.SetMaxIdleConns("data", 50)
  35. orm.SetMaxOpenConns("data", 100)
  36. data_db, _ := orm.GetDB("data")
  37. data_db.SetConnMaxLifetime(10 * time.Minute)
  38. }
  39. if utils.MYSQL_URL_GL != "" {
  40. _ = orm.RegisterDataBase("gl", "mysql", utils.MYSQL_URL_GL)
  41. orm.SetMaxIdleConns("gl", 50)
  42. orm.SetMaxOpenConns("gl", 100)
  43. gl, _ := orm.GetDB("gl")
  44. gl.SetConnMaxLifetime(10 * time.Minute)
  45. }
  46. if utils.MYSQL_URL_ETA != "" {
  47. _ = orm.RegisterDataBase("eta", "mysql", utils.MYSQL_URL_ETA)
  48. orm.SetMaxIdleConns("eta", 50)
  49. orm.SetMaxOpenConns("eta", 100)
  50. etaDb, _ := orm.GetDB("eta")
  51. etaDb.SetConnMaxLifetime(10 * time.Minute)
  52. }
  53. orm.Debug = true
  54. orm.DebugLog = orm.NewLog(utils.Binlog)
  55. initEdbDataTable()
  56. initFutureGoodEdbDataTable()
  57. initTradePositionTop()
  58. initReport()
  59. initSmartReport()
  60. initEdbRefresh()
  61. data_manage.InitEdbSourceVar()
  62. }
  63. func initEdbDataTable() {
  64. orm.RegisterModel(
  65. new(data_manage.EdbInfoCalculateMapping),
  66. new(data_manage.EdbInfo), //hz_data库的edb_info表
  67. new(data_manage.BusinessSysInteractionLog), // 商家系统交互记录表
  68. new(data_manage.EdbInfoRelation), //指标引用关联表
  69. )
  70. }
  71. func initFutureGoodEdbDataTable() {
  72. orm.RegisterModel(
  73. new(future_good.FutureGoodEdbInfo),
  74. )
  75. }
  76. func initTradePositionTop() {
  77. orm.RegisterModel(
  78. new(data_manage.TradePositionDalianTop),
  79. new(data_manage.TradePositionZhengzhouTop),
  80. new(data_manage.TradePositionShanghaiTop),
  81. new(data_manage.TradePositionIneTop),
  82. new(data_manage.TradePositionCffexTop),
  83. new(data_manage.BaseFromTradeClassify), // 交易所分类
  84. new(data_manage.TradePositionGuangzhouTop),
  85. )
  86. }
  87. func initReport() {
  88. orm.RegisterModel(
  89. new(Report),
  90. new(ReportChapter),
  91. new(report.ReportChapterPermissionMapping), // 报告章节的权限关系表
  92. )
  93. }
  94. func initSmartReport() {
  95. orm.RegisterModel(
  96. new(SmartReport),
  97. new(ReportStateRecord),
  98. )
  99. }
  100. func initEdbRefresh() {
  101. orm.RegisterModel(
  102. new(edb_refresh.EdbRefreshSource), // 刷新的数据源表
  103. new(edb_refresh.EdbRefreshDefaultConfig), // 指标的默认刷新时间配置表
  104. new(edb_refresh.EdbRefreshConfig), // 指标的刷新时间配置表
  105. new(edb_refresh.EdbRefreshMapping), // 指标刷新时间配置关系表
  106. )
  107. }
  108. func AfterInitTable() {
  109. data_manage.InitEdbSourceVar()
  110. }