From 3704b2de230fd00ad6a71ffbbfadf0229194ec3c Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期二, 03 十二月 2019 11:53:24 +0800 Subject: [PATCH] add fileAnalysis --- go.sum | 8 +- controllers/fileAnalysisSetting.go | 38 +++++++++ go.mod | 4 controllers/fileAnalysis.go | 130 ++++++++++++++++++++++++++++++++ router/router.go | 14 +++ 5 files changed, 188 insertions(+), 6 deletions(-) diff --git a/controllers/fileAnalysis.go b/controllers/fileAnalysis.go new file mode 100644 index 0000000..da6c3af --- /dev/null +++ b/controllers/fileAnalysis.go @@ -0,0 +1,130 @@ +package controllers + +import ( + "basic.com/dbapi.git" + "github.com/gin-gonic/gin" + "webserver/extend/code" + "webserver/extend/util" +) + +type FileAnalysisController struct { + +} + +// @Security ApiKeyAuth +// @Summary 鑾峰彇鏈湴鏂囦欢鍒楄〃 +// @Description 鑾峰彇鏈湴鏂囦欢鍒楄〃 +// @Produce json +// @Tags 鏈湴鏂囦欢 +// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}" +// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}" +// @Router /data/api-v/fileAnalysis/findAllFile [get] +func (fac FileAnalysisController) FindAllFile(c *gin.Context) { + fileName := c.Query("fileName") + var api dbapi.FileAnalysisApi + arr, _ := api.FindAllFile(fileName) + if arr !=nil && len(arr) >0 { + util.ResponseFormat(c,code.Success,arr) + } else { + util.ResponseFormat(c,code.Success,[]interface{}{}) + } +} + +type IdArrVo struct { + Ids []string `json:"ids" binding:"required"` +} + + +type SortVo struct { + Id string `json:"id" binding:"required"` + Direct int `json:"direct" binding:"required" example:"1:鍚戜笂锛�2锛氬悜涓�"` +} + +type FileStatusVo struct { + Ids []string `json:"ids" binding:"required"` + Status int `json:"status" binding:"required"` +} + +// @Security ApiKeyAuth +// @Summary 寮�鍚垨鏆傚仠鏂囦欢鍒嗘瀽 +// @Description 寮�鍚垨鏆傚仠鏂囦欢鍒嗘瀽 +// @Accept json +// @Produce json +// @Tags 鏈湴鏂囦欢 +// Param reqBody body controllers.FileStatusVo true "寮�鍚殏鍋滃弬鏁�,鏆傚仠status=0锛屽紑鍚痵tatus=1" +// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}" +// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}" +// @Router /data/api-v/fileAnalysis/updateStatus [post] +func (fac FileAnalysisController) UpdateStatus(c *gin.Context) { + var reqBody FileStatusVo + err := c.BindJSON(&reqBody) + if err !=nil { + util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎") + return + } + + var api dbapi.FileAnalysisApi + if api.UpdateStatus(reqBody.Ids, reqBody.Status) { + util.ResponseFormat(c,code.Success,"") + } else { + util.ResponseFormat(c,code.ComError,"") + } +} + +// @Security ApiKeyAuth +// @Summary 鍒犻櫎鏈湴鏂囦欢 +// @Description 鍒犻櫎鏈湴鏂囦欢 +// @Accept json +// @Produce json +// @Tags 鏈湴鏂囦欢 +// Param reqBody body controllers.IdArrVo true "鍒犻櫎鏂囦欢id鍒楄〃" +// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}" +// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}" +// @Router /data/api-v/fileAnalysis/delete [post] +func (fac FileAnalysisController) Delete(c *gin.Context) { + var reqBody IdArrVo + err := c.BindJSON(&reqBody) + if err !=nil { + util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎") + return + } + + var api dbapi.FileAnalysisApi + if api.Delete(reqBody.Ids) { + util.ResponseFormat(c,code.DelSuccess,"") + } else { + util.ResponseFormat(c,code.ComError,"") + } +} + +const ( + Sort_Up = 1 + Sort_Down = 2 +) + +// @Security ApiKeyAuth +// @Summary 鏈湴鏂囦欢鎺掑簭 +// @Description 鏈湴鏂囦欢鎺掑簭 +// @Accept json +// @Produce json +// @Tags 鏈湴鏂囦欢 +// Param reqBody body controllers.SortVo true "鎺掑簭鍙傛暟,鍚戜笂direct=1锛屽悜涓媎irect=2" +// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}" +// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}" +// @Router /data/api-v/fileAnalysis/sortFile [post] +func (fac FileAnalysisController) SortFile(c *gin.Context) { + var reqBody SortVo + err := c.BindJSON(&reqBody) + if err !=nil || (reqBody.Direct !=Sort_Up && reqBody.Direct !=Sort_Down) { + util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎") + return + } + + var api dbapi.FileAnalysisApi + if api.SortFile(reqBody.Id,reqBody.Direct) { + util.ResponseFormat(c,code.UpdateSuccess,"鏇存柊鎴愬姛") + } else { + util.ResponseFormat(c,code.UpdateFail,"鏇存柊澶辫触") + } + +} diff --git a/controllers/fileAnalysisSetting.go b/controllers/fileAnalysisSetting.go new file mode 100644 index 0000000..b7d7628 --- /dev/null +++ b/controllers/fileAnalysisSetting.go @@ -0,0 +1,38 @@ +package controllers + +import ( + "basic.com/dbapi.git" + "github.com/gin-gonic/gin" + "webserver/extend/code" + "webserver/extend/util" +) + +type FileAnalysisSettingController struct { + +} + + +func (fsc FileAnalysisSettingController) Show(c *gin.Context) { + var api dbapi.FileAnalysisApi + setting, err := api.GetFileAnalysisSet() + if err == nil { + util.ResponseFormat(c,code.Success, setting) + } else { + util.ResponseFormat(c,code.ComError, setting) + } +} + +type EnableSet struct { + Enable bool `json:"enable"` +} + +func (fsc FileAnalysisSettingController) ChangeEnable(c *gin.Context) { + var reqBody EnableSet + c.BindJSON(&reqBody) + var api dbapi.FileAnalysisApi + if api.ChangeEnable(reqBody.Enable) { + util.ResponseFormat(c,code.UpdateSuccess,"鏇存柊鎴愬姛") + } else { + util.ResponseFormat(c,code.UpdateFail,"鏇存柊澶辫触") + } +} diff --git a/go.mod b/go.mod index ca9ba27..8796de8 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,12 @@ go 1.12 require ( - basic.com/dbapi.git v0.0.0-20191122064621-1675117bdb57 // indirect + basic.com/dbapi.git v0.0.0-20191202091445-8ddb48697708 // indirect basic.com/fileServer/WeedFSClient.git v0.0.0-20190919054037-0182b6c3f5cb // indirect basic.com/gb28181api.git v0.0.0-20191028082253-472438a8407b // indirect basic.com/pubsub/cache.git v0.0.0-20190718093725-6a413e1d7d48 // indirect basic.com/pubsub/esutil.git v0.0.0-20191120125514-865efa73a9ae // indirect - basic.com/pubsub/protomsg.git v0.0.0-20191120124614-c1105ad8821c // indirect + basic.com/pubsub/protomsg.git v0.0.0-20191202120753-f20294c1ff90 // indirect basic.com/valib/capture.git v0.0.0-20191126081138-bf954c0fa627 // indirect basic.com/valib/deliver.git v0.0.0-20190531095353-25d8c3b20051 basic.com/valib/godraw.git v0.0.0-20191122082247-26e9987cd183 // indirect diff --git a/go.sum b/go.sum index 0350050..ec3ae49 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -basic.com/dbapi.git v0.0.0-20191122064621-1675117bdb57 h1:RHd4ZKtKR9oEJ0zNUwz/hHSpqPS63LFe7CxRqRJWFWc= -basic.com/dbapi.git v0.0.0-20191122064621-1675117bdb57/go.mod h1:eDXPnxaz6jZPDvBSk7ya7oSASWPCuUEgRTJCjsfKt/Q= +basic.com/dbapi.git v0.0.0-20191202091445-8ddb48697708 h1:8lk1xOxDhlOftb7xaFSaB554zP97Y2m2oW4dJrHZnNM= +basic.com/dbapi.git v0.0.0-20191202091445-8ddb48697708/go.mod h1:eDXPnxaz6jZPDvBSk7ya7oSASWPCuUEgRTJCjsfKt/Q= basic.com/fileServer/WeedFSClient.git v0.0.0-20190919054037-0182b6c3f5cb h1:fM6DojeInFSCFO+wkba1jtyPiSDqw0jYKi4Tk+e+ka4= basic.com/fileServer/WeedFSClient.git v0.0.0-20190919054037-0182b6c3f5cb/go.mod h1:FTryK8BsVLfUplx8a3+l8hJWub6VbAWZCUH7sPRZaso= basic.com/gb28181api.git v0.0.0-20191028082253-472438a8407b h1:Qh7x2PY3HA9B404Llq+olY5/YlGYrM58bpOHa2CGcro= @@ -8,8 +8,8 @@ basic.com/pubsub/cache.git v0.0.0-20190718093725-6a413e1d7d48/go.mod h1:gHLJZz2ee1cGL0X0ae69fs56bAxkDgEQwDhhXZJNUcY= basic.com/pubsub/esutil.git v0.0.0-20191120125514-865efa73a9ae h1:/j1dIDLxzEp51N+ZHZIq1xeYVK9zz8epWEAfw01uWe8= basic.com/pubsub/esutil.git v0.0.0-20191120125514-865efa73a9ae/go.mod h1:yIvppFPFGC61DOdm71ujnsxZBMFUu2yKjr5O43bMWCw= -basic.com/pubsub/protomsg.git v0.0.0-20191120124614-c1105ad8821c h1:iVBONjMIxCXKJ/kWFgw0kTws9/ZWdTQqJC3otzRGLyo= -basic.com/pubsub/protomsg.git v0.0.0-20191120124614-c1105ad8821c/go.mod h1:un5NV5VWQoblVLZfx1Rt5vyLgwR0jI92d3VJhfrJhWU= +basic.com/pubsub/protomsg.git v0.0.0-20191202120753-f20294c1ff90 h1:bQiuJTp4+7KvCfDmVQPDUwk3n/sqHD6/YyO/akh94Ek= +basic.com/pubsub/protomsg.git v0.0.0-20191202120753-f20294c1ff90/go.mod h1:un5NV5VWQoblVLZfx1Rt5vyLgwR0jI92d3VJhfrJhWU= basic.com/valib/capture.git v0.0.0-20191126081138-bf954c0fa627 h1:26J3wU05U/v72SvUvtFc6Ymgvlill9SXbRn/cMGE5k0= basic.com/valib/capture.git v0.0.0-20191126081138-bf954c0fa627/go.mod h1:y+h7VUnoSQ3jOtf2K3twXNA8fYDfyUsifSswcyKLgNw= basic.com/valib/deliver.git v0.0.0-20190531095353-25d8c3b20051/go.mod h1:bkYiTUGzckyNOjAgn9rB/DOjFzwoSHJlruuWQ6hu6IY= diff --git a/router/router.go b/router/router.go index bb66024..6012c52 100644 --- a/router/router.go +++ b/router/router.go @@ -45,6 +45,8 @@ sysRoleController := new(controllers.RoleController) ptzController := new(controllers.PanTiltZoomController) licenseController := new(controllers.LicenseController) + fileAnalysisC := new(controllers.FileAnalysisController) + fileSettingC := new(controllers.FileAnalysisSettingController) urlPrefix := "/data/api-v" // wp 娣诲姞 璺緞 鍓嶇紑 @@ -287,6 +289,18 @@ clusterApi.POST("/updateClusterName", clusterController.UpdateClusterName) clusterApi.POST("/leave", clusterController.Leave) } + 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) + } + fileSettingApi := r.Group(urlPrefix + "/fileSetting") + { + fileSettingApi.GET("/show",fileSettingC.Show) + fileSettingApi.POST("/changeEnable", fileSettingC.ChangeEnable) + } // 鏂囦欢 涓婁紶 r.Static("static", "./static") // 闈欐�佹枃浠� -- Gitblit v1.8.0