Browse Source

报警专项边缘端优化

zhangqiankun 3 years ago
parent
commit
ea9c3cdaba

+ 37 - 12
src/main/java/com/persagy/cache/AlarmInfoCache.java

@@ -1,22 +1,23 @@
 package com.persagy.cache;
 
 
-import cn.hutool.core.collection.CollectionUtil;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
 import com.alibaba.fastjson.JSONObject;
 import com.googlecode.aviator.AviatorEvaluator;
-import com.googlecode.aviator.Expression;
 import com.persagy.entity.AlarmDefine;
 import com.persagy.entity.AlarmState;
 import com.persagy.entity.Condition;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-import org.springframework.util.CollectionUtils;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.stream.Collectors;
+import cn.hutool.core.collection.CollectionUtil;
+import lombok.extern.slf4j.Slf4j;
 
 /**
  * @description: 报警存放报警定义缓存的的数据
@@ -169,14 +170,14 @@ public class AlarmInfoCache {
         String trigger = condition.getTrigger();
         String end = condition.getEnd();
         try {
-            Expression triggerCompiledExp = AviatorEvaluator.compile(trigger, true);
+			AviatorEvaluator.compile(trigger, true);
         } catch (Exception e) {
             log.info("触发表达式:", trigger);
             log.error("触发表表达式不合法,请校验", e);
             throw new IllegalArgumentException("触发表表达式不合法", e);
         }
         try {
-            Expression endCompiledExp = AviatorEvaluator.compile(end, true);
+            AviatorEvaluator.compile(end, true);
         } catch (Exception e) {
             log.error("恢复表达式:", end);
             log.error("恢复表达式不合法,请校验", e);
@@ -196,6 +197,30 @@ public class AlarmInfoCache {
     }
 
     /**
+     * 隔离或取消隔离报警规则信息
+     * 
+     * @param alarmConfig
+     * @date 2022年2月16日 下午4:26:15
+     */
+    public void isolationAlarmDefinitionById(JSONObject alarmConfig) {
+    	String defineId = getAlarmDefineId(alarmConfig);
+    	AlarmDefine alarmDefine = this.alarmDefineMap.get(defineId);
+    	if (alarmDefine == null) {
+			return;
+		}
+    	alarmDefine.setOpen(alarmConfig.getIntValue("open"));
+    	
+    	JSONObject condition = alarmConfig.getJSONObject("condition");
+    	if (condition != null) {
+    		JSONObject effectTime = condition.getJSONObject("effectTime");
+    		if (effectTime != null) {
+    			alarmDefine.getCondition().setEffectTime(effectTime);
+			}
+		}
+    	
+    }
+    
+    /**
      * @param meterId: 表号
      * @param funcId:  功能号
      * @description:根据表号功能号获取多条报警定义id

+ 1 - 2
src/main/java/com/persagy/entity/AlarmDefine.java

@@ -1,11 +1,10 @@
 package com.persagy.entity;
 
 import com.alibaba.fastjson.JSONObject;
+
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
-import javax.persistence.Transient;
-
 /**
  * @description:
  * @author:LuoGuangyi

+ 7 - 8
src/main/java/com/persagy/entity/Condition.java

@@ -1,11 +1,10 @@
 package com.persagy.entity;
 
+import java.util.List;
+
 import com.alibaba.fastjson.JSONObject;
-import io.swagger.annotations.ApiModelProperty;
-import lombok.Data;
 
-import java.time.LocalDateTime;
-import java.util.List;
+import lombok.Data;
 
 /**
  * @description:报警定义条件
@@ -56,11 +55,11 @@ public class Condition {
     /**
      * 抑制时间以分钟为单位
      */
-    @ApiModelProperty(value = "抑制时间以分钟为单位")
-    private Long restraintTime;
+    //@ApiModelProperty(value = "抑制时间以分钟为单位")
+    //private Long restraintTime;
 
