From 9dbf52d751cd6b347210550eb5217c3eb2c0306d Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期五, 23 八月 2019 15:59:06 +0800
Subject: [PATCH] add UpdateDbTableStatus
---
controllers/dbtablesCon.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
router/router.go | 1 +
2 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/controllers/dbtablesCon.go b/controllers/dbtablesCon.go
index fd8ddd0..9746d1d 100644
--- a/controllers/dbtablesCon.go
+++ b/controllers/dbtablesCon.go
@@ -63,6 +63,25 @@
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
b, data := tApi.UpdateDbTables(paramBody)
@@ -89,6 +108,37 @@
//}
}
+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
+
+ 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 +
diff --git a/router/router.go b/router/router.go
index 7680086..a058287 100644
--- a/router/router.go
+++ b/router/router.go
@@ -152,6 +152,7 @@
vdbtable.POST("/updateDbTables", tableController.UpdateDbTables)
vdbtable.POST("/deleteDBtablesById/:id", tableController.DeleteDbTables)
vdbtable.PUT("/addDbTableInfo", tableController.AddDbTableInfo)
+ vdbtable.POST("/updateDbTableStatus", tableController.UpdateDbTableStatus)
}
// 搴曞簱浜哄憳 鎿嶄綔
--
Gitblit v1.8.0