From eff19d68fed3bbeb1e671455b502885f98fc11cb Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期一, 02 三月 2020 17:20:12 +0800
Subject: [PATCH] fix

---
 controllers/camera.go |   58 +++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 49 insertions(+), 9 deletions(-)

diff --git a/controllers/camera.go b/controllers/camera.go
index 374accf..16633b6 100644
--- a/controllers/camera.go
+++ b/controllers/camera.go
@@ -1,10 +1,12 @@
 package controllers
 
 import (
+	"basic.com/pubsub/protomsg.git"
 	"encoding/json"
 	"fmt"
 	"strconv"
 	"basic.com/valib/logger.git"
+	"strings"
 	"webserver/cache"
 
 	"github.com/gin-gonic/gin"
@@ -201,18 +203,27 @@
 // @Security ApiKeyAuth
 // @Summary 灏嗘憚鍍忔満鎸傚埌鎸囧畾鐨勭洰褰曟爲涓�
 // @Description 灏嗘憚鍍忔満鎸傚埌鎸囧畾鐨勭洰褰曟爲涓�
+// @Accept x-www-form-urlencoded
 // @Produce json
 // @Tags camera
-// @Param cameraId path string true "鎽勫儚鏈篿d"
-// @Param areaId path string true "鐩綍鍖哄煙id"
+// @Param cameraId formData string true "鎽勫儚鏈篿d"
+// @Param areaId formData 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/camera/cameraAreaAdd [get]
-func (ac CameraController) CameraAreaAdd(c *gin.Context) {
-	cameraId := c.Param("cameraId")
-	areaId := c.Param("areaId")
-	fmt.Println(cameraId)
-	fmt.Println(areaId)
+// @Router /data/api-v/camera/updateCameraArea [post]
+func (ac CameraController) UpdateCameraArea(c *gin.Context) {
+	cameraId := c.PostForm("cameraId")
+	areaId := c.PostForm("areaId")
+    if cameraId == "" || areaId == "" {
+        util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎")
+        return
+    }
+    var api dbapi.CameraApi
+    if api.UpdateCameraArea(cameraId, areaId) {
+        util.ResponseFormat(c,code.Success,"鏇存柊鎴愬姛")
+    } else {
+        util.ResponseFormat(c,code.ComError,"")
+    }
 }
 
 // @Security ApiKeyAuth
@@ -333,13 +344,42 @@
 func(cc CameraController) UpdateSnapshotUrl(c *gin.Context){
     cid := c.Param("cid")
     //filename, err := service.UpdateSnapshotUrl(cid)
+    if cid == "" {
+		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎")
+		return
+	}
+    if strings.HasPrefix(cid, File_Video_Id_Pre) || strings.HasPrefix(cid, File_Img_Id_Pre) || strings.HasPrefix(cid, File_Audio_Id_Pre) {
+		var fileApi dbapi.FileAnalysisApi
+		b, d := fileApi.Show(cid)
+		if b {
+			var file protomsg.FileAnalysis
+			bytes, _ := json.Marshal(d)
+			err := json.Unmarshal(bytes, &file)
+			if err == nil {
+				util.ResponseFormat(c, code.Success, map[string]string{
+					"cameraId": cid,
+					"snapshotUrl": file.SnapshotUrl,
+				})
+				return
+			} else {
+				util.ResponseFormat(c, code.ComError, "鏇存柊澶辫触")
+				return
+			}
+		} else {
+			util.ResponseFormat(c, code.ComError, "鏇存柊澶辫触")
+			return
+		}
+	}
 	filename, err := service.UpdateCapture(cid)
     if err != nil {
     	logger.Debug("UpdateSnapshotUrl.err:",err)
 		util.ResponseFormat(c, code.ComError, "鏇存柊澶辫触")
         return 
     }
-    util.ResponseFormat(c, code.Success, filename)
+    util.ResponseFormat(c, code.Success, map[string]string{
+    	"cameraId": cid,
+    	"snapshotUrl": filename,
+	})
 } 
 
 type CameraChangeRunVo struct {

--
Gitblit v1.8.0