package main

import (
	"Cold_Data/Nats"
	_ "Cold_Data/StatisticsTask"
	"Cold_Data/conf"
	"Cold_Data/models/Device"
	_ "Cold_Data/routers"
	"github.com/beego/beego/v2/adapter/orm"
	beego "github.com/beego/beego/v2/server/web"
	_ "github.com/go-sql-driver/mysql"
	"strconv"
)

func init() {

	orm.RegisterDriver("mysql", orm.DRMySQL)
	orm.RegisterDataBase("default", "mysql",
		conf.MysqlServer_Username+":"+conf.MysqlServer_Password+"@tcp("+conf.MysqlServer_UrlPort+")/"+conf.MysqlServer_Database+"?charset=utf8mb4&loc=Local&parseTime=True",
		conf.MysqlServer_MaxIdleConnections, conf.MysqlServer_MaxOpenConnections)
	//orm.RunSyncdb("default", false, true) // 创建数据库

	//logs.Println("MysqlServer:" + conf.MysqlServer_Username + ":" + conf.MysqlServer_Password + "@tcp(" + conf.MysqlServer_UrlPort + ")/" + conf.MysqlServer_Database + "?charset=utf8mb4&loc=Local&parseTime=True")

}

func main() {

	beego.BConfig.AppName = conf.AppName + "_" + strconv.Itoa(conf.HTTPPort)    // 项目名
	beego.BConfig.ServerName = conf.AppName + "_" + strconv.Itoa(conf.HTTPPort) //server  名称
	beego.BConfig.RunMode = "dev"                                               //  应用的运行模式
	beego.BConfig.Listen.HTTPPort = conf.HTTPPort                               //监听端口  本地：8518  线上：8528

	Device.Hande_device_sensor_type() // 设备类型统计

	go Nats.NatsInit() // Nats 通讯

	beego.Run()
}
