Commit ba16a830 authored by Zheng Jie's avatar Zheng Jie
Browse files

Merge branch 'master' into deploy

# Conflicts:
#	README.md
#	eladmin-system/src/main/java/me/zhengjie/modules/security/rest/OnlineController.java
parents 6c9901a8 cf3655ad
...@@ -68,7 +68,7 @@ public class DeployServiceImpl implements DeployService { ...@@ -68,7 +68,7 @@ public class DeployServiceImpl implements DeployService {
@Override @Override
public Object queryAll(DeployQueryCriteria criteria, Pageable pageable) { public PageResult<DeployDto> queryAll(DeployQueryCriteria criteria, Pageable pageable) {
Page<Deploy> page = deployRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable); Page<Deploy> page = deployRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
return PageUtil.toPage(page.map(deployMapper::toDto)); return PageUtil.toPage(page.map(deployMapper::toDto));
} }
......
...@@ -23,10 +23,7 @@ import me.zhengjie.modules.mnt.service.dto.ServerDeployDto; ...@@ -23,10 +23,7 @@ import me.zhengjie.modules.mnt.service.dto.ServerDeployDto;
import me.zhengjie.modules.mnt.service.dto.ServerDeployQueryCriteria; import me.zhengjie.modules.mnt.service.dto.ServerDeployQueryCriteria;
import me.zhengjie.modules.mnt.service.mapstruct.ServerDeployMapper; import me.zhengjie.modules.mnt.service.mapstruct.ServerDeployMapper;
import me.zhengjie.modules.mnt.util.ExecuteShellUtil; import me.zhengjie.modules.mnt.util.ExecuteShellUtil;
import me.zhengjie.utils.FileUtil; import me.zhengjie.utils.*;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.ValidationUtil;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -47,7 +44,7 @@ public class ServerDeployServiceImpl implements ServerDeployService { ...@@ -47,7 +44,7 @@ public class ServerDeployServiceImpl implements ServerDeployService {
private final ServerDeployMapper serverDeployMapper; private final ServerDeployMapper serverDeployMapper;
@Override @Override
public Object queryAll(ServerDeployQueryCriteria criteria, Pageable pageable){ public PageResult<ServerDeployDto> queryAll(ServerDeployQueryCriteria criteria, Pageable pageable){
Page<ServerDeploy> page = serverDeployRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); Page<ServerDeploy> page = serverDeployRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(serverDeployMapper::toDto)); return PageUtil.toPage(page.map(serverDeployMapper::toDto));
} }
......
...@@ -22,8 +22,10 @@ import lombok.extern.slf4j.Slf4j; ...@@ -22,8 +22,10 @@ import lombok.extern.slf4j.Slf4j;
import me.zhengjie.annotation.Log; import me.zhengjie.annotation.Log;
import me.zhengjie.exception.BadRequestException; import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.quartz.domain.QuartzJob; import me.zhengjie.modules.quartz.domain.QuartzJob;
import me.zhengjie.modules.quartz.domain.QuartzLog;
import me.zhengjie.modules.quartz.service.QuartzJobService; import me.zhengjie.modules.quartz.service.QuartzJobService;
import me.zhengjie.modules.quartz.service.dto.JobQueryCriteria; import me.zhengjie.modules.quartz.service.dto.JobQueryCriteria;
import me.zhengjie.utils.PageResult;
import me.zhengjie.utils.SpringContextHolder; import me.zhengjie.utils.SpringContextHolder;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
...@@ -52,7 +54,7 @@ public class QuartzJobController { ...@@ -52,7 +54,7 @@ public class QuartzJobController {
@ApiOperation("查询定时任务") @ApiOperation("查询定时任务")
@GetMapping @GetMapping
@PreAuthorize("@el.check('timing:list')") @PreAuthorize("@el.check('timing:list')")
public ResponseEntity<Object> queryQuartzJob(JobQueryCriteria criteria, Pageable pageable){ public ResponseEntity<PageResult<QuartzJob>> queryQuartzJob(JobQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(quartzJobService.queryAll(criteria,pageable), HttpStatus.OK); return new ResponseEntity<>(quartzJobService.queryAll(criteria,pageable), HttpStatus.OK);
} }
...@@ -73,7 +75,7 @@ public class QuartzJobController { ...@@ -73,7 +75,7 @@ public class QuartzJobController {
@ApiOperation("查询任务执行日志") @ApiOperation("查询任务执行日志")
@GetMapping(value = "/logs") @GetMapping(value = "/logs")
@PreAuthorize("@el.check('timing:list')") @PreAuthorize("@el.check('timing:list')")
public ResponseEntity<Object> queryQuartzJobLog(JobQueryCriteria criteria, Pageable pageable){ public ResponseEntity<PageResult<QuartzLog>> queryQuartzJobLog(JobQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(quartzJobService.queryAllLog(criteria,pageable), HttpStatus.OK); return new ResponseEntity<>(quartzJobService.queryAllLog(criteria,pageable), HttpStatus.OK);
} }
......
...@@ -18,6 +18,7 @@ package me.zhengjie.modules.quartz.service; ...@@ -18,6 +18,7 @@ package me.zhengjie.modules.quartz.service;
import me.zhengjie.modules.quartz.domain.QuartzJob; import me.zhengjie.modules.quartz.domain.QuartzJob;
import me.zhengjie.modules.quartz.domain.QuartzLog; import me.zhengjie.modules.quartz.domain.QuartzLog;
import me.zhengjie.modules.quartz.service.dto.JobQueryCriteria; import me.zhengjie.modules.quartz.service.dto.JobQueryCriteria;
import me.zhengjie.utils.PageResult;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
...@@ -36,7 +37,7 @@ public interface QuartzJobService { ...@@ -36,7 +37,7 @@ public interface QuartzJobService {
* @param pageable 分页参数 * @param pageable 分页参数
* @return / * @return /
*/ */
Object queryAll(JobQueryCriteria criteria, Pageable pageable); PageResult<QuartzJob> queryAll(JobQueryCriteria criteria, Pageable pageable);
/** /**
* 查询全部 * 查询全部
...@@ -51,7 +52,7 @@ public interface QuartzJobService { ...@@ -51,7 +52,7 @@ public interface QuartzJobService {
* @param pageable 分页参数 * @param pageable 分页参数
* @return / * @return /
*/ */
Object queryAllLog(JobQueryCriteria criteria, Pageable pageable); PageResult<QuartzLog> queryAllLog(JobQueryCriteria criteria, Pageable pageable);
/** /**
* 查询全部 * 查询全部
......
...@@ -50,12 +50,12 @@ public class QuartzJobServiceImpl implements QuartzJobService { ...@@ -50,12 +50,12 @@ public class QuartzJobServiceImpl implements QuartzJobService {
private final RedisUtils redisUtils; private final RedisUtils redisUtils;
@Override @Override
public Object queryAll(JobQueryCriteria criteria, Pageable pageable){ public PageResult<QuartzJob> queryAll(JobQueryCriteria criteria, Pageable pageable){
return PageUtil.toPage(quartzJobRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable)); return PageUtil.toPage(quartzJobRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable));
} }
@Override @Override
public Object queryAllLog(JobQueryCriteria criteria, Pageable pageable){ public PageResult<QuartzLog> queryAllLog(JobQueryCriteria criteria, Pageable pageable){
return PageUtil.toPage(quartzLogRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable)); return PageUtil.toPage(quartzLogRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable));
} }
......
...@@ -124,7 +124,7 @@ public class ExecutionJob extends QuartzJobBean { ...@@ -124,7 +124,7 @@ public class ExecutionJob extends QuartzJobBean {
data.put("task", quartzJob); data.put("task", quartzJob);
data.put("msg", msg); data.put("msg", msg);
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH)); TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
Template template = engine.getTemplate("email/taskAlarm.ftl"); Template template = engine.getTemplate("taskAlarm.ftl");
emailVo.setContent(template.render(data)); emailVo.setContent(template.render(data));
List<String> emails = Arrays.asList(quartzJob.getEmail().split("[,,]")); List<String> emails = Arrays.asList(quartzJob.getEmail().split("[,,]"));
emailVo.setTos(emails); emailVo.setTos(emails);
......
...@@ -39,7 +39,7 @@ public class LoginProperties { ...@@ -39,7 +39,7 @@ public class LoginProperties {
private LoginCode loginCode; private LoginCode loginCode;
public static final String cacheKey = "USER-LOGIN-DATA"; public static final String cacheKey = "user-login-cache:";
public boolean isSingleLogin() { public boolean isSingleLogin() {
return singleLogin; return singleLogin;
......
...@@ -44,6 +44,7 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio ...@@ -44,6 +44,7 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -105,23 +106,24 @@ public class AuthorizationController { ...@@ -105,23 +106,24 @@ public class AuthorizationController {
// SecurityContextHolder.getContext().setAuthentication(authentication); // SecurityContextHolder.getContext().setAuthentication(authentication);
String token = tokenProvider.createToken(authentication); String token = tokenProvider.createToken(authentication);
final JwtUserDto jwtUserDto = (JwtUserDto) authentication.getPrincipal(); final JwtUserDto jwtUserDto = (JwtUserDto) authentication.getPrincipal();
// 保存在线信息
onlineUserService.save(jwtUserDto, token, request);
// 返回 token 与 用户信息 // 返回 token 与 用户信息
Map<String, Object> authInfo = new HashMap<String, Object>(2) {{ Map<String, Object> authInfo = new HashMap<String, Object>(2) {{
put("token", properties.getTokenStartWith() + token); put("token", properties.getTokenStartWith() + token);
put("user", jwtUserDto); put("user", jwtUserDto);
}}; }};
if (loginProperties.isSingleLogin()) { if (loginProperties.isSingleLogin()) {
//踢掉之前已经登录的token // 踢掉之前已经登录的token
onlineUserService.checkLoginOnUser(authUser.getUsername(), token); onlineUserService.kickOutForUsername(authUser.getUsername());
} }
// 保存在线信息
onlineUserService.save(jwtUserDto, token, request);
// 返回登录信息
return ResponseEntity.ok(authInfo); return ResponseEntity.ok(authInfo);
} }
@ApiOperation("获取用户信息") @ApiOperation("获取用户信息")
@GetMapping(value = "/info") @GetMapping(value = "/info")
public ResponseEntity<Object> getUserInfo() { public ResponseEntity<UserDetails> getUserInfo() {
return ResponseEntity.ok(SecurityUtils.getCurrentUser()); return ResponseEntity.ok(SecurityUtils.getCurrentUser());
} }
......
...@@ -15,11 +15,13 @@ ...@@ -15,11 +15,13 @@
*/ */
package me.zhengjie.modules.security.rest; package me.zhengjie.modules.security.rest;
import cn.hutool.db.PageResult;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import me.zhengjie.exception.BadRequestException; import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.security.service.OnlineUserService; import me.zhengjie.modules.security.service.OnlineUserService;
import me.zhengjie.modules.security.service.dto.OnlineUserDto;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -43,15 +45,15 @@ public class OnlineController { ...@@ -43,15 +45,15 @@ public class OnlineController {
@ApiOperation("查询在线用户") @ApiOperation("查询在线用户")
@GetMapping @GetMapping
@PreAuthorize("@el.check()") @PreAuthorize("@el.check()")
public ResponseEntity<Object> queryOnlineUser(String filter, Pageable pageable){ public ResponseEntity<PageResult<OnlineUserDto>> queryOnlineUser(String username, Pageable pageable){
return new ResponseEntity<>(onlineUserService.getAll(filter, pageable),HttpStatus.OK); return new ResponseEntity<>(onlineUserService.getAll(username, pageable),HttpStatus.OK);
} }
@ApiOperation("导出数据") @ApiOperation("导出数据")
@GetMapping(value = "/download") @GetMapping(value = "/download")
@PreAuthorize("@el.check()") @PreAuthorize("@el.check()")
public void exportOnlineUser(HttpServletResponse response, String filter) throws IOException { public void exportOnlineUser(HttpServletResponse response, String username) throws IOException {
onlineUserService.download(onlineUserService.getAll(filter), response); onlineUserService.download(onlineUserService.getAll(username), response);
} }
@ApiOperation("踢出用户") @ApiOperation("踢出用户")
......
...@@ -70,7 +70,8 @@ public class TokenFilter extends GenericFilterBean { ...@@ -70,7 +70,8 @@ public class TokenFilter extends GenericFilterBean {
OnlineUserDto onlineUserDto = null; OnlineUserDto onlineUserDto = null;
boolean cleanUserCache = false; boolean cleanUserCache = false;
try { try {
onlineUserDto = onlineUserService.getOne(properties.getOnlineKey() + token); String loginKey = tokenProvider.loginKey(token);
onlineUserDto = onlineUserService.getOne(loginKey);
} catch (ExpiredJwtException e) { } catch (ExpiredJwtException e) {
log.error(e.getMessage()); log.error(e.getMessage());
cleanUserCache = true; cleanUserCache = true;
......
...@@ -18,6 +18,7 @@ package me.zhengjie.modules.security.security; ...@@ -18,6 +18,7 @@ package me.zhengjie.modules.security.security;
import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.digest.DigestUtil;
import io.jsonwebtoken.*; import io.jsonwebtoken.*;
import io.jsonwebtoken.io.Decoders; import io.jsonwebtoken.io.Decoders;
import io.jsonwebtoken.security.Keys; import io.jsonwebtoken.security.Keys;
...@@ -120,4 +121,15 @@ public class TokenProvider implements InitializingBean { ...@@ -120,4 +121,15 @@ public class TokenProvider implements InitializingBean {
} }
return null; return null;
} }
/**
* 获取登录用户RedisKey
* @param token /
* @return key
*/
public String loginKey(String token) {
Claims claims = getClaims(token);
String md5Token = DigestUtil.md5Hex(token);
return properties.getOnlineKey() + claims.getSubject() + "-" + md5Token;
}
} }
...@@ -15,7 +15,10 @@ ...@@ -15,7 +15,10 @@
*/ */
package me.zhengjie.modules.security.service; package me.zhengjie.modules.security.service;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.security.security.TokenProvider;
import me.zhengjie.utils.PageResult;
import me.zhengjie.modules.security.config.bean.SecurityProperties; import me.zhengjie.modules.security.config.bean.SecurityProperties;
import me.zhengjie.modules.security.service.dto.JwtUserDto; import me.zhengjie.modules.security.service.dto.JwtUserDto;
import me.zhengjie.modules.security.service.dto.OnlineUserDto; import me.zhengjie.modules.security.service.dto.OnlineUserDto;
...@@ -27,6 +30,7 @@ import javax.servlet.http.HttpServletRequest; ...@@ -27,6 +30,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
/** /**
* @author Zheng Jie * @author Zheng Jie
...@@ -34,16 +38,13 @@ import java.util.*; ...@@ -34,16 +38,13 @@ import java.util.*;
*/ */
@Service @Service
@Slf4j @Slf4j
@AllArgsConstructor
public class OnlineUserService { public class OnlineUserService {
private final SecurityProperties properties; private final SecurityProperties properties;
private final TokenProvider tokenProvider;
private final RedisUtils redisUtils; private final RedisUtils redisUtils;
public OnlineUserService(SecurityProperties properties, RedisUtils redisUtils) {
this.properties = properties;
this.redisUtils = redisUtils;
}
/** /**
* 保存在线用户信息 * 保存在线用户信息
* @param jwtUserDto / * @param jwtUserDto /
...@@ -61,62 +62,49 @@ public class OnlineUserService { ...@@ -61,62 +62,49 @@ public class OnlineUserService {
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(),e); log.error(e.getMessage(),e);
} }
redisUtils.set(properties.getOnlineKey() + token, onlineUserDto, properties.getTokenValidityInSeconds()/1000); String loginKey = tokenProvider.loginKey(token);
redisUtils.set(loginKey, onlineUserDto, properties.getTokenValidityInSeconds(), TimeUnit.MILLISECONDS);
} }
/** /**
* 查询全部数据 * 查询全部数据
* @param filter / * @param username /
* @param pageable / * @param pageable /
* @return / * @return /
*/ */
public Map<String,Object> getAll(String filter, Pageable pageable){ public PageResult<OnlineUserDto> getAll(String username, Pageable pageable){
List<OnlineUserDto> onlineUserDtos = getAll(filter); List<OnlineUserDto> onlineUserDtos = getAll(username);
return PageUtil.toPage( return PageUtil.toPage(
PageUtil.toPage(pageable.getPageNumber(),pageable.getPageSize(), onlineUserDtos), PageUtil.paging(pageable.getPageNumber(),pageable.getPageSize(), onlineUserDtos),
onlineUserDtos.size() onlineUserDtos.size()
); );
} }
/** /**
* 查询全部数据,不分页 * 查询全部数据,不分页
* @param filter / * @param username /
* @return / * @return /
*/ */
public List<OnlineUserDto> getAll(String filter){ public List<OnlineUserDto> getAll(String username){
List<String> keys = redisUtils.scan(properties.getOnlineKey() + "*"); String loginKey = properties.getOnlineKey() +
(StringUtils.isBlank(username) ? "" : "*" + username);
List<String> keys = redisUtils.scan(loginKey + "*");
Collections.reverse(keys); Collections.reverse(keys);
List<OnlineUserDto> onlineUserDtos = new ArrayList<>(); List<OnlineUserDto> onlineUserDtos = new ArrayList<>();
for (String key : keys) { for (String key : keys) {
OnlineUserDto onlineUserDto = (OnlineUserDto) redisUtils.get(key); onlineUserDtos.add((OnlineUserDto) redisUtils.get(key));
if(StringUtils.isNotBlank(filter)){
if(onlineUserDto.toString().contains(filter)){
onlineUserDtos.add(onlineUserDto);
}
} else {
onlineUserDtos.add(onlineUserDto);
}
} }
onlineUserDtos.sort((o1, o2) -> o2.getLoginTime().compareTo(o1.getLoginTime())); onlineUserDtos.sort((o1, o2) -> o2.getLoginTime().compareTo(o1.getLoginTime()));
return onlineUserDtos; return onlineUserDtos;
} }
/**
* 踢出用户
* @param key /
*/
public void kickOut(String key){
key = properties.getOnlineKey() + key;
redisUtils.del(key);
}
/** /**
* 退出登录 * 退出登录
* @param token / * @param token /
*/ */
public void logout(String token) { public void logout(String token) {
String key = properties.getOnlineKey() + token; String loginKey = tokenProvider.loginKey(token);
redisUtils.del(key); redisUtils.del(loginKey);
} }
/** /**
...@@ -149,43 +137,13 @@ public class OnlineUserService { ...@@ -149,43 +137,13 @@ public class OnlineUserService {
return (OnlineUserDto)redisUtils.get(key); return (OnlineUserDto)redisUtils.get(key);
} }
/**
* 检测用户是否在之前已经登录,已经登录踢下线
* @param userName 用户名
*/
public void checkLoginOnUser(String userName, String igoreToken){
List<OnlineUserDto> onlineUserDtos = getAll(userName);
if(onlineUserDtos ==null || onlineUserDtos.isEmpty()){
return;
}
for(OnlineUserDto onlineUserDto : onlineUserDtos){
if(onlineUserDto.getUserName().equals(userName)){
try {
String token =EncryptUtils.desDecrypt(onlineUserDto.getKey());
if(StringUtils.isNotBlank(igoreToken)&&!igoreToken.equals(token)){
this.kickOut(token);
}else if(StringUtils.isBlank(igoreToken)){
this.kickOut(token);
}
} catch (Exception e) {
log.error("checkUser is error",e);
}
}
}
}
/** /**
* 根据用户名强退用户 * 根据用户名强退用户
* @param username / * @param username /
*/ */
@Async @Async
public void kickOutForUsername(String username) throws Exception { public void kickOutForUsername(String username) {
List<OnlineUserDto> onlineUsers = getAll(username); String loginKey = properties.getOnlineKey() + username + "*";
for (OnlineUserDto onlineUser : onlineUsers) { redisUtils.scanDel(loginKey);
if (onlineUser.getUserName().equals(username)) {
String token =EncryptUtils.desDecrypt(onlineUser.getKey());
kickOut(token);
}
}
} }
} }
...@@ -46,7 +46,7 @@ public class UserCacheManager { ...@@ -46,7 +46,7 @@ public class UserCacheManager {
public JwtUserDto getUserCache(String userName) { public JwtUserDto getUserCache(String userName) {
if (StringUtils.isNotEmpty(userName)) { if (StringUtils.isNotEmpty(userName)) {
// 获取数据 // 获取数据
Object obj = redisUtils.hget(LoginProperties.cacheKey, userName); Object obj = redisUtils.get(LoginProperties.cacheKey + userName);
if(obj != null){ if(obj != null){
return (JwtUserDto)obj; return (JwtUserDto)obj;
} }
...@@ -63,7 +63,7 @@ public class UserCacheManager { ...@@ -63,7 +63,7 @@ public class UserCacheManager {
if (StringUtils.isNotEmpty(userName)) { if (StringUtils.isNotEmpty(userName)) {
// 添加数据, 避免数据同时过期 // 添加数据, 避免数据同时过期
long time = idleTime + RandomUtil.randomInt(900, 1800); long time = idleTime + RandomUtil.randomInt(900, 1800);
redisUtils.hset(LoginProperties.cacheKey, userName, user, time); redisUtils.set(LoginProperties.cacheKey + userName, user, time);
} }
} }
...@@ -76,7 +76,7 @@ public class UserCacheManager { ...@@ -76,7 +76,7 @@ public class UserCacheManager {
public void cleanUserCache(String userName) { public void cleanUserCache(String userName) {
if (StringUtils.isNotEmpty(userName)) { if (StringUtils.isNotEmpty(userName)) {
// 清除数据 // 清除数据
redisUtils.hdel(LoginProperties.cacheKey, userName); redisUtils.del(LoginProperties.cacheKey + userName);
} }
} }
} }
\ No newline at end of file
...@@ -25,6 +25,7 @@ import me.zhengjie.modules.system.domain.Dept; ...@@ -25,6 +25,7 @@ import me.zhengjie.modules.system.domain.Dept;
import me.zhengjie.modules.system.service.DeptService; import me.zhengjie.modules.system.service.DeptService;
import me.zhengjie.modules.system.service.dto.DeptDto; import me.zhengjie.modules.system.service.dto.DeptDto;
import me.zhengjie.modules.system.service.dto.DeptQueryCriteria; import me.zhengjie.modules.system.service.dto.DeptQueryCriteria;
import me.zhengjie.utils.PageResult;
import me.zhengjie.utils.PageUtil; import me.zhengjie.utils.PageUtil;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -57,22 +58,22 @@ public class DeptController { ...@@ -57,22 +58,22 @@ public class DeptController {
@ApiOperation("查询部门") @ApiOperation("查询部门")
@GetMapping @GetMapping
@PreAuthorize("@el.check('user:list','dept:list')") @PreAuthorize("@el.check('user:list','dept:list')")
public ResponseEntity<Object> queryDept(DeptQueryCriteria criteria) throws Exception { public ResponseEntity<PageResult<DeptDto>> queryDept(DeptQueryCriteria criteria) throws Exception {
List<DeptDto> deptDtos = deptService.queryAll(criteria, true); List<DeptDto> depts = deptService.queryAll(criteria, true);
return new ResponseEntity<>(PageUtil.toPage(deptDtos, deptDtos.size()),HttpStatus.OK); return new ResponseEntity<>(PageUtil.toPage(depts, depts.size()),HttpStatus.OK);
} }
@ApiOperation("查询部门:根据ID获取同级与上级数据") @ApiOperation("查询部门:根据ID获取同级与上级数据")
@PostMapping("/superior") @PostMapping("/superior")
@PreAuthorize("@el.check('user:list','dept:list')") @PreAuthorize("@el.check('user:list','dept:list')")
public ResponseEntity<Object> getDeptSuperior(@RequestBody List<Long> ids) { public ResponseEntity<Object> getDeptSuperior(@RequestBody List<Long> ids) {
Set<DeptDto> deptDtos = new LinkedHashSet<>(); Set<DeptDto> deptSet = new LinkedHashSet<>();
for (Long id : ids) { for (Long id : ids) {
DeptDto deptDto = deptService.findById(id); DeptDto deptDto = deptService.findById(id);
List<DeptDto> depts = deptService.getSuperior(deptDto, new ArrayList<>()); List<DeptDto> depts = deptService.getSuperior(deptDto, new ArrayList<>());
deptDtos.addAll(depts); deptSet.addAll(depts);
} }
return new ResponseEntity<>(deptService.buildTree(new ArrayList<>(deptDtos)),HttpStatus.OK); return new ResponseEntity<>(deptService.buildTree(new ArrayList<>(deptSet)),HttpStatus.OK);
} }
@Log("新增部门") @Log("新增部门")
......
...@@ -22,7 +22,10 @@ import me.zhengjie.annotation.Log; ...@@ -22,7 +22,10 @@ import me.zhengjie.annotation.Log;
import me.zhengjie.exception.BadRequestException; import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.Dict; import me.zhengjie.modules.system.domain.Dict;
import me.zhengjie.modules.system.service.DictService; import me.zhengjie.modules.system.service.DictService;
import me.zhengjie.modules.system.service.dto.DictDto;
import me.zhengjie.modules.system.service.dto.DictQueryCriteria; import me.zhengjie.modules.system.service.dto.DictQueryCriteria;
import me.zhengjie.utils.PageResult;
import me.zhengjie.utils.PageUtil;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -31,6 +34,7 @@ import org.springframework.validation.annotation.Validated; ...@@ -31,6 +34,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.Set; import java.util.Set;
/** /**
...@@ -56,14 +60,14 @@ public class DictController { ...@@ -56,14 +60,14 @@ public class DictController {
@ApiOperation("查询字典") @ApiOperation("查询字典")
@GetMapping(value = "/all") @GetMapping(value = "/all")
@PreAuthorize("@el.check('dict:list')") @PreAuthorize("@el.check('dict:list')")
public ResponseEntity<Object> queryAllDict(){ public ResponseEntity<List<DictDto>> queryAllDict(){
return new ResponseEntity<>(dictService.queryAll(new DictQueryCriteria()),HttpStatus.OK); return new ResponseEntity<>(dictService.queryAll(new DictQueryCriteria()),HttpStatus.OK);
} }
@ApiOperation("查询字典") @ApiOperation("查询字典")
@GetMapping @GetMapping
@PreAuthorize("@el.check('dict:list')") @PreAuthorize("@el.check('dict:list')")
public ResponseEntity<Object> queryDict(DictQueryCriteria resources, Pageable pageable){ public ResponseEntity<PageResult<DictDto>> queryDict(DictQueryCriteria resources, Pageable pageable){
return new ResponseEntity<>(dictService.queryAll(resources,pageable),HttpStatus.OK); return new ResponseEntity<>(dictService.queryAll(resources,pageable),HttpStatus.OK);
} }
......
...@@ -24,6 +24,7 @@ import me.zhengjie.modules.system.domain.DictDetail; ...@@ -24,6 +24,7 @@ import me.zhengjie.modules.system.domain.DictDetail;
import me.zhengjie.modules.system.service.DictDetailService; import me.zhengjie.modules.system.service.DictDetailService;
import me.zhengjie.modules.system.service.dto.DictDetailDto; import me.zhengjie.modules.system.service.dto.DictDetailDto;
import me.zhengjie.modules.system.service.dto.DictDetailQueryCriteria; import me.zhengjie.modules.system.service.dto.DictDetailQueryCriteria;
import me.zhengjie.utils.PageResult;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault; import org.springframework.data.web.PageableDefault;
...@@ -51,8 +52,8 @@ public class DictDetailController { ...@@ -51,8 +52,8 @@ public class DictDetailController {
@ApiOperation("查询字典详情") @ApiOperation("查询字典详情")
@GetMapping @GetMapping
public ResponseEntity<Object> queryDictDetail(DictDetailQueryCriteria criteria, public ResponseEntity<PageResult<DictDetailDto>> queryDictDetail(DictDetailQueryCriteria criteria,
@PageableDefault(sort = {"dictSort"}, direction = Sort.Direction.ASC) Pageable pageable){ @PageableDefault(sort = {"dictSort"}, direction = Sort.Direction.ASC) Pageable pageable){
return new ResponseEntity<>(dictDetailService.queryAll(criteria,pageable),HttpStatus.OK); return new ResponseEntity<>(dictDetailService.queryAll(criteria,pageable),HttpStatus.OK);
} }
......
...@@ -22,7 +22,9 @@ import me.zhengjie.annotation.Log; ...@@ -22,7 +22,9 @@ import me.zhengjie.annotation.Log;
import me.zhengjie.exception.BadRequestException; import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.Job; import me.zhengjie.modules.system.domain.Job;
import me.zhengjie.modules.system.service.JobService; import me.zhengjie.modules.system.service.JobService;
import me.zhengjie.modules.system.service.dto.JobDto;
import me.zhengjie.modules.system.service.dto.JobQueryCriteria; import me.zhengjie.modules.system.service.dto.JobQueryCriteria;
import me.zhengjie.utils.PageResult;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -56,7 +58,7 @@ public class JobController { ...@@ -56,7 +58,7 @@ public class JobController {
@ApiOperation("查询岗位") @ApiOperation("查询岗位")
@GetMapping @GetMapping
@PreAuthorize("@el.check('job:list','user:list')") @PreAuthorize("@el.check('job:list','user:list')")
public ResponseEntity<Object> queryJob(JobQueryCriteria criteria, Pageable pageable){ public ResponseEntity<PageResult<JobDto>> queryJob(JobQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(jobService.queryAll(criteria, pageable),HttpStatus.OK); return new ResponseEntity<>(jobService.queryAll(criteria, pageable),HttpStatus.OK);
} }
......
...@@ -22,10 +22,12 @@ import lombok.RequiredArgsConstructor; ...@@ -22,10 +22,12 @@ import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log; import me.zhengjie.annotation.Log;
import me.zhengjie.modules.system.domain.Menu; import me.zhengjie.modules.system.domain.Menu;
import me.zhengjie.exception.BadRequestException; import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.vo.MenuVo;
import me.zhengjie.modules.system.service.MenuService; import me.zhengjie.modules.system.service.MenuService;
import me.zhengjie.modules.system.service.dto.MenuDto; import me.zhengjie.modules.system.service.dto.MenuDto;
import me.zhengjie.modules.system.service.dto.MenuQueryCriteria; import me.zhengjie.modules.system.service.dto.MenuQueryCriteria;
import me.zhengjie.modules.system.service.mapstruct.MenuMapper; import me.zhengjie.modules.system.service.mapstruct.MenuMapper;
import me.zhengjie.utils.PageResult;
import me.zhengjie.utils.PageUtil; import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.SecurityUtils; import me.zhengjie.utils.SecurityUtils;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
...@@ -61,16 +63,16 @@ public class MenuController { ...@@ -61,16 +63,16 @@ public class MenuController {
@GetMapping(value = "/build") @GetMapping(value = "/build")
@ApiOperation("获取前端所需菜单") @ApiOperation("获取前端所需菜单")
public ResponseEntity<Object> buildMenus(){ public ResponseEntity<List<MenuVo>> buildMenus(){
List<MenuDto> menuDtoList = menuService.findByUser(SecurityUtils.getCurrentUserId()); List<MenuDto> menuDtoList = menuService.findByUser(SecurityUtils.getCurrentUserId());
List<MenuDto> menuDtos = menuService.buildTree(menuDtoList); List<MenuDto> menus = menuService.buildTree(menuDtoList);
return new ResponseEntity<>(menuService.buildMenus(menuDtos),HttpStatus.OK); return new ResponseEntity<>(menuService.buildMenus(menus),HttpStatus.OK);
} }
@ApiOperation("返回全部的菜单") @ApiOperation("返回全部的菜单")
@GetMapping(value = "/lazy") @GetMapping(value = "/lazy")
@PreAuthorize("@el.check('menu:list','roles:list')") @PreAuthorize("@el.check('menu:list','roles:list')")
public ResponseEntity<Object> queryAllMenu(@RequestParam Long pid){ public ResponseEntity<List<MenuDto>> queryAllMenu(@RequestParam Long pid){
return new ResponseEntity<>(menuService.getMenus(pid),HttpStatus.OK); return new ResponseEntity<>(menuService.getMenus(pid),HttpStatus.OK);
} }
...@@ -89,7 +91,7 @@ public class MenuController { ...@@ -89,7 +91,7 @@ public class MenuController {
@GetMapping @GetMapping
@ApiOperation("查询菜单") @ApiOperation("查询菜单")
@PreAuthorize("@el.check('menu:list')") @PreAuthorize("@el.check('menu:list')")
public ResponseEntity<Object> queryMenu(MenuQueryCriteria criteria) throws Exception { public ResponseEntity<PageResult<MenuDto>> queryMenu(MenuQueryCriteria criteria) throws Exception {
List<MenuDto> menuDtoList = menuService.queryAll(criteria, true); List<MenuDto> menuDtoList = menuService.queryAll(criteria, true);
return new ResponseEntity<>(PageUtil.toPage(menuDtoList, menuDtoList.size()),HttpStatus.OK); return new ResponseEntity<>(PageUtil.toPage(menuDtoList, menuDtoList.size()),HttpStatus.OK);
} }
...@@ -97,7 +99,7 @@ public class MenuController { ...@@ -97,7 +99,7 @@ public class MenuController {
@ApiOperation("查询菜单:根据ID获取同级与上级数据") @ApiOperation("查询菜单:根据ID获取同级与上级数据")
@PostMapping("/superior") @PostMapping("/superior")
@PreAuthorize("@el.check('menu:list')") @PreAuthorize("@el.check('menu:list')")
public ResponseEntity<Object> getMenuSuperior(@RequestBody List<Long> ids) { public ResponseEntity<List<MenuDto>> getMenuSuperior(@RequestBody List<Long> ids) {
Set<MenuDto> menuDtos = new LinkedHashSet<>(); Set<MenuDto> menuDtos = new LinkedHashSet<>();
if(CollectionUtil.isNotEmpty(ids)){ if(CollectionUtil.isNotEmpty(ids)){
for (Long id : ids) { for (Long id : ids) {
......
...@@ -26,6 +26,7 @@ import me.zhengjie.modules.system.service.RoleService; ...@@ -26,6 +26,7 @@ import me.zhengjie.modules.system.service.RoleService;
import me.zhengjie.modules.system.service.dto.RoleDto; import me.zhengjie.modules.system.service.dto.RoleDto;
import me.zhengjie.modules.system.service.dto.RoleQueryCriteria; import me.zhengjie.modules.system.service.dto.RoleQueryCriteria;
import me.zhengjie.modules.system.service.dto.RoleSmallDto; import me.zhengjie.modules.system.service.dto.RoleSmallDto;
import me.zhengjie.utils.PageResult;
import me.zhengjie.utils.SecurityUtils; import me.zhengjie.utils.SecurityUtils;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
...@@ -57,7 +58,7 @@ public class RoleController { ...@@ -57,7 +58,7 @@ public class RoleController {
@ApiOperation("获取单个role") @ApiOperation("获取单个role")
@GetMapping(value = "/{id}") @GetMapping(value = "/{id}")
@PreAuthorize("@el.check('roles:list')") @PreAuthorize("@el.check('roles:list')")
public ResponseEntity<Object> findRoleById(@PathVariable Long id){ public ResponseEntity<RoleDto> findRoleById(@PathVariable Long id){
return new ResponseEntity<>(roleService.findById(id), HttpStatus.OK); return new ResponseEntity<>(roleService.findById(id), HttpStatus.OK);
} }
...@@ -71,14 +72,14 @@ public class RoleController { ...@@ -71,14 +72,14 @@ public class RoleController {
@ApiOperation("返回全部的角色") @ApiOperation("返回全部的角色")
@GetMapping(value = "/all") @GetMapping(value = "/all")
@PreAuthorize("@el.check('roles:list','user:add','user:edit')") @PreAuthorize("@el.check('roles:list','user:add','user:edit')")
public ResponseEntity<Object> queryAllRole(){ public ResponseEntity<List<RoleDto>> queryAllRole(){
return new ResponseEntity<>(roleService.queryAll(),HttpStatus.OK); return new ResponseEntity<>(roleService.queryAll(),HttpStatus.OK);
} }
@ApiOperation("查询角色") @ApiOperation("查询角色")
@GetMapping @GetMapping
@PreAuthorize("@el.check('roles:list')") @PreAuthorize("@el.check('roles:list')")
public ResponseEntity<Object> queryRole(RoleQueryCriteria criteria, Pageable pageable){ public ResponseEntity<PageResult<RoleDto>> queryRole(RoleQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(roleService.queryAll(criteria,pageable),HttpStatus.OK); return new ResponseEntity<>(roleService.queryAll(criteria,pageable),HttpStatus.OK);
} }
......
...@@ -20,6 +20,7 @@ import io.swagger.annotations.Api; ...@@ -20,6 +20,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log; import me.zhengjie.annotation.Log;
import me.zhengjie.utils.PageResult;
import me.zhengjie.config.RsaProperties; import me.zhengjie.config.RsaProperties;
import me.zhengjie.modules.system.domain.Dept; import me.zhengjie.modules.system.domain.Dept;
import me.zhengjie.modules.system.service.DataService; import me.zhengjie.modules.system.service.DataService;
...@@ -77,7 +78,7 @@ public class UserController { ...@@ -77,7 +78,7 @@ public class UserController {
@ApiOperation("查询用户") @ApiOperation("查询用户")
@GetMapping @GetMapping
@PreAuthorize("@el.check('user:list')") @PreAuthorize("@el.check('user:list')")
public ResponseEntity<Object> queryUser(UserQueryCriteria criteria, Pageable pageable){ public ResponseEntity<PageResult<UserDto>> queryUser(UserQueryCriteria criteria, Pageable pageable){
if (!ObjectUtils.isEmpty(criteria.getDeptId())) { if (!ObjectUtils.isEmpty(criteria.getDeptId())) {
criteria.getDeptIds().add(criteria.getDeptId()); criteria.getDeptIds().add(criteria.getDeptId());
// 先查找是否存在子节点 // 先查找是否存在子节点
...@@ -99,7 +100,7 @@ public class UserController { ...@@ -99,7 +100,7 @@ public class UserController {
criteria.getDeptIds().addAll(dataScopes); criteria.getDeptIds().addAll(dataScopes);
return new ResponseEntity<>(userService.queryAll(criteria,pageable),HttpStatus.OK); return new ResponseEntity<>(userService.queryAll(criteria,pageable),HttpStatus.OK);
} }
return new ResponseEntity<>(PageUtil.toPage(null,0),HttpStatus.OK); return new ResponseEntity<>(PageUtil.noData(),HttpStatus.OK);
} }
@Log("新增用户") @Log("新增用户")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment