From 5d78b36e851a5862302f2e40c99a4477020c79bc Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期五, 20 九月 2019 13:46:52 +0800
Subject: [PATCH] 查找此人时先切图

---
 controllers/dbtablesCon.go |   96 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 93 insertions(+), 3 deletions(-)

diff --git a/controllers/dbtablesCon.go b/controllers/dbtablesCon.go
index fd8ddd0..9d0d09a 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)
@@ -62,6 +69,25 @@
 	if err !=nil || dbtable.Id == "" || dbtable.TableName == "" {
 		util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
 		return
+	}
+	currentTime := time.Now()
+	startTime := dbtable.StartTime
+	endTime := ""
+	if dbtable.EndTime != "" {
+		endTime = dbtable.EndTime
+	}
+	st, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime, time.Local)
+	if endTime != "" {
+		et, _ := time.ParseInLocation("2006-01-02 15:04:05", endTime, time.Local)
+		if et.After(currentTime) && st.Before(currentTime) {
+			dbtable.Enable = 1
+		} else {
+			dbtable.Enable = 0
+		}
+	} else if st.Before(currentTime) && endTime == "" {
+		dbtable.Enable = 1
+	} else {
+		dbtable.Enable = 0
 	}
 	paramBody := util.Struct2Map(dbtable)
 	var tApi dbapi.DbTableApi
@@ -89,9 +115,73 @@
 	//}
 }
 
+type DbTStatusVo struct {
+	Id string `json:"id"`
+	Enable int `json:"enable"`
+}
+
+// @Summary 淇敼搴曞簱鐘舵��
+// @Description 淇敼鍚屾鎴栨湰鍦板簱搴曞簱鐘舵��
+// @Accept  json
+// @Produce json
+// @Tags dbtable
+// @Param obj body controllers.DbTStatusVo true "搴曞簱鐘舵�佷慨鏀瑰弬鏁�"
+// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}"
+// @Failure 500 {string} json "{"code":500,  msg:"杩斿洖閿欒淇℃伅", success:false}"
+// @Router /data/api-v/dbtable/updateDbTableStatus [POST]
+func (dbt DbTableController) UpdateDbTableStatus(c *gin.Context) {
+	var ds DbTStatusVo
+	err := c.BindJSON(&ds)
+	if err !=nil || ds.Id == "" || (ds.Enable !=0 && ds.Enable !=1)  {
+		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 {
+		util.ResponseFormat(c,code.UpdateSuccess,"鏇存柊鎴愬姛")
+	} else {
+		util.ResponseFormat(c,code.ComError,"鏇存柊澶辫触")
+	}
+}
+
 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))

--
Gitblit v1.8.0