fix: 批处理统一过滤离线设备,时间同步跳过无偏差设备
This commit is contained in:
parent
47655b75d2
commit
aa20bdaeb1
@ -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 {
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user