From 9d4762cee4c0762dde9ee8712c3460c6f986f876 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期六, 19 十月 2024 14:27:35 +0800
Subject: [PATCH] 修复V2

---
 model/model.go    |  105 ++++++++++++++++++++++++++
 service/server.go |   91 ++++++++--------------
 2 files changed, 139 insertions(+), 57 deletions(-)

diff --git a/model/model.go b/model/model.go
index 037246b..7016d1c 100644
--- a/model/model.go
+++ b/model/model.go
@@ -19,12 +19,117 @@
 	DataSource:   "smart-ai",
 }
 
+type BaseCompareInfo struct {
+	BwType       string  `json:"bwType"`
+	TableId      string  `json:"tableId"`
+	TableName    string  `json:"tableName"`
+	CompareScore float32 `json:"compareScore"`
+	OriginScore  float32 `json:"originScore"`
+	TargetId     string  `json:"targetId"`
+	TargetPicUrl string  `json:"targetPicUrl"`
+	MonitorLevel string  `json:"monitorLevel"`
+	Content      string  `json:"content"`
+	DbLabel      string  `json:"labels"`
+}
+
+type AlarmRule struct {
+	RuleId     string `json:"ruleId"`
+	RuleText   string `json:"ruleText"`
+	AlarmLevel string `json:"alarmLevel"`
+}
+
+type Point struct {
+	X int32 `json:"x"`
+	Y int32 `json:"y"`
+}
+
+type Points struct {
+	TopLeft     Point `json:"topLeft"`
+	BottomRight Point `json:"bottomRight"`
+}
+
+type TargetInfo struct {
+	TargetId       string  `json:"targetId"`
+	TargetScore    float64 `json:"targetScore"`
+	FrontFaceScore float64 `json:"frontFaceScore"`
+	ImgQuality     float64 `json:"imgQuality"`
+	FaceQuality    float64 `json:"faceQuality"`
+	TargetType     string  `json:"targetType"`
+	Feature        string  `json:"-"`
+	PicSmUrl       string  `json:"picSmUrl"`
+	TargetLocation Points  `json:"targetLocation"`
+	Attribute      string  `json:"attribute"`
+}
+
+type PicWidHei struct {
+	PicW int `json:"picW"`
+	PicH int `json:"picH"`
+}
+
 type pushDataInfoV2 struct {
 	CameraId     string   `json:"cameraId"`
 	CameraFloor  string   `json:"cameraFloor"` //鎽勫儚鏈烘ゼ灞�
+	Direction    string   `json:"direction"`   // 鎽勫儚鏈鸿繍琛屾柟鍚� up or down
 	PicDate      string   `json:"picDate"`
 	PicId        string   `json:"picId"`
 	DataSource   string   `json:"dataSource"`
 	PicMaxImages [][]byte `json:"picMaxImages"`
 	PicSmImages  [][]byte `json:"picSmImages"`
 }
