|
|
@@ -1,9 +1,16 @@
|
|
|
package com.zksy.pressure.utils;
|
|
|
|
|
|
import cn.hutool.core.lang.UUID;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.zksy.api.domain.WarningThreshold;
|
|
|
+import com.zksy.api.service.WarningThresholdService;
|
|
|
+import com.zksy.api.utils.SmsUtil;
|
|
|
import com.zksy.common.exception.InvalidMessageException;
|
|
|
+import com.zksy.pressure.domain.Enum.FirefightingDeviceCodeEnum;
|
|
|
+import com.zksy.pressure.domain.Enum.FirefightingWarningCodeEnum;
|
|
|
import com.zksy.pressure.domain.FirefightingPressure;
|
|
|
import com.zksy.pressure.service.FirefightingPressureService;
|
|
|
+import com.zksy.utils.DevicePhoneFetchUtil;
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
import io.netty.buffer.Unpooled;
|
|
|
import io.netty.channel.ChannelHandler;
|
|
|
@@ -15,6 +22,11 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
@ChannelHandler.Sharable
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
@@ -22,6 +34,12 @@ public class MessageHandler extends ChannelInboundHandlerAdapter {
|
|
|
private static Logger logger = LoggerFactory.getLogger(MessageHandler.class);
|
|
|
private final FirefightingPressureService firefightingPressureService;
|
|
|
@Autowired
|
|
|
+ private WarningThresholdService service;
|
|
|
+ @Autowired
|
|
|
+ private SmsUtil smsUtil;
|
|
|
+ @Autowired
|
|
|
+ private DevicePhoneFetchUtil devicePhoneFetchUtil;
|
|
|
+ @Autowired
|
|
|
public MessageHandler(FirefightingPressureService firefightingPressureService) {
|
|
|
this.firefightingPressureService = firefightingPressureService;
|
|
|
}
|
|
|
@@ -59,6 +77,8 @@ public class MessageHandler extends ChannelInboundHandlerAdapter {
|
|
|
//String addressCode = resultData.getAddressCode();
|
|
|
//DeviceOfflineCheckTask.deviceLastReceiveTimeMap.put(addressCode, new Date());
|
|
|
firefightingPressureService.save(resultData);
|
|
|
+
|
|
|
+ checkIfSmsAlertNeeded(resultData);
|
|
|
}
|
|
|
} catch (InvalidMessageException e) {
|
|
|
logger.error("数据入库失败: {}", e.getMessage());
|
|
|
@@ -115,4 +135,69 @@ public class MessageHandler extends ChannelInboundHandlerAdapter {
|
|
|
logger.error("发送数据失败: {}", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
+ //检查是否会触发短信预警
|
|
|
+ public void checkIfSmsAlertNeeded(FirefightingPressure resultData){
|
|
|
+ try {
|
|
|
+ //用遥测站地址作为设备的设备编号
|
|
|
+ String deviceId = resultData.getTelemeteringStation();
|
|
|
+ //1、获取到压力阈值
|
|
|
+ Double warningValue = null;
|
|
|
+ //1.1获取到设备编码
|
|
|
+ String deviceWarningCode = FirefightingDeviceCodeEnum.FIREFIGHTING_DEVICE.getCode();
|
|
|
+ FirefightingWarningCodeEnum targetWarningType=FirefightingWarningCodeEnum.PRESSURE;
|
|
|
+
|
|
|
+ String warningCode = targetWarningType.getCode();
|
|
|
+ String warningMsg = targetWarningType.getName();
|
|
|
+ try {
|
|
|
+ //1.2根据设备编码获取压力阈值
|
|
|
+ WarningThreshold threshold = service.getWarningThresholdByDeviceAndCode(deviceWarningCode, warningCode);
|
|
|
+ warningValue = threshold.getWarningValue();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询预警阈值失败");
|
|
|
+ }
|
|
|
+ //1.2获取到实际压力值
|
|
|
+ Double pressureValue = resultData.getPressureValue();
|
|
|
+ boolean isOverThreshold = pressureValue > warningValue;
|
|
|
+ //1.3超出了阈值则发送短信,设备编号这里不是很清楚
|
|
|
+ if(isOverThreshold){
|
|
|
+ sendMessage(deviceId,warningMsg,resultData.getLongitude(),resultData.getLatitude());
|
|
|
+ }
|
|
|
+ if(resultData.getD14()==1){
|
|
|
+ sendMessage(deviceId,"压力变幅报警",resultData.getLongitude(),resultData.getLatitude());
|
|
|
+ }
|
|
|
+ if(resultData.getD13()==1){
|
|
|
+ sendMessage(deviceId,"压力下下限报警",resultData.getLongitude(),resultData.getLatitude());
|
|
|
+ }
|
|
|
+ if(resultData.getD12()==1){
|
|
|
+ sendMessage(deviceId,"压力上上限报警",resultData.getLongitude(),resultData.getLatitude());
|
|
|
+ }
|
|
|
+ if(resultData.getD11()==1){
|
|
|
+ sendMessage(deviceId,"压力下线报警",resultData.getLongitude(),resultData.getLatitude());
|
|
|
+ }
|
|
|
+ if(resultData.getD10()==1){
|
|
|
+ sendMessage(deviceId,"压力上限报警",resultData.getLongitude(),resultData.getLatitude());
|
|
|
+ }
|
|
|
+ if(resultData.getD9()==1){
|
|
|
+ sendMessage(deviceId,"传感器状态",resultData.getLongitude(),resultData.getLatitude());
|
|
|
+ }
|
|
|
+ if(resultData.getD1()==1){
|
|
|
+ sendMessage(deviceId,"倾斜报警1",resultData.getLongitude(),resultData.getLatitude());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("设备报警处理失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //构造发送短信参数&&发送短信
|
|
|
+ public void sendMessage(String deviceNo,String alarmType,BigDecimal lng,BigDecimal lat){
|
|
|
+ // 构造短信参数
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
+ params.put("deviceNo", deviceNo);
|
|
|
+ params.put("alarmType", alarmType);
|
|
|
+ // 经纬度处理(为执行信息处理)
|
|
|
+ params.put("location", String.format("经纬度:%.6f,%.8f", lng, lat));
|
|
|
+ List<String> phoneListByDeviceId = devicePhoneFetchUtil.getPhoneListByDeviceId(deviceNo);
|
|
|
+ Map<String, Boolean> sendResults = smsUtil.sendBatchSms(phoneListByDeviceId, params.toJSONString());
|
|
|
+ log.info("发送信息完成");
|
|
|
+ }
|
|
|
}
|