1.修改判断用户是否登录 AI 逻辑
This commit is contained in:
@@ -9,6 +9,7 @@ import com.yupi.springbootinit.model.vo.country.CountryInfoVO;
|
|||||||
import com.yupi.springbootinit.rabbitMQ.MQSender;
|
import com.yupi.springbootinit.rabbitMQ.MQSender;
|
||||||
import com.yupi.springbootinit.service.HostInfoService;
|
import com.yupi.springbootinit.service.HostInfoService;
|
||||||
import com.yupi.springbootinit.utils.JsonUtils;
|
import com.yupi.springbootinit.utils.JsonUtils;
|
||||||
|
import com.yupi.springbootinit.utils.RedisUtils;
|
||||||
import com.yupi.springbootinit.utils.SseEmitterUtil;
|
import com.yupi.springbootinit.utils.SseEmitterUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
@@ -40,6 +41,8 @@ public class HostInfoServiceImpl extends ServiceImpl<NewHostsMapper, NewHosts> i
|
|||||||
private RedisTemplate redisTemplate;
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RedisUtils redisUtils;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private MQSender mqSender;
|
private MQSender mqSender;
|
||||||
@@ -72,8 +75,7 @@ public class HostInfoServiceImpl extends ServiceImpl<NewHostsMapper, NewHosts> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Boolean o = (Boolean) redisTemplate.opsForValue().get("ai_login:"+newHosts.get(0).getTenantId());
|
// Boolean o = (Boolean) redisTemplate.opsForValue().get("ai_login:"+newHosts.get(0).getTenantId());
|
||||||
Set<String> keys = redisTemplate.keys("ai_login:"+newHosts.get(0).getTenantId()+":*");
|
if (redisUtils.hasKeyByPrefix("ai_login:"+ newHosts.get(0).getTenantId())) {
|
||||||
if (!keys.isEmpty()) {
|
|
||||||
newHosts.forEach(newHost -> {
|
newHosts.forEach(newHost -> {
|
||||||
mqSender.send(newHost.getTenantId(),newHost);
|
mqSender.send(newHost.getTenantId(),newHost);
|
||||||
});
|
});
|
||||||
|
|||||||
38
src/main/java/com/yupi/springbootinit/utils/RedisUtils.java
Normal file
38
src/main/java/com/yupi/springbootinit/utils/RedisUtils.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package com.yupi.springbootinit.utils;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author: ziin
|
||||||
|
* @date: 2025/8/27 20:35
|
||||||
|
*/
|
||||||
|
|
||||||
|
import org.springframework.data.redis.core.Cursor;
|
||||||
|
import org.springframework.data.redis.core.RedisCallback;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.ScanOptions;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class RedisUtils {
|
||||||
|
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RedisTemplate<String,Object> redisTemplate;
|
||||||
|
|
||||||
|
public boolean hasKeyByPrefix(String prefix) {
|
||||||
|
return Boolean.TRUE.equals(
|
||||||
|
redisTemplate.execute((RedisCallback<Boolean>) conn -> {
|
||||||
|
try (Cursor<byte[]> cursor = conn.scan(
|
||||||
|
ScanOptions.scanOptions()
|
||||||
|
.match(prefix + ":*")
|
||||||
|
.count(100) // 每次返回条数,可调整
|
||||||
|
.build())) {
|
||||||
|
return cursor.hasNext(); // 只要存在一条就返回 true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user