+
+type TaskResultInfoV2 struct {
+	Id              string           `json:"id"`
+	AnalyServerId   string           `json:"analyServerId"`
+	AnalyServerName string           `json:"analyServerName"`
+	AnalyServerIp   string           `json:"analyServerIp"`
+	ClusterId       string           `json:"clusterId"`
+	CameraId        string           `json:"cameraId"`
+	CameraAddr      string           `json:"cameraAddr"` // 鎽勫儚鏈哄湴鍧�
+	CameraName      string           `json:"cameraName"` // 鎽勫儚鏈哄悕绉�
+	CommunityId     string           `json:"communityId"`
+	CommunityName   string           `json:"communityName"`
+	CameraLocation  CameraLocation   `json:"cameraLocation"`
+	DocumentNumber  string           `json:"documentNumber"` // 妗f缂栧彿
+	OrgId           string           `json:"orgId"`          //鏈烘瀯鍚嶇О
+	OrgName         string           `json:"orgName"`        //鏈烘瀯鍚嶇О
+	PicDate         string           `json:"picDate"`
+	PicId           string           `json:"picId"`
+	PicMaxUrl       string           `json:"picMaxUrl"`
+	PicWH           PicWidHei        `json:"picWH"`
+	TaskId          string           `json:"taskId"`
+	TaskName        string           `json:"taskName"`
+	SdkName         string           `json:"sdkName"`
+	Content         string           `json:"content"`
+	ShowLabels      string           `json:"showLabels"`
+	OtherLabels     string           `json:"otherLabels"`
+	VideoUrl        string           `json:"videoUrl"`
+	IsAlarm         bool             `json:"isAlarm"`
+	IsAckAlarm      bool             `json:"isAckAlarm"`
+	IsDelete        bool             `json:"isDelete"`
+	IsKeyPerson     bool             `json:"isKeyPerson"`
+	KeyPersonType   []string         `json:"keyPersonType"`
+	AlarmRules      []AlarmRule      `json:"alarmRules"`
+	BaseInfo        *BaseCompareInfo `json:"baseInfo"`
+	TargetInfo      TargetInfo       `json:"targetInfo"`
+	DataSource      string           `json:"dataSource"` // 鏁版嵁鏉ユ簮:鎽勫儚鏈�, 鏁版嵁鏍�
+}
+
+type CameraLocation struct {
+	Building  string `json:"building"`
+	Unit      string `json:"unit"`
+	Pos       string `json:"pos"`
+	Floor     string `json:"floor"`
+	Direction string `json:"direction"`
+}
+
+func (cl *CameraLocation) Join() string {
+	return cl.Building + cl.Unit + cl.Pos + cl.Floor
+}
+
+// es瑙嗛鍒嗘瀽鐨勬暟鎹粨鏋�
+type ESInfoV2 struct {
+	TaskResultInfoV2
+	Version    string `json:"version"`
+	UpdateTime string `json:"updateTime"`
+	LikeDate   string `json:"likeDate"`
+}
diff --git a/service/server.go b/service/server.go
index 4bbf983..45d3db3 100644
--- a/service/server.go
+++ b/service/server.go
@@ -30,7 +30,7 @@
 }
 
 func GetTotal() (total int, err error) {
-	url := "http://" + config.Options.EsUrl + "/ai_ocean/_search"
+	url := "http://" + config.Options.EsUrl + "/ai_face_ocean/_search"
 	queryDSL := `{
     "size": "1",
     "query": {
@@ -69,7 +69,7 @@
 func GetData() (interface{}, error) {
 	//fmt.Println(config.Options.EsUrl)
 	//fmt.Println(config.Options.ServerUrl)
-	url := "http://" + config.Options.EsUrl + "/ai_ocean/_search"
+	url := "http://" + config.Options.EsUrl + "/ai_face_ocean/_search"
 	queryDSL := `{
     "size": "1",
     "query": {
@@ -91,8 +91,7 @@
         }
     ]
 }`
-	//fmt.Println(url)
-	//fmt.Println(queryDSL)
+
 	buf, err := esutil.EsReq("POST", url, []byte(queryDSL))
 	if err != nil {
 		return nil, err
@@ -104,74 +103,52 @@
 	if len(source) == 0 {
 		return nil, nil
 	}
-	picMaxImages := make([][]byte, 0) // 瀛樺偍鍥剧墖鏁版嵁鐨勬暟缁�
-	if source[0]["picMaxUrl"].([]interface{}) != nil {
-		//picMaxUrls := source[0]["picMaxUrl"].([]interface{})
-		if len(source[0]["picMaxUrl"].([]interface{})) > 0 {
-			for _, picMaxUrl := range source[0]["picMaxUrl"].([]interface{}) {
-				picMaxImageData, err := GetImageData("http://" + picMaxUrl.(string))
-				if err != nil {
-					logger.Warn("鑾峰彇澶у浘鏁版嵁澶辫触:", err.Error())
-					continue
-				}
-				picMaxImages = append(picMaxImages, picMaxImageData)
-			}
+
+	b, _ := json.Marshal(source[0])
+
+	var esInfoV2 model.ESInfoV2
+	err = json.Unmarshal(b, &esInfoV2)
+	if err != nil {
+		return nil, err
+	}
+
+	picMaxImages := make([]byte, 0) // 瀛樺偍鍥剧墖鏁版嵁鐨勬暟缁�
+	if esInfoV2.PicMaxUrl != "" {
+		picMaxImages, err = GetImageData("http://" + esInfoV2.PicMaxUrl)
+		if err != nil {
+			logger.Warn("鑾峰彇澶у浘鏁版嵁澶辫触:", err.Error())
 		}
 	}
 
 	if len(picMaxImages) == 0 {
-		return nil, errors.New("鑾峰彇澶у浘澶辫触, id:" + source[0]["id"].(string))
+		return nil, errors.New("鑾峰彇澶у浘澶辫触, id:" + esInfoV2.TargetInfo.PicSmUrl)
 	}
 
 	//fmt.Println("鍥剧墖鏁版嵁鏁扮粍澶у皬:", len(picMaxImages))
 
-	picSmImages := make([][]byte, 0) // 瀛樺偍鍥剧墖鏁版嵁鐨勬暟缁�
-	if source[0]["targetInfo"].(interface{}) != nil {
-		for _, target := range source[0]["targetInfo"].([]interface{}) {
-			info := target.(map[string]interface{})
-			picSmUrl := info["picSmUrl"].(string)
-			if picSmUrl == "" {
-				continue
-			}
-			picSmImageData, err := GetImageData("http://" + picSmUrl)
-			if err != nil {
-				fmt.Println("鑾峰彇灏忓浘鏁版嵁澶辫触:", err)
-				continue
-			}
-			picSmImages = append(picSmImages, picSmImageData)
+	picSmImages := make([]byte, 0) // 瀛樺偍鍥剧墖鏁版嵁鐨勬暟缁�
+	if esInfoV2.TargetInfo.PicSmUrl != "" {
+		picSmImages, err = GetImageData("http://" + esInfoV2.TargetInfo.PicSmUrl)
+		if err != nil {
+			fmt.Println("鑾峰彇灏忓浘鏁版嵁澶辫触:", err)
 		}
 	}
 
 	if len(picSmImages) == 0 {
-		return nil, errors.New("鑾峰彇灏忓浘鏁版嵁澶辫触, id:" + source[0]["id"].(string))
+		return nil, errors.New("鑾峰彇灏忓浘鏁版嵁澶辫触, id:" + esInfoV2.Id)
 	}
 
-	// 涓婃姤鏈烘瀯鍚嶇О
-	//source[0]["orgName"] = config.Options.OrgName
-
-	cameraAddr := source[0]["cameraAddr"].(string)
-	if len(cameraAddr) > 6 {
-		if cameraAddr[len(cameraAddr)-3:] == "妤�" {
-			cameraAddr = cameraAddr[:len(cameraAddr)-3] + "F"
-		}
-		if cameraAddr[len(cameraAddr)-3:] == "灞�" {
-			cameraAddr = cameraAddr[:len(cameraAddr)-3] + "F"
-		}
-	}
-
-	if strings.HasSuffix(cameraAddr, "F") {
-		model.PushDataInfoV2.CameraFloor = extractFloor(cameraAddr)
-	} else {
-		model.PushDataInfoV2.CameraFloor = ""
-	}
-
-	model.PushDataInfoV2.CameraId = source[0]["cameraId"].(string)
-	model.PushDataInfoV2.PicDate = source[0]["picDate"].(string)
-	model.PushDataInfoV2.PicId = source[0]["id"].(string)
-	model.PushDataInfoV2.PicMaxImages = picMaxImages
-	model.PushDataInfoV2.PicSmImages = picSmImages
+	var pushData = model.PushDataInfoV2
+	pushData.CameraId = esInfoV2.CameraId
+	pushData.PicDate = esInfoV2.PicDate
+	pushData.PicId = esInfoV2.PicId
+	pushData.CameraFloor = esInfoV2.CameraLocation.Floor
+	pushData.Direction = esInfoV2.CameraLocation.Direction
+	pushData.PicMaxImages = append(pushData.PicMaxImages, picMaxImages)
+	pushData.PicSmImages = append(pushData.PicSmImages, picSmImages)
 	//fmt.Println(model.PushDataInfo.SourceData)
-	return model.PushDataInfoV2, nil
+
+	return pushData, nil
 }
 
 func extractFloor(s string) string {

--
Gitblit v1.8.0