Browse Source

feat: 添加仿真测试记录

HeWang 8 months ago
parent
commit
db3ab2f8f3

+ 13 - 0
biz/dal/mysql/simulation_test_record.go

@@ -0,0 +1,13 @@
+package mysql
+
+import (
+	"context"
+	"pji_desktop_http/biz/dal/query"
+	"pji_desktop_http/biz/model"
+)
+
+func AddSimulationTestRecords(ctx context.Context, records []*model.SimulationTestRecord) error {
+	r := query.SimulationTestRecord
+	err := r.WithContext(ctx).Create(records...)
+	return err
+}

+ 23 - 7
biz/dal/query/simulation_test_record.gen.go

@@ -36,13 +36,17 @@ func newSimulationTestRecord(db *gorm.DB, opts ...gen.DOOption) simulationTestRe
 	_simulationTestRecord.PgmPath = field.NewString(tableName, "pgm_path")
 	_simulationTestRecord.WorldPath = field.NewString(tableName, "world_path")
 	_simulationTestRecord.TestBagPath = field.NewString(tableName, "test_bag_path")
-	_simulationTestRecord.TestDuration = field.NewInt32(tableName, "test_duration")
-	_simulationTestRecord.TestDistance = field.NewInt32(tableName, "test_distance")
+	_simulationTestRecord.TestDuration = field.NewString(tableName, "test_duration")
+	_simulationTestRecord.TestDistance = field.NewString(tableName, "test_distance")
 	_simulationTestRecord.AlgoEvaluationLevel = field.NewString(tableName, "algo_evaluation_level")
 	_simulationTestRecord.AlgoEvaluationReport = field.NewString(tableName, "algo_evaluation_report")
 	_simulationTestRecord.CreatedAt = field.NewTime(tableName, "created_at")
 	_simulationTestRecord.UpdatedAt = field.NewTime(tableName, "updated_at")
 	_simulationTestRecord.DeletedAt = field.NewField(tableName, "deleted_at")
+	_simulationTestRecord.TestTime = field.NewString(tableName, "test_time")
+	_simulationTestRecord.Round = field.NewInt32(tableName, "round")
+	_simulationTestRecord.SceneID = field.NewString(tableName, "scene_id")
+	_simulationTestRecord.DeviceNo = field.NewString(tableName, "device_no")
 
 	_simulationTestRecord.fillFieldMap()
 
@@ -62,13 +66,17 @@ type simulationTestRecord struct {
 	PgmPath              field.String
 	WorldPath            field.String
 	TestBagPath          field.String
-	TestDuration         field.Int32
-	TestDistance         field.Int32
+	TestDuration         field.String
+	TestDistance         field.String
 	AlgoEvaluationLevel  field.String
 	AlgoEvaluationReport field.String
 	CreatedAt            field.Time
 	UpdatedAt            field.Time
 	DeletedAt            field.Field
+	TestTime             field.String
+	Round                field.Int32
+	SceneID              field.String
+	DeviceNo             field.String
 
 	fieldMap map[string]field.Expr
 }
@@ -94,13 +102,17 @@ func (s *simulationTestRecord) updateTableName(table string) *simulationTestReco
 	s.PgmPath = field.NewString(table, "pgm_path")
 	s.WorldPath = field.NewString(table, "world_path")
 	s.TestBagPath = field.NewString(table, "test_bag_path")
-	s.TestDuration = field.NewInt32(table, "test_duration")
-	s.TestDistance = field.NewInt32(table, "test_distance")
+	s.TestDuration = field.NewString(table, "test_duration")
+	s.TestDistance = field.NewString(table, "test_distance")
 	s.AlgoEvaluationLevel = field.NewString(table, "algo_evaluation_level")
 	s.AlgoEvaluationReport = field.NewString(table, "algo_evaluation_report")
 	s.CreatedAt = field.NewTime(table, "created_at")
 	s.UpdatedAt = field.NewTime(table, "updated_at")
 	s.DeletedAt = field.NewField(table, "deleted_at")
