1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package main
- import (
- "Cold_Api/conf"
- "Cold_Api/models/Device"
- _ "Cold_Api/routers"
- "fmt"
- "github.com/beego/beego/v2/adapter/orm"
- beego "github.com/beego/beego/v2/server/web"
- "github.com/beego/beego/v2/server/web/filter/cors"
- _ "github.com/go-sql-driver/mysql"
- "runtime"
- "strconv"
- "time"
- )
- func init() {
- fmt.Println(runtime.GOOS)
- orm.RegisterDriver("mysql", orm.DRMySQL)
- //orm.RegisterDataBase("default", "mysql", "zdxq:7e5853d9178edfcc@tcp(47.108.133.234:3306)/zdxq?charset=utf8",100,200)
- 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, false) // 创建数据库
- println(conf.MysqlServer_Username+":"+conf.MysqlServer_Password+"@tcp("+conf.MysqlServer_UrlPort+")/"+conf.MysqlServer_Database+"?charset=utf8mb4&loc=Local&parseTime=True")
- }
- func main() {
- HTTPPort_int, _ := strconv.Atoi(conf.HTTPPort)
- beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
- AllowAllOrigins: true,
- AllowMethods: []string{"*"},
- AllowHeaders: []string{"Origin", "Authorization", "Access-Control-Allow-Origin"},
- ExposeHeaders: []string{"Content-Length", "Access-Control-Allow-Origin"},
- AllowCredentials: true,
- }))
- beego.BConfig.AppName = conf.AppName // 项目名
- beego.BConfig.ServerName = conf.AppName + conf.HTTPPort //server 名称
- beego.BConfig.RunMode = "dev" // 应用的运行模式
- beego.BConfig.Listen.HTTPPort = HTTPPort_int //监听端口 本地:8518 线上:8528
- beego.AddFuncMap("convertm", convertM)
- fmt.Println("======= beego.Run ======")
- beego.Run()
- }
- // 转十进制
- func convertM(Devicesensor Device.DeviceSensor) (out string) {
- var TouTime float64
- TouTime = 2 * 60
- now := time.Now()
- //DeviceData_, is := Device.Read_DeviceSensorData_ById_New(Devicesensor.T_sn, Devicesensor.T_id)
- //if is {
- // // 谁 是最新的
- // fmt.Println(DeviceData_.T_time, DeviceData_.T_time.Format("2006-01-02 15:04:05"))
- // fmt.Println(Devicesensor.T_time, Devicesensor.T_time.Format("2006-01-02 15:04:05"))
- // if DeviceData_.T_time.Unix() > Devicesensor.T_time.Unix() {
- // subM := now.Sub(DeviceData_.T_time)
- // fmt.Println(subM.Minutes(), "分钟")
- // if subM.Minutes() > TouTime {
- // return "温湿度传感器-2.png"
- // } else {
- // return "温湿度传感器-1.png"
- // }
- //
- // }
- //}
- //fmt.Println(Devicesensor.T_time, Devicesensor.T_time.Format("2006-01-02 15:04:05"))
- subM := now.Sub(Devicesensor.T_time)
- //fmt.Println(int(subM.Minutes()), "分钟")
- if subM.Minutes() > TouTime {
- // 传感器超时
- return "温湿度传感器-2.png"
- }
- if (0 == Devicesensor.T_Tlower && 0 == Devicesensor.T_RHlower) && (0 == Devicesensor.T_Tupper && 0 == Devicesensor.T_RHupper) {
- return "温湿度传感器-1.png"
- }
- if Devicesensor.T_t < Devicesensor.T_Tlower || Devicesensor.T_rh < Devicesensor.T_RHlower || Devicesensor.T_t > Devicesensor.T_Tupper || Devicesensor.T_rh > Devicesensor.T_RHupper {
- // 传感器 超标
- return "温湿度传感器-3.png"
- }
- // 传感器正常
- return "温湿度传感器-1.png"
- }
|