db.go 5.3 KB

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