-    @ApiModelProperty(value = "抑制时间,误报操作时间+抑制时间")
-    private LocalDateTime realRestraintTime;
+    //@ApiModelProperty(value = "抑制时间,误报操作时间+抑制时间")
+    //private LocalDateTime realRestraintTime;
 
     @Override
     public String toString() {

+ 7 - 2
src/main/java/com/persagy/netty/client/CenterClientHandler.java

@@ -141,7 +141,7 @@ public class CenterClientHandler extends SimpleChannelInboundHandler<NettyMessag
                 alarmDefineService.deleteAlarmDefine(definesList);
             }
         } else if (msg.getOpCode() == 11) {
-            //更新隔离的系统对象
+            // 更新隔离的系统对象
             NettyMessage<String> AlarmDefineMessage = JSONObject.parseObject(msg.toString(), new TypeReference<NettyMessage<String>>() {
             });
             List<String> isolationSystemList = AlarmDefineMessage.getContent();
@@ -149,10 +149,15 @@ public class CenterClientHandler extends SimpleChannelInboundHandler<NettyMessag
                 AlarmInfoCache.isolationSystemList = isolationSystemList;
             }
         } else if (msg.getOpCode() == 12) {
-            //云端更新报警记录状态
+            // 云端更新报警记录状态
             NettyMessage<JSONObject> AlarmStateMessage = JSONObject.parseObject(msg.toString(), new TypeReference<NettyMessage<JSONObject>>() {});
             List<JSONObject> stateList = AlarmStateMessage.getContent();
             alarmDefineService.updateAlarmDefine(stateList);
+        } else if (msg.getOpCode() == 13) {
+            // 报警隔离或取消隔离
+            NettyMessage<JSONObject> alarmConfigMessage = JSONObject.parseObject(msg.toString(), new TypeReference<NettyMessage<JSONObject>>() {});
+            List<JSONObject> alarmConfigs = alarmConfigMessage.getContent();
+            alarmDefineService.isolationAlarmDefine(alarmConfigs);
         }
         NettyMessage response = new NettyMessage(3);
         response.setRemark("已经收到消息");

+ 4 - 0
src/main/java/com/persagy/netty/collect/ReturnDifferentAlarm.java

