Browse Source

报警定义中的JSONObject改成String

lixing 3 years ago
parent
commit
75ed62a56c

+ 3 - 3
src/main/java/com/persagy/cache/AlarmRedisCache.java

@@ -136,10 +136,10 @@ public class AlarmRedisCache implements RedisCache {
 	 */
 	public boolean lock(String key, String value, Integer timeout) {
 		boolean bool;
-		int i = 1;
+//		int i = 1;
 		while (true) {
 			Boolean b = alarmRedisTemplate.opsForValue().setIfAbsent(key, value, timeout, TimeUnit.SECONDS);
-			System.out.println(key + "---key----" + b);
+//			System.out.println(key + "---key----" + b);
 			if (b) {
 				bool = b;
 				break;
@@ -150,7 +150,7 @@ public class AlarmRedisCache implements RedisCache {
 					Thread.currentThread().interrupt();
 				}
 			}
-			System.out.println(i);
+//			System.out.println(i);
 		}
 		return bool;
 

+ 20 - 0
src/main/java/com/persagy/config/RabbitmqMsgConverterConfig.java

@@ -0,0 +1,20 @@
+package com.persagy.config;
+
+import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
+import org.springframework.amqp.support.converter.MessageConverter;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author: yaoll
+ * @date: 2020-09-22
+ * @verison: 1.0
+ */
+@Configuration
+public class RabbitmqMsgConverterConfig {
+    // JMS 使用
+    @Bean
+    public MessageConverter customMessageConvert() {
+        return new Jackson2JsonMessageConverter();
+    }
+}

+ 10 - 3
src/main/java/com/persagy/entity/AlarmDefine.java

@@ -1,8 +1,10 @@
 package com.persagy.entity;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.persagy.entity.v2.AlarmCondition;
 import lombok.Data;
+import org.apache.commons.lang3.StringUtils;
 
 /**
  * @description:
@@ -116,9 +118,14 @@ public class AlarmDefine {
         // 设置报警条件
         Condition condition = new Condition();
         condition.setInfoCode(alarmCondition.getInfoCodes());
-        condition.setConfigs(JSONObject.toJSONString(alarmCondition.getTriggerFrontend()));
-        JSONObject effectTime = alarmCondition.getEffectTimeDetail();
-        effectTime = effectTime == null ? new JSONObject() : effectTime;
+        if (StringUtils.isNotBlank(alarmCondition.getConfigs())) {
+            condition.setConfigs(alarmCondition.getConfigs());
+        } else {
+            condition.setConfigs(JSONObject.toJSONString(alarmCondition.getTriggerFrontend()));
+        }
+        String effectTimeStr = alarmCondition.getEffectTimeDetail();
+        JSONObject effectTime = new JSONObject();
+        effectTime = StringUtils.isBlank(effectTimeStr) ? new JSONObject() : JSON.parseObject(effectTimeStr);
         effectTime.put("type", alarmCondition.getEffectTimeType());
         condition.setEffectTime(effectTime);
         condition.setRules(alarmCondition.getTriggerRules());

+ 6 - 1
src/main/java/com/persagy/entity/v2/AlarmCondition.java

@@ -74,5 +74,10 @@ public class AlarmCondition {
     /**
      * 生效时间详情
      */
-    private JSONObject effectTimeDetail;
+    private String effectTimeDetail;
+
+    /**
+     * 数据中台中需要展示给前端的内容
+     */
+    private String configs;
 }

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

@@ -373,7 +373,7 @@ public class AlarmHandleServiceImpl {
             String alarmId = alarmRecordDO.getAlarmId();
             alarmRedisCache.lock(RedisConstant.alarmRecordLockPrefix + alarmId, alarmId, 10);
             // 发送报警恢复消息
-            sendAlarmRecoverMessage(defineId, alarmSuspendStartTime, paramMap, alarmId, alarmDefine.getItemCode());
+            sendAlarmRecoverMessage(alarmDefine.getProjectId(), alarmSuspendStartTime, paramMap, alarmId, alarmDefine.getItemCode());
             // 取消过期任务
             cancelRelatedExpireJob(alarmId);
             // 报警恢复,报警状态重置回默认
@@ -413,7 +413,7 @@ public class AlarmHandleServiceImpl {
         dmpMessage.setGroupCode(groupCode);
         dmpMessage.setExts(JSONObject.parseObject(JSONObject.toJSONString(alarmRecoverRecord)));
         rabbitTemplate.convertAndSend(RabbitConfig.exchangeAlarm, RabbitConfig.alarmMsgRoutingKey,
-                JSON.toJSONString(dmpMessage));
+                dmpMessage);
     }
 
     /**
@@ -697,6 +697,6 @@ public class AlarmHandleServiceImpl {
         dmpMessage.setExts(message);
         alarmRedisCache.lock(RedisConstant.alarmRecordLockPrefix + alarmId, alarmId, 10);
         rabbitTemplate.convertAndSend(RabbitConfig.exchangeAlarm, RabbitConfig.alarmMsgRoutingKey,
-                JSON.toJSONString(dmpMessage));
+                dmpMessage);
     }
 }