db.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. package models
  2. import (
  3. "eta/eta_task/models/data_manage"
  4. "eta/eta_task/models/data_manage/edb_refresh"
  5. "eta/eta_task/models/data_manage/future_good"
  6. "eta/eta_task/models/report"
  7. "eta/eta_task/utils"
  8. "time"
  9. _ "github.com/go-sql-driver/mysql"
  10. "github.com/beego/beego/v2/client/orm"
  11. )
  12. func init() {
  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. // 用户主库
  54. if utils.MYSQL_WEEKLY_URL != `` && (utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox || utils.BusinessCode == utils.BusinessCodeDebug) {
  55. _ = orm.RegisterDataBase("weekly", "mysql", utils.MYSQL_WEEKLY_URL)
  56. orm.SetMaxIdleConns("weekly", 50)
  57. orm.SetMaxOpenConns("weekly", 100)
  58. weeklyDb, _ := orm.GetDB("weekly")
  59. weeklyDb.SetConnMaxLifetime(10 * time.Minute)
  60. }
  61. orm.Debug = true
  62. orm.DebugLog = orm.NewLog(utils.Binlog)
  63. // 注册Edb指标 数据表
  64. initEdbDataTable()
  65. // 注册商品期货 相关数据表
  66. initFutureGoodEdbDataTable()
  67. //注册持仓分析 数据表
  68. initTradePositionTop()
  69. // 研报数据表
  70. initReport()
  71. // 智能研报数据表
  72. initSmartReport()
  73. // 初始化指标刷新
  74. initEdbRefresh()
  75. // 初始化部分数据表变量(直接init会有顺序问题=_=!)
  76. data_manage.InitEdbSourceVar()
  77. }
  78. // initEdbDataTable 注册Edb指标 数据表
  79. func initEdbDataTable() {
  80. //注册对象
  81. orm.RegisterModel(
  82. new(data_manage.EdbDataWind),
  83. new(data_manage.EdbDataThs),
  84. new(data_manage.EdbDataPb),
  85. new(data_manage.BaseFromSmm),
  86. new(data_manage.BaseFromSmmIndex),
  87. new(data_manage.BaseFromSmmData),
  88. new(data_manage.EdbDataYs),
  89. new(data_manage.EdbInfoCalculateMapping),
  90. new(data_manage.EdbInfo), //hz_data库的edb_info表
  91. new(data_manage.EdbDataCalculateZjpj), //直接拼接
  92. new(data_manage.EdbDataCalculateLjztbpj), //累计同比值拼接
  93. new(data_manage.BaseFromTradeZhengzhouIndex),
  94. new(data_manage.BaseFromTradeDalianIndex),
  95. new(data_manage.BaseFromTradeShanghaiIndex),
  96. new(data_manage.BaseFromTradeCffexIndex),
  97. new(data_manage.BaseFromTradeIneIndex),
  98. new(data_manage.BaseFromChangesVisitorsCovid),
  99. new(data_manage.BaseFromEiaSteoIndex),
  100. new(data_manage.BaseFromEiaSteoClassify),
  101. new(data_manage.BaseFromEiaSteoData),
  102. new(data_manage.ComTradeIndex), // 联合国指标表
  103. new(data_manage.ComTradeCodeMapping), // 联合国指标关系表
  104. new(data_manage.ComTradeData), // 联合国数据表
  105. new(data_manage.MeetingProbabilities), // 联储加息概率
  106. new(data_manage.BaseFromTradeEicIndexV2), // 欧洲天然气
  107. //广期所
  108. new(data_manage.BaseFromTradeGuangzhouClassify),
  109. new(data_manage.BaseFromTradeGuangzhouContract),
  110. new(data_manage.BaseFromTradeGuangzhouIndex),
  111. new(data_manage.BaseFromTradeGuangzhouData),
  112. //ICPI
  113. new(data_manage.BaseFromIcpiIndex),
  114. new(data_manage.BaseFromIcpiClassify),
  115. new(data_manage.BaseFromIcpiData),
  116. new(data_manage.BusinessSysInteractionLog), // 商家系统交互记录表
  117. new(data_manage.EdbInfoRelation), //指标引用关联表
  118. new(data_manage.BaseFromThsHfIndex),
  119. )
  120. }
  121. // initFutureGoodEdbDataTable 注册商品期货Edb指标 数据表
  122. func initFutureGoodEdbDataTable() {
  123. //注册对象
  124. orm.RegisterModel(
  125. new(future_good.FutureGoodEdbInfo),
  126. )
  127. }
  128. // initTradePositionTop 注册持仓分析 数据表
  129. func initTradePositionTop() {
  130. //注册对象
  131. orm.RegisterModel(
  132. new(data_manage.TradePositionDalianTop),
  133. new(data_manage.TradePositionZhengzhouTop),
  134. new(data_manage.TradePositionShanghaiTop),
  135. new(data_manage.TradePositionIneTop),
  136. new(data_manage.TradePositionCffexTop),
  137. new(data_manage.BaseFromTradeClassify), // 交易所分类
  138. new(data_manage.TradePositionGuangzhouTop),
  139. )
  140. }
  141. // initReport 注册研报数据表
  142. func initReport() {
  143. orm.RegisterModel(
  144. new(Report),
  145. new(ReportChapter),
  146. new(report.ReportChapterPermissionMapping), // 报告章节的权限关系表
  147. )
  148. }
  149. // initSmartReport 注册智能研报数据表
  150. func initSmartReport() {
  151. orm.RegisterModel(
  152. new(SmartReport),
  153. new(ReportStateRecord),
  154. )
  155. }
  156. // initEdbRefresh 初始化指标刷新
  157. func initEdbRefresh() {
  158. orm.RegisterModel(
  159. new(edb_refresh.EdbRefreshSource), // 刷新的数据源表
  160. new(edb_refresh.EdbRefreshDefaultConfig), // 指标的默认刷新时间配置表
  161. new(edb_refresh.EdbRefreshConfig), // 指标的刷新时间配置表
  162. new(edb_refresh.EdbRefreshMapping), // 指标刷新时间配置关系表
  163. )
  164. }