package controllers import ( "basic.com/valib/bhomeclient.git" "basic.com/valib/bhomedbapi.git" "basic.com/valib/logger.git" "strconv" "vamicro/config" "vamicro/search-service/esutil" ) // @Security ApiKeyAuth // @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}" // @Router /data/api-v/es/taskList [POST] func (sc *EsSearchController) PostEsTaskList(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply { var sApi bhomedbapi.SysSetApi flag, localConf := sApi.GetServerInfo() if !flag || localConf.AlarmIp == "" ||localConf.AlarmPort ==0 { logger.Debug("localConf err") return &bhomeclient.Reply{Success:false, Msg: "localConf err"} } url := "http://" + localConf.AlarmIp + ":" + strconv.Itoa(int(localConf.AlarmPort)) + "/" + config.EsInfo.EsIndex.AiOcean.IndexName + "/_search" prama := "{\"size\":0,\"aggs\":{\"taskId_list\":{\"terms\":{\"field\":\"taskId\"}}}}" tokenRes := esutil.GetEsDataReq(url, prama, false) //var taskId_list map[string]interface{} aggs := tokenRes["aggregations"].(map[string]interface{}) sources := make([]map[string]string, 0) if aggs != nil { taskId_list, ok := aggs["taskId_list"].(map[string]interface{})["buckets"].([]interface{}) if !ok { logger.Debug("It's not ok for type string") } for _, value := range taskId_list { var key = value.(map[string]interface{})["key"] source := make(map[string]string) source["title"] = key.(string) source["value"] = key.(string) source["key"] = key.(string) sources = append(sources, source) logger.Debug(key) } logger.Debug(sources) } return &bhomeclient.Reply{Success:true,Data:sources} }