Selaa lähdekoodia

解锁逻辑修改

miaolijing 3 vuotta sitten
vanhempi
commit
f7462f946f

+ 15 - 11
src/main/java/com/persagy/apm/diagnose/maintenance/controller/MaintenanceController.java

@@ -46,19 +46,23 @@ public class MaintenanceController {
         String objId = "Eq1101060001f00f2ed121f9407783ac0f0a520a9616", alarmItemCode=EnumAlarmItem.EvapAbnormal.getCode();
         String lockKey = objId+"-"+alarmItemCode;
         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));
+            while (true){
+                Object isLock = redisUtil.get(lockKey);
+                if (isLock == null){
+                    break;
                 }
-                //推送
-                rabbitConfig.sendMsg(array);
+                Thread.sleep(100);
             }
+            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);
         }
     }
 

+ 5 - 4
src/main/java/com/persagy/apm/diagnose/utils/RedisLock.java

@@ -4,7 +4,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 
+import java.util.HashMap;
+import java.util.Map;
 import java.util.concurrent.TimeUnit;
+import java.util.logging.Handler;
 
 @Component
 public class RedisLock {
@@ -50,16 +53,14 @@ public class RedisLock {
 	 */
 	public void unlock(String key, String value) {
 		try {
-			String currentValue = String.valueOf(redisTemplate.opsForValue().get(key));
-			if (!StringUtils.isEmpty(currentValue) && currentValue.equals(value)) {
-				redisTemplate.opsForValue().getOperations().delete(key);
-			}
+		    redisTemplate.delete(key);
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
 	}
 
     public void sendDataLock(String key, String value) {
+//	    redisTemplate.opsForHash().put("ALARM-DATA-LOCK",key,value);
         redisTemplate.opsForValue().setIfAbsent(key, value);
         redisTemplate.expire(key,10, TimeUnit.SECONDS);
     }