Commit 28db3b8a authored by 赵啸非's avatar 赵啸非

添加告警统计信息

parent 17a72034
......@@ -32,6 +32,7 @@ import com.mortals.xhx.busiz.rsp.*;
import com.mortals.xhx.common.code.*;
import com.mortals.xhx.common.key.Constant;
import com.mortals.xhx.common.key.QueueKey;
import com.mortals.xhx.common.key.RedisKey;
import com.mortals.xhx.common.model.DefaultTbQueueMsgHeaders;
import com.mortals.xhx.common.model.MessageHeader;
import com.mortals.xhx.common.pdu.RespData;
......@@ -231,7 +232,10 @@ public class DeviceApiController {
deviceEntity.setOnlineTime(new Date());
deviceEntity.setDeviceStatus(DeviceStatusEnum.在线.getValue());
deviceEntity.setDeviceVersion(req.getDeviceVersion() == null ? "" : req.getDeviceVersion());
deviceService.getDeviceDao().update(deviceEntity);
//todo 延迟队列更新 此时进入redis 队列
cacheService.rpush(RedisKey.KEY_DEVICE_ONLINE_QUEUE,deviceEntity);
//deviceService.getDeviceDao().update(deviceEntity);
rsp.setData(deviceResp);
SendThirdPartyTask sendThirdPartyTask = new SendThirdPartyTask(deviceEntity, productEntity, platformEntity, deviceService);
sendTaskThreadPool.execute(sendThirdPartyTask);
......
......@@ -15,6 +15,10 @@ public class RedisKey {
public static final String KEY_DEVICE_ONLINE_CACHE = "device:online:";
/**
* 设备上线更新队列
*/
public static final String KEY_DEVICE_ONLINE_QUEUE = "device:online:queue";
public static final String KEY_SITE_CACHE = "siteDict";
......
......@@ -10,7 +10,6 @@ import com.mortals.xhx.module.device.service.DeviceModuleUseService;
import com.mortals.xhx.module.device.service.DeviceService;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Date;
......@@ -25,7 +24,7 @@ import java.util.stream.Collectors;
* @date: 2022/3/9 15:19
*/
@CommonsLog
@Service("DeviceModuleUseTask")
//@Service("DeviceModuleUseTask")
public class DeviceModuleUseTaskImpl implements ITaskExcuteService {
@Autowired
......
......@@ -19,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
......@@ -41,11 +42,25 @@ public class DeviceStatTaskImpl implements ITaskExcuteService {
@Override
public void excuteTask(ITask task) throws AppException {
log.info("设备状态修正任务");
List<DeviceEntity> waitDeviceInfos = new ArrayList<>();
while (true) {
DeviceEntity deviceEntity = cacheService.lpop(RedisKey.KEY_DEVICE_ONLINE_QUEUE, DeviceEntity.class);
if (ObjectUtils.isEmpty(deviceEntity)) {
break;
} else {
waitDeviceInfos.add(deviceEntity);
}
}
if (!ObjectUtils.isEmpty(waitDeviceInfos)) {
deviceService.update(waitDeviceInfos);
}
//获取所有在线设备
List<DeviceEntity> deviceList = deviceService.find(new DeviceQuery().deviceStatus(DeviceStatusEnum.在线.getValue()));
//更新离线
List<DeviceEntity> deviceOfflineList = deviceList.parallelStream().map(item -> {
if(ObjectUtils.isEmpty(item.getDeviceCode())) return null;
if (ObjectUtils.isEmpty(item.getDeviceCode())) return null;
boolean exists = cacheService.exists(RedisKey.KEY_DEVICE_ONLINE_CACHE + item.getDeviceCode());
if (!exists) {
item.setDeviceStatus(DeviceStatusEnum.离线.getValue());
......@@ -53,10 +68,10 @@ public class DeviceStatTaskImpl implements ITaskExcuteService {
return item;
}
return null;
}).filter(f -> f!=null).collect(Collectors.toList());
}).filter(f -> f != null).collect(Collectors.toList());
if (!ObjectUtils.isEmpty(deviceOfflineList)) {
log.info("修正设备数量:size:{}",deviceOfflineList.size());
log.info("修正设备数量:size:{}", deviceOfflineList.size());
deviceService.update(deviceOfflineList);
deviceOfflineList.forEach(deviceEntity -> {
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment