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
52
53
54
55
56
57
58
59
60
61
62
63
package service
 
import (
    "encoding/json"
    "vamicro/scene-service/models"
    "vamicro/scene-service/vo"
)
 
type AreaCamPolygonService struct {
 
}
 
 
func (sv *AreaCamPolygonService) Save(reqBody vo.AreaCamPVo) bool {
    var acp models.AreaCameraPolygon
    rows, _ := acp.SelectById(reqBody.Id)
    pgnB, _ := json.Marshal(reqBody.CamPolygons)
    if rows >0 { //已经存在,则更新
        a := models.AreaCameraPolygon{
            Id: reqBody.Id,
            Name: reqBody.Name,
            Desc: reqBody.Desc,
            CameraPgn: string(pgnB),
        }
        return a.Update()
    } else {
        a := models.AreaCameraPolygon{
            Id: reqBody.Id,
            Name: reqBody.Name,
            Desc: reqBody.Desc,
            CameraPgn: string(pgnB),
        }
        return a.Insert()
    }
}
 
func (sv *AreaCamPolygonService) Delete(ids []string) bool {
    var acp models.AreaCameraPolygon
    if acp.Delete(ids) {
        return true
    }
    return false
}
func (sv *AreaCamPolygonService) FindAll() (list []vo.AreaCamPVo) {
    var acp models.AreaCameraPolygon
    all, _ := acp.FindAll()
    if all != nil {
        for _, entity :=range all {
            var cPgnList []vo.CamP
            err := json.Unmarshal([]byte(entity.CameraPgn), &cPgnList)
            v := vo.AreaCamPVo{
                Id: entity.Id,
                Name: entity.Name,
                Desc: entity.Desc,
            }
            if err ==nil {
                v.CamPolygons = cPgnList
            }
            list = append(list, v)
        }
    }
    return list
}