From 52bd382203ebdcce84c93f01a2806e16b5416dc5 Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期一, 23 九月 2019 14:06:49 +0800 Subject: [PATCH] verify dbt tableName exist when add --- controllers/dbtablesCon.go | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 44 insertions(+), 4 deletions(-) diff --git a/controllers/dbtablesCon.go b/controllers/dbtablesCon.go index 9746d1d..9436848 100644 --- a/controllers/dbtablesCon.go +++ b/controllers/dbtablesCon.go @@ -6,11 +6,13 @@ "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" ) @@ -40,7 +42,12 @@ // 渚濇嵁搴曞簱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 == "" || localConf.ServerId == "" { + 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) @@ -129,7 +136,35 @@ 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 涓簍rue鎵嶅厑璁稿紑鍚� + if !b { + util.ResponseFormat(c,code.UpdateFail,"褰撳墠涓嶅厑璁稿惎鐢�") + return + } + } b,_ := dtApi.UpdateDbTableStatus(ds.Id, ds.Enable) if b { @@ -141,7 +176,12 @@ 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 == "" || localConf.ServerId == "" { + 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)) @@ -225,7 +265,7 @@ if b { util.ResponseFormat(c,code.AddSuccess, data) } else { - util.ResponseFormat(c,code.ComError,"鏂板澶辫触") + util.ResponseFormat(c,code.ComError, data) } } -- Gitblit v1.8.0