From 63e024e77d8e0fefd8818f1b744cbfc5e36b50fe Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期六, 14 十二月 2019 14:56:32 +0800
Subject: [PATCH] fix localconfig

---
 controllers/syssetcont.go |  159 ++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 140 insertions(+), 19 deletions(-)

diff --git a/controllers/syssetcont.go b/controllers/syssetcont.go
index 1ba05ba..8bc66fc 100644
--- a/controllers/syssetcont.go
+++ b/controllers/syssetcont.go
@@ -1,6 +1,7 @@
 package controllers
 
 import (
+	"regexp"
 	"webserver/extend/code"
 	"webserver/extend/config"
 	"webserver/extend/sys"
@@ -15,6 +16,7 @@
 
 type LocalConfigVo struct {
 	Id                 string `json:"id"`
+
 	AlarmIp            string `json:"alarm_ip,omitempty" example:"192.168.1.182"`
 	AlarmPort          int    `json:"alarm_port,omitempty" example:"22122"`
 	AlarmThresholdType int    `json:"alarm_threshold_type"` //鎶ヨ闃堝�肩被鍨嬭缃細1:鎸夋渶楂樺垎,2:鎸夐槇鍊间互涓�
@@ -30,6 +32,12 @@
 	ServerType         int    `json:"server_type,omitempty" example:"1"`
 	Reserved           string `json:"reserved,omitempty" example:"1"`
 	RealMax            int    `json:"real_max"` //瀹炴椂澶勭悊鐨勬渶澶ц矾鏁�
+}
+
+type ResourceConfigVo struct {
+	IpType 		int   	`json:"ipType"` //0:鏈満ip锛�1锛氭紓绉籭p
+	ServiceIp   string 	`json:"serviceIp"`  //澶栭儴鏈嶅姟ip
+	Domain 		string  `json:"domain"` //鍩熷悕
 }
 
 type Gb28181ConfigVo struct {
@@ -51,6 +59,7 @@
 	NewTime   string `json:"newTime" example:"鎵嬪姩鎸囧畾鏃堕棿"`
 }
 
+// @Security ApiKeyAuth
 // @Summary 瀛樺偍淇℃伅鏌ヨ
 // @Description 瀛樺偍淇℃伅鏌ヨ
 // @Accept  json
@@ -69,14 +78,15 @@
 	}
 }
 
+// @Security ApiKeyAuth
 // @Summary 瀛樺偍淇℃伅淇敼
 // @Description 瀛樺偍淇℃伅淇敼
 // @Accept  json
 // @Produce json
 // @Tags sysset
 // @Param config body controllers.LocalConfigVo true "鎶ヨ鍜屽瓨鍌ㄤ俊鎭暟鎹�"
-// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}"
-// @Failure 500 {string} json "{"code":500,  msg:"杩斿洖閿欒淇℃伅", success:false}"
+// @Success 200 {string} json "{"code":200, msg:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
 // @Router /data/api-v/sysset/alarmEdit [POST]
 func (sset SysSetController) AlarmEdit(c *gin.Context) {
 	var args LocalConfigVo
@@ -95,9 +105,9 @@
 	}
 }
 
+// @Security ApiKeyAuth
 // @Summary 瀛樺偍淇℃伅淇敼
 // @Description 瀛樺偍淇℃伅淇敼
-// @Accept  json
 // @Produce json
 // @Tags sysset
 // @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}"
@@ -117,6 +127,7 @@
 	}
 }
 
+// @Security ApiKeyAuth
 // @Summary 瑙嗛鎴彇鏃堕暱淇敼
 // @Description 瑙嗛鎴彇鏃堕暱淇℃伅
 // @Accept  x-www-form-urlencoded
@@ -142,6 +153,7 @@
 	}
 }
 
+// @Security ApiKeyAuth
 // @Summary 鑾峰彇鍒嗘瀽璁惧淇℃伅
 // @Description  鍒嗘瀽璁惧淇℃伅
 // @Accept  json
@@ -153,7 +165,7 @@
 func (sset SysSetController) GetDevInfo(c *gin.Context) {
 	var api dbapi.SysSetApi
 	b, sysconf := api.GetServerInfo()
-	resData := make(map[string]string, 0)
+	resData := make(map[string]interface{}, 0)
 	if !b { // 鏌ヨ鏄惁瀛樺湪
 		util.ResponseFormat(c, code.ServiceInsideError, "鏌ヨ澶辫触")
 	} else {
@@ -166,6 +178,14 @@
 		resData["subMask"] = mask
 		resData["gateway"] = gateway
 		resData["dns"] = dns
+		resData["min_video_len"] = sysconf.CutMinDuration
+		resData["max_video_len"] = sysconf.CutMaxDuration
+		resData["alarm_ip"] = sysconf.AlarmIp
+		resData["alarm_port"] = sysconf.AlarmPort
+		resData["web_pic_ip"] = sysconf.WebPicIp
+		resData["web_pic_port"] = sysconf.WebPicPort
+		resData["es_pic_ip"] = sysconf.EsPicIp
+		resData["es_pic_port"] = sysconf.EsPicPort
 
 		resData["deviceNum"] = config.Server.DeviceNum
 		resData["deviceType"] = config.Server.DeviceType
@@ -179,6 +199,7 @@
 	}
 }
 