+	s.TestTime = field.NewString(table, "test_time")
+	s.Round = field.NewInt32(table, "round")
+	s.SceneID = field.NewString(table, "scene_id")
+	s.DeviceNo = field.NewString(table, "device_no")
 
 	s.fillFieldMap()
 
@@ -129,7 +141,7 @@ func (s *simulationTestRecord) GetFieldByName(fieldName string) (field.OrderExpr
 }
 
 func (s *simulationTestRecord) fillFieldMap() {
-	s.fieldMap = make(map[string]field.Expr, 16)
+	s.fieldMap = make(map[string]field.Expr, 20)
 	s.fieldMap["id"] = s.ID
 	s.fieldMap["device_id"] = s.DeviceID
 	s.fieldMap["device_name"] = s.DeviceName
@@ -146,6 +158,10 @@ func (s *simulationTestRecord) fillFieldMap() {
 	s.fieldMap["created_at"] = s.CreatedAt
 	s.fieldMap["updated_at"] = s.UpdatedAt
 	s.fieldMap["deleted_at"] = s.DeletedAt
+	s.fieldMap["test_time"] = s.TestTime
+	s.fieldMap["round"] = s.Round
+	s.fieldMap["scene_id"] = s.SceneID
+	s.fieldMap["device_no"] = s.DeviceNo
 }
 
 func (s simulationTestRecord) clone(db *gorm.DB) simulationTestRecord {

+ 162 - 5
biz/handler/simulation_service/simulation_service.go

@@ -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: "仿真测试记录添加成功"})
+}

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

@@ -17,7 +17,6 @@ import (
 // UploadWorldFile 将world文件上传到oss
 // @router /world/upload/worldfile [GET]
 func UploadWorldFile(ctx context.Context, c *app.RequestContext) {
-
 	equipmentNo := c.Query("equipmentNo")
 	fmt.Println("equipmentNo", equipmentNo)
 
@@ -55,10 +54,9 @@ func UploadWorldFile(ctx context.Context, c *app.RequestContext) {
 	mysql.AddWorld(ctx, world)
 }
 
-// UploadSTLFile 将map.stl文件上传到oss
+// UploadStlFile 将map.stl文件上传到oss
 // @router /world/upload/stlfile [GET]
-func UploadSTLFile(ctx context.Context, c *app.RequestContext) {
-
+func UploadStlFile(ctx context.Context, c *app.RequestContext) {
 	equipmentNo := c.Query("equipmentNo")
 	fmt.Println("equipmentNo", equipmentNo)
 
@@ -108,8 +106,8 @@ func CheckWorldFileStatus(ctx context.Context, c *app.RequestContext) {
 
 	world, err := mysql.QueryWorld(ctx, sceneID)
 	if err != nil || world == nil {
-		c.JSON(consts.StatusOK, entity.HttpResult{Status: false, Code: "", Message: "world文件不存在"})
+		c.JSON(consts.StatusOK, entity.HttpResult{Status: false, Code: "", Message: "world文件不存在", Details: ""})
 		return
 	}
-	c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "world文件已存在"})
+	c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "world文件已存在", Details: world.WorldURL})
 }

+ 6 - 2
biz/model/simulation_test_record.go

@@ -23,13 +23,17 @@ type SimulationTestRecord struct {
 	PgmPath              string         `gorm:"column:pgm_path;type:varchar(255);not null" json:"pgm_path"`
 	WorldPath            string         `gorm:"column:world_path;type:varchar(255);not null" json:"world_path"`
 	TestBagPath          string         `gorm:"column:test_bag_path;type:varchar(255);not null" json:"test_bag_path"`
-	TestDuration         int32          `gorm:"column:test_duration;type:int(11);not null" json:"test_duration"`
-	TestDistance         int32          `gorm:"column:test_distance;type:int(11);not null" json:"test_distance"`
+	TestDuration         string         `gorm:"column:test_duration;type:varchar(50);not null" json:"test_duration"`
+	TestDistance         string         `gorm:"column:test_distance;type:varchar(50);not null" json:"test_distance"`
 	AlgoEvaluationLevel  string         `gorm:"column:algo_evaluation_level;type:varchar(50);not null" json:"algo_evaluation_level"`
 	AlgoEvaluationReport string         `gorm:"column:algo_evaluation_report;type:varchar(100);not null" json:"algo_evaluation_report"`
 	CreatedAt            time.Time      `gorm:"column:created_at;type:datetime;not null" json:"created_at"`
 	UpdatedAt            *time.Time     `gorm:"column:updated_at;type:datetime" json:"updated_at"`
 	DeletedAt            gorm.DeletedAt `gorm:"column:deleted_at;type:datetime" json:"deleted_at"`
+	TestTime             string         `gorm:"column:test_time;type:varchar(50);not null" json:"test_time"`
+	Round                int32          `gorm:"column:round;type:int(11);not null" json:"round"`
+	SceneID              string         `gorm:"column:scene_id;type:varchar(50);not null" json:"scene_id"`
+	DeviceNo             string         `gorm:"column:device_no;type:varchar(100);not null" json:"device_no"`
 }
 
 // TableName SimulationTestRecord's table name

