From 88d229d880079db1d31af1d4cbed3b8eb12fd47d Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期五, 28 六月 2019 14:31:08 +0800
Subject: [PATCH] Merge branch 'master' of http://192.168.1.14:10010/r/webserver

---
 controllers/fileController.go |   18 +
 controllers/camera.go         |  137 ++++++++-
 controllers/pollConfig.go     |  110 ++++++++
 controllers/eventPush.go      |  191 ++++++++++++++
 main.go                       |    3 
 controllers/dictionary.go     |   32 ++
 service/FaceSdkService.go     |  180 +++++++++++++
 middlewares/auth/jwt.go       |   47 +-
 router/router.go              |   27 ++
 9 files changed, 695 insertions(+), 50 deletions(-)

diff --git a/controllers/camera.go b/controllers/camera.go
index 7d73101..9cf2351 100644
--- a/controllers/camera.go
+++ b/controllers/camera.go
@@ -3,6 +3,7 @@
 import (
 	"encoding/json"
 	"fmt"
+	"strconv"
 
 	"github.com/gin-gonic/gin"
 
@@ -14,20 +15,25 @@
 type CameraController struct{}
 
 type CameraVo struct {
-	Id        string       `json:"id"`
-	Name      string       `json:"name"`
-	Type      int          `json:"type" `
-	Addr      string       `json:"addr"`
-	Areaid    uint         `json:"areaid"`
-	Longitude float64      `json:"longitude"`
-	Latitude  float64      `json:"latitude"`
-	Rtsp      string       `json:"rtsp"`
-	Ip        string       `json:"ip"`
-	Port      int          `json:"port"`
-	Username  string       `json:"username"`
-	Password  string       `json:"password"`
-	Brand     string       `json:"brand"`
-	Reserved  string       `json:"reserved"`
+	Id        string  `json:"id"`
+	Name      string  `json:"name"`
+	Type      int     `json:"type" `
+	Addr      string  `json:"addr"`
+	Areaid    uint    `json:"areaid"`
+	Longitude float64 `json:"longitude"`
+	Latitude  float64 `json:"latitude"`
+	Rtsp      string  `json:"rtsp"`
+	Ip        string  `json:"ip"`
+	Port      int     `json:"port"`
+	Username  string  `json:"username"`
+	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 娣诲姞鎽勫儚鏈�
@@ -49,7 +55,7 @@
 		return
 	}
 	cam.Id = util.PseudoUuid()
-	paramBody :=util.Struct2Map(cam)
+	paramBody := util.Struct2Map(cam)
 	if api.CameraAdd(paramBody) {
 		util.ResponseFormat(c, code.Success, cam)
 		return
@@ -76,7 +82,7 @@
 		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟閿欒")
 		return
 	}
-	paramBody :=util.Struct2Map(cam)
+	paramBody := util.Struct2Map(cam)
 	if api.CameraAdd(paramBody) {
 		util.ResponseFormat(c, code.Success, cam)
 		return
@@ -97,11 +103,11 @@
 	var api dbapi.CameraApi
 	cid := c.Param("cid")
 
-	if api.CameraDelete(cid){
+	if api.CameraDelete(cid) {
 		util.ResponseFormat(c, code.Success, "鍒犻櫎鎴愬姛")
 		return
 	}
-	util.ResponseFormat(c, code.ComError,"鍒犻櫎澶辫触")
+	util.ResponseFormat(c, code.ComError, "鍒犻櫎澶辫触")
 }
 
 // @Summary 鏄剧ず鎽勫儚鏈�
@@ -115,9 +121,9 @@
 func (ac CameraController) CameraSel(c *gin.Context) {
 	var api dbapi.CameraApi
 	cid := c.Param("cid")
-	camera,err := api.GetCameraById(cid)
-	if err !=nil {
-		util.ResponseFormat(c,code.ComError,"鏌ヨ澶辫触")
+	camera, err := api.GetCameraById(cid)
+	if err != nil {
+		util.ResponseFormat(c, code.ComError, "鏌ヨ澶辫触")
 		return
 	}
 
@@ -187,3 +193,92 @@
 	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, cameraName)
+	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)
+	fmt.Println("data:", data)
+	if b {
+		util.ResponseFormat(c, code.Success, data)
+	} else {
+		util.ResponseFormat(c, code.ComError, "鏇存柊澶辫触")
+	}
+}
+
+type CameraChangeRunVo struct {
+	CameraIds []string `json:"camera_ids"`
+	RunType   int      `json:"run_type"`
+}
+
+// @Summary 鎽勫儚鏈鸿疆璇㈠拰瀹炴椂鐘舵�佸垏鎹�
+// @Description 鎽勫儚鏈鸿疆璇㈠拰瀹炴椂鐘舵�佸垏鎹�
+// @Produce json
+// @Tags camera
+// @Param changeRunBody body controllers.CameraChangeRunVo 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) {
+	var ccrVo CameraChangeRunVo
+	if err := c.BindJSON(&ccrVo); err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎")
+		return
+	}
+	paramBody := util.Struct2Map(ccrVo)
+	var api dbapi.CameraApi
+	b, data := api.ChangeRunType(paramBody)
+	if b {
+		util.ResponseFormat(c, code.Success, data)
+	} else {
+		util.ResponseFormat(c, code.ComError, "鏇存柊澶辫触")
+	}
+}
diff --git a/controllers/dictionary.go b/controllers/dictionary.go
index 4c66dd2..a68bc28 100644
--- a/controllers/dictionary.go
+++ b/controllers/dictionary.go
@@ -2,13 +2,12 @@
 
 import (
 	"basic.com/dbapi.git"
+	"github.com/gin-gonic/gin"
 	"webserver/extend/code"
 	"webserver/extend/util"
-	"github.com/gin-gonic/gin"
 )
 
 type DictionaryController struct {
-
 }
 
 // @Summary 鏍规嵁绫诲瀷鏌ユ壘瀛楀吀
