debug:设备启动更新设备状态

This commit is contained in:
墨大叔 2024-09-21 17:38:46 +08:00
parent ddb0b75468
commit 7ff418ef44
3 changed files with 27 additions and 27 deletions

View File

@ -579,23 +579,23 @@ public class DeviceServiceImpl implements DeviceService
this.pullDeviceInfoAsync(Collections.singletonList(deviceId), 3, TimeUnit.SECONDS); this.pullDeviceInfoAsync(Collections.singletonList(deviceId), 3, TimeUnit.SECONDS);
// 时长结束后修改设备状态 // 时长结束后修改设备状态
scheduledExecutorService.schedule(()-> { // scheduledExecutorService.schedule(()-> {
freshStatus(deviceId); // freshStatus(deviceId);
}, seconds, TimeUnit.SECONDS); // }, seconds, TimeUnit.SECONDS);
} }
return success; return success;
} }
private void freshStatus(Long deviceId) { // private void freshStatus(Long deviceId) {
DeviceVO device = deviceMapper.selectSmDeviceByDeviceId(deviceId); // DeviceVO device = deviceMapper.selectSmDeviceByDeviceId(deviceId);
freshStatus(device); // freshStatus(device);
} // }
@Override @Override
public void freshStatus(DeviceVO device) { public void freshStatus(DeviceVO device) {
if (device == null) { if (device == null || device.getExpireTime() == null) {
return; return;
} }
if (!DeviceStatus.USING.getStatus().equals(device.getStatus())) { if (!DeviceStatus.USING.getStatus().equals(device.getStatus())) {
@ -610,12 +610,12 @@ public class DeviceServiceImpl implements DeviceService
return; return;
} }
// 如果没有过期则延迟至过期时间继续查询 // // 如果没有过期则延迟至过期时间继续查询
if (between.getSeconds() > 0) { // if (between.getSeconds() > 0) {
scheduledExecutorService.schedule(() -> { // scheduledExecutorService.schedule(() -> {
freshStatus(device.getDeviceId()); // freshStatus(device.getDeviceId());
}, between.getSeconds() , TimeUnit.SECONDS); // }, between.getSeconds() , TimeUnit.SECONDS);
} // }
} }
/** /**

View File

@ -31,18 +31,18 @@ public class DeviceStatusTask implements ApplicationRunner {
*/ */
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
log.info("项目启动,查询正在使用中的设备"); // log.info("项目启动,查询正在使用中的设备");
DeviceQuery query = new DeviceQuery(); // DeviceQuery query = new DeviceQuery();
query.setStatus(DeviceStatus.USING.getStatus()); // query.setStatus(DeviceStatus.USING.getStatus());
List<DeviceVO> list = deviceService.selectSmDeviceList(query); // List<DeviceVO> list = deviceService.selectSmDeviceList(query);
if (CollectionUtils.isEmptyElement(list)) { // if (CollectionUtils.isEmptyElement(list)) {
log.info("没有正在使用中的设备"); // log.info("没有正在使用中的设备");
return; // return;
} // }
//
for (DeviceVO device : list) { // for (DeviceVO device : list) {
deviceService.freshStatus(device); // deviceService.freshStatus(device);
} // }
} }
} }

View File

@ -33,7 +33,7 @@ wx:
# 设备配置 # 设备配置
device: device:
# 项目启动时抄表 # 项目启动时抄表
startRecord: true startRecord: false
spring: spring:
# redis 配置 # redis 配置