db_init.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. _ "github.com/go-sql-driver/mysql"
  5. "hongze/hongze_open_api/models/tables"
  6. "hongze/hongze_open_api/models/tables/admin"
  7. "hongze/hongze_open_api/models/tables/company"
  8. "hongze/hongze_open_api/models/tables/company_product"
  9. "hongze/hongze_open_api/models/tables/cygx/article"
  10. "hongze/hongze_open_api/models/tables/cygx/cygx_activity"
  11. "hongze/hongze_open_api/models/tables/cygx/cygx_chart"
  12. "hongze/hongze_open_api/models/tables/cygx/cygx_three_api_log"
  13. "hongze/hongze_open_api/models/tables/day_new"
  14. "hongze/hongze_open_api/models/tables/open_api_user"
  15. "hongze/hongze_open_api/models/tables/qs_event"
  16. "hongze/hongze_open_api/models/tables/qs_event_user"
  17. "hongze/hongze_open_api/models/tables/wx_user"
  18. "hongze/hongze_open_api/models/tables/yb_activity"
  19. "hongze/hongze_open_api/utils"
  20. "time"
  21. )
  22. func init() {
  23. _ = orm.RegisterDataBase("default", "mysql", utils.MYSQL_URL)
  24. orm.SetMaxIdleConns("default", 50)
  25. orm.SetMaxOpenConns("default", 100)
  26. db, _ := orm.GetDB("default")
  27. db.SetConnMaxLifetime(10 * time.Minute)
  28. //rddp数据库
  29. _ = orm.RegisterDataBase("rddp", "mysql", utils.MYSQL_URL_RDDP)
  30. orm.SetMaxIdleConns("rddp", 50)
  31. orm.SetMaxOpenConns("rddp", 100)
  32. report_db, _ := orm.GetDB("rddp")
  33. report_db.SetConnMaxLifetime(10 * time.Minute)
  34. _ = orm.RegisterDataBase("hz_cygx", "mysql", utils.MYSQL_URL_CYGX)
  35. orm.SetMaxIdleConns("hz_cygx", 50)
  36. orm.SetMaxOpenConns("hz_cygx", 100)
  37. cygx_db, _ := orm.GetDB("hz_cygx")
  38. cygx_db.SetConnMaxLifetime(10 * time.Minute)
  39. //注册对象
  40. orm.RegisterModel(
  41. new(open_api_user.OpenApiUser), //开放API用户表
  42. new(admin.Admin), //系统用户表
  43. new(article.CygxArticleCeluePush), //策略平台推送过来更新的文章
  44. new(cygx_chart.CygxChartCeluePush), //策略平台推送过来更新的图表
  45. new(cygx_activity.CygxActivitySignup), //易董报名审核
  46. new(cygx_activity.CygxYidongActivitySignupLog), //易董报名记录日志
  47. new(cygx_activity.CygxYidongActivityExamineStatus), //易董审核记录日志
  48. new(cygx_activity.CygxMySchedule), //易董审核通过之后添加我的日程
  49. new(cygx_three_api_log.CygxThreeApiLog), //易董审核通过之后添加我的日程
  50. )
  51. orm.Debug = true
  52. orm.DebugLog = orm.NewLog(utils.Binlog)
  53. // 注册研报相关的表
  54. initYb()
  55. // 注册客户相关的表
  56. initCompany()
  57. initEnglishReport()
  58. }
  59. // initYb 研报活动相关
  60. func initYb() {
  61. orm.RegisterModel(
  62. new(yb_activity.Activity), //研报活动
  63. new(qs_event.QsEvent), //全时与ficc研报活动的关系表
  64. new(qs_event_user.QsEventUser), //全时参会信息
  65. new(day_new.WeworkMsg), // 企业微信会话存档表
  66. new(day_new.WeworkMsgLog), // 企业微信群消息拉取日志表
  67. new(day_new.WeworkUser), // 企业微信用户信息表
  68. )
  69. }
  70. // initCompany 注册客户相关的
  71. func initCompany() {
  72. orm.RegisterModel(
  73. new(company.Company), //company客户表
  74. new(company_product.CompanyProduct), //company_product客户产品表
  75. new(wx_user.WxUser), //微信用户表
  76. )
  77. }
  78. // initEnglishReport 英文研报
  79. func initEnglishReport() {
  80. orm.RegisterModel(
  81. new(tables.EnglishClassify), //EnglishClassify 英文分类表
  82. new(tables.EnglishPolicyReport), //EnglishPolicyReport 英文策略表
  83. new(tables.EnglishReport), //英文研报表
  84. )
  85. }