qixiaoning
2025-07-08 84d2ef9760af0a4a4aa933937294400b3caa291d
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
52
53
54
55
56
57
58
package serializer
 
import (
    "vamicro/iotData-service/model"
)
 
// 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是
//
// }
type WarnRsp struct {
    Id           uint    `json:"id"`
    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已处理
    CreatedAt    string  `json:"created_at"`
    UpdatedAt    string  `json:"updated_at"`
    SnapShot     string  `json:"snap_shot"`
}
 
func BuildWarnRsp(item model.Warning) WarnRsp {
    return WarnRsp{
        Id:           item.ID,
        SN:           item.SN,
        Lng:          item.Lng,
        Lat:          item.Lat,
        Battery:      item.Battery,
        High:         item.High,
        GpsType:      item.GpsType,
        IsLowBattery: item.IsLowBattery,
        IsOutBound:   item.IsOutBound,
        Status:       item.Status,
        CreatedAt:    item.CreatedAt.Local().Format("2006-01-02 15:04:05"),
        UpdatedAt:    item.UpdatedAt.Local().Format("2006-01-02 15:04:05"),
        SnapShot:     item.SnapShot,
    }
}
 
func BuildWarnsRsp(items []model.Warning) (dvs []WarnRsp) {
    for _, item := range items {
        dv := BuildWarnRsp(item)
        dvs = append(dvs, dv)
    }
    return
}