完善运行轨迹点展示与模拟数据

This commit is contained in:
czl231
2026-08-15 22:51:23 +08:00
parent e82ae18fb9
commit cc14cb9f62
7 changed files with 125 additions and 4 deletions

View File

@@ -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 {