@@ -143,6 +143,10 @@ public class ReturnDifferentAlarm {
 			String dataTime = split[0];
 			String meter = split[1];
 			String funcid = split[2];
+			String valueStr = split[3];
+			if (StrUtil.isBlank(valueStr)) {
+				return;
+			}
 			BigDecimal dataValue = new BigDecimal(split[3]);
 			
 			// 根据表号和功能号判断是否需要进行控返不一致的报警验证

+ 9 - 0
src/main/java/com/persagy/service/AlarmDefineService.java

@@ -22,4 +22,13 @@ public interface AlarmDefineService {
     void updateAlarmDefine(List<JSONObject> alarmDefineList);
 
     void updateAlarmDefine();
+
+    /**
+     * 隔离或取消隔离报警信息
+     * 
+     * @param alarmConfigs
+     * @date 2022年2月16日 下午4:21:12
+     */
+	void isolationAlarmDefine(List<JSONObject> alarmConfigs);
+	
 }

+ 21 - 59
src/main/java/com/persagy/service/impl/AlarmDefineServiceImpl.java

@@ -1,7 +1,11 @@
 package com.persagy.service.impl;
 
-import cn.hutool.core.collection.CollectionUtil;
-import cn.hutool.core.util.ObjectUtil;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
 import com.alibaba.fastjson.JSONObject;
 import com.persagy.cache.AlarmInfoCache;
 import com.persagy.entity.AlarmDefine;
@@ -11,12 +15,10 @@ import com.persagy.entity.ZktAlarmRecordDO;
 import com.persagy.job.ExpireAlarmQueue;
 import com.persagy.repository.AlarmRecordRepository;
 import com.persagy.service.AlarmDefineService;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
 
-import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.ObjectUtil;
+import lombok.extern.slf4j.Slf4j;
 
 /**
  * @description:报警定义逻辑实现类(项目报警定义全量获取,报警定义添加修改删除同步更新)
@@ -28,63 +30,16 @@ import java.util.concurrent.ConcurrentHashMap;
 @Slf4j
 @Service
 public class AlarmDefineServiceImpl implements AlarmDefineService {
-    @Autowired
+    
+	@Autowired
     AlarmInfoCache alarmInfoCache;
-    @Autowired
+    
+	@Autowired
     AlarmRecordRepository alarmRecordRepository;
 
     @Override
     public List listAllAlarmDefine(List<AlarmDefine> alarmDefineList) {
-//        String ad = "{\n" +
-//                "    \"streamId\": \"\",\n" +
-//                "    \"opCode\": \"\",\n" +
-//                "    \"content\": [\n" +
-//                "        {\n" +
-//                "            \"id\": 1,\n" +
-//                "            \"objId\": \"obj1\",\n" +
-//                "            \"itemCode\": \"1055\",\n" +
-//                "            \"projectId\": \"xxx\",\n" +
-//                "            \"name\": \"室内高温\",\n" +
-//                "            \"dealFunc\": \"point\",\n" +
-//                "            \"category\": \"环境报警\",\n" +
-//                "            \"level\": \"B\",\n" +
-//                "            \"remark\": \"我是备注哈\",\n" +
-//                "            \"open\": 1,\n" +
-//                "            \"condition\": {\n" +
-//                "                \"infoCode\": [\n" +
-//                "                    \"$infoCode1\",\n" +
-//                "                    \"$infoCode1\"\n" +
-//                "                ],\n" +
-//                "                \"infoCodeId\": [\n" +
-//                "                    {\n" +
-//                "                        \"infoCode\": \"infoCode1\",\n" +
-//                "                        \"meterId\": \"11\",\n" +
-//                "                        \"funcId\": \"12\"\n" +
-//                "                    },\n" +
-//                "                    {\n" +
-//                "                        \"infoCode\": \"infoCode2\",\n" +
-//                "                        \"meterId\": \"21\",\n" +
-//                "                        \"funcId\": \"22\"\n" +
-//                "                    }\n" +
-//                "                ],\n" +
-//                "                \"trigger\": \"($infoCode1 > 10 && $infoCode1 < 20) && ($infoCode2 < 20)\",\n" +
-//                "                \"end\": \"!($infoCode1 < 20 && $infoCode1 > 10)\",\n" +
-//                "                \"$triggerUphold\": 10,\n" +
-//                "                \"$endUphold\": 5,\n" +
-//                "                \"$time\": {\n" +
-//                "                    \"type\": \"period\",\n" +
-//                "                    \"period\": {\n" +
-//                "                        \"$gt\": \"090000\",\n" +
-//                "                        \"$lt\": \"210000\"\n" +
-//                "                    }\n" +
-//                "                }\n" +
-//                "            }\n" +
-//                "        }\n" +
-//                "    ]\n" +
-//                "}";
-//        NettyMessage<AlarmDefine> message = JSONObject.parseObject(ad,  new TypeReference<NettyMessage<AlarmDefine>>(){});
-//        List<AlarmDefine> alarmDefineList =message.getContent();
-        alarmInfoCache.clearAllAlarmDefine();
+    	alarmInfoCache.clearAllAlarmDefine();
         for (AlarmDefine alarmDefine : alarmDefineList) {
             alarmInfoCache.putAlarmDefinitionById(alarmDefine);
         }
@@ -189,4 +144,11 @@ public class AlarmDefineServiceImpl implements AlarmDefineService {
         }
     }
 
+	@Override
+	public void isolationAlarmDefine(List<JSONObject> alarmConfigs) {
+		for (JSONObject alarmConfig : alarmConfigs) {
+			alarmInfoCache.isolationAlarmDefinitionById(alarmConfig);
+        }
+	}
+
 }

+ 9 - 8
src/main/java/com/persagy/service/impl/AlarmHandleServiceImpl.java

@@ -94,12 +94,13 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
             String dateTime = split[i * 4];
             String meterId = split[i * 4 + 1];
             String funcId = split[i * 4 + 2];
-            double value = Double.parseDouble(split[i * 4 + 3]);
-
-            if (alarmInfoCache.hasKey(meterId, funcId)) {
-                validIotData(dateTime, meterId, funcId, value);
-            }
-
+            String valueStr = split[i * 4 + 3];
+            if (StrUtil.isNotBlank(valueStr)) {
+            	double value = Double.parseDouble(valueStr);
+                if (alarmInfoCache.hasKey(meterId, funcId)) {
+                    validIotData(dateTime, meterId, funcId, value);
+                }
+			}
         }
     }
 
@@ -114,11 +115,11 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
                 boolean match = codeDetail.stream().allMatch(p -> currentDataCache.hasKey(p.getString("meterId"), p.getString("funcId")));
                 //报警定义的所有信息点都有采集数值,具备判断条件
                 if (match) {
-                    if(condition.getRealRestraintTime()!=null) {
+                    /*if(condition.getRealRestraintTime()!=null) {
                         if (condition.getRealRestraintTime().compareTo(LocalDateTime.now()) > 0) {
                             continue;
                         }
-                    }
+                    }*/
                     String trigger = condition.getTrigger();
                     String end = condition.getEnd();
                     HashMap paramMap = new HashMap<>();

+ 43 - 24
src/main/resources/application-XGPj5001120003.yml

@@ -1,24 +1,43 @@
-group:
-  #需要更改
-  code: XG   #标识哪个接团 比如万达使用WD
-  alarm:
-    #需要更改
-    host: 127.0.0.1 #39.102.43.179  #netty IP
-    #需要更改
-    port: 9986          #netty 端口8826
-    #需要更改
-terminal: #边缘端IOT采集程序地址
-  alarm: # 拼接后的地址为ws://host:port/suffix
-    #需要更改
-    compress: false    #采用的是压缩方式还是不压缩方式  true-压缩 false-不压缩
-    #需要更改
-    host: 192.168.64.16
-    #需要更改
-    port: 8852 #9989
-    #需要更改
-    suffix: websocket   #websocker后缀
-project:
-  #需要更改
-  iotid: 5001120003 #4403070003  #iot使用项目ID,不包含PJ
-  #需要更改
-  id: Pj5001120003 #Pj4403070003   #项目ID
+config:
+  # 标识哪个接团 比如万达使用WD,需修改
+  group-code: XG
+  # 项目ID,需修改
+  project-id: Pj5001120003
+  # iot数据汇总所使用的项目ID,切记不包含Pj,需修改
+  building: 5001120003
+
+# 报警服务
+remote: 
+  ibms-alarm:
+    # 推送消息时,是否会开启压缩,true-压缩 false-不压缩
+    compress: false
+    # 需要更改
+    host: 192.168.100.102
+    # 需要更改
+    port: 30050
+
+  # IOT程序
+  iot:
+    # iot-collect 服务
+    collect:
+      # 是否启用collect服务的netty客户端,true-启用
+      enable: false
+      # iot-collect 服务的ip
+      host: 192.168.100.102
+      # iot-collect 服务的收数端口,切记不是服务端口
+      port: 30054
+    # iot-project服务
+    project:
+      # 需要更改,修改其中的项目ID和ip、port,其中port为websocket的端口,切记不是服务端口
+      websocket: ws://192.168.100.102:30055/websocket?projectId=5001120003&type=pointset,iot
+  # 管理范围服务地址
+  persagy:
+    zkt:
+      dmp: http://ibmsdev.persagy.com/persagy-zkt-dmp
+
+spring:
+  datasource:
+    # 需要更改
+    url: jdbc:mysql://192.168.100.134:9934/alarm-quartz-pj5001120003?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&autoReconnect=true&failOverReadOnly=false
+    username: root
+    password: zaq1@WSX

+ 1 - 1
src/main/resources/return-alarm.json

@@ -1,5 +1,5 @@
 {
-	"alarm-enable": true,
+	"alarm-enable": false,
     "alarm-config": [
         {
 			"ibmsSceneCode": "lzqk",