|
@@ -139,8 +139,21 @@ func DownloadMapZipFile(ctx context.Context, c *app.RequestContext) {
|
|
|
originUrl := deviceMap.PjiMapZipURL
|
|
|
fmt.Println("originUrl", originUrl)
|
|
|
|
|
|
+ // 获取原始地图map.pgm url
|
|
|
+ originalMaps, err := mysql.QueryOriginalMapByMapIdAndDeviceNo(ctx, mapId, deviceNo)
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "查询原始地图失败"})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(originalMaps) == 0 {
|
|
|
+ c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "未查询到对应原始备地图"})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ originalMap := originalMaps[0]
|
|
|
+ mapPgmUrl := *originalMap.CicvMapPgmURL
|
|
|
+
|
|
|
// 根据id生成用于地图更新的压缩包
|
|
|
- filePath, tmpDir, err := generateMapZipById(ids, originUrl)
|
|
|
+ filePath, tmpDir, err := generateMapZipById(ids, originUrl, mapPgmUrl)
|
|
|
if err != nil {
|
|
|
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
|
|
}
|
|
@@ -216,7 +229,7 @@ func DownloadMapBagFile(ctx context.Context, c *app.RequestContext) {
|
|
|
}
|
|
|
|
|
|
// 根据id生成用于地图更新的压缩包
|
|
|
-func generateMapZipById(ids []string, originUrl string) (file string, tmpDir string, err error) {
|
|
|
+func generateMapZipById(ids []string, mapZipUrl string, mapPgmUrl string) (file string, tmpDir string, err error) {
|
|
|
// 根据id获取对应的oss文件列表
|
|
|
allFileList, err := util.GetExactedMapFileByIds(ids)
|
|
|
//fmt.Println("allFileList", allFileList)
|
|
@@ -310,11 +323,17 @@ func generateMapZipById(ids []string, originUrl string) (file string, tmpDir str
|
|
|
//}
|
|
|
//err = config.OssBucket.GetObjectToFile(originUrl, filepath.Join(originMapFolderDir, filepath.Base(originUrl)))
|
|
|
|
|
|
- err = util.Downloadfile(originUrl, filepath.Join(originMapFolderDir, filepath.Base(originUrl)))
|
|
|
+ err = util.Downloadfile(mapZipUrl, filepath.Join(originMapFolderDir, filepath.Base(mapZipUrl)))
|
|
|
if err != nil {
|
|
|
fmt.Println("Error downloading origin_map file:", err)
|
|
|
return "", "", err
|
|
|
}
|
|
|
+
|
|
|
+ err = config.OssBucket.GetObjectToFile(mapPgmUrl, filepath.Join(originMapFolderDir, filepath.Base(mapPgmUrl)))
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error downloading map.pgm file:", err)
|
|
|
+ return "", "", err
|
|
|
+ }
|
|
|
c_log.GlobalLogger.Info("下载文件到origin_map_folder文件夹 - 成功")
|
|
|
|
|
|
// 创建压缩文件
|
|
@@ -817,6 +836,138 @@ func UpdateOriginalMap(ctx context.Context, c *app.RequestContext) {
|
|
|
c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "原始地图数据更新成功"})
|
|
|
}
|
|
|
|
|
|
+// UploadOriginalMapById 根据id,将原始地图朴津压缩包(及其中的map.pgm)上传到oss
|
|
|
+// @router /map/upload/originalMap/oneRecord [GET]
|
|
|
+func UploadOriginalMapById(ctx context.Context, c *app.RequestContext) {
|
|
|
+ sceneId := c.Query("sceneId")
|
|
|
+ fmt.Println("sceneId", sceneId)
|
|
|
+ deviceNo := c.Query("deviceNo")
|
|
|
+ fmt.Println("deviceNo", deviceNo)
|
|
|
+
|
|
|
+ // 根据场景id查询地图id
|
|
|
+ mapId, err := getMapIdById(sceneId)
|
|
|
+ if err != nil || mapId == "" {
|
|
|
+ c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取mapId失败"})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ fmt.Println("mapId", mapId)
|
|
|
+
|
|
|
+ // 查询原始地图对应记录
|
|
|
+ records, err := mysql.QueryOriginalMapByMapIdAndDeviceNo(ctx, mapId, deviceNo)
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "查询原始地图失败"})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ fmt.Println("records", len(records))
|
|
|
+ for _, record := range records {
|
|
|
+ fmt.Println("record", record)
|
|
|
+ var zipName string
|
|
|
+ var zipPath string
|
|
|
+ var destPath string
|
|
|
+ updateFlag := false
|
|
|
+ if record.CicvMapZipURL == nil || *record.CicvMapZipURL == "" || record.CicvMapPgmURL == nil || *record.CicvMapPgmURL == "" {
|
|
|
+ updateFlag = true
|
|
|
+ // 创建临时文件夹
|
|
|
+ tmpDir, err := os.MkdirTemp("", "temp-download-*")
|
|
|
+
|
|
|
+ fmt.Println("tmpDir:", tmpDir)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error creating temporary directory:", err)
|
|
|
+ c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "创建临时文件夹失败"})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 下载朴津地图压缩包
|
|
|
+ zipName = filepath.Base(record.PjiMapZipURL)
|
|
|
+ zipPath = filepath.Join(tmpDir, zipName)
|
|
|
+ destPath = filepath.Join(tmpDir, "map")
|
|
|
+ err = util.Downloadfile(record.PjiMapZipURL, zipPath)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error downloading origin_map file:", err)
|
|
|
+ c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "下载原始地图文件失败"})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c_log.GlobalLogger.Info("创建下载-临时文件夹:", tmpDir)
|
|
|
+ // 检查文件是否存在
|
|
|
+ if _, err := os.Stat(zipPath); os.IsNotExist(err) {
|
|
|
+ c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "下载原始地图文件失败"})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 上传朴津地图压缩包到oss
|
|
|
+ if record.CicvMapZipURL == nil || *record.CicvMapZipURL == "" {
|
|
|
+ ossObjectKey := config.OriginalMapOssBasePrefix + "/" + record.DeviceNo + "/" + record.MapID + "/" + record.MapVersion + "/" + zipName
|
|
|
+ fmt.Println("ossObjectKey", ossObjectKey)
|
|
|
+
|
|
|
+ // 打开文件
|
|
|
+ f, err := os.Open(zipPath)
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "打开原始地图文件失败"})
|
|
|
+ fmt.Println("Failed to open file")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer f.Close()
|
|
|
+
|
|
|
+ config.OssMutex.Lock()
|
|
|
+ err = config.OssBucket.PutObject(ossObjectKey, f)
|
|
|
+ config.OssMutex.Unlock()
|
|
|
+ if err != nil {
|
|
|
+ c_log.GlobalLogger.Error("程序异常退出。上传文件", zipName, "->", ossObjectKey, "出错:", err)
|
|
|
+ c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "上传原始地图文件失败"})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c_log.GlobalLogger.Info("上传文件", zipName, "->", ossObjectKey, "成功。")
|
|
|
+ record.CicvMapZipURL = &ossObjectKey
|
|
|
+ }
|
|
|
+ // 上传朴津原始地图到oss
|
|
|
+ if record.CicvMapPgmURL == nil || *record.CicvMapPgmURL == "" {
|
|
|
+ ossObjectKey := config.OriginalMapOssBasePrefix + "/" + record.DeviceNo + "/" + record.MapID + "/" + record.MapVersion + "/" + "map.pgm"
|
|
|
+ // 压缩包解压
|
|
|
+ err := Unzip(zipPath, destPath)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error unzipping file:", err)
|
|
|
+ c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "解压原始地图文件失败"})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 文件 - map.pgm
|
|
|
+ pgmPath := filepath.Join(destPath, "map.pgm")
|
|
|
+ // 检查文件是否存在
|
|
|
+ if _, err := os.Stat(pgmPath); os.IsNotExist(err) {
|
|
|
+ fmt.Println("解压目录中map.pgm不存在")
|
|
|
+ c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "解压目录中map.pgm不存在"})
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 打开文件
|
|
|
+ f, err := os.Open(pgmPath)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Failed to open file")
|
|
|
+ c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "打开map.pgm失败"})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer f.Close()
|
|
|
+
|
|
|
+ config.OssMutex.Lock()
|
|
|
+ err = config.OssBucket.PutObject(ossObjectKey, f)
|
|
|
+ config.OssMutex.Unlock()
|
|
|
+ if err != nil {
|
|
|
+ c_log.GlobalLogger.Error("程序异常退出。上传文件", "map.pgm", "->", ossObjectKey, "出错:", err)
|
|
|
+ c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "上传map.pgm失败"})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c_log.GlobalLogger.Info("上传文件", "map.pgm", "->", ossObjectKey, "成功。")
|
|
|
+ record.CicvMapPgmURL = &ossObjectKey
|
|
|
+ }
|
|
|
+ if updateFlag {
|
|
|
+ _, err = mysql.UpdateOriginalMapOneRecord(ctx, *record)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("更新原始地图失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "原始地图文件上传成功"})
|
|
|
+}
|
|
|
+
|
|
|
// UploadOriginalMapWithoutHttp 将原始地图朴津压缩包(及其中的map.pgm)上传到oss
|
|
|
func UploadOriginalMapWithoutHttp(ctx context.Context) bool {
|
|
|
// 查询原始地图压缩包/pgm为空的记录
|
|
@@ -831,7 +982,9 @@ func UploadOriginalMapWithoutHttp(ctx context.Context) bool {
|
|
|
var zipName string
|
|
|
var zipPath string
|
|
|
var destPath string
|
|
|
+ updateFlag := false
|
|
|
if record.CicvMapZipURL == nil || *record.CicvMapZipURL == "" || record.CicvMapPgmURL == nil || *record.CicvMapPgmURL == "" {
|
|
|
+ updateFlag = true
|
|
|
// 创建临时文件夹
|
|
|
tmpDir, err := os.MkdirTemp("", "temp-download-*")
|
|
|
|
|
@@ -913,10 +1066,12 @@ func UploadOriginalMapWithoutHttp(ctx context.Context) bool {
|
|
|
c_log.GlobalLogger.Info("上传文件", "map.pgm", "->", ossObjectKey, "成功。")
|
|
|
record.CicvMapPgmURL = &ossObjectKey
|
|
|
}
|
|
|
- _, err = mysql.UpdateOriginalMapOneRecord(ctx, *record)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("更新原始地图失败")
|
|
|
- return false
|
|
|
+ if updateFlag {
|
|
|
+ _, err = mysql.UpdateOriginalMapOneRecord(ctx, *record)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("更新原始地图失败")
|
|
|
+ return false
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return true
|