db.go 7.3 KB

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