From ca0affbce745df4e071dc256c5f47b2a8165a443 Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期三, 26 六月 2019 17:00:54 +0800
Subject: [PATCH] pollconfig done

---
 controllers/fileController.go |   17 ++++
 controllers/camera.go         |   91 ++++++++++++++++++++++
 controllers/pollConfig.go     |  109 +++++++++++++++++++++++++++
 router/router.go              |   16 +++
 4 files changed, 232 insertions(+), 1 deletions(-)

diff --git a/controllers/camera.go b/controllers/camera.go
index 7d73101..d532222 100644
--- a/controllers/camera.go
+++ b/controllers/camera.go
@@ -3,6 +3,7 @@
 import (
 	"encoding/json"
 	"fmt"
+	"strconv"
 
 	"github.com/gin-gonic/gin"
 
@@ -28,6 +29,11 @@
 	Password  string       `json:"password"`
 	Brand     string       `json:"brand"`
 	Reserved  string       `json:"reserved"`
+
+	IsRunning bool 		   `json:"is_running"`//鏄惁姝e湪瑙g爜
+	RunEnable bool 		   `json:"run_enable"`//鎺у埗瀹炴椂澶勭悊鎴栬疆璇㈠鐞嗙殑寮�鍏�
+	RunType   int 		   `json:"run_type"`//澶勭悊绫诲瀷锛�0锛氳疆璇紝1锛氬疄鏃�
+	RunServerId string 	   `json:"run_server_id"`//褰撳墠姝e湪澶勭悊鐨勫垎鏋愭湇鍔″櫒id
 }
 
 // @Summary 娣诲姞鎽勫儚鏈�
@@ -187,3 +193,88 @@
 	fmt.Println(cameraId)
 	fmt.Println(areaId)
 }
+
+// @Summary 鑾峰彇杩愯绫诲瀷鑾峰彇鎽勫儚鏈哄垪琛�
+// @Description 鑾峰彇杩愯绫诲瀷鑾峰彇鎽勫儚鏈哄垪琛�
+// @Produce json
+// @Tags camera
+// @Param runType query int true "0锛氭煡杞锛�1锛氭煡瀹炴椂"
+// @Param cameraName query string false "鏌ヨ鏉′欢"
+// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
+// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
+// @Router /data/api-v/camera/getCamerasByRunType [get]
+func (cc CameraController) GetCamerasByRunType(c *gin.Context) {
+
+	runTypeStr := c.Query("runType")
+	cameraName := c.Query("cameraName")
+	fmt.Println("runType:",runTypeStr)
+	fmt.Println("cameraName:",cameraName)
+	runType, err := strconv.Atoi(runTypeStr)
+	if err !=nil || (runType !=0 && runType !=1) {
+		util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
+		return
+	}
+	var api dbapi.CameraApi
+	b,list := api.GetCamerasByRunType(runType)
+	if b {
+		dataBytes, _ := json.Marshal(list)
+		var cams []CameraVo
+		json.Unmarshal(dataBytes, &cams)
+		util.ResponseFormat(c,code.Success,cams)
+	} else {
+		util.ResponseFormat(c,code.ComError,err)
+	}
+}
+
+// @Summary 鍒囨崲鎽勫儚鏈鸿繍琛屽疄鏃舵垨杞鐨勫紑鍏�
+// @Description 鍒囨崲鎽勫儚鏈鸿繍琛屽疄鏃舵垨杞鐨勫紑鍏�
+// @Produce json
+// @Tags camera
+// @Param cameraId query string true "鎽勫儚鏈篿d"
+// @Param runEnable query bool true "寮�鍚細true锛屽叧闂細false"
+// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
+// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
+// @Router /data/api-v/camera/updateRunEnable [post]
+func (cc CameraController) UpdateRunEnable(c *gin.Context){
+	cameraId := c.PostForm("cameraId")
+	enableStr := c.PostForm("runEnable")
+	runEnable, err := strconv.ParseBool(enableStr)
+	if cameraId == "" || err !=nil {
+		util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
+		return
+	}
+	var api dbapi.CameraApi
+	b, data := api.UpdateRunEnable(cameraId, runEnable)
+	if b {
+		util.ResponseFormat(c,code.Success,data)
+	} else {
+		util.ResponseFormat(c,code.ComError,"鏇存柊澶辫触")
+	}
+}
+
+// @Summary 鎽勫儚鏈鸿疆璇㈠拰瀹炴椂鐘舵�佸垏鎹�
+// @Description 鎽勫儚鏈鸿疆璇㈠拰瀹炴椂鐘舵�佸垏鎹�
+// @Produce json
+// @Tags camera
+// @Param cameraId query string true "鎽勫儚鏈篿d"
+// @Param runType query int true "0锛氬疄鏃跺垏杞锛�1锛氳疆璇㈠垏瀹炴椂"
+// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
+// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
+// @Router /data/api-v/camera/changeRunType [post]
+func (cc CameraController) ChangeRunType(c *gin.Context){
+	cameraId := c.PostForm("cameraId")
+	runTypeStr := c.PostForm("runType")
+	runType,err := strconv.Atoi(runTypeStr)
+	if cameraId == "" || err!=nil || (runType !=0 && runType !=1){
+		util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
+		return
+	}
+
+	var api dbapi.CameraApi
+	b, data := api.ChangeRunType(cameraId, runType)
+	if b {
+		util.ResponseFormat(c,code.Success,data)
+	} else {
+		util.ResponseFormat(c,code.ComError,"鏇存柊澶辫触")
+	}
+}
\ No newline at end of file
diff --git a/controllers/fileController.go b/controllers/fileController.go
index 1c1f606..15b4d48 100644
--- a/controllers/fileController.go
+++ b/controllers/fileController.go
@@ -84,6 +84,23 @@
 		util.ResponseFormat(c, code.Success, field)
 	}
 }
