From 5457fe77b87d5d1b191958aafa4974affb93a7ec Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期五, 13 十二月 2019 10:44:19 +0800
Subject: [PATCH] 前者包含后者

---
 ruleserver/pushPolygonForTrack.go |  116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 116 insertions(+), 0 deletions(-)

diff --git a/ruleserver/pushPolygonForTrack.go b/ruleserver/pushPolygonForTrack.go
new file mode 100644
index 0000000..1ddadb5
--- /dev/null
+++ b/ruleserver/pushPolygonForTrack.go
@@ -0,0 +1,116 @@
+package ruleserver
+
+import (
+	"basic.com/pubsub/protomsg.git"
+	"ruleprocess/cache"
+	"basic.com/valib/logger.git"
+	"ruleprocess/structure"
+	"github.com/kirinlabs/HttpRequest"
+	"strconv"
+)
+
+type CameraPolygon struct {
+	CameraId string
+	CameraAddr string
+	Rtsp string
+	Area []Polygon
+}
+type Polygon struct {
+	CameraId string
+	CameraAddr string
+	Polygon []structure.Point
+}
+var camps []CameraPolygon
+
+func Handle () {
+	taskRules := cache.GetCameraTaskRulesAll()
+	for _,taskRule := range taskRules {
+		for _,groupRule := range taskRule.GroupRules {
+			for _,rule := range groupRule.Rules {
+				camp := GetCameraPolygon(rule,groupRule)
+				camps = append(camps,*camp)
+			}
+		}
+	}
+}
+
+func GetCameraPolygon(rule *protomsg.Rule,groupRule *protomsg.GroupRule) *CameraPolygon{
+	if rule.SdkId == "鏍囧畾绠楁硶鐨刬d" {
+		// 寰楀埌鏍囧畾绠楁硶鐨勫尯鍩�
+		cameraPolygon := new(CameraPolygon)
+		polygon := cache.GetPolygonsById(rule.PolygonId)
+		cameraPolygon.CameraId = rule.CameraId
+		camera,err := cache.GetCameraById(rule.CameraId)
+		if err != nil {
+			logger.Error("鏌ヨ鎽勫儚鏈轰俊鎭け璐ワ紒",err)
+		}
+		cameraPolygon.CameraAddr = camera.Addr
+		cameraPolygon.Rtsp = camera.Rtsp
+		if rule.SdkArgAlias == "鍏ㄦ櫙鎽勫儚鏈�" { // 濉炵殑鏄嚜宸辩殑鍖哄煙
+			polygon1 := new(Polygon)
+			polygon1.Polygon = Json2points(polygon.Polygon)
+			polygon1.CameraId = rule.CameraId
+			polygon1.CameraAddr = camera.Addr
+			cameraPolygon.Area = append(cameraPolygon.Area,*polygon1)
+		} else { // 濉炵殑鏄笌涔嬬浉鍏崇殑鍏ㄦ櫙鎽勫儚鏈虹殑鍖哄煙
+			for _,rule := range groupRule.Rules {
+				if rule.SdkArgAlias == "鍏ㄦ櫙鎽勫儚鏈�" {
+					polygon1 := new(Polygon)
+					polygon1.Polygon = Json2points(polygon.Polygon)
+					polygon1.CameraId = rule.CameraId
+					polygon1.CameraAddr = camera.Addr
+					cameraPolygon.Area = append(cameraPolygon.Area,*polygon1)
+				}
+			}
+		}
+		return cameraPolygon
+	} else {
+		return nil
+	}
+}
+
+func Struct2JsonString(camps []CameraPolygon) string{
+	str := "["
+	for index,cam := range camps {
+		str1 := "{\"CameraId\":\""+cam.CameraId+"\",\"CameraAddr\":"+cam.CameraAddr+"\",\"Rtsp\":\""+cam.Rtsp+"\",\"Area\":\"["
+		for j,ar := range cam.Area {
+			str2 := "{\""+ar.CameraId+"\": {\"area\": ["
+			for i,point := range ar.Polygon {
+				str3 := ""
+				if i < len(ar.Polygon) - 1 {
+					str3 = "{\"coordinate\": {\"x\": \""+strconv.FormatFloat(point.X, 'f', -1, 64)+"\",\"y\": \""+strconv.FormatFloat(point.Y, 'f', -1, 64)+"\"}},"
+				} else { // 鏈�鍚庝竴涓粨鏋勪綋涓嶅姞閫楀彿
+					str3 = "{\"coordinate\": {\"x\": \""+strconv.FormatFloat(point.X, 'f', -1, 64)+"\",\"y\": \""+strconv.FormatFloat(point.Y, 'f', -1, 64)+"\"}}"
+				}
+				str2 += str3
+			}
+			if j < len(cam.Area) - 1{
+				str2 += "]}},"
+			} else {
+				str2 += "]}}"
+			}
+			str1 += str2
+		}
+		str += str1
+		if index < len(camps) - 1{
+			str += "]},"
+		} else {
+			str += "]}"
+		}
+	}
+	str += "]"
+	return str
+}
+
+func PushPolygon() string{
+	Handle()
+	param := Struct2JsonString(camps)
+	req := HttpRequest.NewRequest()
+	res,err := req.JSON().Post("http://192.168.20.109:7011/tracking/get_region",param)
+	body,err := res.Body()
+	if err != nil {
+		return "璇锋眰澶辫触"+err.Error()
+	}
+	return string(body)
+}
+

--
Gitblit v1.8.0