+ 2 - 1
common/config/c_oss.go

@@ -21,7 +21,8 @@ var (
 )
 
 var (
-	WorldOssBasePrefix = "world"
+	WorldOssBasePrefix      = "world"
+	SimulationOssBasePrefix = "simulation"
 )
 
 func InitOssConfig() {

+ 0 - 1
gen/main.go

@@ -10,7 +10,6 @@ import (
 var dsn = "root:1qaz2wsx!@tcp(10.14.85.240:3306)/pji_desktop?charset=utf8&parseTime=True&loc=Local"
 
 func main() {
-
 	// 连接数据库
 	db, err := gorm.Open(mysql.Open(dsn))
 	if err != nil {

+ 19 - 9
router.go

@@ -17,24 +17,34 @@ func customizedRegister(r *server.Hertz) {
 
 	r.GET("/test/query/user", user_service.TestQueryUser)
 
-	r.POST("/map/check/mapbufconsistency", map_service.CheckMapBufConsistency)
+	r.POST("/map/check/mapbuf/consistency", map_service.CheckMapBufConsistency)
 
-	r.GET("/map/download/ossfile", map_service.DownloadOSSFile)
+	r.GET("/map/download/oss", map_service.DownloadOSSFile)
 
-	r.GET("/map/download/zipfile", map_service.DownloadMapZipFile)
+	r.GET("/map/download/zip", map_service.DownloadMapZipFile)
 
-	r.GET("/map/download/mapbagfile", map_service.DownloadMapBagFile)
+	r.GET("/map/download/mapbag", map_service.DownloadMapBagFile)
 
-	r.GET("/world/upload/worldfile", world_service.UploadWorldFile)
-	r.POST("/world/upload/worldfile", world_service.UploadWorldFile)
+	r.GET("/world/upload/world", world_service.UploadWorldFile)
+	r.POST("/world/upload/world", world_service.UploadWorldFile)
 
-	r.GET("/world/upload/stlfile", world_service.UploadSTLFile)
-	r.POST("/world/upload/stlfile", world_service.UploadSTLFile)
+	r.GET("/world/upload/stl", world_service.UploadStlFile)
+	r.POST("/world/upload/stl", world_service.UploadStlFile)
+
+	r.GET("/simulation/upload/pdf", simulation_service.UploadPdfFile)
+	r.POST("/simulation/upload/pdf", simulation_service.UploadPdfFile)
+
+	r.GET("/simulation/upload/bag", simulation_service.UploadBagFile)
+	r.POST("/simulation/upload/bag", simulation_service.UploadBagFile)
+
+	r.GET("/simulation/upload/pgm", simulation_service.UploadPgmFile)
+	r.POST("/simulation/upload/pgm", simulation_service.UploadPgmFile)
 
 	r.GET("/world/check/file/world/status", world_service.CheckWorldFileStatus)
 
-	r.GET("/simulation/download/zipfile", simulation_service.DownloadSimulationZipFile)
+	r.GET("/simulation/download/zip", simulation_service.DownloadSimulationZipFile)
 
 	r.GET("/simulation/check/file/data/status", simulation_service.CheckDataFileStatus)
 
+	r.POST("/simulation/add/record", simulation_service.AddSimulationRecord)
 }