add task
This commit is contained in:
@@ -20,7 +20,6 @@ import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* @author liulu
|
||||
@@ -51,27 +50,25 @@ public class DeviceTask implements InitializingBean {
|
||||
if (CollectionUtils.isEmpty(records)) {
|
||||
break;
|
||||
}
|
||||
Executors.newSingleThreadExecutor().execute(() -> {
|
||||
for (Device record : records) {
|
||||
DeviceCheckRes checkRes = tmkService.checkDevice(record);
|
||||
Device up = new Device();
|
||||
up.setId(record.getId());
|
||||
up.setConnected(checkRes.getStatus() != DeviceTmkStatus.device_error);
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if (up.getConnected()) {
|
||||
up.setLastConnectedTime(now);
|
||||
}
|
||||
up.setLastCheckTime(now);
|
||||
|
||||
up.setTmkStatus(checkRes.getStatus().name());
|
||||
up.setDeviceSerial(checkRes.getDeviceSerial());
|
||||
if (!Objects.equals(checkRes.getPubKey(), record.getPubKey())) {
|
||||
up.setPubKey(checkRes.getPubKey());
|
||||
}
|
||||
up.setEncTmk(checkRes.getEncTmk());
|
||||
spDeviceMapper.updateById(up);
|
||||
for (Device record : records) {
|
||||
DeviceCheckRes checkRes = tmkService.checkDevice(record);
|
||||
Device up = new Device();
|
||||
up.setId(record.getId());
|
||||
up.setConnected(checkRes.getStatus() != DeviceTmkStatus.device_error);
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if (up.getConnected()) {
|
||||
up.setLastConnectedTime(now);
|
||||
}
|
||||
});
|
||||
up.setLastCheckTime(now);
|
||||
|
||||
up.setTmkStatus(checkRes.getStatus().name());
|
||||
up.setDeviceSerial(checkRes.getDeviceSerial());
|
||||
if (!Objects.equals(checkRes.getPubKey(), record.getPubKey())) {
|
||||
up.setPubKey(checkRes.getPubKey());
|
||||
}
|
||||
up.setEncTmk(checkRes.getEncTmk());
|
||||
spDeviceMapper.updateById(up);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +76,7 @@ public class DeviceTask implements InitializingBean {
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (Platform.isLinux() || Platform.isWindows()) {
|
||||
threadPoolTaskScheduler.scheduleWithFixedDelay(this::checkDeviceStatus, Duration.ofMinutes(5L));
|
||||
threadPoolTaskScheduler.scheduleWithFixedDelay(tmkService::checkSoftDeviceTmk, Duration.ofMinutes(5L));
|
||||
} else {
|
||||
log.warn("操作系统: {} 不支持启动检查设备状态定时任务", System.getProperty("os.name"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user