소스 검색

feat: 完成仿真接口

HeWang 9 달 전
부모
커밋
e4725ec291

+ 2 - 1
biz/dal/mysql/init.go

@@ -7,7 +7,8 @@ import (
 	"time"
 )
 
-var dsn = "root:1qaz2wsx!@tcp(36.110.106.156:3306)/pji_desktop?charset=utf8&parseTime=True&loc=Local"
+// var dsn = "root:1qaz2wsx!@tcp(36.110.106.156:3306)/pji_desktop?charset=utf8&parseTime=True&loc=Local" // 外网地址
+var dsn = "root:1qaz2wsx!@tcp(10.14.85.240:3306)/pji_desktop?charset=utf8&parseTime=True&loc=Local" // 内网地址
 
 var db *gorm.DB
 

+ 39 - 3
biz/handler/simulation_service/simulation_service.go

@@ -5,6 +5,7 @@ import (
 	"context"
 	"fmt"
 	"github.com/cloudwego/hertz/pkg/app"
+	"github.com/cloudwego/hertz/pkg/protocol/consts"
 	"io"
 	"net/http"
 	"os"
@@ -12,6 +13,7 @@ import (
 	"pji_desktop_http/biz/dal/mysql"
 	"pji_desktop_http/common/config"
 	"pji_desktop_http/common/config/c_log"
+	"pji_desktop_http/common/entity"
 	"pji_desktop_http/common/util"
 )
 
@@ -86,18 +88,19 @@ func generateSimulationZipById(ctx context.Context, id string) (file string, tmp
 	}
 	c_log.GlobalLogger.Info("创建文件打包根目录:", baseDir)
 
-	// 从oss下载data.zip文件到根目录(data.zip中的mapBuf文件夹包含map.pgm, map.yaml)
+	// 从oss下载data.zip, map.pgm, map.yaml文件到根目录
 	// 过滤特定后缀的文件列表
 	simulationFileList := util.FilterBySuffixes(allFileList, config.SimulationFiltersuffixes...)
+	fmt.Println("simulationFileList", simulationFileList)
 	// 从oss下载文件到 根目录
 	for _, file := range simulationFileList {
 		err = config.OssBucket.GetObjectToFile(file, filepath.Join(baseDir, filepath.Base(file)))
 		if err != nil {
-			fmt.Println("Error downloading mapBuf file:", err)
+			fmt.Println("Error downloading file - data.zip, map.pgm, map.yaml:", err)
 			return "", "", err
 		}
 	}
-	c_log.GlobalLogger.Info("下载data.zip文件到根目录 - 成功")
+	c_log.GlobalLogger.Info("下载data.zip, map.pgm, map.yaml文件到根目录 - 成功")
 
 	// 下载world文件
 	// 查询状态
@@ -115,6 +118,19 @@ func generateSimulationZipById(ctx context.Context, id string) (file string, tmp
 		c_log.GlobalLogger.Info("下载world文件到根目录 - 成功")
 	}
 
+	// 下载原始bag
+	rosField, err := util.GetRosFileById(id)
+	if err != nil {
+		fmt.Println("Error querying origin map's bag file:", err)
+		return "", "", err
+	}
+	err = config.OssBucket.GetObjectToFile(rosField, filepath.Join(baseDir, "origin_map.bag"))
+	if err != nil {
+		fmt.Println("Error downloading origin map's bag file:", err)
+		return "", "", err
+	}
+	c_log.GlobalLogger.Info("下载origin_map.bag文件到根目录 - 成功")
+
 	// 创建压缩文件
 	zipPath := filepath.Join(tmpDir, "simulationFile-"+id+".zip")
 	zipFile, err := os.Create(zipPath)
@@ -138,3 +154,23 @@ func generateSimulationZipById(ctx context.Context, id string) (file string, tmp
 
 	return zipPath, tmpDir, nil
 }
+
+// CheckDataFileStatus 检查data目录是否存在
+// @router /simulation/check/file/data/status [GET]
+func CheckDataFileStatus(ctx context.Context, c *app.RequestContext) {
+	sceneID := c.Query("id")
+	fmt.Println("id", sceneID)
+
+	// 根据id获取对应的oss文件列表
+	allFileList, err := util.GetExactedMapFileById(sceneID)
+	if err != nil {
+		return
+	}
+	// 过滤特定后缀的文件列表(data.zip)
+	simulationFileList := util.FilterBySuffixes(allFileList, config.DataFiltersuffixes...)
+	if len(simulationFileList) == 0 {
+		c.JSON(consts.StatusOK, entity.HttpResult{Status: false, Code: "", Message: "data目录不存在"})
+		return
+	}
+	c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "data目录存在"})
+}

