Ver código fonte

refactor: 仿真测试记录查询由固定字段调整为根据结构体任意非零字段查询

HeWang 8 meses atrás
pai
commit
2b93b9d958

+ 14 - 2
biz/dal/mysql/simulation_test_record.go

@@ -3,6 +3,7 @@ package mysql
 import (
 	"context"
 	"fmt"
+	"gorm.io/gen/field"
 	"pji_desktop_http/biz/dal/query"
 	"pji_desktop_http/biz/model"
 )
@@ -13,9 +14,20 @@ func AddSimulationTestRecords(ctx context.Context, records []*model.SimulationTe
 	return err
 }
 
-func QuerySimulationTestRecords(ctx context.Context, sceneId string, testTime string) ([]*model.SimulationTestRecord, error) {
+//func QuerySimulationTestRecords(ctx context.Context, sceneId string, testTime string) ([]*model.SimulationTestRecord, error) {
+//	r := query.SimulationTestRecord
+//	records, err := r.WithContext(ctx).Where(r.SceneID.Eq(sceneId), r.TestTime.Eq(testTime)).Order(r.Round.Asc()).Find()
+//	if err != nil {
+//		fmt.Println("Query simulation records failed:", err.Error())
+//		return nil, err
+//	}
+//	fmt.Print("Query simulation records successfully:", records)
+//	return records, err
+//}
+
+func QuerySimulationTestRecords(ctx context.Context, record *model.SimulationTestRecord) ([]*model.SimulationTestRecord, error) {
 	r := query.SimulationTestRecord
-	records, err := r.WithContext(ctx).Where(r.SceneID.Eq(sceneId), r.TestTime.Eq(testTime)).Order(r.Round.Asc()).Find()
+	records, err := r.WithContext(ctx).Where(field.Attrs(record)).Order(r.Round.Asc()).Find()
 	if err != nil {
 		fmt.Println("Query simulation records failed:", err.Error())
 		return nil, err

+ 8 - 10
biz/handler/simulation_service/simulation_service.go

@@ -335,16 +335,14 @@ func AddSimulationRecord(ctx context.Context, c *app.RequestContext) {
 	c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "仿真测试记录添加成功"})
 }
 
-// QueryEvalRecord 查询算法评价记录(根据场景id及时间戳)
-// @router /simulation/query/eval/record [GET]
-func QueryEvalRecord(ctx context.Context, c *app.RequestContext) {
-	sceneId := c.Query("sceneId")
-	fmt.Println("sceneId", sceneId)
-
-	testTime := c.Query("testTime")
-	fmt.Println("testTime", testTime)
-
-	records, err := mysql.QuerySimulationTestRecords(ctx, sceneId, testTime)
+// QueryTestRecord 根据条件查询仿真测试记录
+// @router /simulation/query/test/record [GET]
+func QueryTestRecord(ctx context.Context, c *app.RequestContext) {
+	var record model.SimulationTestRecord
+	err := c.BindAndValidate(&record)
+	fmt.Println("record", record)
+
+	records, err := mysql.QuerySimulationTestRecords(ctx, &record)
 	if err != nil {
 		c.JSON(consts.StatusOK, entity.HttpResult{Status: false, Code: "", Message: "仿真测试记录查询失败", Details: ""})
 		return

+ 1 - 1
router.go

@@ -48,7 +48,7 @@ func customizedRegister(r *server.Hertz) {
 
 	r.POST("/simulation/add/record", simulation_service.AddSimulationRecord)
 
-	r.GET("/simulation/query/eval/record", simulation_service.QueryEvalRecord)
+	r.POST("/simulation/query/test/record", simulation_service.QueryTestRecord)
 
 	r.POST("/simulation/download/oss/key", simulation_service.DownloadFileByKeys)
 }