db.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package models
  2. import (
  3. "eta/eta_forum_admin/models/company"
  4. "eta/eta_forum_admin/models/eta_business"
  5. "eta/eta_forum_admin/models/eta_training_video"
  6. "eta/eta_forum_admin/models/eta_trial"
  7. "eta/eta_forum_admin/models/help_doc"
  8. "eta/eta_forum_admin/models/system"
  9. "eta/eta_forum_admin/utils"
  10. "github.com/beego/beego/v2/client/orm"
  11. _ "github.com/go-sql-driver/mysql"
  12. "time"
  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("weekly", "mysql", utils.MYSQL_WEEKLY_URL)
  21. orm.SetMaxIdleConns("weekly", 50)
  22. orm.SetMaxOpenConns("weekly", 100)
  23. weeklyDb, _ := orm.GetDB("weekly")
  24. weeklyDb.SetConnMaxLifetime(10 * time.Minute)
  25. orm.Debug = true
  26. orm.DebugLog = orm.NewLog(utils.Binlog)
  27. initChart()
  28. initEdbData()
  29. initUser()
  30. initETATrial()
  31. initEtaBusiness()
  32. initSystem()
  33. // ETA版本更新日志
  34. initEtaVersionUpdateLog()
  35. // 帮助文档
  36. initHelpDoc()
  37. // ETA培训视频相关表
  38. initEtaTrainingVideo()
  39. }
  40. // initChart 图表 数据表
  41. func initChart() {
  42. orm.RegisterModel(
  43. new(ChartClassify),
  44. new(ChartInfo),
  45. new(ChartEdbMapping),
  46. new(ChartTheme),
  47. new(ChartThemeType),
  48. new(ChartInfoLog),
  49. new(SearchKeyword),
  50. )
  51. }
  52. // initEdbData 指标服务 数据表
  53. func initEdbData() {
  54. orm.RegisterModel(
  55. new(EdbInfoCalculateMapping),
  56. new(EdbInfo),
  57. )
  58. }
  59. // 初始化用户服务
  60. func initUser() {
  61. orm.RegisterModel(
  62. new(system.SysSession),
  63. new(system.SysUserLoginRecord),
  64. new(system.Admin),
  65. new(system.AdminOperateRecord),
  66. )
  67. }
  68. // initETATrial ETA试用
  69. func initETATrial() {
  70. orm.RegisterModel(
  71. new(eta_trial.EtaTrial),
  72. new(eta_trial.EtaTrialApproval),
  73. //new(eta_trial.EtaTrialQuestionnaire),
  74. new(company.CompanyApprovalMessage),
  75. )
  76. }
  77. // initEtaBusiness ETA商家相关表
  78. func initEtaBusiness() {
  79. orm.RegisterModel(
  80. new(eta_business.EtaBusiness), // ETA商家表
  81. new(eta_business.EtaBusinessContract), // ETA合同表
  82. new(eta_business.EtaBusinessOperationRecord), // ETA操作记录表
  83. new(eta_business.EtaBusinessMenu), // ETA商家菜单表
  84. new(eta_business.EtaBusinessMenuRelate), // ETA商家菜单关联表
  85. new(eta_business.EtaBusinessConfigRelate), // ETA商家配置关联表
  86. new(eta_business.EtaBusinessMenuIcon), // ETA商家菜单icon表
  87. new(User), // 商家用户表
  88. new(eta_business.BusinessChartClassifyPermission), //商家图表权限表
  89. new(eta_business.BusinessReportPermission), // 商家报告权限表
  90. )
  91. }
  92. // initSystem 系统表 数据表
  93. func initSystem() {
  94. orm.RegisterModel(
  95. new(system.SysRole),
  96. new(system.SysMenuButton),
  97. new(system.SysRoleAdmin), //管理员账号和角色映射表
  98. new(system.SysRoleMenu),
  99. )
  100. }
  101. // initEtaVersionUpdateLog ETA版本更新日志
  102. func initEtaVersionUpdateLog() {
  103. orm.RegisterModel(
  104. new(EtaVersionUpdateLog), // 更新日志表
  105. )
  106. }
  107. func initHelpDoc() {
  108. //注册对象
  109. orm.RegisterModel(
  110. new(help_doc.HelpDocClassify), //分类
  111. new(help_doc.HelpDoc), //文章
  112. new(Resource), //文件
  113. )
  114. }
  115. // initEtaTrainingVideo ETA培训视频相关表
  116. func initEtaTrainingVideo() {
  117. orm.RegisterModel(
  118. new(eta_training_video.EtaTrainingVideo), // 视频表
  119. new(eta_training_video.EtaTrainingVideoOpLog), // 视频操作记录表
  120. //new(eta_training_video.EtaTrainingVideoViewLog), // 视频访问记录表
  121. new(eta_training_video.EtaTrainingVideoTag), // 标签表
  122. new(eta_training_video.EtaTrainingVideoTagRelate), // 标签关联表
  123. new(eta_training_video.EtaTrainingVideoClassify), // 分类表
  124. new(eta_training_video.EtaTrainingVideoClassifyRelate), // 分类关联表
  125. )
  126. }