From 0d3187502608ff279f08039e78c33444393b8f51 Mon Sep 17 00:00:00 2001
From: 16639036659 <577530412@qq.com>
Date: Mon, 26 Feb 2024 08:43:51 +0800
Subject: [PATCH] 预警信息-添加内容
---
src/main/java/com/gkhy/fourierSpecialGasMonitor/service/impl/DataReceiveServiceImpl.java | 53 ++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 38 insertions(+), 15 deletions(-)
diff --git a/src/main/java/com/gkhy/fourierSpecialGasMonitor/service/impl/DataReceiveServiceImpl.java b/src/main/java/com/gkhy/fourierSpecialGasMonitor/service/impl/DataReceiveServiceImpl.java
index 6890cd6..ee3ecc3 100644
--- a/src/main/java/com/gkhy/fourierSpecialGasMonitor/service/impl/DataReceiveServiceImpl.java
+++ b/src/main/java/com/gkhy/fourierSpecialGasMonitor/service/impl/DataReceiveServiceImpl.java
@@ -40,10 +40,7 @@
import java.text.MessageFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
@@ -115,8 +112,13 @@
private static final String warnContentFormat = "【气体监测预警提示】{0} {1}气体浓度连续超标系统判断为{2},请相关负责人及时检查处置。";
+ private static final String deviceExcLogFormat = "【设备预警提示】{0} 硬件设备离线。";
+
+ private static final DateTimeFormatter deviceExcLogFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
+
private static final DateTimeFormatter warnLogFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
+ private static final String[] DEVICE_EXC_RECEIVER = {"17625323889","18019908965"};
@PostConstruct
public void init() {
@@ -168,6 +170,9 @@
return ForeignResult.success();
}
+ /**
+ * 设备预警
+ * */
@Override
public ForeignResult deviceMonitor(DeviceMonitorReqDTO reqDTO) {
if (reqDTO == null)
@@ -180,7 +185,7 @@
throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"通量数据状态不能为空");
Boolean push = false;
List<String> descs = new ArrayList<>();
- if (reqDTO.getHardwareState().size() > 1){
+ if (!(reqDTO.getHardwareState().size() == 1 && reqDTO.getHardwareState().get(0) == 0)){
push = true;
for (int i = 0; i < reqDTO.getHardwareState().size(); i++) {
descs.add(HardwareStateEnum.getValue(reqDTO.getHardwareState().get(i)));
@@ -202,24 +207,39 @@
logger.info("【警告】设备异常提醒推送>>>>>>>>>>>>>>>>>>失败");
}
if (push){
- //todo 线上环境还是异常才向前端推送
- //String message = JSON.toJSONString(reqDTO);
- //try {
- // GasDeviceExcWebsocketServer.sendInfo(message,null);
- //} catch (IOException e) {
- // logger.info("【警告】设备异常提醒推送>>>>>>>>>>>>>>>>>>失败");
- //}
+ DeviceExceptionLog lastLog = deviceExceptionLogService.getLastLog();
+ LocalDateTime now = LocalDateTime.now();
+ if (lastLog == null || now.compareTo(lastLog.getTime().plusHours(1)) >= 0) {
+ Map<String, String> mesMap = new HashMap<>();
+ mesMap.put("message","数据异常,无法进行监测");
+ mesMap.put(" level","设备离线");
+ //// TODO: 2024/2/22
+ List<String> deviceExcReceiver = Arrays.asList(DEVICE_EXC_RECEIVER);
+ if (!CollectionUtils.isEmpty(deviceExcReceiver)) {
+ List<String> distinctPhone = deviceExcReceiver.stream().distinct().collect(Collectors.toList());
+ logger.info("【气体浓度异常短信发送】-----发送内容:" + "克拉玛依富城数据异常,无法进行监测 气体浓度连续超标,系统判断为设备离线,请相关负责人及时检查处置。"
+ + " 发送时间: " + LocalDateTime.now()+ " 接收人手机号:" + distinctPhone);
+ if (!org.springframework.util.StringUtils.isEmpty(smsSendEnabledStatus) && "true".equals(smsSendEnabledStatus)) {
+ sendMessageUtil.sendMessageCheck(deviceExcReceiver.toArray(new String[deviceExcReceiver.size()]), mesMap);
+ }
+ }
+ }
String execInfo = JSON.toJSONString(descs);
logger.info("【警告】设备异常,异常原因: "+ execInfo);
DeviceExceptionLog log = new DeviceExceptionLog();
- log.setTime(LocalDateTime.now());
+ String content = MessageFormat.format(deviceExcLogFormat,deviceExcLogFormatter.format(now));
+ log.setContent(content);
+ log.setTime(now);
log.setExecDesc(execInfo);
DeviceExceptionLog save = deviceExceptionLogService.save(log);
- if (save == null)
+ if (save == null) {
logger.info("【警告】设备异常日志保存>>>>>>>>>>>>>>>>>>失败");
+ }
+
}
return ForeignResult.success();
}
+
private void gasFluxDataCacheAndPush(){
LocalDateTime time = LocalDateTime.now();
@@ -309,6 +329,9 @@
}
}
+ /**
+ * 气体数据--预警信息推送
+ * */
private void warnLogGenerateAndExecPush(Integer warnThresholdEnumCode,GasCategory gasCategory,Double value){
if (gasCategory == null)
throw new DataReceiveException(this.getClass(), ForeignResultCode.SYSTEM_ERROR_DATABASE_FAIL.getCode(),"该气体不存在于对照表");
@@ -353,7 +376,7 @@
throw new DataReceiveException(this.getClass(), ForeignResultCode.SYSTEM_ERROR_DATABASE_FAIL.getCode(),"预警异常短信接收人保存失败");
Map<String, String> mesMap = new HashMap<>();
mesMap.put("message",warnTime+" "+gasCategory.getName());
- mesMap.put("level",warnThresholdName);
+ mesMap.put(" level",warnThresholdName);
//todo
if (!CollectionUtils.isEmpty(phone)) {
List<String> distinctPhone = phone.stream().distinct().collect(Collectors.toList());
--
Gitblit v1.9.2