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 lombok.Data;
|
||||
@@ -8,7 +8,7 @@ import java.util.Date;
|
||||
* 在线用户
|
||||
*/
|
||||
@Data
|
||||
public class UserOnlineDto {
|
||||
public class UserOnlineResponse {
|
||||
@ApiModelProperty(value = "Token编号")
|
||||
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.service.impl.UserOnlineServiceImpl;
|
||||
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 org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
@@ -43,9 +43,9 @@ public class TokenFilter extends GenericFilterBean {
|
||||
if (StrUtil.isNotBlank(token)) {
|
||||
// 获取用户Token的Key
|
||||
String loginKey = tokenProvider.loginKey(token);
|
||||
UserOnlineDto userOnlineDto = onlineUserService.getOnlineUserByKey(loginKey);
|
||||
UserOnlineResponse userOnlineResponse = onlineUserService.getOnlineUserByKey(loginKey);
|
||||
// 判断用户在线信息是否为空
|
||||
if (userOnlineDto != null) {
|
||||
if (userOnlineResponse != null) {
|
||||
// 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.base.PageResult;
|
||||
import cn.odboy.model.system.dto.UserOnlineDto;
|
||||
import cn.odboy.model.system.response.UserOnlineResponse;
|
||||
import cn.odboy.util.DesEncryptUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -31,7 +31,7 @@ public class OnlineController {
|
||||
@ApiOperation("查询在线用户")
|
||||
@GetMapping
|
||||
@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);
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -2,7 +2,7 @@ package cn.odboy.application.core.service;
|
||||
|
||||
import cn.odboy.base.PageResult;
|
||||
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 javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -26,7 +26,7 @@ public interface UserOnlineService {
|
||||
* @param pageable /
|
||||
* @return /
|
||||
*/
|
||||
PageResult<UserOnlineDto> queryOnlineUserPage(String username, Pageable pageable);
|
||||
PageResult<UserOnlineResponse> queryOnlineUserPage(String username, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询全部数据,不分页
|
||||
@@ -34,7 +34,7 @@ public interface UserOnlineService {
|
||||
* @param username /
|
||||
* @return /
|
||||
*/
|
||||
List<UserOnlineDto> selectOnlineUserByUsername(String username);
|
||||
List<UserOnlineResponse> selectOnlineUserByUsername(String username);
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
@@ -50,7 +50,7 @@ public interface UserOnlineService {
|
||||
* @param response /
|
||||
* @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 /
|
||||
* @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.constant.SystemRedisKey;
|
||||
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.util.BrowserUtil;
|
||||
import cn.odboy.util.DesEncryptUtil;
|
||||
@@ -45,40 +45,40 @@ public class UserOnlineServiceImpl implements UserOnlineService {
|
||||
String id = tokenProvider.getId(token);
|
||||
String version = BrowserUtil.getVersion(request);
|
||||
String address = IpUtil.getCityInfo(ip);
|
||||
UserOnlineDto userOnlineDto = null;
|
||||
UserOnlineResponse userOnlineResponse = null;
|
||||
try {
|
||||
userOnlineDto = new UserOnlineDto();
|
||||
userOnlineDto.setUid(id);
|
||||
userOnlineDto.setUserName(userJwtDto.getUsername());
|
||||
userOnlineDto.setNickName(userJwtDto.getUser().getNickName());
|
||||
userOnlineDto.setDept(dept);
|
||||
userOnlineDto.setBrowser(version);
|
||||
userOnlineDto.setIp(ip);
|
||||
userOnlineDto.setAddress(address);
|
||||
userOnlineDto.setKey(DesEncryptUtil.desEncrypt(token));
|
||||
userOnlineDto.setLoginTime(new Date());
|
||||
userOnlineResponse = new UserOnlineResponse();
|
||||
userOnlineResponse.setUid(id);
|
||||
userOnlineResponse.setUserName(userJwtDto.getUsername());
|
||||
userOnlineResponse.setNickName(userJwtDto.getUser().getNickName());
|
||||
userOnlineResponse.setDept(dept);
|
||||
userOnlineResponse.setBrowser(version);
|
||||
userOnlineResponse.setIp(ip);
|
||||
userOnlineResponse.setAddress(address);
|
||||
userOnlineResponse.setKey(DesEncryptUtil.desEncrypt(token));
|
||||
userOnlineResponse.setLoginTime(new Date());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
String loginKey = tokenProvider.loginKey(token);
|
||||
redisHelper.set(loginKey, userOnlineDto, properties.getTokenValidityInSeconds(), TimeUnit.MILLISECONDS);
|
||||
redisHelper.set(loginKey, userOnlineResponse, properties.getTokenValidityInSeconds(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<UserOnlineDto> queryOnlineUserPage(String username, Pageable pageable) {
|
||||
List<UserOnlineDto> onlineUserList = selectOnlineUserByUsername(username);
|
||||
List<UserOnlineDto> paging = PageUtil.softPaging(pageable.getPageNumber(), pageable.getPageSize(), onlineUserList);
|
||||
public PageResult<UserOnlineResponse> queryOnlineUserPage(String username, Pageable pageable) {
|
||||
List<UserOnlineResponse> onlineUserList = selectOnlineUserByUsername(username);
|
||||
List<UserOnlineResponse> paging = PageUtil.softPaging(pageable.getPageNumber(), pageable.getPageSize(), onlineUserList);
|
||||
return PageUtil.toPage(paging, onlineUserList.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserOnlineDto> selectOnlineUserByUsername(String username) {
|
||||
public List<UserOnlineResponse> selectOnlineUserByUsername(String username) {
|
||||
String loginKey = SystemRedisKey.ONLINE_USER + (StringUtil.isBlank(username) ? "" : "*" + username);
|
||||
List<String> keys = redisHelper.scan(loginKey + "*");
|
||||
Collections.reverse(keys);
|
||||
List<UserOnlineDto> onlineUserList = new ArrayList<>();
|
||||
List<UserOnlineResponse> onlineUserList = new ArrayList<>();
|
||||
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()));
|
||||
return onlineUserList;
|
||||
@@ -91,9 +91,9 @@ public class UserOnlineServiceImpl implements UserOnlineService {
|
||||
}
|
||||
|
||||
@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<>();
|
||||
for (UserOnlineDto user : all) {
|
||||
for (UserOnlineResponse user : all) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("用户名", user.getUserName());
|
||||
map.put("部门", user.getDept());
|
||||
@@ -107,8 +107,8 @@ public class UserOnlineServiceImpl implements UserOnlineService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserOnlineDto getOnlineUserByKey(String key) {
|
||||
return redisHelper.get(key, UserOnlineDto.class);
|
||||
public UserOnlineResponse getOnlineUserByKey(String key) {
|
||||
return redisHelper.get(key, UserOnlineResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user