db.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. new(data_manage.BaseFromUsdaFasIndex),
  121. new(data_manage.BaseFromUsdaFasClassify),
  122. new(data_manage.BaseFromUsdaFasData),
  123. )
  124. }
  125. // initFutureGoodEdbDataTable 注册商品期货Edb指标 数据表
  126. func initFutureGoodEdbDataTable() {
  127. //注册对象
  128. orm.RegisterModel(
  129. new(future_good.FutureGoodEdbInfo),
  130. )
  131. }
  132. // initTradePositionTop 注册持仓分析 数据表
  133. func initTradePositionTop() {
  134. //注册对象
  135. orm.RegisterModel(
  136. new(data_manage.TradePositionDalianTop),
  137. new(data_manage.TradePositionZhengzhouTop),
  138. new(data_manage.TradePositionShanghaiTop),
  139. new(data_manage.TradePositionIneTop),
  140. new(data_manage.TradePositionCffexTop),
  141. new(data_manage.BaseFromTradeClassify), // 交易所分类
  142. new(data_manage.TradePositionGuangzhouTop),
  143. )
  144. }
  145. // initReport 注册研报数据表
  146. func initReport() {
  147. orm.RegisterModel(
  148. new(Report),
  149. new(ReportChapter),
  150. new(report.ReportChapterPermissionMapping), // 报告章节的权限关系表
  151. )
  152. }
  153. // initSmartReport 注册智能研报数据表
  154. func initSmartReport() {
  155. orm.RegisterModel(
  156. new(SmartReport),
  157. new(ReportStateRecord),
  158. )
  159. }
  160. // initEdbRefresh 初始化指标刷新
  161. func initEdbRefresh() {
  162. orm.RegisterModel(
  163. new(edb_refresh.EdbRefreshSource), // 刷新的数据源表
  164. new(edb_refresh.EdbRefreshDefaultConfig), // 指标的默认刷新时间配置表
  165. new(edb_refresh.EdbRefreshConfig), // 指标的刷新时间配置表
  166. new(edb_refresh.EdbRefreshMapping), // 指标刷新时间配置关系表
  167. )
  168. }