From aa20bdaeb12f0dddfc3f6588ff7c35d017add69b Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Sun, 26 Jul 2026 13:48:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=89=B9=E5=A4=84=E7=90=86=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E8=BF=87=E6=BB=A4=E7=A6=BB=E7=BA=BF=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=EF=BC=8C=E6=97=B6=E9=97=B4=E5=90=8C=E6=AD=A5=E8=B7=B3=E8=BF=87?= =?UTF-8?q?=E6=97=A0=E5=81=8F=E5=B7=AE=E8=AE=BE=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/service/task.go | 18 ++++++++++++++++++ internal/web/ui.go | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/internal/service/task.go b/internal/service/task.go index b370a1a..48ba0c9 100644 --- a/internal/service/task.go +++ b/internal/service/task.go @@ -431,6 +431,24 @@ func (s *TaskService) executeOnDevice(task *models.Task, did string) { case "time_sync": nowMS := time.Now().UnixMilli() + // Check current drift first — skip if already in sync + devBody, devCode, devErr := s.agent.Do("GET", dev.IP, dev.AgentPort, "/v1/time", nil) + if devErr == nil && devCode == 200 { + var tresp struct { + UnixMS int64 `json:"unix_ms"` + } + if json.Unmarshal(devBody, &tresp) == nil { + diff := (nowMS - tresp.UnixMS) / 1000 + if diff < 0 { + diff = -diff + } + if diff <= 5 { + s.updateDeviceStatus(task.ID, did, models.TaskSuccess, 1.0, "时间已同步") + s.appendAuditLog(task, did, models.TaskSuccess, "") + return + } + } + } body, _ := json.Marshal(map[string]int64{"unix_ms": nowMS}) _, code, err := s.agent.Do("POST", dev.IP, dev.AgentPort, "/v1/time/set", body) if err != nil { diff --git a/internal/web/ui.go b/internal/web/ui.go index 238525c..fb906f4 100644 --- a/internal/web/ui.go +++ b/internal/web/ui.go @@ -1737,6 +1737,22 @@ func (u *UI) actionDiscoverySearch(w http.ResponseWriter, r *http.Request) { u.render(w, r, "devices", data) } +func filterOnlineDeviceIDs(devices []*models.Device, ids []string) []string { + online := map[string]bool{} + for _, d := range devices { + if d != nil && d.Online { + online[d.DeviceID] = true + } + } + out := make([]string, 0, len(ids)) + for _, id := range ids { + if online[id] { + out = append(out, id) + } + } + return out +} + func (u *UI) actionDevicesBatchAction(w http.ResponseWriter, r *http.Request) { _ = r.ParseForm() action := strings.TrimSpace(r.FormValue("action")) @@ -1746,6 +1762,8 @@ func (u *UI) actionDevicesBatchAction(w http.ResponseWriter, r *http.Request) { return } deviceIDs := filterSelectedDeviceIDs(u.registry.GetDevices(), r.Form["device_id"]) + // Common filter: remove offline devices for all actions except cleanup_offline + deviceIDs = filterOnlineDeviceIDs(u.registry.GetDevices(), deviceIDs) if len(deviceIDs) == 0 { u.render(w, r, "devices", u.deviceOverviewPageData(r, nil, "请先选择设备")) return