+ 4 - 4
biz/handler/world_service/world_service.go

@@ -55,11 +55,11 @@ func UploadWorldFile(ctx context.Context, c *app.RequestContext) {
 	mysql.AddWorld(ctx, world)
 }
 
-// CheckWorldFileStatus 检查world文件oss中是否存在
-// @router /world/check/file/status [GET]
+// CheckWorldFileStatus 检查world文件oss中是否存在
+// @router /world/check/file/world/status [GET]
 func CheckWorldFileStatus(ctx context.Context, c *app.RequestContext) {
-	sceneID := c.Query("sceneID")
-	fmt.Println("sceneID", sceneID)
+	sceneID := c.Query("id")
+	fmt.Println("id", sceneID)
 
 	world, err := mysql.QueryWorld(ctx, sceneID)
 	if err != nil || world == nil {

+ 2 - 1
common/config/c_map.go

@@ -4,5 +4,6 @@ var (
 	MapBufFiltersuffixes      = []string{"map.pgm", "map.yaml", "map.json", "forbid_area.json"}
 	BuildMapBagFiltersuffixes = []string{"build_map.bag"}
 	OriginMapFiltersuffixes   = []string{"map.pgm", "map.yaml"}
-	SimulationFiltersuffixes  = []string{"data.zip"}
+	SimulationFiltersuffixes  = []string{"data.zip", "map.pgm", "map.yaml"}
+	DataFiltersuffixes        = []string{"data.zip"}
 )

+ 3 - 2
common/config/c_oss.go

@@ -30,12 +30,13 @@ func InitOssConfig() {
 
 	// 1 OSS 配置
 	var ossConnectInfo OssConnectInfoStruct
-	ossConnectInfo.Endpoint = "http://pji-bucket1.oss.icvdc.com"
+	//ossConnectInfo.Endpoint = "http://pji-bucket1.oss.icvdc.com" // 外网
+	ossConnectInfo.Endpoint = "http://oss-cn-beijing-gqzl-d01-a.ops.gqzl-cloud.com" // 内网
 	ossConnectInfo.BucketName = "pji-bucket1"
 	ossConnectInfo.AccessKeyId = "n8glvFGS25MrLY7j"
 	ossConnectInfo.AccessKeySecret = "xZ2Fozoarpfw0z28FUhtg8cu0yDc5d"
 
-	OssClient, err = oss.New(ossConnectInfo.Endpoint, ossConnectInfo.AccessKeyId, ossConnectInfo.AccessKeySecret, oss.UseCname(true))
+	OssClient, err = oss.New(ossConnectInfo.Endpoint, ossConnectInfo.AccessKeyId, ossConnectInfo.AccessKeySecret, oss.UseCname(false))
 	if err != nil {
 		c_log.GlobalLogger.Error("无法创建阿里云client:", err)
 		os.Exit(-1)

+ 4 - 2
common/config/c_pji/c_pji.go

@@ -1,8 +1,10 @@
 package c_pji
 
 var (
-	SenceOssDownUrl = "http://36.110.106.156:11121/open/scene/oss/down/"
-	SenceInfoUrl    = "http://36.110.106.156:11121/open/scene/"
+	//SenceOssDownUrl = "http://36.110.106.156:11121/open/scene/oss/down/" // 外网
+	SenceOssDownUrl = "http://10.14.86.147:9081/open/scene/oss/down/" // 内网
+	//SenceInfoUrl    = "http://36.110.106.156:11121/open/scene/" // 外网
+	SenceInfoUrl = "http://10.14.86.147:9081/open/scene/" // 内网
 
 	Token = "4773hd92ysj54paflw2jem3onyhywxt2"
 )

+ 3 - 1
router.go

@@ -28,8 +28,10 @@ func customizedRegister(r *server.Hertz) {
 	r.GET("/world/upload/worldfile", world_service.UploadWorldFile)
 	r.POST("/world/upload/worldfile", world_service.UploadWorldFile)
 
-	r.GET("/world/check/file/status", world_service.CheckWorldFileStatus)
+	r.GET("/world/check/file/world/status", world_service.CheckWorldFileStatus)
 
 	r.GET("/simulation/download/zipfile", simulation_service.DownloadSimulationZipFile)
 
+	r.GET("/simulation/check/file/data/status", simulation_service.CheckDataFileStatus)
+
 }