From 7c811247ecf143e08c576986a884bedadc57dd66 Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期五, 05 六月 2020 18:29:41 +0800
Subject: [PATCH] add refresh token to resp

---
 controllers/syssetcont.go |  233 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 219 insertions(+), 14 deletions(-)

diff --git a/controllers/syssetcont.go b/controllers/syssetcont.go
index 96705e3..ee7e0d6 100644
--- a/controllers/syssetcont.go
+++ b/controllers/syssetcont.go
@@ -1,11 +1,16 @@
 package controllers
 
 import (
+	"basic.com/valib/logger.git"
+	"net/http"
 	"regexp"
+	"strconv"
 	"webserver/extend/code"
 	"webserver/extend/config"
 	"webserver/extend/sys"
 	"webserver/extend/util"
+	"webserver/middlewares/auth"
+	"webserver/service"
 
 	"basic.com/dbapi.git"
 	"github.com/gin-gonic/gin"
@@ -16,6 +21,7 @@
 
 type LocalConfigVo struct {
 	Id                 string `json:"id"`
+
 	AlarmIp            string `json:"alarm_ip,omitempty" example:"192.168.1.182"`
 	AlarmPort          int    `json:"alarm_port,omitempty" example:"22122"`
 	AlarmThresholdType int    `json:"alarm_threshold_type"` //鎶ヨ闃堝�肩被鍨嬭缃細1:鎸夋渶楂樺垎,2:鎸夐槇鍊间互涓�
@@ -31,6 +37,13 @@
 	ServerType         int    `json:"server_type,omitempty" example:"1"`
 	Reserved           string `json:"reserved,omitempty" example:"1"`
 	RealMax            int    `json:"real_max"` //瀹炴椂澶勭悊鐨勬渶澶ц矾鏁�
+}
+
+type ResourceConfigVo struct {
+	IpType 		int   	`json:"ipType"` //0:鏈満ip锛�1锛氭紓绉籭p
+	ServiceIp   string 	`json:"serviceIp"`  //澶栭儴鏈嶅姟ip
+	Domain 		string  `json:"domain"` //鍩熷悕
+	FilePort    int 	`json:"filePort"`
 }
 
 type Gb28181ConfigVo struct {
@@ -78,8 +91,8 @@
 // @Produce json
 // @Tags sysset
 // @Param config body controllers.LocalConfigVo true "鎶ヨ鍜屽瓨鍌ㄤ俊鎭暟鎹�"
-// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}"
-// @Failure 500 {string} json "{"code":500,  msg:"杩斿洖閿欒淇℃伅", success:false}"
+// @Success 200 {string} json "{"code":200, msg:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
 // @Router /data/api-v/sysset/alarmEdit [POST]
 func (sset SysSetController) AlarmEdit(c *gin.Context) {
 	var args LocalConfigVo
@@ -101,7 +114,6 @@
 // @Security ApiKeyAuth
 // @Summary 瀛樺偍淇℃伅淇敼
 // @Description 瀛樺偍淇℃伅淇敼
-// @Accept  json
 // @Produce json
 // @Tags sysset
 // @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}"
@@ -159,12 +171,14 @@
 func (sset SysSetController) GetDevInfo(c *gin.Context) {
 	var api dbapi.SysSetApi
 	b, sysconf := api.GetServerInfo()
-	resData := make(map[string]string, 0)
+	resData := make(map[string]interface{}, 0)
 	if !b { // 鏌ヨ鏄惁瀛樺湪
 		util.ResponseFormat(c, code.ServiceInsideError, "鏌ヨ澶辫触")
 	} else {
 		resData["server_id"] = sysconf.GetServerId()
 		resData["server_name"] = sysconf.GetServerName()
+		resData["server_port"] = sys.GetNginxListenPort()
+
 		ipv4, mask, _ := sys.GetLocalIP(config.Server.NetworkAdapter)
 		gateway, _ := sys.GetDefaultRoute(config.Server.NetworkAdapter)
 		dns, _ := sys.GetDnsServer()
@@ -172,6 +186,14 @@
 		resData["subMask"] = mask
 		resData["gateway"] = gateway
 		resData["dns"] = dns
+		resData["min_video_len"] = sysconf.CutMinDuration
+		resData["max_video_len"] = sysconf.CutMaxDuration
+		resData["alarm_ip"] = sysconf.AlarmIp
+		resData["alarm_port"] = sysconf.AlarmPort
+		resData["web_pic_ip"] = sysconf.WebPicIp
+		resData["web_pic_port"] = sysconf.WebPicPort
+		resData["es_pic_ip"] = sysconf.EsPicIp
+		resData["es_pic_port"] = sysconf.EsPicPort
 
 		resData["deviceNum"] = config.Server.DeviceNum
 		resData["deviceType"] = config.Server.DeviceType
@@ -197,19 +219,17 @@
 // @Failure 500 {string} json "{"code":500,  msg:"杩斿洖閿欒淇℃伅", success:false}"
 // @Router /data/api-v/sysset/saveDevInfo [POST]
 func (sset SysSetController) SaveDevInfo(c *gin.Context) {
-	dev_name := c.PostForm("server_name")
 	var api dbapi.SysSetApi
-	paramBody := make(map[string]interface{}, 0)
-	paramBody["serverName"] = dev_name
-
-	// 璁剧疆ip
-	isOk, msg := sys.SetNetworkConfig(c.PostForm("ip"), c.PostForm("subMask"), c.PostForm("gateway"), c.PostForm("dns"))
-	if !isOk {
-		util.ResponseFormat(c, code.ComError, msg)
-		return
+	paramBody := map[string]interface{}{
+		"serverName": c.PostForm("server_name"),
+		"ip": c.PostForm("ip"),
+		"subMask": c.PostForm("subMask"),
+		"gateway": c.PostForm("gateway"),
+		"dns": c.PostForm("dns"),
 	}
 
 	b, data := api.SaveServerInfo(paramBody)
+	logger.Debug("isOk b:",b, "data:", data)
 	if b { // 鏌ヨ鏄惁瀛樺湪
 		util.ResponseFormat(c, code.Success, data)
 	} else { // 瀛樺湪鍙婁慨鏀� 涓嶅瓨鍦� 鍗虫坊鍔�
@@ -283,7 +303,6 @@
 // @Security ApiKeyAuth
 // @Summary 娴嬭瘯鍚屾鏃堕棿
 // @Description 娴嬭瘯鍚屾鏃堕棿鏈嶅姟鍣ㄦ槸鍚﹀彲鐢�
-// @Accept  json
 // @Produce json
 // @Tags sysset
 // @Param server query string true "鏃堕棿鏈嶅姟鍣╥p"
@@ -404,6 +423,7 @@
 
 // @Summary 璁剧疆瀹氭椂閲嶅惎
 // @Description 璁剧疆瀹氭椂閲嶅惎浠诲姟鐨勯厤缃鍒�
+// @Accept x-www-form-urlencoded
 // @Produce json
 // @Tags sysset
 // @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}"
@@ -430,3 +450,188 @@
 
 	util.ResponseFormat(c, code.Success, "閰嶇疆鎴愬姛")
 }
+
+// @Security ApiKeyAuth
+// @Summary 鑾峰彇瀛樺偍瀵瑰鏈嶅姟淇℃伅
+// @Description 鑾峰彇瀛樺偍瀵瑰鏈嶅姟淇℃伅
+// @Produce json
+// @Tags sysset
+// @Success 200 {string} json "{"code":200, msg:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
+// @Router /data/api-v/sysset/getResourceConfig [get]
+func (sset SysSetController) GetResourceConfig(c *gin.Context) {
+	var sysApi dbapi.SysSetApi
+	b,d := sysApi.GetResourceConfig()
+	if b {
+		util.ResponseFormat(c,code.Success,map[string]interface{}{
+			"ipType":d.IpType,
+			"serviceIp": d.ServiceIp,
+			"domain": d.Domain,
+			"filePort": d.FilePort,
+		})
+	} else {
+		util.ResponseFormat(c,code.ComError,"")
+	}
+}
+
+// @Security ApiKeyAuth
+// @Summary 瀛樺偍瀵瑰鏈嶅姟淇℃伅
+// @Description 瀛樺偍瀵瑰鏈嶅姟淇℃伅
+// @Accept  json
+// @Produce json
+// @Tags sysset
+// @Param reqBoby body controllers.ResourceConfigVo true "post璇锋眰锛宩son鍙傛暟"
+// @Success 200 {string} json "{"code":200, msg:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
+// @Router /data/api-v/sysset/saveResourceConfig [post]
+func (sset SysSetController) SaveResourceConfig(c *gin.Context) {
+	var reqBody ResourceConfigVo
+	c.BindJSON(&reqBody)
+	if reqBody.ServiceIp == "" && reqBody.Domain == "" {
+		util.ResponseFormat(c, code.RequestParamError, "")
+		return
+	}
+	var sysApi dbapi.SysSetApi
+	paramBody := util.Struct2Map(reqBody)
+	if b, _ := sysApi.SaveResourceConfig(paramBody); b {
+		util.ResponseFormat(c, code.Success, "")
+	} else {
+		util.ResponseFormat(c, code.ComError, "")
+	}
+}
+// @Summary 绯荤粺鏇存柊鍖呬笂浼�(鍒嗗潡妫�鏌�)
+// @Description 绯荤粺鏇存柊鍖呬笂浼�(鍒嗗潡妫�鏌�)
+// @Accept multipart/form-data
+// @Produce json
+// @Tags sysset
+// @Param chunkNumber formData int true "褰撳墠鏄鍑犱釜鍒嗗潡"
+// @Param chunkSize formData int true "姣忎竴鍧楃殑澶у皬"
+// @Param currentChunkSize formData int true "褰撳墠鍧楃殑澶у皬"
+// @Param identifier formData string true "鏁翠釜鏂囦欢鐨勫敮涓�鏍囪瘑锛岀洰鍓嶆槸md5"
+// @Param filename formData string true "鏂囦欢鍚嶇О"
+// @Param relativePath formData string true "鏂囦欢鍦ㄥ鎴风鐢佃剳鐨勮矾寰�"
+// @Param totalChunks formData int true "鏂囦欢鎬诲潡鏁�"
+// @Success 200 {string} json "{"code":200, msg:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
+// @Router /data/api-v/sysset/patchUpdate [get]
+func (sset SysSetController) PatchUpdateCheck(c *gin.Context) {
+	authDriver := auth.GenerateAuthDriver()
+	userM := (*authDriver).User(c)
+	if userM ==nil {
+		util.ResponseFormat(c,code.TokenNotFound,"鐧诲綍杩囨湡锛岃鐧诲綍")
+		return
+	}
+	chunkNumber, e1 := strconv.Atoi(c.Request.FormValue("chunkNumber"))
+	chunkSize, e2 := strconv.Atoi(c.Request.FormValue("chunkSize"))
+	currentChunkSize, e3 := strconv.Atoi(c.Request.FormValue("currentChunkSize"))
+	identifier := c.Request.FormValue("identifier")
+	filename := c.Request.FormValue("filename")
+	relativePath := c.Request.FormValue("relativePath")
+	totalChunks, e5 := strconv.Atoi(c.Request.FormValue("totalChunks"))
+	if identifier == "" || e1 != nil || e2 != nil || e3 != nil || e5 !=nil {
+		util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
+		return
+	}
+	var arg = service.FileChunkCheckVo {
+		UserId: userM["id"].(string),
+		FileName: filename,
+		Identifier: identifier,
+		RelativePath: relativePath,
+		TotalChunks: totalChunks,
+		ChunkNumber: chunkNumber,
+		ChunkSize: chunkSize,
+		CurrentChunkSize:currentChunkSize,
+	}
+	var sv service.SysService
+	if b := sv.CheckUpdateFile(&arg);b {
+		c.String(http.StatusOK,"found")
+	} else {
+		c.String(http.StatusNoContent,"")
+	}
+}
+
+// @Security ApiKeyAuth
+// @Summary 绯荤粺鏇存柊鍖呬笂浼�
+// @Description 绯荤粺鏇存柊鍖呬笂浼�
+// @Accept multipart/form-data
+// @Produce json
+// @Tags sysset
+// @Param chunkNumber formData int true "褰撳墠鏄鍑犱釜鍒嗗潡"
+// @Param chunkSize formData int true "姣忎竴鍧楃殑澶у皬"
+// @Param currentChunkSize formData int true "褰撳墠鍧楃殑澶у皬"
+// @Param totalSize formData string true "鏂囦欢鎬诲ぇ灏�"
+// @Param identifier formData string true "鏁翠釜鏂囦欢鐨勫敮涓�鏍囪瘑锛岀洰鍓嶆槸md5"
+// @Param filename formData string true "鏂囦欢鍚嶇О"
+// @Param relativePath formData string true "鏂囦欢鍦ㄥ鎴风鐢佃剳鐨勮矾寰�"
+// @Param totalChunks formData int true "鏂囦欢鎬诲潡鏁�"
+// @Param file formData file true "鏂囦欢鍒嗙墖鍐呭"
+// @Success 200 {string} json "{"code":200, msg:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
+// @Router /data/api-v/sysset/patchUpdate [post]
+func (sset SysSetController) PatchUpdate(c *gin.Context) {
+	authDriver := auth.GenerateAuthDriver()
+	userM := (*authDriver).User(c)
+	if userM == nil {
+		util.ResponseFormat(c, code.TokenNotFound, "鐧诲綍杩囨湡锛岃鐧诲綍")
+		return
+	}
+	chunkNumber, e1 := strconv.Atoi(c.Request.FormValue("chunkNumber"))
+	chunkSize, e2 := strconv.Atoi(c.Request.FormValue("chunkSize"))
+	currentChunkSize, e3 := strconv.Atoi(c.Request.FormValue("currentChunkSize"))
+	totalSize, e4 := strconv.ParseInt(c.Request.FormValue("totalSize"), 10, 64)
+	identifier := c.Request.FormValue("identifier")
+	filename := c.Request.FormValue("filename")
+	relativePath := c.Request.FormValue("relativePath")
+	totalChunks, e5 := strconv.Atoi(c.Request.FormValue("totalChunks"))
+	file, header, e6 := c.Request.FormFile("file")
+	if identifier == "" || e1 != nil || e2 != nil || e3 != nil || e4 != nil || e5 != nil || e6 != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎")
+		return
+	}
+	var arg = service.FileUploadVo{
+		UserId:           userM["id"].(string),
+		FileName:         filename,
+		Identifier:       identifier,
+		RelativePath:     relativePath,
+		TotalSize:        totalSize,
+		TotalChunks:      totalChunks,
+		ChunkNumber:      chunkNumber,
+		ChunkSize:        chunkSize,
+		CurrentChunkSize: currentChunkSize,
+		File:             &file,
+		Header:           header,
+	}
+	var sv service.SysService
+	if b,_ := sv.PatchUpload(&arg); b {
+		util.ResponseFormat(c, code.Success, "")
+	} else {
+		util.ResponseFormat(c, code.ComError, "")
+	}
+}
+
+
+// @Security ApiKeyAuth
+// @Summary 寮�濮嬪崌绾�
+// @Description 寮�濮嬪崌绾�
+// @Accept multipart/form-data
+// @Produce json
+// @Tags sysset
+// @Param identifier formData string true "鏁翠釜鏂囦欢鐨勫敮涓�鏍囪瘑锛岀洰鍓嶆槸md5"
+// @Param filename formData string true "鏂囦欢鍚嶇О"
+// @Success 200 {string} json "{"code":200, msg:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
+// @Router /data/api-v/sysset/upgrade [post]
+func (sset SysSetController) Upgrade(c *gin.Context) {
+	identifier := c.Request.FormValue("identifier")
+	filename := c.Request.FormValue("filename")
+	if identifier == "" || filename == "" {
+		util.ResponseFormat(c,code.RequestParamError,"")
+		return
+	}
+	var sv service.SysService
+	if b,err := sv.Upgrade(identifier, filename);b {
+		util.ResponseFormat(c,code.UpgradeSuccess,"鍗囩骇鎴愬姛")
+	} else {
+		util.ResponseFormat(c,code.UpgradeFail,err.Error())
+	}
+}

--
Gitblit v1.8.0