upd: 编码规范
This commit is contained in:
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.model.system.dto;
|
package cn.odboy.model.system.response;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -8,7 +8,7 @@ import java.util.Date;
|
|||||||
* 在线用户
|
* 在线用户
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class UserOnlineDto {
|
public class UserOnlineResponse {
|
||||||
@ApiModelProperty(value = "Token编号")
|
@ApiModelProperty(value = "Token编号")
|
||||||
private String uid;
|
private String uid;
|
||||||
|
|
||||||
+3
-3
@@ -4,7 +4,7 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import cn.odboy.application.core.config.SecurityProperties;
|
import cn.odboy.application.core.config.SecurityProperties;
|
||||||
import cn.odboy.application.core.service.impl.UserOnlineServiceImpl;
|
import cn.odboy.application.core.service.impl.UserOnlineServiceImpl;
|
||||||
import cn.odboy.constant.SystemConst;
|
import cn.odboy.constant.SystemConst;
|
||||||
import cn.odboy.model.system.dto.UserOnlineDto;
|
import cn.odboy.model.system.response.UserOnlineResponse;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
@@ -43,9 +43,9 @@ public class TokenFilter extends GenericFilterBean {
|
|||||||
if (StrUtil.isNotBlank(token)) {
|
if (StrUtil.isNotBlank(token)) {
|
||||||
// 获取用户Token的Key
|
// 获取用户Token的Key
|
||||||
String loginKey = tokenProvider.loginKey(token);
|
String loginKey = tokenProvider.loginKey(token);
|
||||||
UserOnlineDto userOnlineDto = onlineUserService.getOnlineUserByKey(loginKey);
|
UserOnlineResponse userOnlineResponse = onlineUserService.getOnlineUserByKey(loginKey);
|
||||||
// 判断用户在线信息是否为空
|
// 判断用户在线信息是否为空
|
||||||
if (userOnlineDto != null) {
|
if (userOnlineResponse != null) {
|
||||||
// Token 续期判断
|
// Token 续期判断
|
||||||
tokenProvider.checkRenewal(token);
|
tokenProvider.checkRenewal(token);
|
||||||
// 获取认证信息,设置上下文
|
// 获取认证信息,设置上下文
|
||||||
|
|||||||
+2
-2
@@ -2,7 +2,7 @@ package cn.odboy.application.core.rest;
|
|||||||
|
|
||||||
import cn.odboy.application.core.service.UserOnlineService;
|
import cn.odboy.application.core.service.UserOnlineService;
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.model.system.dto.UserOnlineDto;
|
import cn.odboy.model.system.response.UserOnlineResponse;
|
||||||
import cn.odboy.util.DesEncryptUtil;
|
import cn.odboy.util.DesEncryptUtil;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
@@ -31,7 +31,7 @@ public class OnlineController {
|
|||||||
@ApiOperation("查询在线用户")
|
@ApiOperation("查询在线用户")
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@PreAuthorize("@el.check()")
|
@PreAuthorize("@el.check()")
|
||||||
public ResponseEntity<PageResult<UserOnlineDto>> queryOnlineUser(String username, Pageable pageable) {
|
public ResponseEntity<PageResult<UserOnlineResponse>> queryOnlineUser(String username, Pageable pageable) {
|
||||||
return new ResponseEntity<>(userOnlineService.queryOnlineUserPage(username, pageable), HttpStatus.OK);
|
return new ResponseEntity<>(userOnlineService.queryOnlineUserPage(username, pageable), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -2,7 +2,7 @@ package cn.odboy.application.core.service;
|
|||||||
|
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.model.system.dto.UserJwtDto;
|
import cn.odboy.model.system.dto.UserJwtDto;
|
||||||
import cn.odboy.model.system.dto.UserOnlineDto;
|
import cn.odboy.model.system.response.UserOnlineResponse;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
@@ -26,7 +26,7 @@ public interface UserOnlineService {
|
|||||||
* @param pageable /
|
* @param pageable /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
PageResult<UserOnlineDto> queryOnlineUserPage(String username, Pageable pageable);
|
PageResult<UserOnlineResponse> queryOnlineUserPage(String username, Pageable pageable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询全部数据,不分页
|
* 查询全部数据,不分页
|
||||||
@@ -34,7 +34,7 @@ public interface UserOnlineService {
|
|||||||
* @param username /
|
* @param username /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<UserOnlineDto> selectOnlineUserByUsername(String username);
|
List<UserOnlineResponse> selectOnlineUserByUsername(String username);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 退出登录
|
* 退出登录
|
||||||
@@ -50,7 +50,7 @@ public interface UserOnlineService {
|
|||||||
* @param response /
|
* @param response /
|
||||||
* @throws IOException /
|
* @throws IOException /
|
||||||
*/
|
*/
|
||||||
void downloadExcel(List<UserOnlineDto> all, HttpServletResponse response) throws IOException;
|
void downloadExcel(List<UserOnlineResponse> all, HttpServletResponse response) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询用户
|
* 查询用户
|
||||||
@@ -58,7 +58,7 @@ public interface UserOnlineService {
|
|||||||
* @param key /
|
* @param key /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
UserOnlineDto getOnlineUserByKey(String key);
|
UserOnlineResponse getOnlineUserByKey(String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户名强退用户
|
* 根据用户名强退用户
|
||||||
|
|||||||
+23
-23
@@ -6,7 +6,7 @@ import cn.odboy.application.core.service.UserOnlineService;
|
|||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.constant.SystemRedisKey;
|
import cn.odboy.constant.SystemRedisKey;
|
||||||
import cn.odboy.model.system.dto.UserJwtDto;
|
import cn.odboy.model.system.dto.UserJwtDto;
|
||||||
import cn.odboy.model.system.dto.UserOnlineDto;
|
import cn.odboy.model.system.response.UserOnlineResponse;
|
||||||
import cn.odboy.redis.RedisHelper;
|
import cn.odboy.redis.RedisHelper;
|
||||||
import cn.odboy.util.BrowserUtil;
|
import cn.odboy.util.BrowserUtil;
|
||||||
import cn.odboy.util.DesEncryptUtil;
|
import cn.odboy.util.DesEncryptUtil;
|
||||||
@@ -45,40 +45,40 @@ public class UserOnlineServiceImpl implements UserOnlineService {
|
|||||||
String id = tokenProvider.getId(token);
|
String id = tokenProvider.getId(token);
|
||||||
String version = BrowserUtil.getVersion(request);
|
String version = BrowserUtil.getVersion(request);
|
||||||
String address = IpUtil.getCityInfo(ip);
|
String address = IpUtil.getCityInfo(ip);
|
||||||
UserOnlineDto userOnlineDto = null;
|
UserOnlineResponse userOnlineResponse = null;
|
||||||
try {
|
try {
|
||||||
userOnlineDto = new UserOnlineDto();
|
userOnlineResponse = new UserOnlineResponse();
|
||||||
userOnlineDto.setUid(id);
|
userOnlineResponse.setUid(id);
|
||||||
userOnlineDto.setUserName(userJwtDto.getUsername());
|
userOnlineResponse.setUserName(userJwtDto.getUsername());
|
||||||
userOnlineDto.setNickName(userJwtDto.getUser().getNickName());
|
userOnlineResponse.setNickName(userJwtDto.getUser().getNickName());
|
||||||
userOnlineDto.setDept(dept);
|
userOnlineResponse.setDept(dept);
|
||||||
userOnlineDto.setBrowser(version);
|
userOnlineResponse.setBrowser(version);
|
||||||
userOnlineDto.setIp(ip);
|
userOnlineResponse.setIp(ip);
|
||||||
userOnlineDto.setAddress(address);
|
userOnlineResponse.setAddress(address);
|
||||||
userOnlineDto.setKey(DesEncryptUtil.desEncrypt(token));
|
userOnlineResponse.setKey(DesEncryptUtil.desEncrypt(token));
|
||||||
userOnlineDto.setLoginTime(new Date());
|
userOnlineResponse.setLoginTime(new Date());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
String loginKey = tokenProvider.loginKey(token);
|
String loginKey = tokenProvider.loginKey(token);
|
||||||
redisHelper.set(loginKey, userOnlineDto, properties.getTokenValidityInSeconds(), TimeUnit.MILLISECONDS);
|
redisHelper.set(loginKey, userOnlineResponse, properties.getTokenValidityInSeconds(), TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<UserOnlineDto> queryOnlineUserPage(String username, Pageable pageable) {
|
public PageResult<UserOnlineResponse> queryOnlineUserPage(String username, Pageable pageable) {
|
||||||
List<UserOnlineDto> onlineUserList = selectOnlineUserByUsername(username);
|
List<UserOnlineResponse> onlineUserList = selectOnlineUserByUsername(username);
|
||||||
List<UserOnlineDto> paging = PageUtil.softPaging(pageable.getPageNumber(), pageable.getPageSize(), onlineUserList);
|
List<UserOnlineResponse> paging = PageUtil.softPaging(pageable.getPageNumber(), pageable.getPageSize(), onlineUserList);
|
||||||
return PageUtil.toPage(paging, onlineUserList.size());
|
return PageUtil.toPage(paging, onlineUserList.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserOnlineDto> selectOnlineUserByUsername(String username) {
|
public List<UserOnlineResponse> selectOnlineUserByUsername(String username) {
|
||||||
String loginKey = SystemRedisKey.ONLINE_USER + (StringUtil.isBlank(username) ? "" : "*" + username);
|
String loginKey = SystemRedisKey.ONLINE_USER + (StringUtil.isBlank(username) ? "" : "*" + username);
|
||||||
List<String> keys = redisHelper.scan(loginKey + "*");
|
List<String> keys = redisHelper.scan(loginKey + "*");
|
||||||
Collections.reverse(keys);
|
Collections.reverse(keys);
|
||||||
List<UserOnlineDto> onlineUserList = new ArrayList<>();
|
List<UserOnlineResponse> onlineUserList = new ArrayList<>();
|
||||||
for (String key : keys) {
|
for (String key : keys) {
|
||||||
onlineUserList.add(redisHelper.get(key, UserOnlineDto.class));
|
onlineUserList.add(redisHelper.get(key, UserOnlineResponse.class));
|
||||||
}
|
}
|
||||||
onlineUserList.sort((o1, o2) -> o2.getLoginTime().compareTo(o1.getLoginTime()));
|
onlineUserList.sort((o1, o2) -> o2.getLoginTime().compareTo(o1.getLoginTime()));
|
||||||
return onlineUserList;
|
return onlineUserList;
|
||||||
@@ -91,9 +91,9 @@ public class UserOnlineServiceImpl implements UserOnlineService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void downloadExcel(List<UserOnlineDto> all, HttpServletResponse response) throws IOException {
|
public void downloadExcel(List<UserOnlineResponse> all, HttpServletResponse response) throws IOException {
|
||||||
List<Map<String, Object>> list = new ArrayList<>();
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
for (UserOnlineDto user : all) {
|
for (UserOnlineResponse user : all) {
|
||||||
Map<String, Object> map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
map.put("用户名", user.getUserName());
|
map.put("用户名", user.getUserName());
|
||||||
map.put("部门", user.getDept());
|
map.put("部门", user.getDept());
|
||||||
@@ -107,8 +107,8 @@ public class UserOnlineServiceImpl implements UserOnlineService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserOnlineDto getOnlineUserByKey(String key) {
|
public UserOnlineResponse getOnlineUserByKey(String key) {
|
||||||
return redisHelper.get(key, UserOnlineDto.class);
|
return redisHelper.get(key, UserOnlineResponse.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user