qixiaoning
2025-08-21 e38654fe9eff4562da4f18f8f018aed7879d493c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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()  {
 
// }