+// @Description 浜哄憳鐓х墖涓婁紶骞惰幏鍙栫壒寰佸��
+// @Router /data/api-v/dbperson/fileUploadTest [POST]
+func (controller FileController) UploadPersonTest(c *gin.Context){
+	file, header, err := c.Request.FormFile("file") //image杩欎釜鏄痷plaodify鍙傛暟瀹氫箟涓殑   'fileObjName':'image'
+	if err != nil {
+		util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
+		return
+	}
+	//鏂囦欢鐨勫悕绉�
+	filename := header.Filename
+	fmt.Println(file, err, filename)
+	if err != nil {
+		log.Fatal(err)
+		filename = uuid.NewV4().String()
+	}
+
+}
 
 /*// 瀵逛笂闈㈢殑缂栫爜缁撴灉杩涜base64瑙g爜
 decodeBytes, err := base64.StdEncoding.DecodeString(encodeString)
diff --git a/controllers/pollConfig.go b/controllers/pollConfig.go
index 2d32936..67ac74f 100644
--- a/controllers/pollConfig.go
+++ b/controllers/pollConfig.go
@@ -1 +1,110 @@
 package controllers
+
+import (
+	"basic.com/dbapi.git"
+	"github.com/gin-gonic/gin"
+	"strconv"
+	"webserver/extend/code"
+	"webserver/extend/util"
+)
+
+type PollConfigController struct {
+
+}
+
+type PollConfig struct {
+	ServerId string `json:"server_id"`//鏈嶅姟鍣╥d
+	PollPeriod int `json:"poll_period"`//杞鍛ㄦ湡
+	Delay int `json:"delay"`//寤舵椂鏃堕棿
+	Enable bool `json:"enable"`//鏄惁鍚敤杞
+}
+
+// @Summary 淇濆瓨杞鍛ㄦ湡
+// @Description 淇濆瓨杞鍛ㄦ湡
+// @Produce json
+// @Tags 杞閰嶇疆
+// @Param period query int true "杞鍛ㄦ湡"
+// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
+// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
+// @Router /data/api-v/pollConfig/savePollPeriod [post]
+func (controller PollConfigController) SavePollPeriod(c *gin.Context){
+	periodStr := c.PostForm("period")
+	period, err := strconv.Atoi(periodStr)
+	if periodStr =="" || err !=nil{
+		util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
+		return
+	}
+	var api dbapi.SysSetApi
+	b, data := api.SavePollDelay(period)
+	if b {
+		util.ResponseFormat(c,code.Success,data)
+	} else {
+		util.ResponseFormat(c,code.ComError,"淇濆瓨澶辫触")
+	}
+}
+
+// @Summary 淇濆瓨杞寤舵椂
+// @Description 淇濆瓨杞寤舵椂
+// @Produce json
+// @Tags 杞閰嶇疆
+// @Param delay query int true "杞寤舵椂鏃堕棿"
+// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
+// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
+// @Router /data/api-v/pollConfig/savePollDelay [post]
+func (controller PollConfigController) SavePollDelay(c *gin.Context){
+	delayStr := c.PostForm("delay")
+	delay, err := strconv.Atoi(delayStr)
+	if delayStr =="" || err !=nil{
+		util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
+		return
+	}
+	var api dbapi.SysSetApi
+	b, data := api.SavePollDelay(delay)
+	if b {
+		util.ResponseFormat(c,code.Success,data)
+	} else {
+		util.ResponseFormat(c,code.ComError,"淇濆瓨澶辫触")
+	}
+}
+
+// @Summary 鑾峰彇鏈満杞閰嶇疆
+// @Description 鑾峰彇鏈満杞閰嶇疆
+// @Produce json
+// @Tags 杞閰嶇疆
+// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
+// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
+// @Router /data/api-v/pollConfig/getPollConfig [get]
+func (controller PollConfigController) GetPollConfig(c *gin.Context){
+	var api dbapi.SysSetApi
+	b, data := api.GetPollConfig()
+	if b {
+		util.ResponseFormat(c,code.Success,data)
+	}else{
+		util.ResponseFormat(c,code.ComError,"鏌ヨ澶辫触")
+	}
+}
+
+type PollEnableVo struct {
+	Enable bool `json:"enable"`
+}
+// @Summary 鍒囨崲杞寮�鍏�
+// @Description 鍒囨崲杞寮�鍏�
+// @Produce json
+// @Tags 杞閰嶇疆
+// @Param argBody body controllers.PollEnableVo true "寮�鍏冲弬鏁�"
+// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
+// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
+// @Router /data/api-v/pollConfig/updateEnable [post]
+func (controller PollConfigController) UpdateEnable(c *gin.Context){
+	var argBody PollEnableVo
+	if err := c.BindJSON(&argBody);err !=nil {
+		util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
+		return
+	}
+	var api dbapi.SysSetApi
+	if api.UpdatePollEnable(argBody.Enable){
+		util.ResponseFormat(c,code.Success,"淇敼鎴愬姛")
+	} else {
+		util.ResponseFormat(c,code.ComError,"淇敼澶辫触")
+	}
+}
\ No newline at end of file
diff --git a/router/router.go b/router/router.go
index 6425bd8..475bf0e 100644
--- a/router/router.go
+++ b/router/router.go
@@ -35,6 +35,8 @@
 	dicController :=new(controllers.DictionaryController)
 	userController :=new(controllers.UserController)
 	eventPushController :=new(controllers.EventPushController)
+	pollConfigController :=new(controllers.PollConfigController)
+	fileController := new(controllers.FileController)
 
 	urlPrefix := "/data/api-v" // wp 娣诲姞 璺緞 鍓嶇紑
 	userApi :=r.Group(urlPrefix+"/user")
@@ -66,6 +68,9 @@
 		camera.GET("/delTask/:cameraId/:taskId", cameraController.CameraDelTask)
 		camera.POST("/saveTask", cameraController.CameraTaskSave)
 		camera.GET("/getRulesByCameraAndTask",cameraTaskArgsController.FindByCameraAndTask)
+		camera.GET("/getCamerasByRunType",cameraController.GetCamerasByRunType)
+		camera.POST("/updateRunEnable",cameraController.UpdateRunEnable)
+		camera.POST("/changeRunType",cameraController.ChangeRunType)
 	}
 
 	cameraTaskArgsApi :=r.Group(urlPrefix + "/cameraTaskArgs")
@@ -136,6 +141,8 @@
 		vdbperson.POST("/deleteDbPersonById/:uuid", dbPersonCont.DeleteDbPerson)
 		vdbperson.POST("/deleteMoreDbPerson", dbPersonCont.DeleteMoreDbPerson)
 		vdbperson.PUT("/addDbPerson", dbPersonCont.AddDbPerson)
+
+		vdbperson.POST("/fileUploadTest",fileController.UploadPersonTest)
 	}
 
 	// 绯荤粺璁剧疆 鎿嶄綔
@@ -180,12 +187,19 @@
 		eventPushApi.POST("/changeStatus",eventPushController.ChangeStatus)
 		eventPushApi.POST("/delete",eventPushController.Delete)
 	}
+	pollCApi :=r.Group(urlPrefix+"/pollConfig")
+	{
+		pollCApi.POST("/savePollPeriod",pollConfigController.SavePollPeriod)
+		pollCApi.POST("/savePollDelay",pollConfigController.SavePollDelay)
+		pollCApi.GET("/getPollConfig",pollConfigController.GetPollConfig)
+		pollCApi.POST("/updateEnable",pollConfigController.UpdateEnable)
+	}
 
 	// 鏂囦欢 涓婁紶
 	r.Static("static", "./static") // 闈欐�佹枃浠�
 	//澶栭儴璁块棶swagger.json
 	r.StaticFile("/swagger.json", "./docs/swagger.json")
-	fileController := new(controllers.FileController)
+
 	vdbperson.POST("/fileupload", fileController.Fileupload)
 	vdbperson.POST("/moreFileUpload", fileController.MoreFileUpload)
 	r.POST(urlPrefix+"/es/ImageUploadReturnPics", fileController.ImageUploadReturnPics)

--
Gitblit v1.8.0