| | |
| | | "fmt" |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/satori/go.uuid" |
| | | "strconv" |
| | | "time" |
| | | "webserver/cache" |
| | | "webserver/extend/code" |
| | | "webserver/extend/config" |
| | | "webserver/extend/esutil" |
| | | "webserver/extend/logger" |
| | | "basic.com/valib/logger.git" |
| | | "webserver/extend/util" |
| | | "webserver/models" |
| | | ) |
| | |
| | | |
| | | // 依据底库id 查询数据 |
| | | func QueryDbTableInfo(tableId string) map[string]interface{} { |
| | | url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + |
| | | localConf, err2 := cache.GetServerInfo() |
| | | if err2 !=nil || localConf.AlarmIp == "" { |
| | | logger.Debug("localConfig is wrong!!!") |
| | | return nil |
| | | } |
| | | url := "http://" + localConf.AlarmIp + ":" + strconv.Itoa(int(localConf.AlarmPort)) + |
| | | "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + tableId |
| | | logger.Debug("请求url:%s;", url) |
| | | data := esutil.GetEsDataInfo(url, true) |
| | |
| | | util.ResponseFormat(c,code.RequestParamError,"参数有误") |
| | | return |
| | | } |
| | | |
| | | var dtApi dbapi.DbTableApi |
| | | dts, err := dtApi.DbtablesById([]string{ds.Id}) |
| | | if err !=nil || dts == nil { |
| | | util.ResponseFormat(c,code.RequestParamError,"底库不存在") |
| | | return |
| | | } |
| | | if ds.Enable == 1 { |
| | | str := dts[0].StartTime |
| | | etr := dts[0].EndTime |
| | | ct := time.Now() |
| | | st, _ := time.ParseInLocation("2006-01-02 15:04:05", str, time.Local) |
| | | b := false |
| | | if etr != "" { |
| | | et,_ := time.ParseInLocation("2006-01-02 15:04:05", etr, time.Local) |
| | | if et.After(ct) && st.Before(ct) { |
| | | b = true |
| | | } |
| | | } else { |
| | | if st.Before(ct) { |
| | | b = true |
| | | } |
| | | } |
| | | //b 为true才允许开启 |
| | | if !b { |
| | | util.ResponseFormat(c,code.UpdateFail,"当前不允许启用") |
| | | return |
| | | } |
| | | } |
| | | |
| | | b,_ := dtApi.UpdateDbTableStatus(ds.Id, ds.Enable) |
| | | if b { |
| | |
| | | |
| | | func UpdateEndTime(id string) (flag bool) { |
| | | flag = false |
| | | url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + |
| | | localConf, err2 := cache.GetServerInfo() |
| | | if err2 !=nil || localConf.AlarmIp == "" { |
| | | logger.Debug("localConfig is wrong!!!") |
| | | return false |
| | | } |
| | | url := "http://" + localConf.AlarmIp + ":" + strconv.Itoa(int(localConf.AlarmPort)) + |
| | | "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + config.EsInfo.EsIndex.DbTables.IndexType + "/" + id + "/_update?refresh=wait_for" |
| | | prama := "{\"script\":\"ctx._source.remove(\\\"endTime\\\")\"}" |
| | | buf, err := esutil.EsReq("POST", url, []byte(prama)) |