+// @Security ApiKeyAuth
 // saveDevInfo  dev_id dev_name
 // @Summary 淇濆瓨瑙嗛鍒嗘瀽璁惧淇℃伅
 // @Description 鍒嗘瀽璁惧淇℃伅
@@ -190,7 +211,6 @@
 // @Failure 500 {string} json "{"code":500,  msg:"杩斿洖閿欒淇℃伅", success:false}"
 // @Router /data/api-v/sysset/saveDevInfo [POST]
 func (sset SysSetController) SaveDevInfo(c *gin.Context) {
-
 	dev_name := c.PostForm("server_name")
 	var api dbapi.SysSetApi
 	paramBody := make(map[string]interface{}, 0)
@@ -211,6 +231,7 @@
 	}
 }
 
+// @Security ApiKeyAuth
 // @Summary GB28181璁剧疆鏌ヨ
 // @Description GB28181璁剧疆淇℃伅鏌ヨ
 // @Accept  json
@@ -229,6 +250,7 @@
 	}
 }
 
+// @Security ApiKeyAuth
 // @Summary GB28181璁剧疆淇℃伅淇敼
 // @Description GB28181璁剧疆淇敼
 // @Accept  json
@@ -255,6 +277,7 @@
 	}
 }
 
+// @Security ApiKeyAuth
 // @Summary 鑾峰彇鏃堕棿閰嶇疆
 // @Description  绯荤粺鏃堕棿閰嶇疆淇℃伅
 // @Accept  json
@@ -271,9 +294,9 @@
 	util.ResponseFormat(c, code.Success, resData)
 }
 
+// @Security ApiKeyAuth
 // @Summary 娴嬭瘯鍚屾鏃堕棿
 // @Description 娴嬭瘯鍚屾鏃堕棿鏈嶅姟鍣ㄦ槸鍚﹀彲鐢�
-// @Accept  json
 // @Produce json
 // @Tags sysset
 // @Param server query string true "鏃堕棿鏈嶅姟鍣╥p"
@@ -288,19 +311,17 @@
 		return
 	}
 
-	isIP, err := sys.RunNTPDate(ntpServer)
-	if !isIP {
-		util.ResponseFormat(c, code.RequestParamError, "鎸囧畾鐨勬湇鍔″櫒鍦板潃閿欒")
+	isConn := sys.RunNTPDate(ntpServer)
+	if !isConn {
+		util.ResponseFormat(c, code.RequestParamError, "NTP鏈嶅姟鍣ㄤ笉鍙敤")
 		return
 	}
 
-	if err == nil {
-		util.ResponseFormat(c, code.Success, "")
-	} else {
-		util.ResponseFormat(c, code.TaskStoped, "")
-	}
+	util.ResponseFormat(c, code.Success, "")
+
 }
 
+// @Security ApiKeyAuth
 // @Summary 璁剧疆绯荤粺鏃堕棿
 // @Description 鏍℃绯荤粺鏃堕棿
 // @Accept  json
@@ -315,11 +336,6 @@
 	err := c.BindJSON(&args)
 	if err != nil {
 		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎")
-		return
-	}
-
-	if root := sys.CheckRootPermissions(); !root {
-		util.ResponseFormat(c, code.ServiceInsideError, "鏈嶅姟鍣ㄦ病鏈変慨鏀规椂闂寸殑鏉冮檺")
 		return
 	}
 
@@ -345,6 +361,7 @@
 	util.ResponseFormat(c, code.UpdateSuccess, "閰嶇疆鎴愬姛")
 }
 
+// @Security ApiKeyAuth
 // @Summary 鏌ヨ绯荤粺杩愯淇℃伅
 // @Description 鑾峰彇褰撳墠绯荤粺鐨勮繍琛岀姸鎬侊紝CPU, GPU, 鍐呭瓨绛�
 // @Produce json
@@ -357,6 +374,7 @@
 	util.ResponseFormat(c, code.UpdateSuccess, info)
 }
 
+// @Security ApiKeyAuth
 // @Summary 鏌ヨ绯荤粺鐘舵�侀槇鍊艰缃�
 // @Description 鑾峰彇褰撳墠绯荤粺鐨勮繍琛岀姸鎬侊紝CPU, GPU, 鍐呭瓨鐨勯槇鍊奸厤缃�
 // @Produce json
