add
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package com.qiaoba.auth.service;
|
||||
|
||||
import com.qiaoba.auth.entity.OnlineUser;
|
||||
import com.qiaoba.common.base.entity.BasePage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -62,4 +63,13 @@ public interface OnlineUserService {
|
||||
*/
|
||||
Boolean checkIsLastLogged(String username, String deviceSn);
|
||||
|
||||
/**
|
||||
* 分页查询列表
|
||||
*
|
||||
* @param pageNum pageNum
|
||||
* @param pageSize pageSize
|
||||
* @param username username
|
||||
* @return list
|
||||
*/
|
||||
BasePage selectPageList(Integer pageNum, Integer pageSize, String username);
|
||||
}
|
||||
|
@ -43,11 +43,13 @@ public class AuthConfigServiceImpl implements AuthConfigApiService {
|
||||
if (StrUtil.isBlank(code) || StrUtil.isBlank(uuid)) {
|
||||
throw new ServiceException("验证码或uuid获取失败!");
|
||||
}
|
||||
|
||||
String realCode = redisService.getObject(SecurityConstant.CAPTCHA_KEY + uuid, String.class);
|
||||
try {
|
||||
if (!redisService.hasKey(SecurityConstant.CAPTCHA_KEY + uuid)) {
|
||||
if (StrUtil.isBlank(realCode)) {
|
||||
throw new ServiceException("验证码已经过期失效!");
|
||||
} else {
|
||||
if (!code.equalsIgnoreCase(redisService.get(SecurityConstant.CAPTCHA_KEY + uuid).toString())) {
|
||||
if (!code.equalsIgnoreCase(realCode)) {
|
||||
throw new ServiceException("验证码输入错误!");
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.qiaoba.auth.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.qiaoba.api.auth.service.SysUserDetailsApiService;
|
||||
import com.qiaoba.auth.constants.SecurityConstant;
|
||||
@ -8,6 +9,7 @@ import com.qiaoba.auth.entity.dto.OnlineUserDto;
|
||||
import com.qiaoba.auth.service.OnlineUserService;
|
||||
import com.qiaoba.auth.utils.TokenUtil;
|
||||
import com.qiaoba.common.base.constants.BaseConstant;
|
||||
import com.qiaoba.common.base.entity.BasePage;
|
||||
import com.qiaoba.common.base.exceptions.ServiceException;
|
||||
import com.qiaoba.common.redis.service.RedisService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -60,11 +62,7 @@ public class OnlineUserServiceImpl implements OnlineUserService {
|
||||
|
||||
@Override
|
||||
public OnlineUser selectOne(String username, String deviceSn) {
|
||||
String key = handleKey(username, deviceSn);
|
||||
if (redisService.hasKey(key)) {
|
||||
return redisService.getObject(key, OnlineUser.class);
|
||||
}
|
||||
return null;
|
||||
return redisService.getObject(handleKey(username, deviceSn), OnlineUser.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -88,6 +86,21 @@ public class OnlineUserServiceImpl implements OnlineUserService {
|
||||
return deviceSn.equals(loggedDevice);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasePage<OnlineUser> selectPageList(Integer pageNum, Integer pageSize, String username) {
|
||||
String key = SecurityConstant.ONLINE_USER_REDIS_KEY + "*";
|
||||
if (StrUtil.isNotBlank(username)) {
|
||||
key = key + username + "*";
|
||||
}
|
||||
List<String> allKeys = CollUtil.newArrayList(redisService.getKeys(key));
|
||||
List<String> keys = CollUtil.page(pageNum - 1, pageSize, allKeys);
|
||||
List<OnlineUser> users = new ArrayList<>();
|
||||
for (String temp : keys) {
|
||||
users.add(redisService.getObject(redisService.removeTenantPrefix(temp), OnlineUser.class));
|
||||
}
|
||||
return BasePage.build(((Integer) allKeys.size()).longValue(), users);
|
||||
}
|
||||
|
||||
private String handleKey(String key, String deviceSn) {
|
||||
return SecurityConstant.ONLINE_USER_REDIS_KEY + key + BaseConstant.COLON_JOIN_STR + deviceSn;
|
||||
}
|
||||
|
Reference in New Issue
Block a user