|
|
@@ -52,59 +52,64 @@ public class HardwareDeviceMonitor {
|
|
|
|
|
|
@Scheduled(cron = "0 */9 * * * ?")
|
|
|
public void checkPowerUse() {
|
|
|
- if (dingTalkNotice != null && dingTalkNotice) {
|
|
|
- log.info("【设备监听提醒】 开始执行检查..............");
|
|
|
- ResultData result = remoteLabHardwareService.statistics();
|
|
|
- if (result != null && result.getCode() == HttpStatus.SUCCESS && result.getData() != null) {
|
|
|
- String jsonStr = JSONObject.toJSONString(result.getData());
|
|
|
- JSONObject json = JSONObject.parseObject(jsonStr);
|
|
|
- Integer offline = json.getInteger("powerSupplyOffline");
|
|
|
- log.info("【设备监听提醒】 异常设备掉线数量:" + offline);
|
|
|
- if (offline != null && offline > 0) {
|
|
|
- //获取离线列表
|
|
|
- ResultData data = remoteLabHardwareService.list("SWITCH", "OFFLINE");
|
|
|
- //log.info("【设备监听提醒】 获取异常列表:"+JSONObject.toJSONString(data));
|
|
|
- if (data != null && data.getCode() == HttpStatus.SUCCESS && data.getData() != null) {
|
|
|
- //log.info("【设备监听提醒】 异常设备列表信息:" + data.getData());
|
|
|
- String listStr = JSONObject.toJSONString(data.getData());
|
|
|
- List<Map<String, Object>> list = JSONObject.parseObject(listStr, List.class);
|
|
|
- if (list != null && list.size() > 0) {
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
- for (Map m : list) {
|
|
|
- String code = (String) m.get("relayCode");
|
|
|
- if (!map.containsKey(code)) {
|
|
|
- map.put(code, "---信息[名称:" +
|
|
|
- "" + m.get("name") + ",所在学院:" + m.get("deptName") + ",所在实验室:" + m.get("subjectName") + "]\n");
|
|
|
- }
|
|
|
- }
|
|
|
- //封装消息
|
|
|
- if (!map.isEmpty()) {
|
|
|
- Set<String> code = map.keySet();
|
|
|
- StringBuffer buffer = new StringBuffer();
|
|
|
- buffer.append("系统接入继电器设备离线信息:\n");
|
|
|
- boolean isSend = Boolean.FALSE;
|
|
|
- for (String key : code) {
|
|
|
- Integer num = redisService.getCacheObject(redisPrefix+key);
|
|
|
- if (num != null && num > 2) {
|
|
|
- buffer.append("继电器[" + key + "] " + map.get(key));
|
|
|
- redisService.deleteObject(redisPrefix+key);
|
|
|
- isSend = Boolean.TRUE;
|
|
|
- } else {
|
|
|
- int value = num == null ? 1:num+1;
|
|
|
- redisService.setCacheObject(redisPrefix+key, value, expire, TimeUnit.MINUTES);
|
|
|
+ String lockKey = "electric-relay-monitor";
|
|
|
+ if (!redisService.isExistLock(lockKey)) {
|
|
|
+ //添加锁
|
|
|
+ redisService.lock(lockKey,180);
|
|
|
+ if (dingTalkNotice != null && dingTalkNotice) {
|
|
|
+ ResultData result = remoteLabHardwareService.statistics();
|
|
|
+ if (result != null && result.getCode() == HttpStatus.SUCCESS && result.getData() != null) {
|
|
|
+ String jsonStr = JSONObject.toJSONString(result.getData());
|
|
|
+ JSONObject json = JSONObject.parseObject(jsonStr);
|
|
|
+ Integer offline = json.getInteger("powerSupplyOffline");
|
|
|
+ log.info("【设备监听提醒】 继电器异常监控--掉线数量:" + offline);
|
|
|
+ if (offline != null && offline > 0) {
|
|
|
+ //获取离线列表
|
|
|
+ ResultData data = remoteLabHardwareService.list("SWITCH", "OFFLINE");
|
|
|
+ log.info("【设备监听提醒】 继电器异常监控--获取异常列表:" + JSONObject.toJSONString(data));
|
|
|
+ if (data != null && data.getCode() == HttpStatus.SUCCESS && data.getData() != null) {
|
|
|
+ //log.info("【设备监听提醒】 异常设备列表信息:" + data.getData());
|
|
|
+ String listStr = JSONObject.toJSONString(data.getData());
|
|
|
+ List<Map<String, Object>> list = JSONObject.parseObject(listStr, List.class);
|
|
|
+ if (list != null && list.size() > 0) {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ for (Map m : list) {
|
|
|
+ String code = (String) m.get("relayCode");
|
|
|
+ if (!map.containsKey(code)) {
|
|
|
+ map.put(code, "---信息[名称:" +
|
|
|
+ "" + m.get("name") + ",所在学院:" + m.get("deptName") + ",所在实验室:" + m.get("subjectName") + "]\n");
|
|
|
}
|
|
|
}
|
|
|
- //通知
|
|
|
- if (isSend) {
|
|
|
- String msg = "{\"msgtype\": \"text\",\"text\": {\"content\":\"" + buffer.toString() + "\"}}";
|
|
|
- DingTalkAlert.sendAlert(msg);
|
|
|
- //log.info("【设备监听提醒】 钉钉通知响应:" + rs);
|
|
|
+ //封装消息
|
|
|
+ if (!map.isEmpty()) {
|
|
|
+ Set<String> code = map.keySet();
|
|
|
+ StringBuffer buffer = new StringBuffer();
|
|
|
+ buffer.append("系统接入继电器设备离线信息:\n");
|
|
|
+ boolean isSend = Boolean.FALSE;
|
|
|
+ for (String key : code) {
|
|
|
+ Integer num = redisService.getCacheObject(redisPrefix + key);
|
|
|
+ if (num != null && num > 2) {
|
|
|
+ buffer.append("继电器[" + key + "] " + map.get(key));
|
|
|
+ redisService.deleteObject(redisPrefix + key);
|
|
|
+ isSend = Boolean.TRUE;
|
|
|
+ } else {
|
|
|
+ int value = num == null ? 1 : num + 1;
|
|
|
+ redisService.setCacheObject(redisPrefix + key, value, expire, TimeUnit.MINUTES);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //通知
|
|
|
+ if (isSend) {
|
|
|
+ String resp = DingTalkAlert.sendAlert(buffer.toString());
|
|
|
+ log.info("【设备监听提醒】 继电器异常监控--钉钉通知响应:" + resp);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ //释放锁
|
|
|
+ redisService.unLock(lockKey);
|
|
|
}
|
|
|
}
|
|
|
}
|