|
@@ -1,5 +1,6 @@
|
|
|
package com.ytpm.question.monitor;
|
|
package com.ytpm.question.monitor;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.ytpm.agent.enums.UserStatusEnum;
|
|
import com.ytpm.agent.enums.UserStatusEnum;
|
|
|
import com.ytpm.app.model.YtDyzUser;
|
|
import com.ytpm.app.model.YtDyzUser;
|
|
@@ -16,6 +17,7 @@ import org.springframework.lang.NonNull;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -51,21 +53,21 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
|
|
@Override
|
|
@Override
|
|
|
public void onMessage(@NonNull Message message, byte[] pattern) {
|
|
public void onMessage(@NonNull Message message, byte[] pattern) {
|
|
|
String key = String.valueOf(message);
|
|
String key = String.valueOf(message);
|
|
|
- // 全局监听
|
|
|
|
|
- if (key.startsWith("lock_") || key.startsWith("unlock_")) {
|
|
|
|
|
- String[] arr = key.split("_");
|
|
|
|
|
- if (arr.length < 2) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ String[] arr = key.split("_");
|
|
|
|
|
+ // 全局监听 e.g lock_202510001
|
|
|
|
|
+ if (arr.length >= 2 && (key.startsWith("lock_") || key.startsWith("unlock_"))) {
|
|
|
handleUserLock(key, arr[1], arr[0]);
|
|
handleUserLock(key, arr[1], arr[0]);
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
- // 仅限自身服务的监听
|
|
|
|
|
|
|
+ // 仅限自身服务的监听 e.g lime_lock_202510001
|
|
|
String serviceKey = StrUtil.replace(applicationName, "-service", "");
|
|
String serviceKey = StrUtil.replace(applicationName, "-service", "");
|
|
|
- if (key.startsWith(serviceKey)) {
|
|
|
|
|
- String[] arr = key.split("_");
|
|
|
|
|
- if (arr.length < 3) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (arr.length >= 3 && key.startsWith(serviceKey)) {
|
|
|
|
|
+ handleUserLock(key, arr[2], arr[1]);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ // e.g a685138d49cd2d_lock_202510001
|
|
|
|
|
+ List<String> ids = appUserMapper.queryAppIds();
|
|
|
|
|
+ if (arr.length >= 3 && CollUtil.isNotEmpty(ids) && ids.contains(arr[0])) {
|
|
|
handleUserLock(key, arr[2], arr[1]);
|
|
handleUserLock(key, arr[2], arr[1]);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|