完善运行轨迹点展示与模拟数据
This commit is contained in:
@@ -64,6 +64,13 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("mock gasorder statuses repaired: %d\n", count)
|
||||
case "repair-mock-track-point":
|
||||
count, err := repairMockTrackPoint()
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("mock track points repaired: %d\n", count)
|
||||
case "migrate":
|
||||
if err := migrateDatabase(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
@@ -78,7 +85,7 @@ func main() {
|
||||
}
|
||||
|
||||
func printUsage() {
|
||||
fmt.Fprintln(os.Stderr, "usage: platform-cli <version|resource-contract|gas-resource-contract|delivery-resource-contract|migrate|mock-data|repair-mock-gasorder-status>")
|
||||
fmt.Fprintln(os.Stderr, "usage: platform-cli <version|resource-contract|gas-resource-contract|delivery-resource-contract|migrate|mock-data|repair-mock-gasorder-status|repair-mock-track-point>")
|
||||
}
|
||||
|
||||
type route struct {
|
||||
@@ -209,6 +216,27 @@ func repairMockGasorderStatus() (int64, error) {
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// repairMockTrackPoint 使用独立幂等命令补全固定演示轨迹点,不触发其他模拟数据写入。
|
||||
func repairMockTrackPoint() (int64, error) {
|
||||
config.New(serviceKey)
|
||||
if config.Spec.Databases == nil {
|
||||
return 0, fmt.Errorf("database configuration is required")
|
||||
}
|
||||
databaseService, err := database.NewDatabase(
|
||||
config.Spec.Databases.Driver,
|
||||
config.Spec.Databases.Source,
|
||||
dbsql.SetOptions(nil),
|
||||
)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("connect database: %w", err)
|
||||
}
|
||||
count, err := seed.RepairMockTrackPointSample(databaseService)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("repair mock track point: %w", err)
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func migrateDatabase() error {
|
||||
config.New(serviceKey)
|
||||
options := &types.SqlOptions{
|
||||
|
||||
@@ -252,7 +252,10 @@ func MockData(database *gorm.DB) error {
|
||||
trackPoint := models.GasorderTrackPoint{
|
||||
Entity: entity(23, common.StatusEnable), GasorderTrackID: track.ID,
|
||||
Longitude: address.Longitude, Latitude: address.Latitude,
|
||||
OccurredAt: trackCompletedAt, Source: "gps", Accuracy: "10m",
|
||||
RequestNo: mockTrackPointRequestNo, OccurredAt: trackCompletedAt,
|
||||
ReceivedAt: trackCompletedAt.Add(mockTrackPointReceiveDelay),
|
||||
Source: "gps", Accuracy: "10m", Speed: mockTrackPointSpeed,
|
||||
Direction: mockTrackPointDirection,
|
||||
}
|
||||
if err := put(tx, &trackPoint); err != nil {
|
||||
return err
|
||||
@@ -786,6 +789,43 @@ func RepairMockGasorderInitialStatuses(database *gorm.DB) (int64, error) {
|
||||
return result.RowsAffected, nil
|
||||
}
|
||||
|
||||
const (
|
||||
mockTrackPointRequestNo = "MOCK-TRACK-POINT-001"
|
||||
mockTrackPointSpeed = "12 km/h"
|
||||
mockTrackPointDirection = "东北(45°)"
|
||||
mockTrackPointReceiveDelay = 2 * time.Second
|
||||
)
|
||||
|
||||
// RepairMockTrackPointSample 仅补全固定演示轨迹点的缺失上报字段,不覆盖已有有效数据。
|
||||
func RepairMockTrackPointSample(database *gorm.DB) (int64, error) {
|
||||
var point models.GasorderTrackPoint
|
||||
identity := fmt.Sprintf("%s%012d", mockIdentityPrefix, 23)
|
||||
if err := database.Where("identity = ?", identity).First(&point).Error; err != nil {
|
||||
return 0, fmt.Errorf("find mock track point sample: %w", err)
|
||||
}
|
||||
updates := map[string]any{}
|
||||
if point.RequestNo == "" {
|
||||
updates["request_no"] = mockTrackPointRequestNo
|
||||
}
|
||||
if point.ReceivedAt.IsZero() {
|
||||
updates["received_at"] = point.OccurredAt.Add(mockTrackPointReceiveDelay)
|
||||
}
|
||||
if point.Speed == "" {
|
||||
updates["speed"] = mockTrackPointSpeed
|
||||
}
|
||||
if point.Direction == "" {
|
||||
updates["direction"] = mockTrackPointDirection
|
||||
}
|
||||
if len(updates) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
result := database.Model(&point).Updates(updates)
|
||||
if result.Error != nil {
|
||||
return 0, fmt.Errorf("repair mock track point sample: %w", result.Error)
|
||||
}
|
||||
return result.RowsAffected, nil
|
||||
}
|
||||
|
||||
// linkMockProductProducer 为未来生成的 Mock 智能气阀建立真实生产商关联。
|
||||
func linkMockProductProducer(product *models.ProductInfo, producer models.ProducerAccount) error {
|
||||
if product == nil || producer.ID == 0 {
|
||||
|
||||
@@ -93,3 +93,16 @@ func TestMockGasorderInitialStatusMatchesWorkflow(t *testing.T) {
|
||||
t.Fatal("Mock 配送订单不得使用通用待处理状态")
|
||||
}
|
||||
}
|
||||
|
||||
// TestMockTrackPointSampleRequiredFields 验证演示轨迹点符合真实上报的必填字段和可读展示要求。
|
||||
func TestMockTrackPointSampleRequiredFields(t *testing.T) {
|
||||
if mockTrackPointRequestNo == "" {
|
||||
t.Fatal("Mock 轨迹点必须包含上报流水号")
|
||||
}
|
||||
if mockTrackPointReceiveDelay <= 0 {
|
||||
t.Fatal("Mock 轨迹点接收时间必须晚于定位时间")
|
||||
}
|
||||
if mockTrackPointSpeed == "" || mockTrackPointDirection == "" {
|
||||
t.Fatal("演示轨迹点必须提供可读的速度和方向")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user