sdf api
This commit is contained in:
@@ -22,4 +22,6 @@ public interface DeviceService {
|
||||
|
||||
void delete(Long id);
|
||||
|
||||
void checkDeviceStatus();
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.sunyard.chsm.dto.DeviceDTO;
|
||||
import com.sunyard.chsm.enums.DeviceTmkStatus;
|
||||
import com.sunyard.chsm.enums.ManufacturerEnum;
|
||||
import com.sunyard.chsm.enums.ManufacturerModelEnum;
|
||||
import com.sunyard.chsm.mapper.SpDeviceMapper;
|
||||
@@ -203,4 +204,37 @@ public class DeviceServiceImpl implements DeviceService {
|
||||
Assert.isNull(exist, "设备名称已存在");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkDeviceStatus() {
|
||||
|
||||
for (int i = 1; i < 500; i++) {
|
||||
Page<Device> devicePage = spDeviceMapper.selectPage(
|
||||
new Page<>(i, 20L),
|
||||
new LambdaQueryWrapper<Device>().orderByAsc(Device::getId)
|
||||
);
|
||||
List<Device> records = devicePage.getRecords();
|
||||
if (CollectionUtils.isEmpty(records)) {
|
||||
break;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,15 @@
|
||||
package com.sunyard.chsm.task;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.sun.jna.Platform;
|
||||
import com.sunyard.chsm.enums.DeviceTmkStatus;
|
||||
import com.sunyard.chsm.mapper.SpDeviceMapper;
|
||||
import com.sunyard.chsm.model.dto.DeviceCheckRes;
|
||||
import com.sunyard.chsm.model.entity.Device;
|
||||
import com.sunyard.chsm.service.DeviceService;
|
||||
import com.sunyard.chsm.service.TmkService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author liulu
|
||||
@@ -29,53 +19,17 @@ import java.util.Objects;
|
||||
@Component
|
||||
public class DeviceTask implements InitializingBean {
|
||||
|
||||
@Resource
|
||||
private SpDeviceMapper spDeviceMapper;
|
||||
@Resource
|
||||
private TmkService tmkService;
|
||||
@Resource
|
||||
private ThreadPoolTaskScheduler threadPoolTaskScheduler;
|
||||
private DeviceService deviceService;
|
||||
@Resource
|
||||
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
||||
|
||||
|
||||
private void checkDeviceStatus() {
|
||||
|
||||
for (int i = 1; i < 500; i++) {
|
||||
Page<Device> devicePage = spDeviceMapper.selectPage(
|
||||
new Page<>(i, 20L),
|
||||
new LambdaQueryWrapper<Device>().orderByAsc(Device::getId)
|
||||
);
|
||||
List<Device> records = devicePage.getRecords();
|
||||
if (CollectionUtils.isEmpty(records)) {
|
||||
break;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
private ThreadPoolTaskScheduler threadPoolTaskScheduler;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (Platform.isLinux() || Platform.isWindows()) {
|
||||
threadPoolTaskScheduler.scheduleWithFixedDelay(this::checkDeviceStatus, Duration.ofMinutes(5L));
|
||||
threadPoolTaskScheduler.scheduleWithFixedDelay(deviceService::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