|
@@ -3,7 +3,6 @@ package mysql
|
|
|
import (
|
|
|
"context"
|
|
|
"fmt"
|
|
|
- "gorm.io/gen/field"
|
|
|
"pji_desktop_http/biz/dal/query"
|
|
|
"pji_desktop_http/biz/model"
|
|
|
)
|
|
@@ -25,13 +24,37 @@ func AddSimulationTestRecords(ctx context.Context, records []*model.SimulationTe
|
|
|
// return records, err
|
|
|
//}
|
|
|
|
|
|
-func QuerySimulationTestRecords(ctx context.Context, record *model.SimulationTestRecord) ([]*model.SimulationTestRecord, error) {
|
|
|
+func QuerySimulationTestRecords(ctx context.Context, record *model.SimulationTestRecord, pageFlag bool, page, pageSize int) ([]*model.SimulationTestRecord, int64, error) {
|
|
|
r := query.SimulationTestRecord
|
|
|
- records, err := r.WithContext(ctx).Where(field.Attrs(record)).Order(r.Round.Asc()).Find()
|
|
|
+ q := r.WithContext(ctx)
|
|
|
+ var records []*model.SimulationTestRecord
|
|
|
+ var count int64
|
|
|
+ var err error
|
|
|
+ if record.DeviceType != "" {
|
|
|
+ q = q.Where(r.DeviceType.Eq(record.DeviceType))
|
|
|
+ }
|
|
|
+ if record.AlgoEvaluationLevel != "" {
|
|
|
+ fmt.Println("AlgoEvaluationLevel", record.AlgoEvaluationLevel)
|
|
|
+ q = q.Where(r.AlgoEvaluationLevel.Eq(record.AlgoEvaluationLevel))
|
|
|
+ }
|
|
|
+ if record.DeviceName != "" {
|
|
|
+ q = q.Where(r.DeviceName.Like("%" + record.DeviceName + "%"))
|
|
|
+ }
|
|
|
+ if record.AlgoImageName != "" {
|
|
|
+ q = q.Where(r.AlgoImageName.Like("%" + record.AlgoImageName + "%"))
|
|
|
+ }
|
|
|
+ if pageFlag {
|
|
|
+ offset := (page - 1) * pageSize
|
|
|
+ records, count, err = q.Order(r.TestTime.Desc(), r.Round.Asc()).FindByPage(offset, pageSize)
|
|
|
+ } else {
|
|
|
+ records, err = q.Order(r.TestTime.Desc(), r.Round.Asc()).Find()
|
|
|
+ }
|
|
|
+
|
|
|
if err != nil {
|
|
|
fmt.Println("Query simulation records failed:", err.Error())
|
|
|
- return nil, err
|
|
|
+ return nil, 0, err
|
|
|
}
|
|
|
- fmt.Print("Query simulation records successfully:", records)
|
|
|
- return records, err
|
|
|
+
|
|
|
+ fmt.Println("Query simulation records successfully:", len(records))
|
|
|
+ return records, count, err
|
|
|
}
|