qixiaoning
2025-07-24 343a89f9fa20d2d142469b2a4531e16ce03d3525
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
package serializer
 
import (
    "vamicro/iotData-service/model"
)
 
type Device struct {
    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"`
    VisitTime   string  `json:"visit_time"`
    LocateState string  `json:"locate_state"`
    Ip          string  `json:"ip"`
    Mac         string  `json:"mac"`
    IsOutBound  int     `json:"is_out_bound"`
    BoundId     uint    `json:"bound_id"` // 所处的电子围栏
}
 
func BuildDeviceRsp(item model.Device) Device {
    return Device{
        SN:          item.SN,
        Lng:         item.Lng,
        Lat:         item.Lat,
        Battery:     item.Battery,
        High:        item.High,
        GpsType:     item.GpsType,
        VisitTime:   item.UpdatedAt.Local().Format("2006-01-02 15:04:05"),
        LocateState: item.LocateState,
        Ip:          item.Ip,
        Mac:         item.Mac,
        IsOutBound:  item.IsOutBound,
        BoundId:     item.BoundId,
    }
}
 
func BuildDevicesRsp(items []model.Device) (dvs []Device) {
    for _, item := range items {
        dv := BuildDeviceRsp(item)
        dvs = append(dvs, dv)
    }
    return
}