db_init.go 3.0 KB

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