|
@@ -7,15 +7,21 @@ import com.xy.dto.nfc.UpperDeviceStatusDTO;
|
|
|
import com.xy.entity.DeviceInfo;
|
|
|
import com.xy.entity.DeviceNetWorkSpi;
|
|
|
import com.xy.entity.DeviceSysinfo;
|
|
|
+import com.xy.entity.SysDictRedis;
|
|
|
import com.xy.event.DeviceEvent;
|
|
|
import com.xy.service.*;
|
|
|
+import com.xy.utils.RedisService;
|
|
|
import com.xy.utils.SpiUtils;
|
|
|
+import com.xy.utils.SysDictUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.context.event.EventListener;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
/**
|
|
|
* 设备网络状态事件监听
|
|
|
*/
|
|
@@ -34,6 +40,8 @@ public class DeviceNetWorkEventListener {
|
|
|
|
|
|
private DeviceInfoServiceImpl deviceInfoService;
|
|
|
|
|
|
+ private RedisService<Integer> redisService;
|
|
|
+
|
|
|
/**
|
|
|
* 上报状态
|
|
|
*
|
|
@@ -76,6 +84,29 @@ public class DeviceNetWorkEventListener {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 告警消息处理
|
|
|
+ *
|
|
|
+ * @param netWorkEvent
|
|
|
+ */
|
|
|
+ @EventListener
|
|
|
+ public void msgHandle(DeviceEvent.NetWorkEvent netWorkEvent) {
|
|
|
+ String key = "device:offline:" + netWorkEvent.getValue();
|
|
|
+ if (netWorkEvent.getNetState() == 1) {
|
|
|
+ //在线
|
|
|
+ redisService.remove(key);
|
|
|
+ } else {
|
|
|
+ //离线
|
|
|
+ int minutes = 60;
|
|
|
+ Map<String, SysDictRedis> map = SysDictUtils.get("device_offline_time_code");
|
|
|
+ if (map != null) {
|
|
|
+ minutes = Integer.parseInt(map.get("minutes").getValue());
|
|
|
+ }
|
|
|
+ redisService.set(key, 0);
|
|
|
+ redisService.timeout(key, minutes, TimeUnit.MINUTES);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* spi推送
|
|
|
*
|