1.代码优化
This commit is contained in:
@@ -105,17 +105,17 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
executeMainTask(scheduler,nDid,version);
|
||||
}
|
||||
//自动接入
|
||||
else if (expiredKey.startsWith("autoAccess")) {
|
||||
List<CsEquipmentDeliveryPO> list = csEquipmentDeliveryService.getAll();
|
||||
list.forEach(item->{
|
||||
String version = csTopicService.getVersion(item.getNdid());
|
||||
if (!Objects.isNull(version)){
|
||||
csDeviceService.devAccessAskTemplate(item.getNdid(),version,1);
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + item.getNdid(),1);
|
||||
}
|
||||
});
|
||||
}
|
||||
// //自动接入
|
||||
// else if (expiredKey.startsWith("autoAccess")) {
|
||||
// List<CsEquipmentDeliveryPO> list = csEquipmentDeliveryService.getAll();
|
||||
// list.forEach(item->{
|
||||
// String version = csTopicService.getVersion(item.getNdid());
|
||||
// if (!Objects.isNull(version)){
|
||||
// csDeviceService.devAccessAskTemplate(item.getNdid(),version,1);
|
||||
// redisUtil.saveByKey(AppRedisKey.DEVICE_MID + item.getNdid(),1);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
}
|
||||
|
||||
//主任务
|
||||
@@ -147,15 +147,17 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}
|
||||
//客户端不在线则修改装置状态,进入定时任务
|
||||
else {
|
||||
//装置下线
|
||||
csEquipmentDeliveryService.updateRunStatusBynDid(nDid, AccessEnum.OFFLINE.getCode());
|
||||
logDto.setOperate("主任务执行失败,装置下线,进入定时任务");
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
log.info("客户端离线进入定时任务...");
|
||||
startScheduledTask(scheduler,nDid,version);
|
||||
logDto.setOperate(nDid + "客户端离线进入定时任务");
|
||||
}
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}
|
||||
|
||||
private void startScheduledTask(ScheduledExecutorService scheduler, String nDid, String version) {
|
||||
@@ -212,7 +214,7 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
onlineLogsService.updateById(record);
|
||||
}
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}, 0, 2, TimeUnit.MINUTES);
|
||||
}, 0, 2, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package com.njcn.access.runner;
|
||||
|
||||
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||
import com.njcn.access.service.ICsTopicService;
|
||||
import com.njcn.access.service.impl.CsDeviceServiceImpl;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
@@ -7,6 +12,11 @@ import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 类的介绍:用来重新发起设备的接入,存在程序意外停止了,缓存失效导致无法更新装置的状态,所以需要在程序启动时发起设备的接入
|
||||
@@ -21,10 +31,30 @@ public class AccessApplicationRunner implements ApplicationRunner {
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||
@Resource
|
||||
private ICsTopicService csTopicService;
|
||||
@Resource
|
||||
private CsDeviceServiceImpl csDeviceService;
|
||||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
private static final long ACCESS_TIME = 60L;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
redisUtil.saveByKeyWithExpire("autoAccess",null,60L);
|
||||
//项目启动60s后发起自动接入
|
||||
Runnable task = () -> {
|
||||
List<CsEquipmentDeliveryPO> list = csEquipmentDeliveryService.getAll();
|
||||
list.forEach(item->{
|
||||
String version = csTopicService.getVersion(item.getNdid());
|
||||
if (!Objects.isNull(version)){
|
||||
csDeviceService.devAccessAskTemplate(item.getNdid(),version,1);
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + item.getNdid(),1);
|
||||
}
|
||||
});
|
||||
};
|
||||
scheduler.schedule(task, ACCESS_TIME, TimeUnit.SECONDS);
|
||||
// 关闭调度程序
|
||||
scheduler.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
package com.njcn.zlevent.init;
|
||||
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*
|
||||
* 程序重启设置任务,消费历史录波文件
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class InitEventFiles implements CommandLineRunner {
|
||||
|
||||
private final RedisUtil redisUtil;
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
redisUtil.saveByKeyWithExpire("startFile",null,120L);
|
||||
}
|
||||
}
|
||||
//package com.njcn.zlevent.init;
|
||||
//
|
||||
//import com.njcn.redis.utils.RedisUtil;
|
||||
//import lombok.AllArgsConstructor;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.boot.CommandLineRunner;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * @author xy
|
||||
// *
|
||||
// * 程序重启设置任务,消费历史录波文件
|
||||
// */
|
||||
//@Slf4j
|
||||
//@Component
|
||||
//@AllArgsConstructor
|
||||
//public class InitEventFiles implements CommandLineRunner {
|
||||
//
|
||||
// private final RedisUtil redisUtil;
|
||||
//
|
||||
// @Override
|
||||
// public void run(String... args) {
|
||||
// redisUtil.saveByKeyWithExpire("startFile",null,120L);
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -11,7 +11,6 @@ import com.njcn.access.pojo.dto.file.FileRedisDto;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.stat.enums.StatResponseEnum;
|
||||
@@ -99,17 +98,17 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
downloadFile(missingList,dto.getNDid(),fileName);
|
||||
}
|
||||
}
|
||||
//项目重启或者接入,经过120s开始处理历史录波文件
|
||||
else if (expiredKey.startsWith("startFile")) {
|
||||
List<CsEquipmentDeliveryPO> list = equipmentFeignClient.getAll().getData();
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
list.forEach(item->{
|
||||
redisUtil.delete("handleEvent:" + item.getNdid());
|
||||
//处理缓存数据
|
||||
csWaveAnalysisService.channelWave(item.getNdid());
|
||||
});
|
||||
}
|
||||
}
|
||||
// //项目重启或者接入,经过120s开始处理历史录波文件
|
||||
// else if (expiredKey.startsWith("startFile")) {
|
||||
// List<CsEquipmentDeliveryPO> list = equipmentFeignClient.getAll().getData();
|
||||
// if (CollectionUtil.isNotEmpty(list)) {
|
||||
// list.forEach(item->{
|
||||
// redisUtil.delete("handleEvent:" + item.getNdid());
|
||||
// //处理缓存数据
|
||||
// csWaveAnalysisService.channelWave(item.getNdid());
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
//手动文件下载
|
||||
else if (expiredKey.startsWith(AppRedisKey.FILE_DOWN_TIME)) {
|
||||
List<Integer> missingList = new ArrayList<>();
|
||||
@@ -205,11 +204,11 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
*/
|
||||
public void webSendNextStep(String fileName, String id, int mid,int step) {
|
||||
try {
|
||||
for (int i = 1; i <= 30; i++) {
|
||||
for (int i = 1; i <= 15; i++) {
|
||||
if (step == 0 ){
|
||||
Thread.sleep(5000);
|
||||
Thread.sleep(8000);
|
||||
} else {
|
||||
Thread.sleep(2000);
|
||||
Thread.sleep(4000);
|
||||
}
|
||||
FileRedisDto fileRedisDto = (FileRedisDto) redisUtil.getObjectByKey(AppRedisKey.DOWNLOAD + fileName + mid);
|
||||
if (Objects.isNull(fileRedisDto)) {
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.njcn.zlevent.runner;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.zlevent.service.ICsWaveAnalysisService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 类的介绍:项目重启或者接入,经过120s开始处理历史录波文件
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2024/9/18 13:57
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ZlEventApplicationRunner implements ApplicationRunner {
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private EquipmentFeignClient equipmentFeignClient;
|
||||
@Resource
|
||||
private ICsWaveAnalysisService csWaveAnalysisService;
|
||||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
private static final long EVENT_TIME = 120L;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
//项目启动120s后开始消费缓存的波形文件
|
||||
Runnable task = () -> {
|
||||
log.info("开始消费缓存的波形文件");
|
||||
List<CsEquipmentDeliveryPO> list = equipmentFeignClient.getAll().getData();
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
list.forEach(item->{
|
||||
redisUtil.delete("handleEvent:" + item.getNdid());
|
||||
//处理缓存数据
|
||||
csWaveAnalysisService.channelWave(item.getNdid());
|
||||
});
|
||||
}
|
||||
};
|
||||
scheduler.schedule(task, EVENT_TIME, TimeUnit.SECONDS);
|
||||
// 关闭调度程序
|
||||
scheduler.shutdown();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user