package models import "time" //路灯控制器,数据来自web type Lampstrategy struct { ID string `gorm:"type:varchar(32);primary_key"` //策略编码 Name string `gorm:"type:varchar(64)"` //策略名称 CtlType int `gorm:"type:int"` //单灯控制器类型,nb-iot:1,485:2,zigbee:3 TimeInfo string `gorm:"type:text"` //LampTime数组 时间及亮度内容数组,最多4个元素,最少1个元素 Sunset int `gorm:"type:int"` //是否启用日出日落时间,1启用,0禁用 Start time.Time `gorm:"type:datetime"` //时间格式,类似2020-07-20 06:06:06 End time.Time `gorm:"type:datetime"` //时间格式,类似2020-09-20 06:06:06 Year int `gorm:"type:int"` //是否全年,1全年,0非全年 Auto int `gorm:"type:int"` //1,自动延续,0非自动延续 Tenant string `gorm:"type:varchar(8)"` //租户ID Longitude float64 `gorm:"type:decimal(10,7)"` //东正西负。双精度浮点数,整数最多3字符,小数最多6字符 Latitude float64 `gorm:"type:decimal(10,7)"` //北正南负,双精度浮点数,整数最多2字符,小数最多6字符 LcModel } func (Lampstrategy) TableName() string { //从视图中查询 return "t_lamp_strategy" } func (o Lampstrategy) IsExistedByCode() (bool, error) { var count int = 0 err := G_db.Model(&o).Where(" id = ? ", o.ID).Count(&count).Error return count > 0, err } //设备创建和更新 func (o Lampstrategy) SaveFromWeb() error { has, err := o.IsExistedByCode() if err != nil { return err } if has { return G_db.Model(&o).Updates(map[string]interface{}{ "name": o.Name, "ctl_type": o.CtlType, "time_info": o.TimeInfo, "sunset": o.Sunset, "start": o.Start, "end": o.End, "year": o.Year, "auto": o.Auto, "tenant": o.Tenant, "longitude": o.Longitude, "latitude": o.Latitude}).Error } else { //插入 return G_db.Create(&o).Error } } type LampStrategy struct { Ontime string `json:"ontime"` //开始时间,24小时制,格式{小时}:{分钟}:{秒}类似13:06:00,为13点6分 Offtime string `json:"offtime"` //结束时间,24小时制,格式同ontime Brightness int `json:"brightness"` //亮度,1到100 }