From 49ceaa0374fb3f0d74a4949953b0355359b3bf49 Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期三, 15 一月 2020 18:22:37 +0800
Subject: [PATCH] add clearData

---
 extend/code/code.go      |    3 +
 controllers/clearData.go |   64 ++++++++++++++++++++++++++++++++
 extend/config/config.go  |   16 ++++++--
 router/router.go         |   21 +++++++---
 4 files changed, 92 insertions(+), 12 deletions(-)

diff --git a/controllers/clearData.go b/controllers/clearData.go
new file mode 100644
index 0000000..297dc19
--- /dev/null
+++ b/controllers/clearData.go
@@ -0,0 +1,64 @@
+package controllers
+
+import (
+	"basic.com/pubsub/esutil.git"
+	"basic.com/valib/logger.git"
+	"github.com/gin-gonic/gin"
+	"strconv"
+	"webserver/cache"
+	"webserver/extend/code"
+	"webserver/extend/config"
+	"webserver/extend/util"
+)
+
+type ClearDataController struct{}
+
+type clearParams struct {
+	StartTime string `json:"startTime"`
+	EndTime   string `json:"endTime"`
+}
+
+func (cdc *ClearDataController) ClearEsData(c *gin.Context) {
+	var cp clearParams
+	localConf, err := cache.GetServerInfo()
+	if err != nil || localConf.AlarmIp == "" || localConf.ServerId == "" {
+		logger.Debug("localConfig is wrong!!!")
+		util.ResponseFormat(c, code.ComError, "es config err")
+		return
+	}
+	ip := localConf.AlarmIp
+	port := strconv.Itoa(int(localConf.AlarmPort))
+	analyServerId := localConf.ServerId
+	c.BindJSON(&cp)
+	startTime := cp.StartTime
+	endTime := cp.EndTime
+	queryRes, queryErr := esutil.QueryAnalyServerData(ip, port, config.EsInfo.EsIndex.AiOcean.IndexName, startTime, endTime, analyServerId)
+	if queryErr != nil {
+		util.ResponseFormat(c, code.InvalidRequest, "鏍¢獙鏁版嵁澶辫触")
+		return
+	}
+	if queryRes != true {
+		util.ResponseFormat(c, code.InvalidRequest, "鏁版嵁宸插垹闄ゆ垨璇ユ椂闂存鏃犳暟鎹�")
+		return
+	}
+	addRes, addErr := esutil.AddDelTask(ip, port, config.BasicFS.IndexName, startTime, endTime, analyServerId)
+	if addErr != nil {
+		util.ResponseFormat(c, code.InvalidRequest, "杩藉姞浠诲姟澶辫触")
+		return
+	}
+	if addRes != true {
+		util.ResponseFormat(c, code.InvalidRequest, "杩藉姞浠诲姟澶辫触")
+		return
+	}
+	deleteRes, deleteErr := esutil.DeleteAnalyServerData(ip, port, config.BasicFS.IndexName, startTime, endTime, analyServerId)
+	if deleteErr != nil {
+		util.ResponseFormat(c, code.InvalidRequest, "鏁版嵁鍒犻櫎澶辫触")
+		return
+	}
+	if deleteRes != true {
+		util.ResponseFormat(c, code.InvalidRequest, "鏁版嵁鍒犻櫎澶辫触")
+		return
+	}
+	util.ResponseFormat(c, code.Success, deleteRes)
+	return
+}
diff --git a/extend/code/code.go b/extend/code/code.go
index 4e7ef5a..68c4b24 100644
--- a/extend/code/code.go
+++ b/extend/code/code.go
@@ -29,6 +29,7 @@
 	UploadSuffixError = &Code{http.StatusBadRequest, false, "璇ヤ笂浼犳枃浠舵牸寮忕洰鍓嶆殏涓嶆敮鎸�"}
 	// UploadSizeLimit 鐩墠涓婁紶浠呮敮鎸佸皬浜�5M鐨勬枃浠跺唴瀹�
 	UploadSizeLimit = &Code{http.StatusBadRequest, false, "鐩墠涓婁紶浠呮敮鎸佸皬浜�5M鐨勬枃浠跺唴瀹�"}
+	InvalidRequest  = &Code{http.StatusBadRequest, false, "璇锋眰鏃犳晥"}
 	LoginSuccess    = &Code{http.StatusOK, true, "鐧诲綍鎴愬姛"}
 	// SigninInfoError 璐︽埛鍚嶆垨瀵嗙爜鏈夎
 	LoginInfoError = &Code{http.StatusUnauthorized, false, "鐢ㄦ埛鍚嶆垨瀵嗙爜閿欒"}
@@ -67,5 +68,5 @@
 	AddClusterInfoErr   = &Code{http.StatusInternalServerError, false, "鍔犲叆鑺傜偣澶辫触锛�"}
 
 	UpgradeSuccess = &Code{http.StatusOK, true, "鍗囩骇鎴愬姛"}
-	UpgradeFail = &Code{http.StatusInternalServerError, false, "鍗囩骇澶辫触"}
+	UpgradeFail    = &Code{http.StatusInternalServerError, false, "鍗囩骇澶辫触"}
 )
diff --git a/extend/config/config.go b/extend/config/config.go
index 48aa484..64baeb5 100644
--- a/extend/config/config.go
+++ b/extend/config/config.go
@@ -29,8 +29,8 @@
 	SudoPassword  string      `mapstructure: "sudoPassword"` //绯荤粺瀵嗙爜
 	SysThresholds []threshold `mapstructure: "sysThresholds"`
 	PTZSpeed      int         `mapstructure: "ptzSpeed"` // 浜戝彴绉诲姩閫熷害
