From 257f3ac034e72657e3f9866e106f83d3f7fdb09f Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Sun, 26 Jul 2026 13:53:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=97=B6=E9=97=B4=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E9=98=88=E5=80=BC=E5=8F=AF=E9=85=8D=E7=BD=AE=EF=BC=8C=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E9=A1=B5=E6=B7=BB=E5=8A=A0=E6=9C=AC=E6=9C=BA=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E5=8D=A1=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/config/config.go | 1 + internal/service/task.go | 6 +++++- internal/web/ui.go | 19 +++++++++++++++++++ internal/web/ui/templates/devices.html | 4 ++-- internal/web/ui/templates/system.html | 24 +++++++++++++++++++++--- 5 files changed, 48 insertions(+), 6 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 9e45038..c471d36 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -20,6 +20,7 @@ type Config struct { MediaRepoPath string `json:"media_repo_path,omitempty"` // explicit import-only source; not used for runtime rendering AlarmRetentionDays int `json:"alarm_retention_days"` // auto-delete alarms older than N days, 0=keep forever CompanyName string `json:"company_name,omitempty"` + TimeSyncThresholdSec int `json:"time_sync_threshold_sec"` DeviceAliases map[string]string `json:"device_aliases,omitempty"` path string } diff --git a/internal/service/task.go b/internal/service/task.go index 48ba0c9..cf90511 100644 --- a/internal/service/task.go +++ b/internal/service/task.go @@ -442,7 +442,11 @@ func (s *TaskService) executeOnDevice(task *models.Task, did string) { if diff < 0 { diff = -diff } - if diff <= 5 { + threshold := int64(s.cfg.TimeSyncThresholdSec) + if threshold <= 0 { + threshold = 5 + } + if diff <= threshold { s.updateDeviceStatus(task.ID, did, models.TaskSuccess, 1.0, "时间已同步") s.appendAuditLog(task, did, models.TaskSuccess, "") return diff --git a/internal/web/ui.go b/internal/web/ui.go index fb906f4..e09ad3e 100644 --- a/internal/web/ui.go +++ b/internal/web/ui.go @@ -117,6 +117,7 @@ type PageData struct { SystemAlarmRetention int SystemConcurrency int SystemCompanyName string + TimeSyncThreshold int AlarmFilterDevices []string AlarmFilterRuleTypes []string AlarmDeviceNames map[string]string @@ -4400,6 +4401,10 @@ func (u *UI) renderSystemPage(w http.ResponseWriter, r *http.Request, status int if u.cfg != nil { data.SystemAlarmRetention = u.cfg.AlarmRetentionDays data.SystemCompanyName = u.cfg.CompanyName + data.TimeSyncThreshold = u.cfg.TimeSyncThresholdSec + if data.TimeSyncThreshold <= 0 { + data.TimeSyncThreshold = 5 + } } u.render(w, r, "system", data) } @@ -4422,6 +4427,10 @@ func (u *UI) actionSystemConfig(w http.ResponseWriter, r *http.Request) { u.cfg.CompanyName = company changed = true } + if tval, err := strconv.Atoi(strings.TrimSpace(r.FormValue("time_sync_threshold_sec"))); err == nil && tval >= 1 && u.cfg != nil { + u.cfg.TimeSyncThresholdSec = tval + changed = true + } if changed && u.cfg != nil && strings.TrimSpace(u.configPath) != "" { if data, err := json.MarshalIndent(u.cfg, "", " "); err == nil { os.WriteFile(u.configPath, data, 0o644) @@ -5292,6 +5301,10 @@ func (u *UI) deviceOverviewPageData(r *http.Request, selectedIDs []string, errMs // Check time drift now := time.Now().UnixMilli() + threshold := int64(5) // default + if u.cfg != nil && u.cfg.TimeSyncThresholdSec > 0 { + threshold = int64(u.cfg.TimeSyncThresholdSec) + } for i := range rows { dev := rows[i].Device if dev == nil || !dev.Online || u.agent == nil { @@ -5313,6 +5326,12 @@ func (u *UI) deviceOverviewPageData(r *http.Request, selectedIDs []string, errMs } } + // Common threshold for time drift display + if threshold <= 0 { + threshold = 5 + } + // (threshold used in template comparison: gt .TimeDriftSec $threshold) + data := PageData{ Title: "设备管理", Devices: devices, diff --git a/internal/web/ui/templates/devices.html b/internal/web/ui/templates/devices.html index 01a497b..704ef07 100644 --- a/internal/web/ui/templates/devices.html +++ b/internal/web/ui/templates/devices.html @@ -47,7 +47,7 @@ {{if $allOffline}} {{end}} - {{$drift := false}}{{range .DeviceRows}}{{if and (gt .TimeDriftSec 5) (hasString $.SelectedDeviceIDs .Device.DeviceID)}}{{$drift = true}}{{end}}{{end}} + {{$drift := false}}{{range .DeviceRows}}{{if and (gt .TimeDriftSec $.TimeSyncThreshold) (hasString $.SelectedDeviceIDs .Device.DeviceID)}}{{$drift = true}}{{end}}{{end}} {{if $drift}} {{end}} @@ -97,7 +97,7 @@ 未知 {{end}} {{if .IntegrationStale}}需重新下发{{end}} - {{if gt .TimeDriftSec 5}}⏱ 偏差{{.TimeDriftSec}}秒{{end}} + {{if gt .TimeDriftSec $.TimeSyncThreshold}}⏱ 偏差{{.TimeDriftSec}}秒{{end}} diff --git a/internal/web/ui/templates/system.html b/internal/web/ui/templates/system.html index 2dc5258..0176f2a 100644 --- a/internal/web/ui/templates/system.html +++ b/internal/web/ui/templates/system.html @@ -23,6 +23,13 @@ +