Ver código fonte

发数测试接口

miaolijing 3 anos atrás
pai
commit
6896b92e4e

+ 3 - 3
src/main/java/com/persagy/apm/diagnose/config/RabbitConfig.java

@@ -25,7 +25,7 @@ public class RabbitConfig {
     /**
      * 交换机
      */
-    private final String exchange = "exchange-alarm-service";
+    private final String exchange = "exchange-msg-service";
     /**
      * 报警记录 路由键
      */
@@ -35,7 +35,7 @@ public class RabbitConfig {
      */
     private final String alarmDataQueue = "alarm-data-queue";
 
-    @Bean
+    /*@Bean
     public TopicExchange alarmServiceExchange() {
         return new TopicExchange(exchange);
     }
@@ -46,7 +46,7 @@ public class RabbitConfig {
     @Bean
     public Binding alarmRecordBinding() {
         return BindingBuilder.bind(alarmRecordQueue()).to(alarmServiceExchange()).with(alarmDataRoutingKey);
-    }
+    }*/
 
     public void sendMsg(JSONArray contentArray) {
         CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());

+ 1 - 1
src/main/java/com/persagy/apm/diagnose/indicatorrecord/service/impl/MonitorIndicatorRecordServiceImpl.java

@@ -368,7 +368,7 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
                 continue;
             }
             long time = System.currentTimeMillis() + (10 * 1000);
-            lockUtil.lock(lockKey, String.valueOf(time));
+            lockUtil.sendDataLock(lockKey, String.valueOf(time));
 
             List<String> infCodeList = entry.getValue();
 

+ 22 - 16
src/main/java/com/persagy/apm/diagnose/maintenance/controller/MaintenanceController.java

@@ -20,7 +20,7 @@ import java.util.Map;
 @Api(tags = "维保数据历史记录")
 @Validated
 @RestController
-@RequestMapping("monitorIndicatorRecords")
+@RequestMapping("MaintenanceDataRecords")
 public class MaintenanceController {
     @Autowired
     private RedisLock lockUtil;
@@ -34,26 +34,32 @@ public class MaintenanceController {
 
         Map<String, Boolean> iotDataMap = new LinkedHashMap<>();
         iotDataMap.put("10", true);
-        iotDataMap.put("11", true);
-        iotDataMap.put("12", false);
-        iotDataMap.put("13", true);
+        iotDataMap.put("11", false);
+        iotDataMap.put("12", true);
+        iotDataMap.put("13", false);
         iotDataMap.put("14", true);
-        iotDataMap.put("15", true);
-        iotDataMap.put("16", false);
-        iotDataMap.put("17", true);
+        iotDataMap.put("15", false);
+        iotDataMap.put("16", true);
+        iotDataMap.put("17", false);
         iotDataMap.put("18", true);
 
         String objId = "Eq1101060001f00f2ed121f9407783ac0f0a520a9616", alarmItemCode=EnumAlarmItem.EvapAbnormal.getCode();
         String lockKey = objId+"-"+alarmItemCode;
-        Object isLock = redisUtil.get(lockKey);
-        if (null != isLock){
-            long time = System.currentTimeMillis() + (10 * 1000);
-            lockUtil.lock(lockKey, String.valueOf(time));
-            JSONArray array = getSendArray(iotDataMap,objId,alarmItemCode);
-            //推送
-            rabbitConfig.sendMsg(array);
+        for (String time : iotDataMap.keySet()) {
+            Object isLock = redisUtil.get(lockKey);
+            if (null == isLock){
+                long timeLong = System.currentTimeMillis() + (10 * 1000);
+                lockUtil.sendDataLock(lockKey, String.valueOf(timeLong));
+                JSONArray array = new JSONArray();
+                if (iotDataMap.get(time)) {
+                    array.add(getTriggerData(time,objId,alarmItemCode));
+                } else {
+                    array.add(getNormalData(time,objId,alarmItemCode));
+                }
+                //推送
+                rabbitConfig.sendMsg(array);
+            }
         }
-
     }
 
     public JSONArray getSendArray(Map<String, Boolean> iotDataMap,String objId,String alarmItemCode) {
@@ -86,7 +92,7 @@ public class MaintenanceController {
         jsonObject.put("itemCode", alarmItemCode);
         jsonObject.put("meterId",objId);
         JSONArray funcIdArray = new JSONArray();
-        funcIdArray.add(EnumMaintenanceIndicatorType.ACCCCC_EvapHeatTransferDayAvg);//换热端差日维度平均值阈值
+        funcIdArray.add(EnumMaintenanceIndicatorType.ACCCCC_EvapHeatTransferDayAvg.getCode());//换热端差日维度平均值阈值
         funcIdArray.add(EnumMaintenanceIndicatorType.ACCCCC_EvapContinuousOperation.getCode());//运行持续时间
         JSONArray valueArray = new JSONArray();
         valueArray.add(value1);

+ 1 - 1
src/main/java/com/persagy/apm/diagnose/maintenance/service/impl/ProjectDataRecordServiceImpl.java

@@ -289,7 +289,7 @@ public class ProjectDataRecordServiceImpl implements IProjectDataRecordService {
                 continue;
             }
             long time = System.currentTimeMillis() + (10 * 1000);
-            lockUtil.lock(lockKey, String.valueOf(time));
+            lockUtil.sendDataLock(lockKey, String.valueOf(time));
             List<String> infCodeList = entry.getValue();
             //通过redis查询对象该报警类型下的发数截止时间
             ConfigItemDataSendTimeDTO configItemSendTimeDTO = getConfigItemSendTimeDTO(projectId, objIdAndAlarmItemCode);

+ 8 - 0
src/main/java/com/persagy/apm/diagnose/utils/RedisLock.java

@@ -4,6 +4,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 
+import java.util.concurrent.TimeUnit;
+
 @Component
 public class RedisLock {
 
@@ -24,6 +26,7 @@ public class RedisLock {
 			// 相当于SETNX,setIfAbsent方法设置了为true,没有设置为false
 			return true;
 		}
+
 		// 假设currentValue=A 接下来并发进来的两个线程的value都是B
 		// 其中一个线程拿到锁,除非从始至终所有都是在并发(实际上这中情况是不存在的),只要开始时有数据有先后顺序,则分布式锁就不会出现“多卖”的现象
 		String currentValue = String.valueOf(redisTemplate.opsForValue().get(key));
@@ -56,4 +59,9 @@ public class RedisLock {
 		}
 	}
 
+    public void sendDataLock(String key, String value) {
+        redisTemplate.opsForValue().setIfAbsent(key, value);
+        redisTemplate.expire(key,10, TimeUnit.SECONDS);
+    }
+
 }

+ 2 - 0
src/main/resources/bootstrap.yml

@@ -55,6 +55,8 @@ dmp:
     queue: eq-run-diagnose-alarm-queue              #中控订阅报警定义变化队列
 
 alarm:
+  obj:
+    routingKey: routing-alarm-obj
   category:
     list: Eqwb,Eqdx   #报警系统编码