-	PatchPath       string `mapstructure:"patchPath"`//绯荤粺鏇存柊鍖呰矾寰�
-	BakPath         string `mapstructure:"bakPath"`//绯荤粺鏇存柊鍖呰矾寰�
+	PatchPath     string      `mapstructure:"patchPath"` //绯荤粺鏇存柊鍖呰矾寰�
+	BakPath       string      `mapstructure:"bakPath"`   //绯荤粺鏇存柊鍖呰矾寰�
 }
 
 var Server = &server{}
@@ -42,7 +42,7 @@
 }
 
 type esindexlist struct {
-	AiOcean   index `mapstructure:"aiOcean"`
+	AiOcean index `mapstructure:"aiOcean"`
 }
 type index struct {
 	IndexName string `mapstructure:"index"`
@@ -54,9 +54,16 @@
 	Port string `mapstructure:"port"`
 }
 
+type elastic struct {
+	IndexName string `mapstructure: "indexName"`
+	IndexType string `mapstructure: "indexType"`
+}
+
 var SoPath = &sopath{}
 
 var EsInfo = &esinfo{}
+
+var BasicFS = &elastic{}
 
 type facedetect struct {
 	Ip   string `mapstructure:"Ip"`
@@ -88,7 +95,7 @@
 	viper.AddConfigPath("/opt/vasystem/config/")
 	err = viper.ReadInConfig()
 	if err != nil {
-		log.Fatal("error on parsing configuration file",err)
+		log.Fatal("error on parsing configuration file", err)
 	}
 	viper.UnmarshalKey("es", EsInfo)
 	viper.UnmarshalKey("server", Server)
@@ -96,4 +103,5 @@
 	viper.UnmarshalKey("facedetect", FaceDetectSet)
 	viper.UnmarshalKey("dbpersoncompare", DbPersonCompInfo)
 	viper.UnmarshalKey("espersoncompare", EsCompServerInfo)
+	viper.UnmarshalKey("elastic.basicFS", BasicFS)
 }
diff --git a/router/router.go b/router/router.go
index 27db985..c8165f3 100644
--- a/router/router.go
+++ b/router/router.go
@@ -28,6 +28,7 @@
 	esSearchController := new(controllers.EsSearchController)
 	esManagementController := new(controllers.EsManagementController)
 	realTimeController := new(controllers.RealTimeController)
+	clearDataController := new(controllers.ClearDataController)
 	cameraTimeRuleController := new(controllers.CameraTimeruleController)
 	polygonController := new(controllers.CameraPolygonController)
 	cameraTaskController := new(controllers.CameraTaskController)
@@ -47,7 +48,7 @@
 
 	urlPrefix := "/data/api-v" // wp 娣诲姞 璺緞 鍓嶇紑
 
-	licenseApi :=r.Group(urlPrefix+"/license")
+	licenseApi := r.Group(urlPrefix + "/license")
 	{
 		licenseApi.POST("/getRegisterCode", licenseController.GetRegisterCode)
 		licenseApi.POST("/save", licenseController.Save)
@@ -181,6 +182,12 @@
 		realTime.POST("/initForCaptureData", realTimeController.InitForCaptureData)
 		realTime.POST("/initForMonitoringData", realTimeController.InitForMonitoringData)
 	}
+	//娓呯悊鏁版嵁
+	clearData := r.Group(urlPrefix + "/clearData")
+	{
+		clearData.POST("/clearEsData", clearDataController.ClearEsData)
+	}
+
 	//搴曞簱 鎿嶄綔
 	vdbtable := r.Group(urlPrefix + "/dbtable")
 	{
@@ -233,8 +240,8 @@
 		vsset.GET("/rebootTask", ssController.GetRebootTask)
 		vsset.POST("/rebootTask", ssController.SetRebootTask)
 
-		vsset.GET("/getResourceConfig",ssController.GetResourceConfig)
-		vsset.POST("/saveResourceConfig",ssController.SaveResourceConfig)
+		vsset.GET("/getResourceConfig", ssController.GetResourceConfig)
+		vsset.POST("/saveResourceConfig", ssController.SaveResourceConfig)
 		vsset.GET("/patchUpdate", ssController.PatchUpdateCheck)
 		vsset.POST("/patchUpdate", ssController.PatchUpdate)
 		vsset.POST("/upgrade", ssController.Upgrade)
@@ -299,13 +306,13 @@
 	fileAnalyApi := r.Group(urlPrefix + "/fileAnalysis")
 	{
 		fileAnalyApi.GET("/findAllFile", fileAnalysisC.FindAllFile)
-		fileAnalyApi.POST("/updateStatus",fileAnalysisC.UpdateStatus)
-		fileAnalyApi.POST("/delete",fileAnalysisC.Delete)
-		fileAnalyApi.POST("/sortFile",fileAnalysisC.SortFile)
+		fileAnalyApi.POST("/updateStatus", fileAnalysisC.UpdateStatus)
+		fileAnalyApi.POST("/delete", fileAnalysisC.Delete)
+		fileAnalyApi.POST("/sortFile", fileAnalysisC.SortFile)
 	}
 	fileSettingApi := r.Group(urlPrefix + "/fileSetting")
 	{
-		fileSettingApi.GET("/show",fileSettingC.Show)
+		fileSettingApi.GET("/show", fileSettingC.Show)
 		fileSettingApi.POST("/changeEnable", fileSettingC.ChangeEnable)
 	}
 

--
Gitblit v1.8.0