@@ -367,3 +385,106 @@
 func (sset SysSetController) GetSysThresholds(c *gin.Context) {
 	util.ResponseFormat(c, code.UpdateSuccess, config.Server.SysThresholds)
 }
+
+// @Security ApiKeyAuth
+// @Summary 閲嶅惎绯荤粺
+// @Description 閲嶅惎鎿嶄綔绯荤粺
+// @Produce json
+// @Tags sysset
+// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}"
+// @Failure 500 {string} json "{"code":500,  msg:"杩斿洖閿欒淇℃伅", success:false}"
+// @Router /data/api-v/sysset/reboot [GET]
+func (sset SysSetController) RebootOS(c *gin.Context) {
+	if isOk, msg := sys.Reboot(); !isOk {
+		util.ResponseFormat(c, code.UpdateFail, msg)
+		return
+	}
+
+	util.ResponseFormat(c, code.Success, "姝e湪閲嶅惎")
+}
+
+// @Summary 鑾峰彇瀹氭椂閲嶅惎
+// @Description 鑾峰彇瀹氭椂閲嶅惎浠诲姟鐨勯厤缃鍒�
+// @Produce json
+// @Tags sysset
+// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}"
+// @Failure 500 {string} json "{"code":500,  msg:"杩斿洖閿欒淇℃伅", success:false}"
+// @Router /data/api-v/sysset/rebootTask [GET]
+func (sset SysSetController) GetRebootTask(c *gin.Context) {
+	_, msg := sys.ReadRebootTaskInCrontab()
+	util.ResponseFormat(c, code.Success, msg)
+}
+
+// @Summary 璁剧疆瀹氭椂閲嶅惎
+// @Description 璁剧疆瀹氭椂閲嶅惎浠诲姟鐨勯厤缃鍒�
+// @Accept x-www-form-urlencoded
+// @Produce json
+// @Tags sysset
+// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}"
+// @Failure 500 {string} json "{"code":500,  msg:"杩斿洖閿欒淇℃伅", success:false}"
+// @Router /data/api-v/sysset/rebootTask [POST]
+func (sset SysSetController) SetRebootTask(c *gin.Context) {
+	task := c.PostForm("task")
+	if len(task) < 1 {
+		sys.CleanRebootTask()
+		util.ResponseFormat(c, code.Success, "閰嶇疆鎴愬姛")
+		return
+	}
+
+	regEx := `^([0-9*]+\s){4}[0-9*]+$`
+	if r, _ := regexp.MatchString(regEx, task); !r {
+		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟閿欒")
+		return
+	}
+
+	if r := sys.UpdateRebootTask(task); !r {
+		util.ResponseFormat(c, code.UpdateFail, "閰嶇疆澶辫触")
+		return
+	}
+
+	util.ResponseFormat(c, code.Success, "閰嶇疆鎴愬姛")
+}
+
+// @Security ApiKeyAuth
+// @Summary 鑾峰彇瀛樺偍瀵瑰鏈嶅姟淇℃伅
+// @Description 鑾峰彇瀛樺偍瀵瑰鏈嶅姟淇℃伅
+// @Produce json
+// @Tags sysset
+// @Success 200 {string} json "{"code":200, msg:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
+// @Router /data/api-v/sysset/getResourceConfig [get]
+func (sset SysSetController) GetResourceConfig(c *gin.Context) {
+	var sysApi dbapi.SysSetApi
+	b,d := sysApi.GetResourceConfig()
+	if b {
+		util.ResponseFormat(c,code.Success,d)
+	} else {
+		util.ResponseFormat(c,code.ComError,"")
+	}
+}
+
+// @Security ApiKeyAuth
+// @Summary 瀛樺偍瀵瑰鏈嶅姟淇℃伅
+// @Description 瀛樺偍瀵瑰鏈嶅姟淇℃伅
+// @Accept  json
+// @Produce json
+// @Tags sysset
+// @Param reqBoby body controllers.ResourceConfigVo true "post璇锋眰锛宩son鍙傛暟"
+// @Success 200 {string} json "{"code":200, msg:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
+// @Router /data/api-v/sysset/saveResourceConfig [post]
+func (sset SysSetController) SaveResourceConfig(c *gin.Context) {
+	var reqBody ResourceConfigVo
+	c.BindJSON(&reqBody)
+	if reqBody.ServiceIp == "" && reqBody.Domain == "" {
+		util.ResponseFormat(c,code.RequestParamError,"")
+		return
+	}
+	var sysApi dbapi.SysSetApi
+	paramBody := util.Struct2Map(reqBody)
+	if b,_ := sysApi.SaveResourceConfig(paramBody); b {
+		util.ResponseFormat(c,code.Success,"")
+	} else {
+		util.ResponseFormat(c,code.ComError,"")
+	}
+}
\ No newline at end of file

--
Gitblit v1.8.0