@@ -23,8 +22,31 @@
 	var api dbapi.DicApi
 	flag, data := api.FindByType("")
 	if flag {
-		util.ResponseFormat(c,code.Success,data)
+		util.ResponseFormat(c, code.Success, data)
 	} else {
-		util.ResponseFormat(c,code.ComError,data)
+		util.ResponseFormat(c, code.ComError, data)
 	}
-}
\ No newline at end of file
+}
+
+// @Summary 鏍规嵁鐖禝D鏌ユ壘瀛楀吀
+// @Description  鏍规嵁鐖禝D鏌ユ壘瀛楀吀
+// @Produce json
+// @Tags 瀛楀吀
+// @Param parentId query string false "parentId"
+// @Success 200 {string} json "{"code":200, success:true, msg:"璇锋眰澶勭悊鎴愬姛", data:"鎴愬姛淇℃伅"}"
+// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:"閿欒淇℃伅鍐呭"}"
+// @Router /data/api-v/dictionary/findByParentId [get]
+func (controller DictionaryController) FindByParentId(c *gin.Context) {
+	parentId := c.Query("parentId")
+	if parentId == "" {
+		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎")
+		return
+	}
+	var api dbapi.DicApi
+	flag, data := api.FindByParentId(parentId)
+	if flag {
+		util.ResponseFormat(c, code.Success, data)
+	} else {
+		util.ResponseFormat(c, code.ComError, "鏌ヨ澶辫触")
+	}
+}
diff --git a/controllers/eventPush.go b/controllers/eventPush.go
new file mode 100644
index 0000000..18f8a49
--- /dev/null
+++ b/controllers/eventPush.go
@@ -0,0 +1,191 @@
+package controllers
+
+import (
+	"basic.com/dbapi.git"
+	"github.com/gin-gonic/gin"
+	"webserver/extend/code"
+	"webserver/extend/util"
+)
+
+type EventPushController struct {
+}
+
+type EventPushVo struct {
+	Id           string `json:"id"`
+	Name         string `json:"name"`
+	TimeStart    string `json:"time_start"`
+	TimeEnd      string `json:"time_end"`
+	IsSatisfyAll bool   `json:"is_satisfy_all"`
+	RuleText     string `json:"rule_text"`
+	Enable       bool   `json:"enable"`
+	LinkType     string `json:"link_type"`
+	LinkDevice   string `json:"link_device"`
+
+	IpPorts []EventPushServerPortVo `json:"ip_ports"`
+	Urls    []EventUrlVo            `json:"urls"`
+	Rules   []EventPushRuleVo       `json:"rules"`
+}
+
+type EventPushRuleVo struct {
+	Id           string `json:"id"`
+	TopicType    string `json:"topic_type"` //鍙傛暟涓婚,鐩墠鍒嗕负浜旂被锛堟憚鍍忔満銆佸簳搴撱�佷换鍔°�佷汉鍛樸�佹姤璀︾瓑绾э級
+	TopicArg     string `json:"topic_arg"`  //涓婚瀵瑰簲鐨勫叿浣撳弬鏁�
+	Operator     string `json:"operator"`
+	OperatorType string `json:"operator_type"`
+	RuleValue    string `json:"rule_value"`
+	EventPushId  string `json:"event_push_id"`
+}
+
+type EventPushServerPortVo struct {
+	ServerIp string `json:"server_ip"`
+	Port     int    `json:"port"`
+	Enable   bool   `json:"enable"`
+}
+
+type EventUrlVo struct {
+	Url    string `json:"url"`
+	Enable bool   `json:"enable"`
+}
+
+// @Summary 浜嬩欢鎺ㄩ�佷繚瀛�
+// @Description 浜嬩欢鎺ㄩ�佷繚瀛�
+// @Tags 浜嬩欢鎺ㄩ��
+// @Param SaveArgs body controllers.EventPushVo 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/eventPush/save [post]
+func (epc EventPushController) Save(c *gin.Context) {
+	var saveBody EventPushVo
+	if err := c.BindJSON(&saveBody); err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎")
+		return
+	}
+	var api dbapi.EventPushApi
+	paramBody := util.Struct2Map(saveBody)
+	flag, data := api.Save(paramBody)
+	if flag {
+		util.ResponseFormat(c, code.Success, data)
+	} else {
+		util.ResponseFormat(c, code.ComError, data)
+	}
+}
+
+// @Summary 鏍规嵁浜嬩欢鎺ㄩ�佷富棰樼殑涓�绾у拰浜岀骇閫夐」鑾峰彇鏈�鍚庝笅鎷夎彍鍗曞垪琛�
+// @Description  鏍规嵁浜嬩欢鎺ㄩ�佷富棰樼殑涓�绾у拰浜岀骇閫夐」鑾峰彇鏈�鍚庝笅鎷夎彍鍗曞垪琛�
+// @Produce json
+// @Tags 浜嬩欢鎺ㄩ��
+// @Param topic query string true "涓�绾т富棰橀�夐」,渚嬪锛歝amera(鎽勫儚鏈�)"
+// @Param type query string true "瀛愰�夐」绫诲瀷锛屼緥濡傦細name锛堝悕绉帮級鎴朼ddr锛堜綅缃級"
+// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
+// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
+// @Router /data/api-v/eventPush/findByEventTopic [get]
+func (epc EventPushController) FindByEventTopic(c *gin.Context) {
+	topic := c.Query("topic")
+	childType := c.Query("type")
+	if topic == "" {
+		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎")
+		return
+	}
+	var api dbapi.EventPushApi
+	flag, data := api.FindByEventTopic(topic, childType)
+	if flag {
+		util.ResponseFormat(c, code.Success, data)
+	} else {
+		util.ResponseFormat(c, code.ComError, data)
+	}
+}
+
+// @Summary 鏌ュ叏閮�
+// @Description  鏌ュ叏閮�
+// @Produce json
+// @Tags 浜嬩欢鎺ㄩ��
+// @Param name 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/eventPush/findAll [get]
+func (controller EventPushController) FindAll(c *gin.Context) {
+	name := c.Query("name")
+	var api dbapi.EventPushApi
+	flag, data := api.FindAll(name)
+	if flag {
+		util.ResponseFormat(c, code.Success, data)
+	} else {
+		util.ResponseFormat(c, code.ComError, "")
+	}
+}
+
+// @Summary 浜嬩欢鎺ㄩ�佺紪杈�
+// @Description  浜嬩欢鎺ㄩ�佺紪杈�
+// @Produce json
+// @Tags 浜嬩欢鎺ㄩ��
+// @Param id query string true "id"
+// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
+// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
+// @Router /data/api-v/eventPush/getById [get]
+func (controller EventPushController) GetById(c *gin.Context) {
+	id := c.Query("id")
+	if id == "" {
+		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎")
+		return
+	}
+	var api dbapi.EventPushApi
+	flag, data := api.GetById(id)
+	if flag {
+		util.ResponseFormat(c, code.Success, data)
+	} else {
+		util.ResponseFormat(c, code.ComError, "")
+	}
+}
+
+type ChangeStatusVo struct {
+	Id     string `json:"id"`
+	Enable bool   `json:"enable"`
+}
+
+// @Summary 鏀瑰彉enable鐘舵��
+// @Description  鏀瑰彉enable鐘舵��
+// @Produce json
+// @Tags 浜嬩欢鎺ㄩ��
+// @Param statusBody body controllers.ChangeStatusVo 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/eventPush/changeStatus [post]
+func (controller EventPushController) ChangeStatus(c *gin.Context) {
+	var statusBody ChangeStatusVo
+	err := c.BindJSON(&statusBody)
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎")
+		return
+	}
+	var api dbapi.EventPushApi
+	flag, data := api.ChangeStatus(statusBody.Id, statusBody.Enable)
+	if flag {
+		util.ResponseFormat(c, code.Success, data)
+	} else {
+		util.ResponseFormat(c, code.ComError, data)
+	}
+}
+
+// @Summary 鏍规嵁id鍒犻櫎
+// @Description  鏍规嵁id鍒犻櫎
+// @Accept x-www-form-urlencoded
+// @Produce json
+// @Tags 浜嬩欢鎺ㄩ��
+// @Param id query string true "id"
+// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
+// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
+// @Router /data/api-v/eventPush/delete [post]
+func (controller EventPushController) Delete(c *gin.Context) {
+	id := c.PostForm("id")
+	if id == "" {
+		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎")
+		return
+	}
+	var api dbapi.EventPushApi
+	flag, data := api.Delete(id)
+	if flag {
+		util.ResponseFormat(c, code.Success, data)
+	} else {
+		util.ResponseFormat(c, code.ComError, data)
+	}
+}
diff --git a/controllers/fileController.go b/controllers/fileController.go
index 33a2d81..e175f30 100644
--- a/controllers/fileController.go
+++ b/controllers/fileController.go
@@ -85,6 +85,24 @@
 	}
 }
 
