|
@@ -3,12 +3,10 @@ package map_service
|
|
|
import (
|
|
|
"archive/zip"
|
|
|
"context"
|
|
|
- "encoding/json"
|
|
|
"fmt"
|
|
|
"github.com/cloudwego/hertz/pkg/app"
|
|
|
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
|
|
"io"
|
|
|
- "io/ioutil"
|
|
|
"net/http"
|
|
|
"os"
|
|
|
"path/filepath"
|
|
@@ -39,9 +37,9 @@ func CheckMapBufConsistency(ctx context.Context, c *app.RequestContext) {
|
|
|
var firstValue int
|
|
|
for i, id := range req {
|
|
|
|
|
|
- fileList, err := getExactedMapFileById(id)
|
|
|
+ fileList, err := util.GetExactedMapFileById(id)
|
|
|
|
|
|
- fileList = filterBySuffixes(fileList, config.MapBufFiltersuffixes...)
|
|
|
+ fileList = util.FilterBySuffixes(fileList, config.MapBufFiltersuffixes...)
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
@@ -146,9 +144,9 @@ func DownLoadMapBagFile(ctx context.Context, c *app.RequestContext) {
|
|
|
fmt.Println("id: ", id)
|
|
|
|
|
|
|
|
|
- fileList, err := getExactedMapFileById(id)
|
|
|
+ fileList, err := util.GetExactedMapFileById(id)
|
|
|
|
|
|
- fileList = filterBySuffixes(fileList, "map.bag")
|
|
|
+ fileList = util.FilterBySuffixes(fileList, "map.bag")
|
|
|
|
|
|
|
|
|
objectKey := fileList[0]
|
|
@@ -178,184 +176,13 @@ func DownLoadMapBagFile(ctx context.Context, c *app.RequestContext) {
|
|
|
c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "解析地图Bag下载成功。"})
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-func getExactedMapFileById(id string) (fileList []string, err error) {
|
|
|
- url := config.SenceOssDownUrl + id
|
|
|
-
|
|
|
-
|
|
|
- req, err := http.NewRequest("GET", url, nil)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("Error creating request:", err)
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- req.Header.Set("Authorization", config.Token)
|
|
|
-
|
|
|
-
|
|
|
- client := &http.Client{}
|
|
|
- resp, err := client.Do(req)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("Error executing request:", err)
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
- defer resp.Body.Close()
|
|
|
- body, _ := ioutil.ReadAll(resp.Body)
|
|
|
-
|
|
|
-
|
|
|
- var data map[string]interface{}
|
|
|
- err = json.Unmarshal(body, &data)
|
|
|
-
|
|
|
-
|
|
|
- dataField, ok := data["data"].([]interface{})
|
|
|
- if !ok {
|
|
|
- fmt.Println("Error extracting data field")
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- for _, item := range dataField {
|
|
|
- str, ok := item.(string)
|
|
|
- if !ok {
|
|
|
- fmt.Println("Error converting item to string")
|
|
|
- return nil, err
|
|
|
- }
|
|
|
- fileList = append(fileList, str)
|
|
|
- }
|
|
|
-
|
|
|
- return fileList, nil
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-func getRosFileById(id string) (file string, err error) {
|
|
|
- url := config.SenceInfoUrl + id
|
|
|
-
|
|
|
-
|
|
|
- req, err := http.NewRequest("GET", url, nil)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("Error creating request:", err)
|
|
|
- return "", err
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- req.Header.Set("Authorization", config.Token)
|
|
|
-
|
|
|
-
|
|
|
- client := &http.Client{}
|
|
|
- resp, err := client.Do(req)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("Error executing request:", err)
|
|
|
- return "", err
|
|
|
- }
|
|
|
-
|
|
|
- defer resp.Body.Close()
|
|
|
- body, _ := ioutil.ReadAll(resp.Body)
|
|
|
-
|
|
|
-
|
|
|
- var data map[string]interface{}
|
|
|
- err = json.Unmarshal(body, &data)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- dataField, ok := data["data"].(map[string]interface{})
|
|
|
- if !ok {
|
|
|
- fmt.Println("Error extracting data field")
|
|
|
- return "", err
|
|
|
- }
|
|
|
-
|
|
|
- rosField, ok := dataField["rosFileId"].(string)
|
|
|
- if !ok {
|
|
|
- fmt.Println("ID not found or not a string")
|
|
|
- return
|
|
|
- }
|
|
|
- if !ok {
|
|
|
- fmt.Println("Error extracting rosFileId field")
|
|
|
- return "", err
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- return rosField, nil
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
func generateZipById(id string) (file string, tmpDir string, err error) {
|
|
|
|
|
|
- allFileList, err := getExactedMapFileById(id)
|
|
|
+ allFileList, err := util.GetExactedMapFileById(id)
|
|
|
|
|
|
|
|
|
- mapBuFileList := filterBySuffixes(allFileList, config.MapBufFiltersuffixes...)
|
|
|
+ mapBuFileList := util.FilterBySuffixes(allFileList, config.MapBufFiltersuffixes...)
|
|
|
|
|
|
if err != nil {
|
|
|
return
|
|
@@ -405,7 +232,7 @@ func generateZipById(id string) (file string, tmpDir string, err error) {
|
|
|
|
|
|
|
|
|
|
|
|
- buildMapBagFileList := filterBySuffixes(allFileList, config.BuildMapBagFiltersuffixes...)
|
|
|
+ buildMapBagFileList := util.FilterBySuffixes(allFileList, config.BuildMapBagFiltersuffixes...)
|
|
|
buildMapBagFile := buildMapBagFileList[0]
|
|
|
err = config.OssBucket.GetObjectToFile(buildMapBagFile, filepath.Join(bagFolderDir, filepath.Base(buildMapBagFile)))
|
|
|
if err != nil {
|
|
@@ -426,7 +253,7 @@ func generateZipById(id string) (file string, tmpDir string, err error) {
|
|
|
|
|
|
|
|
|
|
|
|
- originMapFileList := filterBySuffixes(allFileList, config.OriginMapFiltersuffixes...)
|
|
|
+ originMapFileList := util.FilterBySuffixes(allFileList, config.OriginMapFiltersuffixes...)
|
|
|
for _, file := range originMapFileList {
|
|
|
err = config.OssBucket.GetObjectToFile(file, filepath.Join(originMapFolderDir, filepath.Base(file)))
|
|
|
if err != nil {
|
|
@@ -460,24 +287,6 @@ func generateZipById(id string) (file string, tmpDir string, err error) {
|
|
|
return zipPath, tmpDir, nil
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-func filterBySuffixes(strList []string, suffixes ...string) []string {
|
|
|
- var filtered []string
|
|
|
- for _, s := range strList {
|
|
|
- for _, suffix := range suffixes {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if filepath.Base(s) == suffix {
|
|
|
- filtered = append(filtered, s)
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return filtered
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
func calculateTotalFileSize(fileList []string) int {
|
|
|
var totalSize int
|