From ea5df990ee13cf2ca03b0ee757f2f67c789cb93c Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期三, 21 八月 2019 13:14:48 +0800 Subject: [PATCH] tagList get from sqlite --- controllers/taglist.go | 88 +++++++++++++------------------------------- controllers/task.go | 11 +++-- router/router.go | 2 3 files changed, 33 insertions(+), 68 deletions(-) diff --git a/controllers/taglist.go b/controllers/taglist.go index 802b018..107532e 100644 --- a/controllers/taglist.go +++ b/controllers/taglist.go @@ -2,81 +2,45 @@ import ( "basic.com/dbapi.git" - "encoding/json" - "fmt" + "webserver/extend/code" + "webserver/extend/util" "github.com/gin-gonic/gin" - "webserver/extend/code" - "webserver/extend/config" - "webserver/extend/esutil" - "webserver/extend/util" ) -//鏍囩鍒楄〃 -//浠诲姟鍒楄〃 // @Summary 鏍囩鍒楄〃 // @Description 杩斿洖搴曞簱鏍囩 // @Accept json // @Produce json // @Tags es -// @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/es/taskList [POST] func (sc *EsSearchController) PostEsTagList(c *gin.Context) { - url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + - "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/_search" - var setApi dbapi.SysSetApi - _, sysconf := setApi.GetServerInfo() - prama := "{\"query\":{\"bool\":{\"filter\":[{\"terms\":{\"analyServerId\":[\"\",\"" + sysconf.ServerId + "\"]}}]}},\"size\":1000}" - tokenRes := esutil.GetEsDataReq(url, prama, true) - sources := make([]map[string]interface{}, 0) - for _, value := range tokenRes["datalist"].([]interface{}) { - tokenRes := make(map[string]interface{}) - tr := value.(map[string]interface{}) - key := tr["id"].(string) - tokenRes["key"] = key - tokenRes["title"] = tr["tableName"].(string) - tokenRes["value"] = tr["id"].(string) - status := int(tr["isDelete"].(float64)) - tokenRes["status"] = status - if status == 1 { - if GetTotalFromDb(key) == false { - continue + var dtApi dbapi.DbTableApi + var dbpApi dbapi.DbPersonApi + dts, err := dtApi.FindAllDbTablesByCurServer() + if err == nil { + if dts !=nil { + sources := make([]map[string]interface{}, 0) + for _, dt := range dts { + tokenRes := make(map[string]interface{}) + tokenRes["key"] = dt.Id + tokenRes["title"] = dt.TableName + tokenRes["value"] = dt.Id + tokenRes["status"] = dt.IsDelete + if dt.IsDelete == 1 { + personTotal,_ := dbpApi.GetPersonTotal(dt.Id) + if personTotal == 0 { + continue + } + } + sources = append(sources, tokenRes) } + util.ResponseFormat(c, code.Success, sources) + return } - sources = append(sources, tokenRes) } - util.ResponseFormat(c, code.Success, sources) -} - -//鍒ゆ柇搴曞簱鏄惁鏈夋暟鎹� -func GetTotalFromDb(id string) (flag bool) { - flag = false - url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + - "/" + config.EsInfo.EsIndex.VideoPersons.IndexName + "/_search" - prama := "{\"query\":{\"bool\":{\"filter\":[{\"term\":{\"baseInfo.tableId\":\"" + id + "\"}}]}},\"size\":0}" - buf, err := esutil.EsReq("POST", url, []byte(prama)) - if err != nil { - fmt.Println("http request info is err!") - return - } - var info interface{} - json.Unmarshal(buf, &info) - out, ok := info.(map[string]interface{}) - if !ok { - fmt.Println("http response interface can not change map[string]interface{}") - return - } - middle, ok := out["hits"].(map[string]interface{}) - if !ok { - fmt.Println("first hits change error!") - return - } - - total := int(middle["total"].(float64)) - if total > 0 { - flag = true - } - return flag + util.ResponseFormat(c,code.ComError,"鏌ヨ搴曞簱鏍囩澶辫触") } diff --git a/controllers/task.go b/controllers/task.go index 99b61c0..f27e9d0 100644 --- a/controllers/task.go +++ b/controllers/task.go @@ -277,15 +277,16 @@ // @Param id query string 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/task/deleteTaskSdkRuleById [post] -func (tc TaskController) DeleteTaskSdkRuleById(c *gin.Context) { - id := c.PostForm("id") - if id == "" { +// @Router /data/api-v/task/deleteTaskSdkRule [post] +func (tc TaskController) DeleteTaskSdkRule(c *gin.Context) { + taskId := c.PostForm("taskId") + sdkId := c.PostForm("sdkId") + if taskId == "" || sdkId == "" { util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎") return } var api dbapi.TaskSdkRuleApi - if api.DeleteTaskSdkRuleById(id) { + if api.DeleteTaskSdkRule(taskId, sdkId) { util.ResponseFormat(c,code.Success,"鍒犻櫎鎴愬姛") } else { util.ResponseFormat(c,code.ComError, "鍒犻櫎澶辫触") diff --git a/router/router.go b/router/router.go index 453d013..ac00538 100644 --- a/router/router.go +++ b/router/router.go @@ -123,7 +123,7 @@ task.GET("/delTaskSdk", taskController.DeleteTaskSdk) task.POST("/updateTaskName", taskController.UpdateTaskName) task.GET("/getRulesByTaskSdk", taskController.GetRulesByTaskSdk) - task.POST("/deleteTaskSdkRuleById", taskController.DeleteTaskSdkRuleById) + task.POST("/deleteTaskSdkRule", taskController.DeleteTaskSdkRule) task.POST("/saveTaskSdkRule", taskController.SaveTaskSdkRule) } -- Gitblit v1.8.0