From de0be9f4ffb94c8bca74a7da3174e50d93782540 Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期六, 02 十一月 2019 16:53:37 +0800
Subject: [PATCH] camera show return runServerName
---
controllers/cluster.go | 15 +++++++++++++++
controllers/camera.go | 35 +++++++++++++++++++++++++++++++----
2 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/controllers/camera.go b/controllers/camera.go
index 0afa253..83646ba 100644
--- a/controllers/camera.go
+++ b/controllers/camera.go
@@ -123,8 +123,8 @@
// @Produce json
// @Tags camera
// @Param cid path string true "鎽勫儚鏈篿d"
-// @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)
}
diff --git a/controllers/cluster.go b/controllers/cluster.go
index f81dade..bfbda95 100644
--- a/controllers/cluster.go
+++ b/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 鍒涘缓闆嗙兢
--
Gitblit v1.8.0