|
@@ -6,11 +6,13 @@ import (
|
|
|
"fmt"
|
|
|
"github.com/cloudwego/hertz/pkg/app"
|
|
|
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
|
|
+ uuid "github.com/satori/go.uuid"
|
|
|
"io"
|
|
|
"net/http"
|
|
|
"os"
|
|
|
"path/filepath"
|
|
|
"pji_desktop_http/biz/dal/mysql"
|
|
|
+ "pji_desktop_http/biz/model"
|
|
|
"pji_desktop_http/common/config"
|
|
|
"pji_desktop_http/common/config/c_log"
|
|
|
"pji_desktop_http/common/entity"
|
|
@@ -102,13 +104,13 @@ func generateSimulationZipById(ctx context.Context, id string) (file string, tmp
|
|
|
}
|
|
|
c_log.GlobalLogger.Info("下载data.zip, map.pgm, map.yaml, map.bag文件到根目录 - 成功")
|
|
|
|
|
|
- // 下载world文件
|
|
|
+ // 下载world文件&map.stl文件
|
|
|
// 查询状态
|
|
|
world, err := mysql.QueryWorld(ctx, id)
|
|
|
- if err != nil || world == nil { // 文件不存在
|
|
|
- c_log.GlobalLogger.Info("world文件不存在 - 跳过")
|
|
|
- } else { // 文件存在
|
|
|
- // 下载文件
|
|
|
+ if err != nil || world == nil { // 记录不存在
|
|
|
+ c_log.GlobalLogger.Info("world记录不存在 - 跳过")
|
|
|
+ } else { // 记录存在
|
|
|
+ // 下载world文件
|
|
|
worldURL := world.WorldURL
|
|
|
err = config.OssBucket.GetObjectToFile(worldURL, filepath.Join(baseDir, filepath.Base(worldURL)))
|
|
|
if err != nil {
|
|
@@ -116,6 +118,19 @@ func generateSimulationZipById(ctx context.Context, id string) (file string, tmp
|
|
|
return "", "", err
|
|
|
}
|
|
|
c_log.GlobalLogger.Info("下载world文件到根目录 - 成功")
|
|
|
+
|
|
|
+ // 下载map.stl文件
|
|
|
+ stlURL := world.StlURL
|
|
|
+ if stlURL != nil && *stlURL != "" {
|
|
|
+ err = config.OssBucket.GetObjectToFile(*stlURL, filepath.Join(baseDir, filepath.Base(*stlURL)))
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error downloading stl file:", err)
|
|
|
+ return "", "", err
|
|
|
+ }
|
|
|
+ c_log.GlobalLogger.Info("下载map.stl文件到根目录 - 成功")
|
|
|
+ } else {
|
|
|
+ c_log.GlobalLogger.Info("map.stl文件不存在 - 跳过")
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 下载原始bag
|
|
@@ -174,3 +189,145 @@ func CheckDataFileStatus(ctx context.Context, c *app.RequestContext) {
|
|
|
}
|
|
|
c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "data目录存在"})
|
|
|
}
|
|
|
+
|
|
|
+// UploadPdfFile 将result.pdf文件上传到oss
|
|
|
+// @router /simulation/upload/pdf [GET]
|
|
|
+func UploadPdfFile(ctx context.Context, c *app.RequestContext) {
|
|
|
+ equipmentNo := c.Query("equipmentNo")
|
|
|
+ fmt.Println("equipmentNo", equipmentNo)
|
|
|
+
|
|
|
+ sceneNo := c.Query("sceneNo")
|
|
|
+ fmt.Println("sceneNo", sceneNo)
|
|
|
+
|
|
|
+ timeStamp := c.Query("timeStamp")
|
|
|
+ fmt.Println("timeStamp", timeStamp)
|
|
|
+
|
|
|
+ round := c.Query("round")
|
|
|
+ fmt.Println("round", round)
|
|
|
+
|
|
|
+ header, err := c.FormFile("file")
|
|
|
+ if err != nil {
|
|
|
+ c.String(http.StatusBadRequest, fmt.Sprintf("get form err: %s", err.Error()))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ fileName := header.Filename
|
|
|
+ fmt.Println("filename", fileName)
|
|
|
+
|
|
|
+ ossObjectKey := config.SimulationOssBasePrefix + "/" + equipmentNo + "/" + sceneNo + "/" + timeStamp + "/" + round + "/" + fileName
|
|
|
+ fmt.Println("ossObjectKey", ossObjectKey)
|
|
|
+
|
|
|
+ f, _ := header.Open()
|
|
|
+ defer f.Close()
|
|
|
+
|
|
|
+ config.OssMutex.Lock()
|
|
|
+ err = config.OssBucket.PutObject(ossObjectKey, f)
|
|
|
+ config.OssMutex.Unlock()
|
|
|
+ if err != nil {
|
|
|
+ c_log.GlobalLogger.Error("程序异常退出。上传文件", fileName, "->", ossObjectKey, "出错:", err)
|
|
|
+ c.JSON(consts.StatusOK, entity.HttpResult{Status: false, Code: "", Message: "上传文件失败", Details: ""})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c_log.GlobalLogger.Info("上传文件", fileName, "->", ossObjectKey, "成功。")
|
|
|
+ c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "上传文件成功", Details: ossObjectKey})
|
|
|
+}
|
|
|
+
|
|
|
+// UploadBagFile 将test-${i}.bag文件上传到oss
|
|
|
+// @router /simulation/upload/bag [GET]
|
|
|
+func UploadBagFile(ctx context.Context, c *app.RequestContext) {
|
|
|
+ equipmentNo := c.Query("equipmentNo")
|
|
|
+ fmt.Println("equipmentNo", equipmentNo)
|
|
|
+
|
|
|
+ sceneNo := c.Query("sceneNo")
|
|
|
+ fmt.Println("sceneNo", sceneNo)
|
|
|
+
|
|
|
+ timeStamp := c.Query("timeStamp")
|
|
|
+ fmt.Println("timeStamp", timeStamp)
|
|
|
+
|
|
|
+ round := c.Query("round")
|
|
|
+ fmt.Println("round", round)
|
|
|
+
|
|
|
+ header, err := c.FormFile("file")
|
|
|
+ if err != nil {
|
|
|
+ c.String(http.StatusBadRequest, fmt.Sprintf("get form err: %s", err.Error()))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ fileName := header.Filename
|
|
|
+ fmt.Println("filename", fileName)
|
|
|
+
|
|
|
+ ossObjectKey := config.SimulationOssBasePrefix + "/" + equipmentNo + "/" + sceneNo + "/" + timeStamp + "/" + round + "/" + fileName
|
|
|
+ fmt.Println("ossObjectKey", ossObjectKey)
|
|
|
+
|
|
|
+ f, _ := header.Open()
|
|
|
+ defer f.Close()
|
|
|
+
|
|
|
+ config.OssMutex.Lock()
|
|
|
+ err = config.OssBucket.PutObject(ossObjectKey, f)
|
|
|
+ config.OssMutex.Unlock()
|
|
|
+ if err != nil {
|
|
|
+ c_log.GlobalLogger.Error("程序异常退出。上传文件", fileName, "->", ossObjectKey, "出错:", err)
|
|
|
+ c.JSON(consts.StatusOK, entity.HttpResult{Status: false, Code: "", Message: "上传文件失败", Details: ""})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c_log.GlobalLogger.Info("上传文件", fileName, "->", ossObjectKey, "成功。")
|
|
|
+ c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "上传文件成功", Details: ossObjectKey})
|
|
|
+}
|
|
|
+
|
|
|
+// UploadPgmFile 将map.pgm文件上传到oss
|
|
|
+// @router /simulation/upload/pgm [GET]
|
|
|
+func UploadPgmFile(ctx context.Context, c *app.RequestContext) {
|
|
|
+ equipmentNo := c.Query("equipmentNo")
|
|
|
+ fmt.Println("equipmentNo", equipmentNo)
|
|
|
+
|
|
|
+ sceneNo := c.Query("sceneNo")
|
|
|
+ fmt.Println("sceneNo", sceneNo)
|
|
|
+
|
|
|
+ header, err := c.FormFile("file")
|
|
|
+ if err != nil {
|
|
|
+ c.String(http.StatusBadRequest, fmt.Sprintf("get form err: %s", err.Error()))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ fileName := header.Filename
|
|
|
+ fmt.Println("filename", fileName)
|
|
|
+
|
|
|
+ ossObjectKey := config.SimulationOssBasePrefix + "/" + equipmentNo + "/" + sceneNo + "/" + fileName
|
|
|
+ fmt.Println("ossObjectKey", ossObjectKey)
|
|
|
+
|
|
|
+ f, _ := header.Open()
|
|
|
+ defer f.Close()
|
|
|
+
|
|
|
+ config.OssMutex.Lock()
|
|
|
+ err = config.OssBucket.PutObject(ossObjectKey, f)
|
|
|
+ config.OssMutex.Unlock()
|
|
|
+ if err != nil {
|
|
|
+ c_log.GlobalLogger.Error("程序异常退出。上传文件", fileName, "->", ossObjectKey, "出错:", err)
|
|
|
+ c.JSON(consts.StatusOK, entity.HttpResult{Status: false, Code: "", Message: "上传文件失败", Details: ""})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c_log.GlobalLogger.Info("上传文件", fileName, "->", ossObjectKey, "成功。")
|
|
|
+ c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "上传文件成功", Details: ossObjectKey})
|
|
|
+}
|
|
|
+
|
|
|
+// AddSimulationRecord 添加仿真测试记录
|
|
|
+// @router /simulation/add/record [GET]
|
|
|
+func AddSimulationRecord(ctx context.Context, c *app.RequestContext) {
|
|
|
+ var records []*model.SimulationTestRecord
|
|
|
+ err := c.BindAndValidate(&records)
|
|
|
+
|
|
|
+ for _, record := range records {
|
|
|
+ record.ID = uuid.NewV1().String()
|
|
|
+ }
|
|
|
+ fmt.Println("records", records)
|
|
|
+ if err != nil {
|
|
|
+ c.String(http.StatusBadRequest, fmt.Sprintf("get form err: %s", err.Error()))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = mysql.AddSimulationTestRecords(ctx, records)
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(consts.StatusOK, entity.HttpResult{Status: false, Code: "", Message: "仿真测试记录添加失败"})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "仿真测试记录添加成功"})
|
|
|
+}
|