package model
|
|
import "github.com/jinzhu/gorm"
|
|
type Warning struct {
|
gorm.Model
|
SN string `json:"device_sn"`
|
Lng float64 `json:"lng"`
|
Lat float64 `json:"lat"`
|
Battery float64 `json:"battery"`
|
High float64 `json:"high"`
|
GpsType string `json:"gps_type"`
|
IsLowBattery int `json:"isLowBattery" gorm:"default 0"` //0不是 1是
|
IsOutBound int `json:"isOutBound" gorm:"default 0"` //0不是 1是
|
Status int `json:"status" gorm:"default 0"` //0未处理 1已处理
|
SnapShot string `json:"snapShot"`
|
}
|
|
// const (
|
// WarnType_lowBattery = iota
|
// WarnType_outBound
|
// )
|
|
func (obj *Warning) HandleWarning() (err error) {
|
if obj.Battery < 20 && obj.Battery >0{
|
obj.IsLowBattery = 1
|
err = DB.Model(&Warning{}).Create(&obj).Error
|
if err != nil {
|
return err
|
}
|
}
|
/*
|
首先检查当前是否存在画框
|
如果经纬度超出了画框边界,则将obj.IsOutBound置为1
|
*/
|
// CheckInBound()
|
|
return nil
|
}
|
|
func (obj *Warning) GetSumByDate(start, end string) (count int64, err error) {
|
err = DB.Model(&Warning{}).Where("created_at between ? and ?", start, end).Where("is_low_battery = 1 or is_out_bound = 1").Count(&count).Error
|
if err != nil {
|
return 0, err
|
}
|
return count, nil
|
}
|
|
// func CheckInBound() {
|
|
// }
|