package models

import (
	_ "github.com/go-sql-driver/mysql"
	"hongze/hongze_cygx/utils"
	"time"

	"github.com/beego/beego/v2/client/orm"
)

func init() {

	_ = orm.RegisterDataBase("default", "mysql", utils.MYSQL_URL)
	orm.SetMaxIdleConns("default", 50)
	orm.SetMaxOpenConns("default", 100)

	db, _ := orm.GetDB("default")
	db.SetConnMaxLifetime(10 * time.Minute)

	_ = orm.RegisterDataBase("rddp", "mysql", utils.MYSQL_URL_RDDP)
	orm.SetMaxIdleConns("rddp", 50)
	orm.SetMaxOpenConns("rddp", 100)

	report_db, _ := orm.GetDB("rddp")
	report_db.SetConnMaxLifetime(10 * time.Minute)

	orm.RegisterDataBase("tactics", "mysql", utils.MYSQL_URL_TACTICS)
	orm.SetMaxIdleConns("tactics", 50)
	orm.SetMaxOpenConns("tactics", 100)

	tacticsDb, _ := orm.GetDB("tactics")
	tacticsDb.SetConnMaxLifetime(10 * time.Minute)

	orm.RegisterDataBase("comein_data", "mysql", utils.MYSQL_URL_COMEIN_DATA)
	orm.SetMaxIdleConns("comein_data", 50)
	orm.SetMaxOpenConns("comein_data", 100)

	comein_datadb, _ := orm.GetDB("comein_data")
	comein_datadb.SetConnMaxLifetime(10 * time.Minute)
	//
	//orm.RegisterDataBase("comein_data", "mysql", utils.MYSQL_URL_COMEIN_DATA)
	//orm.SetMaxIdleConns("comein_data", 50)
	//orm.SetMaxOpenConns("comein_data", 100)
	//
	//comein_dataDb, _ := orm.GetDB("comein_data")
	//comein_dataDb.SetConnMaxLifetime(10 * time.Minute)

	//注册对象
	orm.RegisterModel(
		new(WxUser),
		new(CygxSession),
		new(WxUserLog),
		new(WxUserCode),
		new(CygxArticleCollect),
		new(CygxArticleViewRecord),
		new(CygxAdvice),
		new(MsgCode),
		new(Resource),
		new(CygxApplyRecord),
		new(CygxInterviewApply),
		new(CygxArticle),
		new(CygxArticleHistoryRecord),
		new(CygxSearchKeyWord),
		new(UserRecord),
		new(CygxIndustryTop),
		new(CygxActivitySignup),
		new(CygxActivitySignupLog),
		new(CygxActivityUserSearchContent),
		new(CygxActivityMeetingReminder),
		new(CygxActivityMeetingReminderLog),
		new(CygxMySchedule),
		new(WxUserWhite),
		new(CygxActivityHelpAsk),
		new(CygxIndustryFllow),
		new(CygxArticleDepartmentFollow),
		new(CygxArticleAsk),
		new(CygxPageHistoryRecord),
		new(CygxReportHistoryRecord),
		new(CygxArticleAuthor),
		new(CygxUserRecord),
		new(CygxReportIndustrialSeaarchHistory),
		new(CygxArticleHistoryRecordNewpv),
		new(CygxActivitySearchHistory),
		new(CygxActivityAttendanceDetail),
		new(CygxActivityRestrictSignup),
		new(CygxActivityMeetDetailLog),
		new(CygxUserSearchKeyWord),
		new(CompanyReportPermission),
		new(Company),
		new(CompanyLog),
		new(CompanyOperationRecord),
		new(CompanyPermissionLog),
		new(CompanyProduct),
		new(CompanyProductLog),
		new(UserSellerRelation),
		new(CygxShanghaiCompanyLog),
		new(CygxShanghaiErrLog),
		new(CygxUserFreeeButton),
		new(UserInvitee),
		new(CygxActivitySpecialSignup),
		new(CygxUserFollowSpecial),
		new(CygxChart),
		new(CygxChartCollect),
		new(CygxChartTop),
		new(CygxCelueArticleHistoryRecord),
		new(CygxArticleHistoryRecordAll),
		new(CygxActivityAppointment),
		new(UserTemplateRecord),
		new(CygxUserInteractionNum),
		new(CygxChartCollectByCygx),
		new(CygxCompanyInteractionNum),
		new(CygxChartAll),
		new(CygxSessionMobile),
		new(CygxSearchKeyWordLog),
		new(CygxActivity),
		new(CygxYidongActivityMeetingApiLog),
		new(CygxIndustrialActivityGroupManagement),
		new(CygxIndustrialActivityGroupSubject),
		new(CygxActivityVoiceHistory),
		new(CygxThreeApiLog),
		new(CygxIndustrialArticleGroupManagement),
		new(ArticleTopHistoryRecord),
		new(CygxActivitySignupDetail),
		new(CygxMicroRoadshowVideoHistory),
		new(MicroRoadshowVideo),
		new(CygxActivityVideoHistory),
		new(CygxActivitySpecialTrip),
		new(CygxArticleData),
		new(CygxArticleComment),
		new(CygxResourceData),
		new(CygxResearchSummaryVoiceHistory),
		new(CygxMinutesSummaryVoiceHistory),
		new(CygxReportSelectionVoiceHistory),
		new(CygxActivitySpecialTripBill),
		new(CygxXzsChooseCategory),
		new(CygxReportSelectionSubjectHistory),
		new(CygxTacticsTimeLineHistory),
		new(CygxActivitySignin),
		new(CygxActivitySigninLog),
		new(CygxActivityOfflineMeetingDetail),
		new(CygxProductInteriorHistory),
		new(CygxMorningMeetingGather),
		new(CygxArticleCategoryMapping),
		new(CygxReportMappingCygx),
		new(CygxReportMappingGroup),
		new(CygxAboutUsVideoHistory),
		new(CygxActivitySignupBreak),
		new(CygxBannerHistory),
		new(CygxReportHistoryRecordLog),
		new(CygxUserLabel),
		new(CygxUserLabelActivity),
		new(CygxUserLabelArticle),
		new(CygxUserLabelActivitySpecial),
		new(CygxInviteCompany),
		new(CygxActivityPointsBill),
		new(CygxActivityPointsCompany),
	)
	// 记录ORM查询日志
	orm.Debug = true
	orm.DebugLog = orm.NewLog(utils.BinLog)

}