db.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. package models
  2. import (
  3. "eta_gn/eta_index_lib/models/data_stat"
  4. "eta_gn/eta_index_lib/models/edb_refresh"
  5. "eta_gn/eta_index_lib/models/excel"
  6. "eta_gn/eta_index_lib/models/future_good"
  7. "eta_gn/eta_index_lib/models/supply_analysis"
  8. "eta_gn/eta_index_lib/utils"
  9. "time"
  10. "github.com/beego/beego/v2/client/orm"
  11. _ "github.com/go-sql-driver/mysql"
  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. // master库
  30. {
  31. _ = orm.RegisterDataBase("master", "mysql", utils.MYSQL_URL_MASTER)
  32. orm.SetMaxIdleConns("master", 50)
  33. orm.SetMaxOpenConns("master", 100)
  34. master, _ := orm.GetDB("master")
  35. master.SetConnMaxLifetime(10 * time.Minute)
  36. }
  37. orm.Debug = true
  38. orm.DebugLog = orm.NewLog(utils.Binlog)
  39. //注册对象
  40. orm.RegisterModel(
  41. new(EdbDataCalculateZjpj),
  42. new(EdbDataCalculateLjztbpj),
  43. new(EdbInfo),
  44. new(EdbInfoRecord),
  45. new(BaseFromSmmRecord),
  46. new(BaseFromMysteelChemicalRecord),
  47. new(EdbInfoCalculateMapping),
  48. new(EdbPythonCode),
  49. new(EdbDataPython),
  50. new(ChartEdbMapping),
  51. new(PredictEdbConf),
  52. new(EdbClassify),
  53. new(PredictEdbConfCalculateMapping),
  54. new(PredictEdbRuleData),
  55. new(EdbDataCalculateNhcc),
  56. new(EdbDataPredictCalculateLjztbpj),
  57. new(EdbDataPredictCalculateNhcc),
  58. new(EdbDataPredictCalculateZjpj),
  59. new(EdbDataInsertConfig),
  60. new(EdbAdjustConf), // 数据调整的配置
  61. new(BaseFromMysteelChemicalClassify),
  62. new(EdbInfoRelation), //指标引用记录
  63. )
  64. // 注册期货数据 数据表
  65. initFutureGood()
  66. // 供应分析 数据表
  67. initSupplyAnalysis()
  68. // 基础指标表
  69. initBaseIndex()
  70. // initDataStat 数据源统计管理相关表
  71. initDataStat()
  72. // Eta表格相关
  73. initExcel()
  74. // 初始化指标刷新
  75. initEdbRefresh()
  76. // 自有数据指标
  77. initBusinessEdb()
  78. // 初始化因子指标系列
  79. initFactorEdbSeries()
  80. // 初始化部分数据表变量(直接init会有顺序问题=_=!)
  81. afterInitTable()
  82. }
  83. // initFutureGood 注册期货数据 数据表
  84. func initFutureGood() {
  85. //注册对象
  86. orm.RegisterModel(
  87. new(future_good.FutureGoodEdbInfo), //期货指标表
  88. new(future_good.FutureGoodEdbData), //期货指标数据表
  89. new(future_good.ChartInfoFutureGoodProfit), //商品期货利润图表相关的信息
  90. )
  91. }
  92. // initSupplyAnalysis 供应分析
  93. func initSupplyAnalysis() {
  94. orm.RegisterModel(
  95. new(supply_analysis.Variety),
  96. new(supply_analysis.VarietyAdminPermission),
  97. new(supply_analysis.VarietyEdbInfo),
  98. new(supply_analysis.VarietyPlant),
  99. new(supply_analysis.BaseFromStockPlantData),
  100. )
  101. }
  102. // initBaseIndex 基础指标表
  103. func initBaseIndex() {
  104. orm.RegisterModel(
  105. new(BaseFromSciIndex),
  106. new(BaseFromSciData),
  107. new(BaseFromBaiinfoIndex),
  108. new(BaseFromBaiinfoData),
  109. new(BaseFromSmmIndex),
  110. new(BaseFromSmmData),
  111. new(BaseFromMysteelChemicalIndex),
  112. new(BaseFromMysteelChemicalData),
  113. new(BaseFromTradeShanghaiIndex),
  114. new(BaseFromTradeIneIndex),
  115. new(BaseFromSmmClassify),
  116. new(BaseFromYongyiIndex),
  117. new(BaseFromYongyiData),
  118. new(BaseFromYongyiClassify),
  119. new(BaseFromCoalmineMapping),
  120. new(BaseFromCoalmineJsmIndex),
  121. new(BaseFromCoalmineCoastalIndex),
  122. new(BaseFromCoalmineInlandIndex),
  123. new(BaseFromCoalmineCompanyIndex),
  124. new(BaseFromCoalmineFirmIndex),
  125. new(BaseFromMtjhMapping),
  126. new(BaseFromMtjhIndex),
  127. new(BaseFromFenweiIndex),
  128. new(BaseFromFenweiData),
  129. new(BaseFromBloombergIndex),
  130. new(BaseFromBloombergData),
  131. new(BaseFromSci99Data),
  132. new(BaseFromSci99Index),
  133. new(BaseFromSci99Classify),
  134. new(BaseFromCCFIndex),
  135. new(BaseFromCCFData),
  136. new(CCFStockExcel),
  137. new(BaseFromSciHqData),
  138. new(BaseFromSciHqIndex),
  139. new(BaseFromThsHfIndex),
  140. new(BaseFromThsHfData),
  141. new(BaseFromEdbMapping),
  142. new(EdbDataThsHf),
  143. new(BaseFromBusinessData), // 数据源中自有数据的明细数据表
  144. new(BaseFromOilchemIndex),
  145. new(BaseFromOilchemData),
  146. new(BaseFromFenweiClassify),
  147. new(EdbDataTradeAnalysis),
  148. )
  149. }
  150. // initDataStat 数据源统计管理相关表
  151. func initDataStat() {
  152. orm.RegisterModel(
  153. new(data_stat.EdbInfoUpdateLog), // 指标更新/刷新日志列表
  154. new(data_stat.EdbInfoUpdateStat), // 数据源明细表
  155. new(data_stat.EdbSourceStat), // 数据源统计表
  156. )
  157. }
  158. // initExcel Excel
  159. func initExcel() {
  160. orm.RegisterModel(
  161. new(excel.ExcelInfo),
  162. new(excel.ExcelClassify),
  163. new(excel.ExcelEdbMapping), //excel与指标的关系表
  164. )
  165. }
  166. // initEdbRefresh 初始化指标刷新
  167. func initEdbRefresh() {
  168. orm.RegisterModel(
  169. new(edb_refresh.EdbRefreshSource), // 刷新的数据源表
  170. new(edb_refresh.EdbRefreshDefaultConfig), // 指标的默认刷新时间配置表
  171. new(edb_refresh.EdbRefreshConfig), // 指标的刷新时间配置表
  172. new(edb_refresh.EdbRefreshMapping), // 指标刷新时间配置关系表
  173. )
  174. }
  175. // initBusinessEdb 初始化指标刷新
  176. func initBusinessEdb() {
  177. orm.RegisterModel(
  178. new(BaseFromBusinessIndex), // 外部指标(商家系统)表
  179. new(EdbBusinessSource), // 自有数据(商家)指标来源
  180. )
  181. }
  182. // initFactorEdbSeries 因子指标系列数据表
  183. func initFactorEdbSeries() {
  184. orm.RegisterModel(
  185. new(FactorEdbSeries), // 因子指标系列
  186. new(FactorEdbSeriesChartMapping), // 因子指标系列-图表关联
  187. new(FactorEdbSeriesMapping), // 因子指标系列-指标计算数据
  188. new(FactorEdbSeriesCalculateData), // 因子指标系列-指标关联
  189. new(FactorEdbSeriesCalculateDataQjjs), // 因子指标系列-区间计算
  190. )
  191. }
  192. // afterInitTable
  193. // @Description: 初始化表结构的的后置操作
  194. // @author: Roc
  195. // @datetime 2024-07-01 13:31:09
  196. func afterInitTable() {
  197. // 初始化指标来源配置
  198. InitEdbSource()
  199. // 初始化是否启用mongo配置
  200. InitUseMongoConf()
  201. // 初始化Smm有色指标数据获取方式
  202. InitSmmDataMethodConf()
  203. }