db.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. package models
  2. import (
  3. "eta/eta_mobile/models/data_manage"
  4. "eta/eta_mobile/models/ppt_english"
  5. "eta/eta_mobile/models/sandbox"
  6. saModel "eta/eta_mobile/models/semantic_analysis"
  7. "eta/eta_mobile/models/system"
  8. "eta/eta_mobile/utils"
  9. _ "github.com/go-sql-driver/mysql"
  10. "time"
  11. "github.com/beego/beego/v2/client/orm"
  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("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. _ = orm.RegisterDataBase("edb", "mysql", utils.MYSQL_URL_EDB)
  25. orm.SetMaxIdleConns("edb", 50)
  26. orm.SetMaxOpenConns("edb", 100)
  27. edb_db, _ := orm.GetDB("edb")
  28. edb_db.SetConnMaxLifetime(10 * time.Minute)
  29. _ = orm.RegisterDataBase("data", "mysql", utils.MYSQL_URL_DATA)
  30. orm.SetMaxIdleConns("data", 50)
  31. orm.SetMaxOpenConns("data", 100)
  32. data_db, _ := orm.GetDB("data")
  33. data_db.SetConnMaxLifetime(10 * time.Minute)
  34. _ = orm.RegisterDataBase("gl", "mysql", utils.MYSQL_URL_GL)
  35. orm.SetMaxIdleConns("gl", 50)
  36. orm.SetMaxOpenConns("gl", 100)
  37. gl, _ := orm.GetDB("gl")
  38. gl.SetConnMaxLifetime(10 * time.Minute)
  39. // 用户主库
  40. if utils.MYSQL_WEEKLY_URL != `` && (utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox) {
  41. _ = orm.RegisterDataBase("weekly", "mysql", utils.MYSQL_WEEKLY_URL)
  42. orm.SetMaxIdleConns("weekly", 50)
  43. orm.SetMaxOpenConns("weekly", 100)
  44. weeklyDb, _ := orm.GetDB("weekly")
  45. weeklyDb.SetConnMaxLifetime(10 * time.Minute)
  46. }
  47. orm.Debug = true
  48. orm.DebugLog = orm.NewLog(utils.Binlog)
  49. //注册对象
  50. orm.RegisterModel(
  51. new(Classify),
  52. new(Resource),
  53. new(Ppt),
  54. new(PptPages),
  55. new(PptPublishRecord),
  56. new(PptV2),
  57. new(PptV2PublishRecord),
  58. new(PptV2SaveLog),
  59. new(PptV2Group),
  60. new(PptV2GroupMapping),
  61. new(PptV2Grant), //ppt授权操作表
  62. )
  63. // 报告相关 数据表
  64. initReport()
  65. initSystem()
  66. initChart()
  67. // 指标服务 数据表
  68. initEdbData()
  69. // 英文ppt
  70. initPptEnglish()
  71. //多图配置
  72. initMultipleGraphConfig()
  73. // 英文报告
  74. initEnglishReport()
  75. // 沙盘推演
  76. initSandbox()
  77. // 文档对比
  78. initSaCompare()
  79. }
  80. // initSystem 系统表 数据表
  81. func initSystem() {
  82. orm.RegisterModel(
  83. new(system.SysUserLoginRecord),
  84. new(system.SysSession),
  85. new(system.Admin),
  86. new(system.AdminConfig), //系统用户配置表
  87. new(system.AdminVerifyCodeRecord), // 用户短信邮箱验证码记录表
  88. )
  89. }
  90. // initReport 报告相关 数据表
  91. func initReport() {
  92. orm.RegisterModel(
  93. new(Report),
  94. new(ChartPermissionSearchKeyWordMapping), //报告分类权限表
  95. new(ReportChapter), // 报告章节表
  96. new(ReportChapterTicker), // 晨报章节ticker
  97. new(ReportChapterTypePermission), // 晨周报章节类型权限表
  98. new(YbPcSuncode),
  99. new(YbSuncodePars),
  100. new(ReportAuthor), //报告作者
  101. new(ClassifyMenu), // 报告分类-子目录表
  102. new(ClassifyMenuRelation), // 报告分类-子目录关联表
  103. new(ReportChapterType), // 报告章节类型表
  104. )
  105. }
  106. // initChart 图表 数据表
  107. func initChart() {
  108. orm.RegisterModel(
  109. new(data_manage.ChartClassify),
  110. new(data_manage.ChartInfo),
  111. new(data_manage.ChartEdbMapping),
  112. new(data_manage.MyChartClassify),
  113. new(data_manage.MyChart),
  114. new(data_manage.MyChartLog),
  115. new(data_manage.MyChartClassifyMapping),
  116. new(data_manage.ChartInfoLog),
  117. new(data_manage.ChartInfoCorrelation),
  118. )
  119. }
  120. // initEdbData 指标服务 数据表
  121. func initEdbData() {
  122. orm.RegisterModel(
  123. new(data_manage.EdbClassify),
  124. new(data_manage.EdbInfo), //hz_data库的edb_info表
  125. new(data_manage.EdbDataThs),
  126. new(data_manage.EdbDataWind),
  127. new(data_manage.EdbDataPb),
  128. new(data_manage.EdbInfoCalculate),
  129. new(data_manage.EdbDataCalculate),
  130. new(data_manage.EdbInfoCalculateTbz),
  131. new(data_manage.SearchKeyword),
  132. new(data_manage.BaseFromSmm),
  133. new(data_manage.BaseFromSmmIndex),
  134. new(data_manage.BaseFromSmmData),
  135. new(data_manage.EdbInfoLog),
  136. new(data_manage.EdbInfoCalculateMapping),
  137. new(data_manage.ExcelClassify), //ETA excel表格分类
  138. new(data_manage.ExcelInfo), //ETA excel表格
  139. new(data_manage.PredictEdbConf), //预测指标配置
  140. new(data_manage.BaseFromMysteelChemicalIndex), //钢联化工
  141. new(data_manage.BaseFromEiaSteoClassify), // Eia steo 报告指标
  142. new(data_manage.BaseFromEiaSteoIndex), // Eia steo 报告指标分类
  143. new(data_manage.PredictEdbRuleData), //预测指标,动态规则的计算数据
  144. new(data_manage.BaseFromSci),
  145. new(data_manage.BaseFromSciIndex),
  146. new(data_manage.BaseFromSciData),
  147. new(data_manage.BaseFromBaiinfo),
  148. new(data_manage.BaseFromBaiinfoIndex),
  149. new(data_manage.BaseFromBaiinfoData),
  150. new(data_manage.EdbDataInsertConfig), // 指标数据插入配置表
  151. new(data_manage.EdbInfoNoPermissionAdmin), //指标不可见用户配置表
  152. )
  153. }
  154. // initPptEnglish ppt英文
  155. func initPptEnglish() {
  156. orm.RegisterModel(
  157. new(ppt_english.PptEnglish),
  158. new(ppt_english.PptEnglishPublishRecord),
  159. new(ppt_english.PptEnglishSaveLog),
  160. new(ppt_english.PptEnglishGroup),
  161. new(ppt_english.PptEnglishGroupMapping),
  162. new(ppt_english.PptEnglishGrant), //ppt授权操作表
  163. new(ppt_english.ReportPptEnglishImg), //Ppt转报告的图片记录表
  164. )
  165. }
  166. // initMultipleGraphConfig 多图配置 数据表
  167. func initMultipleGraphConfig() {
  168. //注册对象
  169. orm.RegisterModel(
  170. new(data_manage.MultipleGraphConfig), //多图配置表
  171. new(data_manage.MultipleGraphConfigChartMapping), //图表与多图配置的关系表
  172. //new(data_manage.MultipleGraphConfigEdbMapping), //指标与多图配置的关系表
  173. )
  174. }
  175. // initEnglishReport 英文报告
  176. func initEnglishReport() {
  177. orm.RegisterModel(
  178. new(EnglishReport),
  179. new(EnglishPolicyReport),
  180. new(EnglishReportEmail),
  181. new(EnglishReportEmailLog),
  182. new(EnglishClassify),
  183. new(EnglishVideo), // 英文研报线上路演
  184. )
  185. }
  186. // initSandbox 注册Edb沙盘 数据表
  187. func initSandbox() {
  188. //注册对象
  189. orm.RegisterModel(
  190. new(sandbox.Sandbox), //沙盘主表
  191. )
  192. }
  193. func initSaCompare() {
  194. orm.RegisterModel(
  195. new(saModel.SaCompare), //文档对比
  196. )
  197. }