db.go 3.6 KB

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