db.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package models
  2. import (
  3. "eta/eta_index_lib/models/data_stat"
  4. "eta/eta_index_lib/models/edb_refresh"
  5. "eta/eta_index_lib/models/excel"
  6. "eta/eta_index_lib/models/future_good"
  7. "eta/eta_index_lib/models/supply_analysis"
  8. "eta/eta_index_lib/utils"
  9. "github.com/beego/beego/v2/client/orm"
  10. _ "github.com/go-sql-driver/mysql"
  11. "time"
  12. )
  13. func init() {
  14. _ = orm.RegisterDataBase("default", "mysql", 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. _ = orm.RegisterDataBase("edb", "mysql", utils.MYSQL_URL_EDB)
  20. orm.SetMaxIdleConns("edb", 50)
  21. orm.SetMaxOpenConns("edb", 100)
  22. edb_db, _ := orm.GetDB("edb")
  23. edb_db.SetConnMaxLifetime(10 * time.Minute)
  24. _ = orm.RegisterDataBase("gl", "mysql", utils.MYSQL_URL_GL)
  25. orm.SetMaxIdleConns("gl", 50)
  26. orm.SetMaxOpenConns("gl", 100)
  27. gl, _ := orm.GetDB("gl")
  28. gl.SetConnMaxLifetime(10 * time.Minute)
  29. orm.Debug = true
  30. orm.DebugLog = orm.NewLog(utils.Binlog)
  31. //注册对象
  32. orm.RegisterModel(
  33. new(EdbDataCalculateZjpj),
  34. new(EdbDataCalculateLjztbpj),
  35. new(EdbInfo),
  36. new(EdbInfoCalculateMapping),
  37. new(EdbPythonCode),
  38. new(EdbDataPython),
  39. new(ChartEdbMapping),
  40. new(PredictEdbConf),
  41. new(EdbClassify),
  42. new(PredictEdbConfCalculateMapping),
  43. new(PredictEdbRuleData),
  44. new(EdbDataCalculateNhcc),
  45. new(EdbDataPredictCalculateLjztbpj),
  46. new(EdbDataPredictCalculateNhcc),
  47. new(EdbDataPredictCalculateZjpj),
  48. new(EdbDataInsertConfig),
  49. new(EdbAdjustConf), // 数据调整的配置
  50. new(BaseFromMysteelChemicalClassify),
  51. )
  52. // 注册期货数据 数据表
  53. initFutureGood()
  54. // 供应分析 数据表
  55. initSupplyAnalysis()
  56. // 基础指标表
  57. initBaseIndex()
  58. // initDataStat 数据源统计管理相关表
  59. initDataStat()
  60. // Eta表格相关
  61. initExcel()
  62. // 初始化指标刷新
  63. initEdbRefresh()
  64. // 初始化部分数据表变量(直接init会有顺序问题=_=!)
  65. InitEdbSource()
  66. }
  67. // initFutureGood 注册期货数据 数据表
  68. func initFutureGood() {
  69. //注册对象
  70. orm.RegisterModel(
  71. new(future_good.FutureGoodEdbInfo), //期货指标表
  72. new(future_good.FutureGoodEdbData), //期货指标数据表
  73. new(future_good.ChartInfoFutureGoodProfit), //商品期货利润图表相关的信息
  74. )
  75. }
  76. // initSupplyAnalysis 供应分析
  77. func initSupplyAnalysis() {
  78. orm.RegisterModel(
  79. new(supply_analysis.Variety),
  80. new(supply_analysis.VarietyAdminPermission),
  81. new(supply_analysis.VarietyEdbInfo),
  82. new(supply_analysis.VarietyPlant),
  83. new(supply_analysis.BaseFromStockPlantData),
  84. )
  85. }
  86. // initBaseIndex 基础指标表
  87. func initBaseIndex() {
  88. orm.RegisterModel(
  89. new(BaseFromSciIndex),
  90. new(BaseFromSciData),
  91. new(BaseFromBaiinfoIndex),
  92. new(BaseFromBaiinfoData),
  93. new(BaseFromSmmIndex),
  94. new(BaseFromSmmData),
  95. new(BaseFromMysteelChemicalIndex),
  96. new(BaseFromMysteelChemicalData),
  97. new(BaseFromTradeShanghaiIndex),
  98. new(BaseFromTradeIneIndex),
  99. new(BaseFromSmmClassify),
  100. new(BaseFromYongyiIndex),
  101. new(BaseFromYongyiData),
  102. new(BaseFromYongyiClassify),
  103. new(BaseFromCoalmineMapping),
  104. new(BaseFromCoalmineJsmIndex),
  105. new(BaseFromCoalmineCoastalIndex),
  106. new(BaseFromCoalmineInlandIndex),
  107. new(BaseFromCoalmineCompanyIndex),
  108. new(BaseFromCoalmineFirmIndex),
  109. new(BaseFromMtjhMapping),
  110. new(BaseFromMtjhIndex),
  111. new(BaseFromFenweiIndex),
  112. new(BaseFromFenweiData),
  113. )
  114. }
  115. // initDataStat 数据源统计管理相关表
  116. func initDataStat() {
  117. orm.RegisterModel(
  118. new(data_stat.EdbInfoUpdateLog), // 指标更新/刷新日志列表
  119. new(data_stat.EdbInfoUpdateStat), // 数据源明细表
  120. new(data_stat.EdbSourceStat), // 数据源统计表
  121. )
  122. }
  123. // initExcel Excel
  124. func initExcel() {
  125. orm.RegisterModel(
  126. new(excel.ExcelInfo),
  127. new(excel.ExcelClassify),
  128. new(excel.ExcelEdbMapping), //excel与指标的关系表
  129. )
  130. }
  131. // initEdbRefresh 初始化指标刷新
  132. func initEdbRefresh() {
  133. orm.RegisterModel(
  134. new(edb_refresh.EdbRefreshSource), // 刷新的数据源表
  135. new(edb_refresh.EdbRefreshDefaultConfig), // 指标的默认刷新时间配置表
  136. new(edb_refresh.EdbRefreshConfig), // 指标的刷新时间配置表
  137. new(edb_refresh.EdbRefreshMapping), // 指标刷新时间配置关系表
  138. )
  139. }