db.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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/beego/beego/v2/client/orm"
  10. _ "github.com/go-sql-driver/mysql"
  11. _ "github.com/lib/pq"
  12. )
  13. func init() {
  14. _ = orm.RegisterDataBase("default", utils.DBDRIVER_NAME, utils.MYSQL_URL)
  15. orm.SetMaxIdleConns("default", 50)
  16. orm.SetMaxOpenConns("default", 100)
  17. db, _ := orm.GetDB("default")
  18. db.SetConnMaxLifetime(10 * time.Minute)
  19. if utils.MYSQL_URL_RDDP != "" {
  20. _ = orm.RegisterDataBase("rddp", utils.DBDRIVER_NAME, utils.MYSQL_URL_RDDP)
  21. orm.SetMaxIdleConns("rddp", 50)
  22. orm.SetMaxOpenConns("rddp", 100)
  23. report_db, _ := orm.GetDB("rddp")
  24. report_db.SetConnMaxLifetime(10 * time.Minute)
  25. }
  26. if utils.MYSQL_URL_EDB != "" {
  27. _ = orm.RegisterDataBase("edb", utils.DBDRIVER_NAME, utils.MYSQL_URL_EDB)
  28. orm.SetMaxIdleConns("edb", 50)
  29. orm.SetMaxOpenConns("edb", 100)
  30. edb_db, _ := orm.GetDB("edb")
  31. edb_db.SetConnMaxLifetime(10 * time.Minute)
  32. }
  33. if utils.MYSQL_URL_DATA != "" {
  34. _ = orm.RegisterDataBase("data", utils.DBDRIVER_NAME, utils.MYSQL_URL_DATA)
  35. orm.SetMaxIdleConns("data", 50)
  36. orm.SetMaxOpenConns("data", 100)
  37. data_db, _ := orm.GetDB("data")
  38. data_db.SetConnMaxLifetime(10 * time.Minute)
  39. }
  40. if utils.MYSQL_URL_GL != "" {
  41. _ = orm.RegisterDataBase("gl", utils.DBDRIVER_NAME, utils.MYSQL_URL_GL)
  42. orm.SetMaxIdleConns("gl", 50)
  43. orm.SetMaxOpenConns("gl", 100)
  44. gl, _ := orm.GetDB("gl")
  45. gl.SetConnMaxLifetime(10 * time.Minute)
  46. }
  47. if utils.MYSQL_URL_ETA != "" {
  48. _ = orm.RegisterDataBase("eta", utils.DBDRIVER_NAME, utils.MYSQL_URL_ETA)
  49. orm.SetMaxIdleConns("eta", 50)
  50. orm.SetMaxOpenConns("eta", 100)
  51. etaDb, _ := orm.GetDB("eta")
  52. etaDb.SetConnMaxLifetime(10 * time.Minute)
  53. }
  54. // 用户主库
  55. if utils.MYSQL_WEEKLY_URL != `` && (utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox || utils.BusinessCode == utils.BusinessCodeDebug) {
  56. _ = orm.RegisterDataBase("weekly", utils.DBDRIVER_NAME, utils.MYSQL_WEEKLY_URL)
  57. orm.SetMaxIdleConns("weekly", 50)
  58. orm.SetMaxOpenConns("weekly", 100)
  59. weeklyDb, _ := orm.GetDB("weekly")
  60. weeklyDb.SetConnMaxLifetime(10 * time.Minute)
  61. }
  62. orm.Debug = true
  63. orm.DebugLog = orm.NewLog(utils.Binlog)
  64. // 注册Edb指标 数据表
  65. initEdbDataTable()
  66. // 注册商品期货 相关数据表
  67. initFutureGoodEdbDataTable()
  68. //注册持仓分析 数据表
  69. initTradePositionTop()
  70. // 研报数据表
  71. initReport()
  72. // 智能研报数据表
  73. initSmartReport()
  74. // 初始化指标刷新
  75. initEdbRefresh()
  76. // 初始化部分数据表变量(直接init会有顺序问题=_=!)
  77. afterInitTable()
  78. }
  79. // initEdbDataTable 注册Edb指标 数据表
  80. func initEdbDataTable() {
  81. //注册对象
  82. orm.RegisterModel(
  83. new(data_manage.EdbDataWind),
  84. new(data_manage.EdbDataThs),
  85. new(data_manage.EdbDataPb),
  86. new(data_manage.BaseFromSmm),
  87. new(data_manage.BaseFromSmmIndex),
  88. new(data_manage.BaseFromSmmData),
  89. new(data_manage.EdbDataYs),
  90. new(data_manage.EdbInfoCalculateMapping),
  91. new(data_manage.EdbInfo), //hz_data库的edb_info表
  92. new(data_manage.EdbDataCalculateZjpj), //直接拼接
  93. new(data_manage.EdbDataCalculateLjztbpj), //累计同比值拼接
  94. new(data_manage.BaseFromTradeZhengzhouIndex),
  95. new(data_manage.BaseFromTradeDalianIndex),
  96. new(data_manage.BaseFromTradeShanghaiIndex),
  97. new(data_manage.BaseFromTradeCffexIndex),
  98. new(data_manage.BaseFromTradeIneIndex),
  99. new(data_manage.BaseFromChangesVisitorsCovid),
  100. new(data_manage.BaseFromEiaSteoIndex),
  101. new(data_manage.BaseFromEiaSteoClassify),
  102. new(data_manage.BaseFromEiaSteoData),
  103. new(data_manage.ComTradeIndex), // 联合国指标表
  104. new(data_manage.ComTradeCodeMapping), // 联合国指标关系表
  105. new(data_manage.ComTradeData), // 联合国数据表
  106. new(data_manage.MeetingProbabilities), // 联储加息概率
  107. new(data_manage.BaseFromTradeEicIndexV2), // 欧洲天然气
  108. //广期所
  109. new(data_manage.BaseFromTradeGuangzhouClassify),
  110. new(data_manage.BaseFromTradeGuangzhouContract),
  111. new(data_manage.BaseFromTradeGuangzhouIndex),
  112. new(data_manage.BaseFromTradeGuangzhouData),
  113. //ICPI
  114. new(data_manage.BaseFromIcpiIndex),
  115. new(data_manage.BaseFromIcpiClassify),
  116. new(data_manage.BaseFromIcpiData),
  117. new(data_manage.BusinessSysInteractionLog), // 商家系统交互记录表
  118. new(data_manage.EdbInfoRelation), //指标引用关联表
  119. new(data_manage.BaseFromThsHfIndex),
  120. //美国农业部
  121. new(data_manage.BaseFromUsdaFasIndex),
  122. new(data_manage.BaseFromUsdaFasClassify),
  123. new(data_manage.BaseFromUsdaFasData),
  124. new(data_manage.BaseFromGprRiskClassify),
  125. new(data_manage.BaseFromGprRiskIndex),
  126. new(data_manage.BaseFromGprRiskData),
  127. )
  128. }
  129. // initFutureGoodEdbDataTable 注册商品期货Edb指标 数据表
  130. func initFutureGoodEdbDataTable() {
  131. //注册对象
  132. orm.RegisterModel(
  133. new(future_good.FutureGoodEdbInfo),
  134. )
  135. }
  136. // initTradePositionTop 注册持仓分析 数据表
  137. func initTradePositionTop() {
  138. //注册对象
  139. orm.RegisterModel(
  140. new(data_manage.TradePositionDalianTop),
  141. new(data_manage.TradePositionZhengzhouTop),
  142. new(data_manage.TradePositionShanghaiTop),
  143. new(data_manage.TradePositionIneTop),
  144. new(data_manage.TradePositionCffexTop),
  145. new(data_manage.BaseFromTradeClassify), // 交易所分类
  146. new(data_manage.TradePositionGuangzhouTop),
  147. )
  148. }
  149. // initReport 注册研报数据表
  150. func initReport() {
  151. orm.RegisterModel(
  152. new(Report),
  153. new(ReportChapter),
  154. new(report.ReportChapterPermissionMapping), // 报告章节的权限关系表
  155. )
  156. }
  157. // initSmartReport 注册智能研报数据表
  158. func initSmartReport() {
  159. orm.RegisterModel(
  160. new(SmartReport),
  161. new(ReportStateRecord),
  162. )
  163. }
  164. // initEdbRefresh 初始化指标刷新
  165. func initEdbRefresh() {
  166. orm.RegisterModel(
  167. new(edb_refresh.EdbRefreshSource), // 刷新的数据源表
  168. new(edb_refresh.EdbRefreshDefaultConfig), // 指标的默认刷新时间配置表
  169. new(edb_refresh.EdbRefreshConfig), // 指标的刷新时间配置表
  170. new(edb_refresh.EdbRefreshMapping), // 指标刷新时间配置关系表
  171. )
  172. }
  173. // afterInitTable
  174. // @Description: 初始化表结构的的后置操作
  175. // @author: Roc
  176. // @datetime 2024-07-01 13:31:09
  177. func afterInitTable() {
  178. // 初始化指标来源配置
  179. data_manage.InitEdbSourceVar()
  180. // 初始化商家基本配置
  181. InitBusinessConf()
  182. }