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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package controllers
 
import (
    "basic.com/pubsub/protomsg.git"
    "basic.com/valib/bhomeclient.git"
    "encoding/json"
    "github.com/satori/go.uuid"
    "strings"
    "vamicro/scene-service/models"
    "vamicro/scene-service/service"
)
 
type CameraGroupController struct {
}
 
// @Summary 查询所有摄像机分组
// @Description  查询所有摄像机分组
// @Produce json
// @Tags 摄像机分组
// @Param  groupName query string true "分组名称"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"", data:""}"
// @Router /data/api-v/camera/group/findAll [get]
func (cgc *CameraGroupController) FindAll(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    var result = make([]CameraGroupVo, 0)
    var cg models.CameraGroup
    arr := cg.FindAll()
    if arr != nil {
        for _, g := range arr {
            gn := CameraGroupVo{
                Id:        g.Id,
                GroupName: g.GroupName,
            }
            gn.CameraIds = strings.Split(g.CameraIds, ",")
 
            result = append(result, gn)
        }
    }
    return &bhomeclient.Reply{Success: true, Data: result}
}
 
type CameraGroupVo struct {
    Id        string   `json:"id" binding:"required"`
    GroupName string   `json:"groupName" binding:"required"`
    CameraIds []string `json:"cameraIds"`
}
 
// @Summary 新增摄像机分组
// @Description  新增摄像机分组
// @Produce json
// @Tags 摄像机分组
// @Param  reqBody body controllers.CameraGroupVo true "分组保存参数"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"", data:""}"
// @Router /data/api-v/camera/group/save [post]
func (cgc *CameraGroupController) Save(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    var reqBody CameraGroupVo
    err := c.BindJSON(&reqBody)
    if err != nil {
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
 
    if reqBody.Id == "" {
        tmp := models.CameraGroup{
            Id:        uuid.NewV4().String(),
            GroupName: reqBody.GroupName,
            CameraIds: strings.Join(reqBody.CameraIds, ","),
        }
        if b, err := tmp.Insert(); b {
            return &bhomeclient.Reply{Success: true, Data: tmp}
        } else {
            return &bhomeclient.Reply{Msg: err.Error()}
        }
    } else {
        tmp := models.CameraGroup{
            Id:        reqBody.Id,
            GroupName: reqBody.GroupName,
            CameraIds: strings.Join(reqBody.CameraIds, ","),
        }
        if b, err := tmp.Update(); b {
            return &bhomeclient.Reply{Success: true, Data: tmp}
        } else {
            return &bhomeclient.Reply{Msg: err.Error()}
        }
    }
}
 
// @Summary 删除摄像机分组
// @Description  删除摄像机分组
// @Produce json
// @Tags 摄像机分组
// @Param  reqBody body controllers.CameraGroupVo true "分组保存参数"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"", data:""}"
// @Router /data/api-v/camera/group/del [delete]
func (cgc *CameraGroupController) Delete(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    groupId := c.Query("groupId")
    if groupId == "" {
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
 
    var cg models.CameraGroup
    if cg.Delete(groupId) {
        cgc.addDbChangeMsg(h.Bk, protomsg.TableChanged_T_CameraPolygonRelation, "", protomsg.DbAction_Delete, "")
        return &bhomeclient.Reply{Success: true, Msg: "删除成功"}
    } else {
        return &bhomeclient.Reply{Msg: "删除失败"}
    }
}
 
func (cgc *CameraGroupController) addDbChangeMsg(bk bhomeclient.Broker, tChanged protomsg.TableChanged, id string, action protomsg.DbAction, info string) {
    dbMsg := protomsg.DbChangeMessage{
        Table:  tChanged,
        Id:     id,
        Action: action,
        Info:   info,
    }
    pb, _ := json.Marshal(dbMsg)
    bk.Publish(service.ProcName, pb)
}