fix delete dbtable add GetTotalFromDb and EsReq
| | |
| | | //c.JSON(200, data) |
| | | util.ResponseFormat(c, code.Success, data) |
| | | } |
| | | |
| | |  |
| | | // 依据底库id 查询数据 |
| | | func QueryDbTableInfo(tableId string) map[string]interface{} { |
| | | func QueryDbTableInfo(tableId string) map[string]interface{} { |
| | | url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + |
| | | "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + tableId |
| | | logger.Debug("请求url:%s;", url) |
| | |
| | | uuid := c.Params.ByName("id") |
| | | url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + |
| | | "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + config.EsInfo.EsIndex.DbTables.IndexType + "/" + uuid + "/_update?refresh=wait_for" |
| | | params := "{\"doc\":{\"isDelete\":\"1\"}}" |
| | | params := "{\"doc\":{\"isDelete\":1}}" |
| | | logger.Debug("删除请求url:%s;\n 请求参数params:%s", url, params) |
| | | data := esutil.GetEsDataReq(url, params, false) |
| | | //c.JSON(200, changeEsRespData(data, "删除成功")) |
| | |
| | | tokenRes["key"] = value.(map[string]interface{})["id"].(string) |
| | | tokenRes["title"] = value.(map[string]interface{})["tableName"].(string) |
| | | tokenRes["value"] = value.(map[string]interface{})["id"].(string) |
| | | tokenRes["status"] = value.(map[string]interface{})["isDelete"] |
| | | tokenRes["status"] = int(value.(map[string]interface{})["isDelete"]) |
| | | if tokenRes["status"] == 1 { |
| | | if GetTotalFromDb(tokenRes["key"]) == false{ |
| | | continue |
| | | } |
| | | |
| | | } |
| | | 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.DbTables.IndexName + "/_search" |
| | | prama := "{\"query\":{\"bool\":{\"filter\":[{\"term\":{\"baseInfo.tableId\":\""+id+"\"}}]}},\"size\":0}" |
| | | buf, err := 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)) |
| | | fmt.Println(total) |
| | | if total>0 { |
| | | flag=true |
| | | } |
| | | return flag |
| | | } |
| | |
| | | return dat |
| | | } |
| | | } |
| | | //解析http |
| | | func EsReq(method string, url string, parama []byte) (buf []byte, err error) { |
| | | timeout := time.Duration(10 * time.Second) |
| | | client := http.Client{ |
| | | Timeout: timeout, |
| | | } |
| | | request, err := http.NewRequest(method, url, bytes.NewBuffer(parama)) |
| | | request.Header.Set("Content-type", "application/json") |
| | | |
| | | if err != nil { |
| | | fmt.Println("build request fail !") |
| | | return nil, err |
| | | } |
| | | |
| | | resp, err := client.Do(request) |
| | | if err != nil{ |
| | | fmt.Println("request error: ", err) |
| | | return nil, err |
| | | } |
| | | |
| | | defer resp.Body.Close() |
| | | body, err := ioutil.ReadAll(resp.Body) |
| | | if err != nil { |
| | | fmt.Println(err) |
| | | return nil , err |
| | | } |
| | | return body, nil |
| | | } |