feat: 推广 V3.5 实时氢耗并完善导出

This commit is contained in:
lingniu
2026-09-04 15:42:02 +08:00
parent a26179c8fe
commit e402eb5e60
53 changed files with 2855 additions and 320 deletions
@@ -91,10 +91,11 @@ type RawFrameQuery struct {
}
type VehicleOverviewBatchQuery struct {
Keywords []string `json:"keywords"`
Protocol string `json:"protocol"`
Limit int `json:"limit"`
Offset int `json:"offset"`
Keywords []string `json:"keywords"`
Protocol string `json:"protocol"`
Limit int `json:"limit"`
Offset int `json:"offset"`
ScopeVINs []string `json:"-"`
}
type Service struct {
@@ -869,10 +870,12 @@ func (s *Service) VehicleServiceOverview(ctx context.Context, keyword string, pr
}
}
if batchStore, ok := s.store.(VehicleOverviewBatchStore); ok {
scopeVINs := principalVehicleVINScope(ctx)
page, err := batchStore.VehicleServiceOverviews(ctx, VehicleOverviewBatchQuery{
Keywords: []string{keyword},
Protocol: protocol,
Limit: 1,
Keywords: []string{keyword},
Protocol: protocol,
Limit: 1,
ScopeVINs: scopeVINs,
})
if err != nil {
return VehicleServiceOverview{}, err
@@ -927,11 +930,13 @@ func (s *Service) VehicleServiceOverviews(ctx context.Context, query VehicleOver
query.Keywords = keywords
query.Limit = limit
query.Offset = offset
query.ScopeVINs = principalVehicleVINScope(ctx)
if batchStore, ok := s.store.(VehicleOverviewBatchStore); ok {
page, err := batchStore.VehicleServiceOverviews(ctx, query)
if err != nil {
return Page[VehicleServiceOverview]{}, err
}
page = restrictVehicleOverviewPage(ctx, page)
page.Total = total
page.Limit = limit
page.Offset = offset
@@ -948,6 +953,34 @@ func (s *Service) VehicleServiceOverviews(ctx context.Context, query VehicleOver
return Page[VehicleServiceOverview]{Items: items, Total: total, Limit: limit, Offset: offset}, nil
}
func principalVehicleVINScope(ctx context.Context) []string {
principal, ok := PrincipalFromContext(ctx)
if !ok || principal.UserType != "customer" {
return nil
}
scope := make([]string, 0, len(principal.VehicleVINs))
for _, vin := range principal.VehicleVINs {
if vin = strings.ToUpper(strings.TrimSpace(vin)); vin != "" {
scope = append(scope, vin)
}
}
return scope
}
func restrictVehicleOverviewPage(ctx context.Context, page Page[VehicleServiceOverview]) Page[VehicleServiceOverview] {
principal, ok := PrincipalFromContext(ctx)
if !ok || principal.UserType != "customer" {
return page
}
for index := range page.Items {
if principal.CanVIN(strings.ToUpper(strings.TrimSpace(page.Items[index].VIN))) {
continue
}
page.Items[index] = *buildVehicleServiceOverview("", "", &VehicleIdentityResolution{Protocols: []string{}}, nil, nil, nil, Page[HistoryLocationRow]{}, Page[RawFrameRow]{}, Page[DailyMileageRow]{}, Page[QualityIssueRow]{})
}
return page
}
func (s *Service) VehicleDetail(ctx context.Context, vin string, protocol string) (VehicleDetail, error) {
keyword := strings.TrimSpace(vin)
protocol = strings.TrimSpace(protocol)