| | |
| | | |
| | | 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 { |
| | | url := config.ServUrls.ServerUrl |
| | | url := config.Options.ServerUrl |
| | | resp, err := http.Get(url) |
| | | if err != nil { |
| | | fmt.Println("连接失败", err) |
| | |
| | | } |
| | | |
| | | func GetTotal() (total int, err error) { |
| | | url := "http://" + config.ServUrls.EsUrl + "/ai_ocean/_search" |
| | | url := "http://" + config.Options.EsUrl + "/ai_face_ocean/_search" |
| | | queryDSL := `{ |
| | | "size": "1", |
| | | "query": { |
| | |
| | | return totals, nil |
| | | } |
| | | |
| | | func GetData() (interface{}, error) { |
| | | //fmt.Println(config.ServUrls.EsUrl) |
| | | //fmt.Println(config.ServUrls.ServerUrl) |
| | | url := "http://" + config.ServUrls.EsUrl + "/ai_ocean/_search" |
| | | func GetData() (*model.PushDataInfoV2, error) { |
| | | //fmt.Println(config.Options.EsUrl) |
| | | //fmt.Println(config.Options.ServerUrl) |
| | | url := "http://" + config.Options.EsUrl + "/ai_face_ocean/_search" |
| | | queryDSL := `{ |
| | | "size": "1", |
| | | "query": { |
| | |
| | | } |
| | | ] |
| | | }` |
| | | //fmt.Println(url) |
| | | //fmt.Println(queryDSL) |
| | | |
| | | buf, err := esutil.EsReq("POST", url, []byte(queryDSL)) |
| | | if err != nil { |
| | | return nil, err |
| | |
| | | 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) |
| | | } |
| | | } |
| | | model.PushDataInfo.SourceData = source[0] |
| | | model.PushDataInfo.PicMaxImages = picMaxImages |
| | | model.PushDataInfo.PicSmImages = picSmImages |
| | | |
| | | if len(picSmImages) == 0 { |
| | | return nil, errors.New("获取小图数据失败, id:" + esInfoV2.Id) |
| | | } |
| | | |
| | | 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 { |
| | | // 使用正则表达式匹配楼层信息 |
| | | 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) { |
| | |
| | | } |
| | | |
| | | func DeleteData(id string) bool { |
| | | url := "http://" + config.ServUrls.EsUrl + "/ai_ocean/_delete_by_query?refresh=true" |
| | | url := "http://" + config.Options.EsUrl + "/ai_face_ocean/_delete_by_query?refresh=true" |
| | | deleteDSL := `{ |
| | | "query":{ |
| | | "bool":{ |
| | |
| | | } |
| | | |
| | | func MarkData(id string) bool { |
| | | url := "http://" + config.ServUrls.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" |
| | |
| | | fmt.Println(err) |
| | | return false |
| | | } |
| | | total, err := util.SourceUpdated(buf) |
| | | total, err := util.SourceUpdated(buf) |
| | | if err != nil { |
| | | fmt.Println(err) |
| | | return false |