Files
xk-hy-transit-go/internal/logweb/labels_api.go
2026-05-22 09:17:39 +08:00

71 lines
1.9 KiB
Go

package logweb
import (
"xk-hy-transit-go/internal/db"
"xk-hy-transit-go/internal/hy"
"xk-hy-transit-go/internal/syncgate"
)
// JobView 任务行(含中文标签)。
type JobView struct {
ID int64 `json:"id"`
AnchorDate string `json:"anchorDate"`
Step string `json:"step"`
StepLabel string `json:"stepLabel"`
Status string `json:"status"`
StatusLabel string `json:"statusLabel"`
TotalCount int `json:"totalCount"`
SuccessCount int `json:"successCount"`
FailedCount int `json:"failedCount"`
StartedAt any `json:"startedAt,omitempty"`
FinishedAt any `json:"finishedAt,omitempty"`
}
func enrichJobs(jobs []db.SyncJobRow) []JobView {
out := make([]JobView, 0, len(jobs))
for _, j := range jobs {
v := JobView{
ID: j.ID,
AnchorDate: j.AnchorDate,
Step: j.Step,
StepLabel: hy.LabelStep(j.Step),
Status: j.Status,
StatusLabel: hy.LabelSyncJobStatus(j.Status),
TotalCount: j.TotalCount,
SuccessCount: j.SuccessCount,
FailedCount: j.FailedCount,
}
if j.StartedAt.Valid {
v.StartedAt = j.StartedAt
}
if j.FinishedAt.Valid {
v.FinishedAt = j.FinishedAt
}
out = append(out, v)
}
return out
}
// TestStatusView 测试同步状态(含中文标签)。
type TestStatusView struct {
Running bool `json:"running"`
LastStep string `json:"last_step,omitempty"`
LastStepLabel string `json:"last_step_label,omitempty"`
LastDate string `json:"last_date,omitempty"`
LastError string `json:"last_error,omitempty"`
StartedAt any `json:"started_at,omitempty"`
FinishedAt any `json:"finished_at,omitempty"`
}
func enrichTestStatus(s syncgate.Status) TestStatusView {
return TestStatusView{
Running: s.Running,
LastStep: s.LastStep,
LastStepLabel: hy.LabelStep(s.LastStep),
LastDate: s.LastDate,
LastError: s.LastError,
StartedAt: s.StartedAt,
FinishedAt: s.FinishedAt,
}
}