From 1ca4879df9cc3c22181b2a200aa4b793116d3d35 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期六, 19 十月 2024 16:23:55 +0800
Subject: [PATCH] fix id

---
 service/server.go |   97 ++++++++++++++++++++++++++++--------------------
 1 files changed, 57 insertions(+), 40 deletions(-)

diff --git a/service/server.go b/service/server.go
index 5f1eb69..6f15812 100644
--- a/service/server.go
+++ b/service/server.go
@@ -2,14 +2,17 @@
 
 import (
 	"basic.com/pubsub/esutil.git"
+	"basic.com/valib/logger.git"
 	"bytes"
 	"data_msg_push_server/config"
 	"data_msg_push_server/model"
 	"data_msg_push_server/util"
 	"encoding/json"
+	"errors"
 	"fmt"
 	"io/ioutil"
 	"net/http"
+	"regexp"
 )
 
 func ConnectControl() bool {
@@ -26,7 +29,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": {
@@ -62,10 +65,10 @@
 	return totals, nil
 }
 
-func GetData() (interface{}, error) {
+func GetData() (*model.PushDataInfoV2, 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": {
@@ -87,8 +90,7 @@
         }
     ]
 }`
-	//fmt.Println(url)
-	//fmt.Println(queryDSL)
+
 	buf, err := esutil.EsReq("POST", url, []byte(queryDSL))
 	if err != nil {
 		return nil, err
@@ -100,47 +102,62 @@
 	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 {
-					fmt.Println("鑾峰彇澶у浘鏁版嵁澶辫触:", err)
-					continue
-				}
-				picMaxImages = append(picMaxImages, picMaxImageData)
-			}
-			fmt.Println("鍥剧墖鏁版嵁鏁扮粍澶у皬:", len(picMaxImages))
+
+	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())
 		}
 	}
 
-	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)
+	if len(picMaxImages) == 0 {
+		return nil, errors.New("鑾峰彇澶у浘澶辫触, id:" + esInfoV2.TargetInfo.PicSmUrl)
+	}
+
+	//fmt.Println("鍥剧墖鏁版嵁鏁扮粍澶у皬:", len(picMaxImages))
+
+	picSmImages := make([]byte, 0) // 瀛樺偍鍥剧墖鏁版嵁鐨勬暟缁�
+	if esInfoV2.TargetInfo.PicSmUrl != "" {
+		picSmImages, err = GetImageData("http://" + esInfoV2.TargetInfo.PicSmUrl)
+		if err != nil {
+			fmt.Println("鑾峰彇灏忓浘鏁版嵁澶辫触:", err)
 		}
 	}
 
-	// 涓婃姤鏈烘瀯鍚嶇О
-	source[0]["orgName"] = config.Options.OrgName
+	if len(picSmImages) == 0 {
+		return nil, errors.New("鑾峰彇灏忓浘鏁版嵁澶辫触, id:" + esInfoV2.Id)
+	}
 
-	model.PushDataInfo.SourceData = source[0]
-	model.PushDataInfo.PicMaxImages = picMaxImages
-	model.PushDataInfo.PicSmImages = picSmImages
+	var pushData = new(model.PushDataInfoV2)
+	pushData.CameraId = esInfoV2.CameraId
+	pushData.PicDate = esInfoV2.PicDate
+	pushData.PicId = esInfoV2.Id
+	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.PushDataInfo, nil
+
+	return pushData, nil
+}
+
+func extractFloor(s string) string {
+	// 浣跨敤姝e垯琛ㄨ揪寮忓尮閰嶆ゼ灞備俊鎭�
+	re := regexp.MustCompile(`[-\d]+F`)
+	matches := re.FindStringSubmatch(s)
+	if len(matches) >= 1 {
+		return matches[0] // 杩斿洖鍖归厤鍒扮殑妤煎眰淇℃伅
+	}
+	return "" // 濡傛灉娌℃湁鍖归厤鍒帮紝杩斿洖绌哄瓧绗︿覆
 }
 
 func SendData(pushDataInfo interface{}, url string) (id string, err error) {
@@ -176,7 +193,7 @@
 }
 
 func DeleteData(id string) bool {
-	url := "http://" + config.Options.EsUrl + "/ai_ocean/_delete_by_query?refresh=true"
+	url := "http://" + config.Options.EsUrl + "/ai_face_ocean/_delete_by_query?refresh=true"
 	deleteDSL := `{
 					"query":{
 						"bool":{
@@ -203,7 +220,7 @@
 }
 
 func MarkData(id string) bool {
-	url := "http://" + config.Options.EsUrl + "/ai_ocean/_update_by_query?refresh=true"
+	url := "http://" + config.Options.EsUrl + "/ai_face_ocean/_update_by_query?refresh=true"
 	markDSL := `{
     "script": {
         "source": "ctx._source.isDelete=true"

--
Gitblit v1.8.0