db_init.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. _ "github.com/go-sql-driver/mysql"
  5. "hongze/hongze_mobile_admin/models/roadshow"
  6. "hongze/hongze_mobile_admin/models/tables/admin"
  7. "hongze/hongze_mobile_admin/models/tables/admin_record"
  8. "hongze/hongze_mobile_admin/models/tables/approval_flow"
  9. "hongze/hongze_mobile_admin/models/tables/approval_flow_node"
  10. "hongze/hongze_mobile_admin/models/tables/chart_permission"
  11. "hongze/hongze_mobile_admin/models/tables/company"
  12. "hongze/hongze_mobile_admin/models/tables/company_approval"
  13. "hongze/hongze_mobile_admin/models/tables/company_approval_message"
  14. "hongze/hongze_mobile_admin/models/tables/company_contract"
  15. "hongze/hongze_mobile_admin/models/tables/company_delay_permission"
  16. "hongze/hongze_mobile_admin/models/tables/company_log"
  17. "hongze/hongze_mobile_admin/models/tables/company_operation_record"
  18. "hongze/hongze_mobile_admin/models/tables/company_permission_log"
  19. "hongze/hongze_mobile_admin/models/tables/company_product"
  20. "hongze/hongze_mobile_admin/models/tables/company_product_log"
  21. "hongze/hongze_mobile_admin/models/tables/company_product_update_log"
  22. "hongze/hongze_mobile_admin/models/tables/company_report_permission"
  23. "hongze/hongze_mobile_admin/models/tables/contract"
  24. "hongze/hongze_mobile_admin/models/tables/contract_approval"
  25. "hongze/hongze_mobile_admin/models/tables/contract_approval_record"
  26. "hongze/hongze_mobile_admin/models/tables/contract_operation_record"
  27. "hongze/hongze_mobile_admin/models/tables/contract_service_detail"
  28. "hongze/hongze_mobile_admin/models/tables/contract_service_template"
  29. "hongze/hongze_mobile_admin/models/tables/contract_template"
  30. "hongze/hongze_mobile_admin/models/tables/h5_admin_session"
  31. "hongze/hongze_mobile_admin/models/tables/report"
  32. "hongze/hongze_mobile_admin/models/tables/research_variety_tag_relation"
  33. "hongze/hongze_mobile_admin/models/tables/resource"
  34. "hongze/hongze_mobile_admin/models/tables/seal"
  35. "hongze/hongze_mobile_admin/models/tables/sys_role"
  36. "hongze/hongze_mobile_admin/models/tables/sys_role_admin"
  37. "hongze/hongze_mobile_admin/models/tables/user_template_record"
  38. "hongze/hongze_mobile_admin/models/tables/variety_classify"
  39. "hongze/hongze_mobile_admin/models/tables/variety_tag"
  40. "hongze/hongze_mobile_admin/models/tables/wx_token"
  41. "hongze/hongze_mobile_admin/models/tables/wx_user"
  42. "hongze/hongze_mobile_admin/models/tables/yb_community_question"
  43. "hongze/hongze_mobile_admin/models/tables/yb_community_question_comment"
  44. "hongze/hongze_mobile_admin/models/tables/yb_price_driven_tag"
  45. "hongze/hongze_mobile_admin/utils"
  46. "time"
  47. )
  48. func init() {
  49. _ = orm.RegisterDataBase("default", "mysql", utils.MYSQL_URL)
  50. orm.SetMaxIdleConns("default", 50)
  51. orm.SetMaxOpenConns("default", 100)
  52. db, _ := orm.GetDB("default")
  53. db.SetConnMaxLifetime(10 * time.Minute)
  54. //rddp数据库
  55. _ = orm.RegisterDataBase("rddp", "mysql", utils.MYSQL_URL_RDDP)
  56. orm.SetMaxIdleConns("rddp", 50)
  57. orm.SetMaxOpenConns("rddp", 100)
  58. report_db, _ := orm.GetDB("rddp")
  59. report_db.SetConnMaxLifetime(10 * time.Minute)
  60. orm.Debug = true
  61. orm.DebugLog = orm.NewLog(utils.Binlog)
  62. //注册对象
  63. orm.RegisterModel(
  64. new(admin.Admin),
  65. new(admin_record.AdminRecord),
  66. new(sys_role.SysRole),
  67. new(sys_role_admin.SysRoleAdmin),
  68. new(approval_flow.ApprovalFlow),
  69. new(approval_flow_node.ApprovalFlowNode),
  70. new(company.Company),
  71. new(company_approval.CompanyApproval),
  72. new(company_approval_message.CompanyApprovalMessage),
  73. new(company_contract.CompanyContract),
  74. new(company_delay_permission.CompanyDelayPermission),
  75. new(company_log.CompanyLog),
  76. new(company_operation_record.CompanyOperationRecord),
  77. new(company_permission_log.CompanyPermissionLog),
  78. new(company_product.CompanyProduct),
  79. new(company_product_log.CompanyProductLog),
  80. new(company_report_permission.CompanyReportPermission),
  81. new(contract.Contract),
  82. new(contract_approval.ContractApproval),
  83. new(contract_approval_record.ContractApprovalRecord),
  84. new(contract_operation_record.ContractOperationRecord),
  85. new(contract_service_detail.ContractServiceDetail),
  86. new(contract_service_template.ContractServiceTemplate),
  87. new(contract_template.ContractTemplate),
  88. new(h5_admin_session.H5AdminSession),
  89. new(report.Report),
  90. new(resource.Resource),
  91. new(wx_token.WxToken),
  92. new(wx_user.WxUser),
  93. new(seal.Seal), //用印表
  94. new(seal.SealOperationRecord), // 用印操作记录表
  95. new(seal.Attachment), //用印附件
  96. new(roadshow.RsCalendar),
  97. new(roadshow.RsCalendarResearcher),
  98. new(roadshow.RsMatters),
  99. new(roadshow.RsCalendarRelation),
  100. new(company_product_update_log.CompanyProductUpdateLog), //客户产品状态变更记录表
  101. new(user_template_record.UserTemplateRecord), //模版消息记录表
  102. new(chart_permission.ChartPermission), // 品种权限表
  103. )
  104. // 社区问答相关
  105. initCommunity()
  106. // 品种标签相关
  107. initVariety()
  108. // 价格驱动相关
  109. initPriceDriven()
  110. }
  111. // initCommunity 社区问答相关
  112. func initCommunity() {
  113. orm.RegisterModel(
  114. new(yb_community_question.CommunityQuestion), //社区问答
  115. new(yb_community_question_comment.YbCommunityQuestionComment), //社区问答评论
  116. )
  117. }
  118. // initVariety 品种标签相关
  119. func initVariety() {
  120. orm.RegisterModel(
  121. new(variety_classify.VarietyClassify), //品种标签分类
  122. new(variety_tag.VarietyTag), //品种标签
  123. new(research_variety_tag_relation.ResearchVarietyTagRelation), //品种标签关系
  124. )
  125. }
  126. // initPriceDriven 价格驱动相关
  127. func initPriceDriven() {
  128. orm.RegisterModel(
  129. new(yb_price_driven_tag.PriceDrivenTag), //价格驱动标签
  130. )
  131. }
  132. func InitDb() {}