package beegodb

import (
	"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/jcq"
	"git.rosy.net.cn/jx-callback/business/model"
	"git.rosy.net.cn/jx-callback/business/model/legacymodel"
	"git.rosy.net.cn/jx-callback/globals"
	"github.com/astaxie/beego/client/orm"
	"github.com/astaxie/beego/server/web"
)

func Init() {
	//正式服务器
	orm.RegisterDataBase("default", "mysql", web.AppConfig.DefaultString("dbConnectStr", ""))
	orm.RegisterDataBase("c4beta", "mysql", "ubuntu:WebServer@1@tcp(111.231.218.230:3306)/jxd_dev_0?charset=utf8mb4&loc=Local&parseTime=true")
	orm.RegisterDataBase("api", "mysql", "root:WebServer@1@tcp(127.0.0.1:3306)/api?charset=utf8mb4&loc=Local&parseTime=true")

	// 本地测试服调试
	//orm.RegisterDataBase("default", "mysql", web.AppConfig.DefaultString("dbConnectStr", ""))
	//orm.RegisterDataBase("c4beta", "mysql", "ubuntu:WebServer@1@tcp(127.0.0.1:3306)/jxd_dev_0?charset=utf8mb4&loc=Local&parseTime=true")
	//orm.RegisterDataBase("api", "mysql", "root:WebServer@1@tcp(127.0.0.1:3306)/api?charset=utf8mb4&loc=Local&parseTime=true")
	// 开启sql打印
	//orm.Debug = true
	orm.RegisterModel(&model.SupermarketSign{})
	orm.RegisterModel(new(legacymodel.Config))
	orm.RegisterModel(new(legacymodel.BlackClient))
	orm.RegisterModel(new(legacymodel.JxBadComments))
	orm.RegisterModel(new(legacymodel.StoreBill))
	// if !globals.DisableWXAuth1 {
	// 	orm.RegisterModel(new(legacymodel.WeiXins))
	// }
	orm.RegisterModel(new(model.GoodsOrder))
	orm.RegisterModel(new(model.GoodsOrderOriginal))
	orm.RegisterModel(new(model.GoodsOrderImg))
	orm.RegisterModel(new(model.TempGoodsOrderMobile))
	orm.RegisterModel(new(model.OrderSku))
	orm.RegisterModel(new(model.Waybill))
	orm.RegisterModel(new(model.OrderStatus))

	orm.RegisterModel(new(model.Message))
	orm.RegisterModel(new(model.MessageStatus))
	orm.RegisterModel(new(model.ImMessageRecord))
	orm.RegisterModel(new(jcq.JcqMessage))

	orm.RegisterModel(&model.Place{})
	orm.RegisterModel(&model.Store{}, &model.StoreSub{}, &model.StoreMap{}, &model.StoreCourierMap{}, &model.StoreCategoryMap{})
	orm.RegisterModel(&model.SkuVendorCategory{}, &model.StoreSkuCategoryMap{}, &model.SkuName{}, &model.Sku{}, &model.SkuNamePlaceBind{}, &model.StoreSkuBind{})
	orm.RegisterModel(&model.SkuVendorCategoryMap{}) //商品映射平台类目
	orm.RegisterModel(&model.VendorCategoryMap{})    //平台分类
	orm.RegisterModel(&model.StoreSkuBindHistory{})
	orm.RegisterModel(&model.StoreSkuAudit{})
	orm.RegisterModel(&model.StoreMapAudit{}) //商户申请授权绑定
	orm.RegisterModel(&model.SkuCategory{})
	orm.RegisterModel(&model.ThingMap{})
	orm.RegisterModel(&model.SkuExinfoMap{})
	orm.RegisterModel(&model.StorePushClient{})
	orm.RegisterModel(&model.StoreAudit{})
	orm.RegisterModel(&model.Brand{}, &model.BrandCategoryMap{})
	orm.RegisterModel(&model.BrandStore{})
	orm.RegisterModel(&model.BrandBill{}, &model.BrandOrder{}, &model.BrandUser{})
	orm.RegisterModel(&model.TaoSkuImg{})

	orm.RegisterModel(&model.AuthBind{}, &model.User{})

	orm.RegisterModel(&model.PageShop{})
	orm.RegisterModel(&model.PageSku{})
	orm.RegisterModel(&model.PageStore{})
	orm.RegisterModel(&model.PageBrand{})
	orm.RegisterModel(&model.VendorStoreSnapshot{})
	orm.RegisterModel(&model.PriceReferSnapshot{})
	orm.RegisterModel(&model.StoreManageState{})
	orm.RegisterModel(&model.StorePriceScoreSnapshot{})
	orm.RegisterModel(&model.StoreSkuNamePrice{})
	orm.RegisterModel(&model.OrderSupplementFee{})
	orm.RegisterModel(&model.OperateEvent{})
	orm.RegisterModel(&model.OperateEventDetail{})
	orm.RegisterModel(&model.SecretNumber{})
	orm.RegisterModel(&model.BiddingInfo{})

	orm.RegisterModel(&model.FreightTemplate{}) //抖店存储门店与 仓库、运费模板、电子围栏的映射关系
	// orm.RegisterModel(&model.ActivityForSku{})
	// orm.RegisterModel(&legacymodel.JxBadComments2{})

	if globals.EnablePendingChange {
		orm.RegisterModel(&model.StoreOpRequest{})
	}

	// 如下语句建表时要出错（INDEX名字太长了），暂时放一下，必须放最后一句
	orm.RegisterModel(&model.OrderFinancial{}, &model.AfsOrder{}, &model.OrderDiscountFinancial{}, &model.OrderSkuFinancial{})
	orm.RegisterModel(&model.PriceDefendOrder{})
	orm.RegisterModel(&model.Act{}, &model.ActOrderRule{}, &model.ActStoreSku{})
	orm.RegisterModel(&model.ActMap{}, &model.ActStoreSkuMap{})
	if globals.IsStoreSkuAct {
		orm.RegisterModel(&model.StoreSkuAct{})
	}
	orm.RegisterModel(&model.ActMtwmVendor{})
	orm.RegisterModel(&model.ActEbaiVendor{})
	orm.RegisterModel(&model.ActEbaiVendorSku{})

	orm.RegisterModel(&model.NewConfig{})

	orm.RegisterModel(&model.CasbinRule{})
	orm.RegisterModel(&model.SensitiveWord{})
	orm.RegisterModel(&model.StoreScore{})
	orm.RegisterModel(&model.StoreFine{})
	orm.RegisterModel(&model.StoreAlert{})
	orm.RegisterModel(&model.FoodRecipe{}, &model.FoodRecipeStep{}, &model.FoodRecipeItem{}, &model.FoodRecipeItemChoice{}, &model.FoodRecipeUser{})
	orm.RegisterModel(&model.DataResource{})

	orm.RegisterModel(&model.UserDeliveryAddress{})
	orm.RegisterModel(&model.UserCartItem{})
	orm.RegisterModel(&model.UserAgreement{})
	orm.RegisterModel(&model.UserMember{})
	orm.RegisterModel(&model.OrderPay{}, &model.OrderPayRefund{})
	orm.RegisterModel(&model.UserOrderSms{})
	orm.RegisterModel(&model.FakeJdThingMap{})
	orm.RegisterModel(&model.VendorOrgCode{})
	orm.RegisterModel(&model.MtJdCategoryMap{})

	//优惠券
	orm.RegisterModel(&model.Coupons{})
	orm.RegisterModel(&model.UserCoupons{})
	orm.RegisterModel(&model.StoreCoupons{})

	//权限
	orm.RegisterModel(&model.Role{})
	orm.RegisterModel(&model.UserRole{})
	orm.RegisterModel(&model.Menu{})
	orm.RegisterModel(&model.RoleMenu{})

	//门店账单
	orm.RegisterModel(&model.StoreAcct{})
	orm.RegisterModel(&model.StoreAcctExpend{})
	orm.RegisterModel(&model.StoreAcctIncome{})
	orm.RegisterModel(&model.StoreAcctOrder{})

	// 拉卡拉分账
	orm.RegisterModel(&model.LakalaContract{})
	orm.RegisterModel(&model.LakalaIncoming{})
	orm.RegisterModel(&model.LakalaRecipient{})
	orm.RegisterModel(&model.LakalaSeparateAmt{})
	orm.RegisterModel(&model.LakalaWithdrawal{})
	orm.RegisterModel(&model.InvoiceMsg{})
	// 存储获取到的美团任务信息
	orm.RegisterModel(&model.ActivityStation{})

	//发送图文消息公众号
	orm.RegisterModel(&model.KnowledgeDepot{})
	// create table
	orm.RunSyncdb("default", false, true)
}