+// @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)
 if err != nil {
diff --git a/controllers/pollConfig.go b/controllers/pollConfig.go
new file mode 100644
index 0000000..014a071
--- /dev/null
+++ b/controllers/pollConfig.go
@@ -0,0 +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.SavePollPeriod(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, "淇敼澶辫触")
+	}
+}
diff --git a/main.go b/main.go
index 14eb75e..58ed362 100644
--- a/main.go
+++ b/main.go
@@ -6,10 +6,13 @@
 	"webserver/extend/config"
 	"webserver/models"
 	"webserver/router"
+	"webserver/service"
 )
 
 func main() {
 
+	service.TestPushImgMsg()
+
 	envirment := flag.String("e", "dev", "")
 	flag.Usage = func() {
 		glog.Exit("flag parse usage !")
diff --git a/middlewares/auth/jwt.go b/middlewares/auth/jwt.go
index c7074e2..0187b2f 100644
--- a/middlewares/auth/jwt.go
+++ b/middlewares/auth/jwt.go
@@ -2,7 +2,6 @@
 
 import (
 	"encoding/json"
-	"errors"
 	jwtLib "github.com/dgrijalva/jwt-go"
 	"github.com/dgrijalva/jwt-go/request"
 	"github.com/gin-gonic/gin"
@@ -14,14 +13,14 @@
 type jwtAuthManager struct {
 	secret string
 	expire time.Duration
-	alg string
+	alg    string
 }
 
-func NewJwtAuthDriver() *jwtAuthManager{
+func NewJwtAuthDriver() *jwtAuthManager {
 	return &jwtAuthManager{
-		secret:TokenKey,
-		expire:time.Hour*8,
-		alg:"HS256",
+		secret: TokenKey,
+		expire: time.Hour * 8,
+		alg:    "HS256",
 	}
 }
 
@@ -35,44 +34,44 @@
 	if len(t) < 2 {
 		return false
 	}
-	var keyFunc = func(token *jwtLib.Token) (interface{},error) {
+	var keyFunc = func(token *jwtLib.Token) (interface{}, error) {
 		b := []byte(jwtAuth.secret)
-		return b,nil
+		return b, nil
 	}
-	authJwtToken, err:= request.ParseFromRequest(c.Request,request.OAuth2Extractor,keyFunc)
-	if err !=nil {
+	authJwtToken, err := request.ParseFromRequest(c.Request, request.OAuth2Extractor, keyFunc)
+	if err != nil {
 		return false
 	}
 
-	c.Set("User",map[string]interface{}{
-		"token":authJwtToken,
+	c.Set("User", map[string]interface{}{
+		"token": authJwtToken,
 	})
 
 	return authJwtToken.Valid
 }
 
-func (jwtAuth *jwtAuthManager) User(c *gin.Context) interface{}{
+func (jwtAuth *jwtAuthManager) User(c *gin.Context) interface{} {
 	var jwtToken *jwtLib.Token
-	if jwtUser, exist := c.Get("User");!exist{
-		tokenStr :=strings.Replace(c.Request.Header.Get("Authorization"),"Bearer ","",-1)
-		if tokenStr == ""{
+	if jwtUser, exist := c.Get("User"); !exist {
+		tokenStr := strings.Replace(c.Request.Header.Get("Authorization"), "Bearer ", "", -1)
+		if tokenStr == "" {
 			return map[interface{}]interface{}{}
 		}
 		var err error
-		jwtToken,err = jwtLib.Parse(tokenStr, func(token *jwtLib.Token) (interface{}, error) {
-			b :=[]byte(jwtAuth.secret)
-			return b,nil
+		jwtToken, err = jwtLib.Parse(tokenStr, func(token *jwtLib.Token) (interface{}, error) {
+			b := []byte(jwtAuth.secret)
+			return b, nil
 		})
-		if err !=nil {
-			panic(err)
+		if err != nil {
+			return nil
 		}
 	} else {
 		jwtToken = jwtUser.(map[string]interface{})["token"].(*jwtLib.Token)
 	}
-	if claims,ok :=jwtToken.Claims.(jwtLib.MapClaims);ok && jwtToken.Valid{
+	if claims, ok := jwtToken.Claims.(jwtLib.MapClaims); ok && jwtToken.Valid {
 		var user map[string]interface{}
 		if err := json.Unmarshal([]byte(claims["user"].(string)), &user); err != nil {
-			panic(err)
+			return nil
 		}
 		c.Set("User", map[string]interface{}{
 			"token": jwtToken,
@@ -80,7 +79,7 @@
 		})
 		return user
 	} else {
-		panic(errors.New("decode jwt user claims fail"))
+		return nil
 	}
 }
 
diff --git a/router/router.go b/router/router.go
index 145b718..c8cdc34 100644
--- a/router/router.go
+++ b/router/router.go
@@ -7,6 +7,8 @@
 	"github.com/szuecs/gin-glog"
 	"time"
 	"webserver/controllers"
+
+	_ "webserver/docs"
 )
 
 func NewRouter() *gin.Engine {
@@ -32,6 +34,9 @@
 	cameraTaskArgsController := new(controllers.CameraTaskArgsController)
 	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")
@@ -63,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")
@@ -133,6 +141,8 @@
 		vdbperson.POST("/deleteDbPersonById/:uuid", dbPersonCont.DeleteDbPerson)
 		vdbperson.POST("/deleteMoreDbPerson", dbPersonCont.DeleteMoreDbPerson)
 		vdbperson.PUT("/addDbPerson", dbPersonCont.AddDbPerson)
+
+		vdbperson.POST("/fileUploadTest", fileController.UploadPersonTest)
 	}
 
 	// 绯荤粺璁剧疆 鎿嶄綔
@@ -166,6 +176,23 @@
 	dicApi := r.Group(urlPrefix + "/dictionary")
 	{
 		dicApi.GET("/findByType", dicController.FindByType)
+		dicApi.GET("/findByParentId", dicController.FindByParentId)
+	}
+	eventPushApi := r.Group(urlPrefix + "/eventPush")
+	{
+		eventPushApi.POST("/save", eventPushController.Save)
+		eventPushApi.GET("/findByEventTopic", eventPushController.FindByEventTopic)
+		eventPushApi.GET("/findAll", eventPushController.FindAll)
+		eventPushApi.GET("/getById", eventPushController.GetById)
+		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)
 	}
 
 	// 鏂囦欢 涓婁紶
diff --git a/service/FaceSdkService.go b/service/FaceSdkService.go
new file mode 100644
index 0000000..6609997
--- /dev/null
+++ b/service/FaceSdkService.go
@@ -0,0 +1,180 @@
+package service
+
+import (
+	"basic.com/pubsub/protomsg.git"
+	"basic.com/valib/deliver.git"
+	"encoding/base64"
+	"fmt"
+	"github.com/gogo/protobuf/proto"
+	"github.com/pierrec/lz4"
+	"github.com/satori/go.uuid"
+	"gocv.io/x/gocv"
+	"time"
+)
+
+const (
+	Ipc_Push_Ext       = "_2.ipc"
+	Ipc_Pull_Ext       = "_1.ipc"
+	Ipc_Url_Pre        = "ipc:///tmp///"
+	Virtual_FaceTaskId = "92496BDF-2BFA-98F2-62E8-96DD9866ABD2"
+	Virtual_FaceSdkId  = "virtual-faceextract-sdk-pull"
+	Url_Service_PUSH   = Ipc_Url_Pre + Virtual_FaceSdkId + Ipc_Push_Ext
+	Url_Service_PULL   = Ipc_Url_Pre + Virtual_FaceSdkId + Ipc_Pull_Ext
+)
+
+var imgPushChan chan []byte
+var client_push deliver.Deliver
+var client_pull deliver.Deliver
+
+func TestPushImgMsg() {
+	InitService()
+
+	i := readImgFile()
+
+	fmt.Printf("width:%d,height:%d,data.length:%d,timestamp:%s,id:%d\n", i.Width, i.Height, len(i.Data), i.Timestamp, i.Id)
+	if b, err := proto.Marshal(&i); err != nil {
+		fmt.Println("protoImage marshal err")
+		return
+	} else {
+		bc := make([]byte, len(b))
+		ht := make([]int, 64<<10)
+		n, err := lz4.CompressBlock(b, bc, ht)
+		if err != nil {
+			fmt.Println(err)
+		}
+		if n >= len(b) {
+			fmt.Println("image is not compressible")
+		}
+		bc = bc[:n]
+		for {
+			PushImgMsg(bc)
+			fmt.Println("pushed img")
+			time.Sleep(5 * time.Second)
+		}
+
+	}
+}
+
+func readImgFile() protomsg.Image {
+	var i protomsg.Image
+	timeUnix := time.Now().Unix()
+	formatTimeStr := time.Unix(timeUnix, 0).Format("2006-01-02 15:04:05")
+	filePath := "/home/user/workspace/timg.jpg"
+
+	picMat := gocv.IMRead(filePath, gocv.IMReadColor)
+
+	defer picMat.Close()
+
+	if picMat.Empty() {
+		fmt.Println("file not exist")
+		return i
+	}
+	height := int32(picMat.Rows())
+	width := int32(picMat.Cols())
+	data := picMat.ToBytes()
+	//wrMat,_ := gocv.NewMatFromBytes(picMat.Rows(),picMat.Cols(),gocv.MatTypeCV8UC3,data)
+	//
+	//gocv.IMWrite("xxx.jpg", wrMat)
+
+	i = protomsg.Image{
+		Width:     width,
+		Height:    height,
+		Timestamp: formatTimeStr,
+		Data:      data,
+		Id:        timeUnix,
+	}
+	i.Cid = uuid.NewV4().String() //鏁版嵁鍞竴id
+	fmt.Println("gocv read img completed")
+	return i
+}
+
+func PushImgMsg(is []byte) {
+	imgPushChan <- is
+}
+
+var resultMap map[string]protomsg.SdkMessage
+
+func InitService() {
+	fmt.Println("service init!")
+	imgPushChan = make(chan []byte)
+	resultMap = make(map[string]protomsg.SdkMessage, 0)
+	client_push = deliver.NewClient(deliver.PushPull, Url_Service_PUSH)
+	client_pull = deliver.NewClient(deliver.PushPull, Url_Service_PULL)
+	defer func() {
+		client_push.Close()
+		client_pull.Close()
+	}()
+	go thSend()
+
+	go thRecv()
+}
+
+func thSend() {
+	for {
+		select {
+		case d := <-imgPushChan:
+			fmt.Println("imgPushChan in")
+			err := client_push.Send(d)
+			if err != nil {
+				fmt.Println("img Send err:", err)
+			}
+		default:
+			//fmt.Println("no img in")
+		}
+	}
+}
+
+func thRecv() {
+	for {
+		resultBytes, err := client_pull.Recv()
+		if err != nil {
+			fmt.Println("pull err:", err)
+			continue
+		}
+		rMsg := protomsg.SdkMessage{}
+		if err := proto.Unmarshal(resultBytes, &rMsg); err == nil {
+			fmt.Println("received MSG:", rMsg.Cid)
+			perId := rMsg.Cid //鏁版嵁id
+			if rMsg.Tasklab != nil && rMsg.Tasklab.Taskid == Virtual_FaceTaskId {
+				sdkInfos := rMsg.Tasklab.Sdkinfos
+				fmt.Println("Len(sdkInfos)=", len(sdkInfos))
+				for _, swt := range sdkInfos {
+					fmt.Println("sdkName:", swt.SdkName)
+					if swt.Sdktype == "FaceDetect" {
+						fmt.Println("浜鸿劯妫�娴嬬粨鏋�")
+						var pfp protomsg.ParamFacePos
+						err := proto.Unmarshal(swt.Sdkdata, &pfp)
+						if err != nil {
+							fmt.Println("faceDetect result unmarshal err:", err)
+						} else {
+							for _, face := range pfp.Faces {
+								fmt.Println("FacePos:", face.Pos)
+								fmt.Println("ThftResult:", face.Result)
+							}
+						}
+					}
+					if swt.Sdktype == "FaceExtract" {
+						fmt.Println("sdkData.len:", len(swt.Sdkdata))
+						var pff protomsg.ParamFaceFeature
+						if err := proto.Unmarshal(swt.Sdkdata, &pff); err != nil {
+							//fmt.Println("ParamFaceFeature unmarshal err:",err)
+						} else {
+							fmt.Println("鐩爣鏁帮細", len(pff.ExtComp))
+							for _, fea := range pff.ExtComp {
+								base64Fea := base64.StdEncoding.EncodeToString(fea.Feats)
+								fmt.Println("perId:", perId)
+								fmt.Println("faceFeature:", base64Fea)
+							}
+						}
+						break
+					}
+				}
+
+			}
+			//resultMap[rMsg.Cid] = rMsg
+		} else {
+			fmt.Println("recv msg Err:", err)
+		}
+
+	}
+}

--
Gitblit v1.8.0