liuxiaolong
2019-11-02 de0be9f4ffb94c8bca74a7da3174e50d93782540
camera show return runServerName
2个文件已修改
50 ■■■■■ 已修改文件
controllers/camera.go 35 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/cluster.go 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/camera.go
@@ -123,8 +123,8 @@
// @Produce json
// @Tags camera
// @Param cid path string true "摄像机id"
// @Success 200 {string} json "{"code":200, success:true,  msg:"请求处理成功", data:"摄像机信息"}"
// @Failure 500 {string} json "{"code":500, success:false   msg:"",data:"错误信息内容"}"
// @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/show/{cid} [get]
func (ac CameraController) CameraSel(c *gin.Context) {
    var api dbapi.CameraApi
@@ -134,8 +134,35 @@
        util.ResponseFormat(c, code.ComError, "查询失败")
        return
    }
    util.ResponseFormat(c, code.Success, camera)
    //2019-11-02新增需求,显示每个摄像机的处理服务器信息,归属的节点服务器名称
    m := util.Struct2Map(camera)
    m["runServerName"] = ""
    if camera.RunServerId !="" {
        localConf, e := cache.GetServerInfo()
        if e ==nil {
            if camera.RunServerId == localConf.ServerId {//归属本台服务器
                m["runServerName"] = localConf.ServerName
            } else {//属于其他服务器
                var clusterApi dbapi.ClusterApi
                b, data := clusterApi.FindCluster()
                if b && data !=nil {
                    cb, _ := json.Marshal(data)
                    var clu ClusterDb
                    if err := json.Unmarshal(cb, &clu);err ==nil {
                        if len(clu.Nodes) >0 {
                            for _,n :=range clu.Nodes {
                                if camera.RunServerId == n.NodeId {
                                    m["runServerName"] = n.NodeName
                                    break
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    util.ResponseFormat(c, code.Success, m)
}
controllers/cluster.go
@@ -54,6 +54,21 @@
    NodeIps []string `json:"nodeIps"`
}
type ClusterDb struct {
    ClusterId   string `json:"clusterId"`
    ClusterName string `json:"clusterName"`
    Nodes []NodeDb     `json:"nodes"`
}
type NodeDb struct {
    Id string `json:"id"`
    ClusterId string `json:"cluster_id"`
    NodeName string `json:"node_name"`
    NodeId string `json:"node_id"`
    NodeIp string `json:"node_ip"`
    CreateTime string `json:"create_time"`
    IsDelete bool `json:"isDelete"`
}
// @Security ApiKeyAuth
// @Summary 创建集群
// @Description 创建集群