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
package serializer
 
import (
    "strconv"
    "strings"
    "vamicro/iotData-service/model"
)
 
type Zone struct {
    Name string       `json:"name"`
    Dots [][2]float64 `json:"dots"`
    Id   uint         `json:"id"`
}
 
func BuildZoneRsp(item model.DrawZone) Zone {
    arr := strings.Split(item.Dots, "&")
    res := [][2]float64{}
    for _, str := range arr {
        sub := strings.Split(str, ",")
        f1, _ := strconv.ParseFloat(sub[0], 64)
        f2, _ := strconv.ParseFloat(sub[1], 64)
        newArr := [2]float64{f1, f2}
        res = append(res, newArr)
    }
    return Zone{
        Name: item.Name,
        Dots: res,
        Id:   item.ID,
    }
}
 
func BuildZonesRsp(items []model.DrawZone) (zones []Zone) {
    for _, item := range items {
        z := BuildZoneRsp(item)
        zones = append(zones, z)
    }
    return
}