db.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. _ "github.com/go-sql-driver/mysql"
  9. "time"
  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.BaseFromEiaSteoData),
  93. new(data_manage.ComTradeIndex), // 联合国指标表
  94. new(data_manage.ComTradeCodeMapping), // 联合国指标关系表
  95. new(data_manage.ComTradeData), // 联合国数据表
  96. new(data_manage.MeetingProbabilities), // 联储加息概率
  97. new(data_manage.BaseFromTradeEicIndexV2), // 欧洲天然气
  98. //广期所
  99. new(data_manage.BaseFromTradeGuangzhouClassify),
  100. new(data_manage.BaseFromTradeGuangzhouContract),
  101. new(data_manage.BaseFromTradeGuangzhouIndex),
  102. new(data_manage.BaseFromTradeGuangzhouData),
  103. //ICPI
  104. new(data_manage.BaseFromIcpiIndex),
  105. new(data_manage.BaseFromIcpiClassify),
  106. new(data_manage.BaseFromIcpiData),
  107. new(data_manage.BusinessSysInteractionLog), // 商家系统交互记录表
  108. new(data_manage.EdbInfoRelation), //指标引用关联表
  109. new(data_manage.BaseFromThsHfIndex),
  110. )
  111. }
  112. // initFutureGoodEdbDataTable 注册商品期货Edb指标 数据表
  113. func initFutureGoodEdbDataTable() {
  114. //注册对象
  115. orm.RegisterModel(
  116. new(future_good.FutureGoodEdbInfo),
  117. )
  118. }
  119. // initTradePositionTop 注册持仓分析 数据表
  120. func initTradePositionTop() {
  121. //注册对象
  122. orm.RegisterModel(
  123. new(data_manage.TradePositionDalianTop),
  124. new(data_manage.TradePositionZhengzhouTop),
  125. new(data_manage.TradePositionShanghaiTop),
  126. new(data_manage.TradePositionIneTop),
  127. new(data_manage.TradePositionCffexTop),
  128. new(data_manage.BaseFromTradeClassify), // 交易所分类
  129. new(data_manage.TradePositionGuangzhouTop),
  130. )
  131. }
  132. // initReport 注册研报数据表
  133. func initReport() {
  134. orm.RegisterModel(
  135. new(Report),
  136. new(ReportChapter),
  137. new(report.ReportChapterPermissionMapping), // 报告章节的权限关系表
  138. )
  139. }
  140. // initSmartReport 注册智能研报数据表
  141. func initSmartReport() {
  142. orm.RegisterModel(
  143. new(SmartReport),
  144. new(ReportStateRecord),
  145. )
  146. }
  147. // initEdbRefresh 初始化指标刷新
  148. func initEdbRefresh() {
  149. orm.RegisterModel(
  150. new(edb_refresh.EdbRefreshSource), // 刷新的数据源表
  151. new(edb_refresh.EdbRefreshDefaultConfig), // 指标的默认刷新时间配置表
  152. new(edb_refresh.EdbRefreshConfig), // 指标的刷新时间配置表
  153. new(edb_refresh.EdbRefreshMapping), // 指标刷新时间配置关系表
  154. )
  155. }