mirror of https://github.com/elunez/eladmin
Merge branch 'source'
# Conflicts: # eladmin-common/src/main/java/me/zhengjie/utils/CacheKey.java # eladmin-common/src/main/java/me/zhengjie/utils/DateUtil.java # eladmin-system/src/main/java/me/zhengjie/modules/security/security/TokenFilter.java # eladmin-system/src/main/java/me/zhengjie/modules/security/security/TokenProvider.java # eladmin-system/src/main/java/me/zhengjie/modules/security/service/UserCacheClean.java # eladmin-system/src/main/java/me/zhengjie/modules/security/service/UserDetailsServiceImpl.java # eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/RoleServiceImpl.java # eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java # eladmin-system/src/test/java/me/zhengjie/LoginCacheTest.javapull/432/head
commit
b2fdf7cb22
|
@ -80,8 +80,8 @@ public @interface Query {
|
||||||
* 适用于简单连接查询,复杂的请自定义该注解,或者使用sql查询
|
* 适用于简单连接查询,复杂的请自定义该注解,或者使用sql查询
|
||||||
*/
|
*/
|
||||||
enum Join {
|
enum Join {
|
||||||
/** jie 2019-6-4 13:18:30 左右连接 */
|
/** jie 2019-6-4 13:18:30 */
|
||||||
LEFT, RIGHT
|
LEFT, RIGHT, INNER
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,16 +13,15 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.zhengjie.utils;
|
package me.zhengjie.utils;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: liaojinlong
|
* @author: liaojinlong
|
||||||
* @date: 2020/6/11 15:49
|
* @date: 2020/6/11 15:49
|
||||||
* @apiNote: 关于缓存的Key 集合
|
* @apiNote: 关于缓存的Key集合
|
||||||
*/
|
*/
|
||||||
public interface CacheKey {
|
public interface CacheKey {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 内置 用户、岗位、应用、菜单、角色 相关key
|
* 内置 用户、岗位、应用、菜单、角色 相关key
|
||||||
*/
|
*/
|
||||||
|
@ -39,9 +38,8 @@ public interface CacheKey {
|
||||||
String USER_ID = "user::id:";
|
String USER_ID = "user::id:";
|
||||||
String USER_NAME = "user::username:";
|
String USER_NAME = "user::username:";
|
||||||
/**
|
/**
|
||||||
* s数据
|
* 数据
|
||||||
*/
|
*/
|
||||||
|
|
||||||
String DATE_USER = "data::user:";
|
String DATE_USER = "data::user:";
|
||||||
/**
|
/**
|
||||||
* 菜单
|
* 菜单
|
||||||
|
@ -51,6 +49,8 @@ public interface CacheKey {
|
||||||
* 角色授权
|
* 角色授权
|
||||||
*/
|
*/
|
||||||
String ROLE_AUTH = "role::auth:";
|
String ROLE_AUTH = "role::auth:";
|
||||||
|
/**
|
||||||
|
* 角色信息
|
||||||
|
*/
|
||||||
String ROLE_ID = "role::id:";
|
String ROLE_ID = "role::id:";
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,14 +26,15 @@ import java.util.Date;
|
||||||
* @apiNote: JDK 8 新日期类 格式化与字符串转换 工具类
|
* @apiNote: JDK 8 新日期类 格式化与字符串转换 工具类
|
||||||
*/
|
*/
|
||||||
public class DateUtil {
|
public class DateUtil {
|
||||||
public static final DateTimeFormatter dfyMdHms = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
||||||
public static final DateTimeFormatter dfyMd = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
public static final DateTimeFormatter DFY_MD_HMS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
public static final DateTimeFormatter DFY_MD = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LocalDateTime 转时间戳
|
* LocalDateTime 转时间戳
|
||||||
*
|
*
|
||||||
* @param localDateTime
|
* @param localDateTime /
|
||||||
* @return/
|
* @return /
|
||||||
*/
|
*/
|
||||||
public static Long getTimeStamp(LocalDateTime localDateTime) {
|
public static Long getTimeStamp(LocalDateTime localDateTime) {
|
||||||
return localDateTime.atZone(ZoneId.systemDefault()).toEpochSecond();
|
return localDateTime.atZone(ZoneId.systemDefault()).toEpochSecond();
|
||||||
|
@ -42,8 +43,8 @@ public class DateUtil {
|
||||||
/**
|
/**
|
||||||
* 时间戳转LocalDateTime
|
* 时间戳转LocalDateTime
|
||||||
*
|
*
|
||||||
* @param timeStamp
|
* @param timeStamp /
|
||||||
* @return/
|
* @return /
|
||||||
*/
|
*/
|
||||||
public static LocalDateTime fromTimeStamp(Long timeStamp) {
|
public static LocalDateTime fromTimeStamp(Long timeStamp) {
|
||||||
return LocalDateTime.ofEpochSecond(timeStamp, 0, OffsetDateTime.now().getOffset());
|
return LocalDateTime.ofEpochSecond(timeStamp, 0, OffsetDateTime.now().getOffset());
|
||||||
|
@ -53,8 +54,8 @@ public class DateUtil {
|
||||||
* LocalDateTime 转 Date
|
* LocalDateTime 转 Date
|
||||||
* Jdk8 后 不推荐使用 {@link Date} Date
|
* Jdk8 后 不推荐使用 {@link Date} Date
|
||||||
*
|
*
|
||||||
* @param localDateTime
|
* @param localDateTime /
|
||||||
* @return/
|
* @return /
|
||||||
*/
|
*/
|
||||||
public static Date toDate(LocalDateTime localDateTime) {
|
public static Date toDate(LocalDateTime localDateTime) {
|
||||||
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
||||||
|
@ -64,8 +65,8 @@ public class DateUtil {
|
||||||
* LocalDate 转 Date
|
* LocalDate 转 Date
|
||||||
* Jdk8 后 不推荐使用 {@link Date} Date
|
* Jdk8 后 不推荐使用 {@link Date} Date
|
||||||
*
|
*
|
||||||
* @param localDate
|
* @param localDate /
|
||||||
* @return/
|
* @return /
|
||||||
*/
|
*/
|
||||||
public static Date toDate(LocalDate localDate) {
|
public static Date toDate(LocalDate localDate) {
|
||||||
return toDate(localDate.atTime(LocalTime.now(ZoneId.systemDefault())));
|
return toDate(localDate.atTime(LocalTime.now(ZoneId.systemDefault())));
|
||||||
|
@ -76,8 +77,8 @@ public class DateUtil {
|
||||||
* Date转 LocalDateTime
|
* Date转 LocalDateTime
|
||||||
* Jdk8 后 不推荐使用 {@link Date} Date
|
* Jdk8 后 不推荐使用 {@link Date} Date
|
||||||
*
|
*
|
||||||
* @param date
|
* @param date /
|
||||||
* @return/
|
* @return /
|
||||||
*/
|
*/
|
||||||
public static LocalDateTime toLocalDateTime(Date date) {
|
public static LocalDateTime toLocalDateTime(Date date) {
|
||||||
return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
|
return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
|
||||||
|
@ -86,9 +87,9 @@ public class DateUtil {
|
||||||
/**
|
/**
|
||||||
* 日期 格式化
|
* 日期 格式化
|
||||||
*
|
*
|
||||||
* @param localDateTime
|
* @param localDateTime /
|
||||||
* @param patten
|
* @param patten /
|
||||||
* @return/
|
* @return /
|
||||||
*/
|
*/
|
||||||
public static String localDateTimeFormat(LocalDateTime localDateTime, String patten) {
|
public static String localDateTimeFormat(LocalDateTime localDateTime, String patten) {
|
||||||
DateTimeFormatter df = DateTimeFormatter.ofPattern(patten);
|
DateTimeFormatter df = DateTimeFormatter.ofPattern(patten);
|
||||||
|
@ -98,9 +99,9 @@ public class DateUtil {
|
||||||
/**
|
/**
|
||||||
* 日期 格式化
|
* 日期 格式化
|
||||||
*
|
*
|
||||||
* @param localDateTime
|
* @param localDateTime /
|
||||||
* @param df
|
* @param df /
|
||||||
* @return/
|
* @return /
|
||||||
*/
|
*/
|
||||||
public static String localDateTimeFormat(LocalDateTime localDateTime, DateTimeFormatter df) {
|
public static String localDateTimeFormat(LocalDateTime localDateTime, DateTimeFormatter df) {
|
||||||
return df.format(localDateTime);
|
return df.format(localDateTime);
|
||||||
|
@ -109,28 +110,28 @@ public class DateUtil {
|
||||||
/**
|
/**
|
||||||
* 日期格式化 yyyy-MM-dd HH:mm:ss
|
* 日期格式化 yyyy-MM-dd HH:mm:ss
|
||||||
*
|
*
|
||||||
* @param localDateTime
|
* @param localDateTime /
|
||||||
* @return/
|
* @return /
|
||||||
*/
|
*/
|
||||||
public static String localDateTimeFormatyMdHms(LocalDateTime localDateTime) {
|
public static String localDateTimeFormatyMdHms(LocalDateTime localDateTime) {
|
||||||
return dfyMdHms.format(localDateTime);
|
return DFY_MD_HMS.format(localDateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日期格式化 yyyy-MM-dd
|
* 日期格式化 yyyy-MM-dd
|
||||||
*
|
*
|
||||||
* @param localDateTime
|
* @param localDateTime /
|
||||||
* @return/
|
* @return /
|
||||||
*/
|
*/
|
||||||
public String localDateTimeFormatyMd(LocalDateTime localDateTime) {
|
public String localDateTimeFormatyMd(LocalDateTime localDateTime) {
|
||||||
return dfyMd.format(localDateTime);
|
return DFY_MD.format(localDateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字符串转 LocalDateTime ,字符串格式 yyyy-MM-dd
|
* 字符串转 LocalDateTime ,字符串格式 yyyy-MM-dd
|
||||||
*
|
*
|
||||||
* @param localDateTime
|
* @param localDateTime /
|
||||||
* @return/
|
* @return /
|
||||||
*/
|
*/
|
||||||
public static LocalDateTime parseLocalDateTimeFormat(String localDateTime, String pattern) {
|
public static LocalDateTime parseLocalDateTimeFormat(String localDateTime, String pattern) {
|
||||||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
|
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
|
||||||
|
@ -140,30 +141,20 @@ public class DateUtil {
|
||||||
/**
|
/**
|
||||||
* 字符串转 LocalDateTime ,字符串格式 yyyy-MM-dd
|
* 字符串转 LocalDateTime ,字符串格式 yyyy-MM-dd
|
||||||
*
|
*
|
||||||
* @param localDateTime
|
* @param localDateTime /
|
||||||
* @return/
|
* @return /
|
||||||
*/
|
*/
|
||||||
public static LocalDateTime parseLocalDateTimeFormat(String localDateTime, DateTimeFormatter dateTimeFormatter) {
|
public static LocalDateTime parseLocalDateTimeFormat(String localDateTime, DateTimeFormatter dateTimeFormatter) {
|
||||||
return LocalDateTime.from(dateTimeFormatter.parse(localDateTime));
|
return LocalDateTime.from(dateTimeFormatter.parse(localDateTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 字符串转 LocalDateTime ,字符串格式 yyyy-MM-dd
|
|
||||||
*
|
|
||||||
* @param localDateTime
|
|
||||||
* @return/
|
|
||||||
*/
|
|
||||||
public static LocalDateTime parseLocalDateTimeFormatyMd(String localDateTime) {
|
|
||||||
return LocalDateTime.from(dfyMd.parse(localDateTime));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字符串转 LocalDateTime ,字符串格式 yyyy-MM-dd HH:mm:ss
|
* 字符串转 LocalDateTime ,字符串格式 yyyy-MM-dd HH:mm:ss
|
||||||
*
|
*
|
||||||
* @param localDateTime
|
* @param localDateTime /
|
||||||
* @return/
|
* @return /
|
||||||
*/
|
*/
|
||||||
public static LocalDateTime parseLocalDateTimeFormatyMdHms(String localDateTime) {
|
public static LocalDateTime parseLocalDateTimeFormatyMdHms(String localDateTime) {
|
||||||
return LocalDateTime.from(dfyMdHms.parse(localDateTime));
|
return LocalDateTime.from(DFY_MD_HMS.parse(localDateTime));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,13 @@ public class QueryHelp {
|
||||||
join = root.join(name, JoinType.RIGHT);
|
join = root.join(name, JoinType.RIGHT);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case INNER:
|
||||||
|
if(ObjectUtil.isNotNull(join) && ObjectUtil.isNotNull(val)){
|
||||||
|
join = join.join(name, JoinType.INNER);
|
||||||
|
} else {
|
||||||
|
join = root.join(name, JoinType.INNER);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import me.zhengjie.modules.quartz.service.QuartzJobService;
|
||||||
import me.zhengjie.service.EmailService;
|
import me.zhengjie.service.EmailService;
|
||||||
import me.zhengjie.utils.RedisUtils;
|
import me.zhengjie.utils.RedisUtils;
|
||||||
import me.zhengjie.utils.SpringContextHolder;
|
import me.zhengjie.utils.SpringContextHolder;
|
||||||
|
import me.zhengjie.utils.StringUtils;
|
||||||
import me.zhengjie.utils.ThrowableUtil;
|
import me.zhengjie.utils.ThrowableUtil;
|
||||||
import org.quartz.JobExecutionContext;
|
import org.quartz.JobExecutionContext;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
@ -55,6 +56,8 @@ public class ExecutionJob extends QuartzJobBean {
|
||||||
QuartzJobService quartzJobService = SpringContextHolder.getBean(QuartzJobService.class);
|
QuartzJobService quartzJobService = SpringContextHolder.getBean(QuartzJobService.class);
|
||||||
RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class);
|
RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class);
|
||||||
|
|
||||||
|
String uuid = quartzJob.getUuid();
|
||||||
|
|
||||||
QuartzLog log = new QuartzLog();
|
QuartzLog log = new QuartzLog();
|
||||||
log.setJobName(quartzJob.getJobName());
|
log.setJobName(quartzJob.getJobName());
|
||||||
log.setBeanName(quartzJob.getBeanName());
|
log.setBeanName(quartzJob.getBeanName());
|
||||||
|
@ -72,7 +75,9 @@ public class ExecutionJob extends QuartzJobBean {
|
||||||
future.get();
|
future.get();
|
||||||
long times = System.currentTimeMillis() - startTime;
|
long times = System.currentTimeMillis() - startTime;
|
||||||
log.setTime(times);
|
log.setTime(times);
|
||||||
redisUtils.set(quartzJob.getUuid(), true);
|
if(StringUtils.isNotBlank(uuid)) {
|
||||||
|
redisUtils.set(uuid, true);
|
||||||
|
}
|
||||||
// 任务状态
|
// 任务状态
|
||||||
log.setIsSuccess(true);
|
log.setIsSuccess(true);
|
||||||
System.out.println("任务执行完毕,任务名称:" + quartzJob.getJobName() + ", 执行时间:" + times + "毫秒");
|
System.out.println("任务执行完毕,任务名称:" + quartzJob.getJobName() + ", 执行时间:" + times + "毫秒");
|
||||||
|
@ -84,7 +89,9 @@ public class ExecutionJob extends QuartzJobBean {
|
||||||
quartzJobService.executionSubJob(tasks);
|
quartzJobService.executionSubJob(tasks);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
redisUtils.set(quartzJob.getUuid(), false);
|
if(StringUtils.isNotBlank(uuid)) {
|
||||||
|
redisUtils.set(uuid, false);
|
||||||
|
}
|
||||||
System.out.println("任务执行失败,任务名称:" + quartzJob.getJobName());
|
System.out.println("任务执行失败,任务名称:" + quartzJob.getJobName());
|
||||||
System.out.println("--------------------------------------------------------------");
|
System.out.println("--------------------------------------------------------------");
|
||||||
long times = System.currentTimeMillis() - startTime;
|
long times = System.currentTimeMillis() - startTime;
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
package me.zhengjie.modules.security.rest;
|
package me.zhengjie.modules.security.rest;
|
||||||
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import com.wf.captcha.ArithmeticCaptcha;
|
|
||||||
import com.wf.captcha.base.Captcha;
|
import com.wf.captcha.base.Captcha;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
@ -38,7 +37,6 @@ import me.zhengjie.utils.RsaUtils;
|
||||||
import me.zhengjie.utils.RedisUtils;
|
import me.zhengjie.utils.RedisUtils;
|
||||||
import me.zhengjie.utils.SecurityUtils;
|
import me.zhengjie.utils.SecurityUtils;
|
||||||
import me.zhengjie.utils.StringUtils;
|
import me.zhengjie.utils.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
|
@ -47,7 +45,6 @@ import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
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;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -91,7 +88,6 @@ public class AuthorizationController {
|
||||||
}
|
}
|
||||||
UsernamePasswordAuthenticationToken authenticationToken =
|
UsernamePasswordAuthenticationToken authenticationToken =
|
||||||
new UsernamePasswordAuthenticationToken(authUser.getUsername(), password);
|
new UsernamePasswordAuthenticationToken(authUser.getUsername(), password);
|
||||||
|
|
||||||
Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken);
|
Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken);
|
||||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||||
// 生成令牌
|
// 生成令牌
|
||||||
|
|
|
@ -93,8 +93,8 @@ public class TokenFilter extends GenericFilterBean {
|
||||||
/**
|
/**
|
||||||
* 初步检测Token
|
* 初步检测Token
|
||||||
*
|
*
|
||||||
* @param request
|
* @param request /
|
||||||
* @return
|
* @return /
|
||||||
*/
|
*/
|
||||||
private String resolveToken(HttpServletRequest request) {
|
private String resolveToken(HttpServletRequest request) {
|
||||||
String bearerToken = request.getHeader(properties.getHeader());
|
String bearerToken = request.getHeader(properties.getHeader());
|
||||||
|
|
|
@ -52,7 +52,6 @@ public class TokenProvider implements InitializingBean {
|
||||||
private final SecurityProperties properties;
|
private final SecurityProperties properties;
|
||||||
private final RedisUtils redisUtils;
|
private final RedisUtils redisUtils;
|
||||||
public static final String AUTHORITIES_KEY = "auth";
|
public static final String AUTHORITIES_KEY = "auth";
|
||||||
private Key key;
|
|
||||||
private JwtParser jwtParser;
|
private JwtParser jwtParser;
|
||||||
private JwtBuilder jwtBuilder;
|
private JwtBuilder jwtBuilder;
|
||||||
|
|
||||||
|
@ -64,7 +63,7 @@ public class TokenProvider implements InitializingBean {
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
byte[] keyBytes = Decoders.BASE64.decode(properties.getBase64Secret());
|
byte[] keyBytes = Decoders.BASE64.decode(properties.getBase64Secret());
|
||||||
this.key = Keys.hmacShaKeyFor(keyBytes);
|
Key key = Keys.hmacShaKeyFor(keyBytes);
|
||||||
jwtParser = Jwts.parserBuilder()
|
jwtParser = Jwts.parserBuilder()
|
||||||
.setSigningKey(key)
|
.setSigningKey(key)
|
||||||
.build();
|
.build();
|
||||||
|
@ -76,11 +75,11 @@ public class TokenProvider implements InitializingBean {
|
||||||
* 创建Token 设置永不过期,
|
* 创建Token 设置永不过期,
|
||||||
* Token 的时间有效性转到Redis 维护
|
* Token 的时间有效性转到Redis 维护
|
||||||
*
|
*
|
||||||
* @param authentication
|
* @param authentication /
|
||||||
* @return
|
* @return /
|
||||||
*/
|
*/
|
||||||
public String createToken(Authentication authentication) {
|
public String createToken(Authentication authentication) {
|
||||||
/**
|
/*
|
||||||
* 获取权限列表
|
* 获取权限列表
|
||||||
*/
|
*/
|
||||||
String authorities = authentication.getAuthorities().stream()
|
String authorities = authentication.getAuthorities().stream()
|
||||||
|
@ -98,8 +97,8 @@ public class TokenProvider implements InitializingBean {
|
||||||
/**
|
/**
|
||||||
* 依据Token 获取鉴权信息
|
* 依据Token 获取鉴权信息
|
||||||
*
|
*
|
||||||
* @param token
|
* @param token /
|
||||||
* @return
|
* @return /
|
||||||
*/
|
*/
|
||||||
Authentication getAuthentication(String token) {
|
Authentication getAuthentication(String token) {
|
||||||
Claims claims = getClaims(token);
|
Claims claims = getClaims(token);
|
||||||
|
|
|
@ -27,12 +27,11 @@ import org.springframework.stereotype.Component;
|
||||||
@Component
|
@Component
|
||||||
public class UserCacheClean {
|
public class UserCacheClean {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清理特定用户缓存信息<br>
|
* 清理特定用户缓存信息<br>
|
||||||
* 用户信息变更时
|
* 用户信息变更时
|
||||||
*
|
*
|
||||||
* @param userName
|
* @param userName /
|
||||||
*/
|
*/
|
||||||
public void cleanUserCache(String userName) {
|
public void cleanUserCache(String userName) {
|
||||||
if (StringUtils.isNotEmpty(userName)) {
|
if (StringUtils.isNotEmpty(userName)) {
|
||||||
|
|
|
@ -27,7 +27,6 @@ import me.zhengjie.modules.system.service.dto.UserDto;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@ -42,7 +41,6 @@ public class UserDetailsServiceImpl implements UserDetailsService {
|
||||||
private final RoleService roleService;
|
private final RoleService roleService;
|
||||||
private final DataService dataService;
|
private final DataService dataService;
|
||||||
private final LoginProperties loginProperties;
|
private final LoginProperties loginProperties;
|
||||||
|
|
||||||
public void setEnableCache(boolean enableCache) {
|
public void setEnableCache(boolean enableCache) {
|
||||||
this.loginProperties.setCacheEnable(enableCache);
|
this.loginProperties.setCacheEnable(enableCache);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,7 @@ 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.SecurityUtils;
|
import me.zhengjie.utils.SecurityUtils;
|
||||||
import me.zhengjie.utils.ThrowableUtil;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
|
||||||
import org.springframework.data.web.PageableDefault;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
|
|
@ -117,7 +117,7 @@ public class RoleServiceImpl implements RoleService {
|
||||||
role.setLevel(resources.getLevel());
|
role.setLevel(resources.getLevel());
|
||||||
roleRepository.save(role);
|
roleRepository.save(role);
|
||||||
// 更新相关缓存
|
// 更新相关缓存
|
||||||
delCaches(role.getId());
|
delCaches(role.getId(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -126,11 +126,10 @@ public class RoleServiceImpl implements RoleService {
|
||||||
List<User> users = userRepository.findByRoleId(role.getId());
|
List<User> users = userRepository.findByRoleId(role.getId());
|
||||||
// 更新菜单
|
// 更新菜单
|
||||||
role.setMenus(resources.getMenus());
|
role.setMenus(resources.getMenus());
|
||||||
cleanCache(resources, users);
|
delCaches(resources.getId(), users);
|
||||||
roleRepository.save(role);
|
roleRepository.save(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void untiedMenu(Long menuId) {
|
public void untiedMenu(Long menuId) {
|
||||||
|
@ -143,7 +142,7 @@ public class RoleServiceImpl implements RoleService {
|
||||||
public void delete(Set<Long> ids) {
|
public void delete(Set<Long> ids) {
|
||||||
for (Long id : ids) {
|
for (Long id : ids) {
|
||||||
// 更新相关缓存
|
// 更新相关缓存
|
||||||
delCaches(id);
|
delCaches(id, null);
|
||||||
}
|
}
|
||||||
roleRepository.deleteAllByIdIn(ids);
|
roleRepository.deleteAllByIdIn(ids);
|
||||||
}
|
}
|
||||||
|
@ -208,40 +207,18 @@ public class RoleServiceImpl implements RoleService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清理缓存
|
* 清理缓存
|
||||||
*
|
|
||||||
* @param id /
|
* @param id /
|
||||||
*/
|
*/
|
||||||
public void delCaches(Long id) {
|
public void delCaches(Long id, List<User> users) {
|
||||||
List<User> users = userRepository.findByRoleId(id);
|
users = CollectionUtil.isEmpty(users) ? userRepository.findByRoleId(id) : users;
|
||||||
if (CollectionUtil.isNotEmpty(users)) {
|
if (CollectionUtil.isNotEmpty(users)) {
|
||||||
users.stream().forEach(item -> {
|
users.forEach(item -> userCacheClean.cleanUserCache(item.getUsername()));
|
||||||
userCacheClean.cleanUserCache(item.getUsername());
|
|
||||||
});
|
|
||||||
Set<Long> userIds = users.stream().map(User::getId).collect(Collectors.toSet());
|
Set<Long> userIds = users.stream().map(User::getId).collect(Collectors.toSet());
|
||||||
redisUtils.delByKeys(CacheKey.DATE_USER, userIds);
|
redisUtils.delByKeys(CacheKey.DATE_USER, userIds);
|
||||||
redisUtils.delByKeys(CacheKey.MENU_USER, userIds);
|
redisUtils.delByKeys(CacheKey.MENU_USER, userIds);
|
||||||
redisUtils.delByKeys(CacheKey.ROLE_AUTH, userIds);
|
redisUtils.delByKeys(CacheKey.ROLE_AUTH, userIds);
|
||||||
|
redisUtils.del(CacheKey.ROLE_ID + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 清理缓存
|
|
||||||
*
|
|
||||||
* @param resources
|
|
||||||
* @param users
|
|
||||||
*/
|
|
||||||
private void cleanCache(Role resources, List<User> users) {
|
|
||||||
// 清理缓存
|
|
||||||
if (CollectionUtil.isNotEmpty(users)) {
|
|
||||||
users.stream().forEach(item -> {
|
|
||||||
userCacheClean.cleanUserCache(item.getUsername());
|
|
||||||
});
|
|
||||||
Set<Long> userIds = users.stream().map(User::getId).collect(Collectors.toSet());
|
|
||||||
redisUtils.delByKeys(CacheKey.MENU_USER, userIds);
|
|
||||||
redisUtils.delByKeys(CacheKey.ROLE_AUTH, userIds);
|
|
||||||
redisUtils.del(CacheKey.ROLE_ID + resources.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,7 +235,7 @@ public class UserServiceImpl implements UserService {
|
||||||
/**
|
/**
|
||||||
* 清理 登陆时 用户缓存信息
|
* 清理 登陆时 用户缓存信息
|
||||||
*
|
*
|
||||||
* @param username
|
* @param username /
|
||||||
*/
|
*/
|
||||||
private void flushCache(String username) {
|
private void flushCache(String username) {
|
||||||
userCacheClean.cleanUserCache(username);
|
userCacheClean.cleanUserCache(username);
|
||||||
|
|
|
@ -17,16 +17,11 @@
|
||||||
<#if betweens??>
|
<#if betweens??>
|
||||||
<#list betweens as column>
|
<#list betweens as column>
|
||||||
<#if column.queryType = 'BetWeen'>
|
<#if column.queryType = 'BetWeen'>
|
||||||
<el-date-picker
|
<date-range-picker
|
||||||
v-model="query.${column.changeColumnName}"
|
v-model="query.${column.changeColumnName}"
|
||||||
:default-time="['00:00:00','23:59:59']"
|
|
||||||
type="daterange"
|
|
||||||
range-separator=":"
|
|
||||||
size="small"
|
|
||||||
class="date-item"
|
|
||||||
value-format="yyyy-MM-dd HH:mm:ss"
|
|
||||||
start-placeholder="${column.changeColumnName}Start"
|
start-placeholder="${column.changeColumnName}Start"
|
||||||
end-placeholder="${column.changeColumnName}End"
|
end-placeholder="${column.changeColumnName}Start"
|
||||||
|
class="date-item"
|
||||||
/>
|
/>
|
||||||
</#if>
|
</#if>
|
||||||
</#list>
|
</#list>
|
||||||
|
@ -125,6 +120,7 @@ import crudOperation from '@crud/CRUD.operation'
|
||||||
import udOperation from '@crud/UD.operation'
|
import udOperation from '@crud/UD.operation'
|
||||||
import pagination from '@crud/Pagination'
|
import pagination from '@crud/Pagination'
|
||||||
|
|
||||||
|
|
||||||
const defaultForm = { <#if columns??><#list columns as column>${column.changeColumnName}: null<#if column_has_next>, </#if></#list></#if> }
|
const defaultForm = { <#if columns??><#list columns as column>${column.changeColumnName}: null<#if column_has_next>, </#if></#list></#if> }
|
||||||
export default {
|
export default {
|
||||||
name: '${className}',
|
name: '${className}',
|
||||||
|
|
|
@ -5,19 +5,19 @@ import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
public class LoginCacheTest {
|
public class LoginCacheTest {
|
||||||
|
|
||||||
@Resource(name = "userDetailsService")
|
@Resource(name = "userDetailsService")
|
||||||
private UserDetailsServiceImpl userDetailsService;
|
private UserDetailsServiceImpl userDetailsService;
|
||||||
private int size = 10000;
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCache() {
|
public void testCache() {
|
||||||
long start1 = System.currentTimeMillis();
|
long start1 = System.currentTimeMillis();
|
||||||
|
int size = 10000;
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
userDetailsService.loadUserByUsername("admin");
|
userDetailsService.loadUserByUsername("admin");
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,6 @@ public class LoginCacheTest {
|
||||||
userDetailsService.loadUserByUsername("admin");
|
userDetailsService.loadUserByUsername("admin");
|
||||||
}
|
}
|
||||||
long end2 = System.currentTimeMillis();
|
long end2 = System.currentTimeMillis();
|
||||||
System.out.printf("使用缓存:" + (end1 - start1) + "毫秒\n 不使用缓存:" + (end2 - start2) + "毫秒");
|
System.out.print("使用缓存:" + (end1 - start1) + "毫秒\n 不使用缓存:" + (end2 - start2) + "毫秒");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,20 +38,20 @@ import java.util.Optional;
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@CacheConfig(cacheNames = "alipay")
|
@CacheConfig(cacheNames = "aliPay")
|
||||||
public class AliPayServiceImpl implements AliPayService {
|
public class AliPayServiceImpl implements AliPayService {
|
||||||
|
|
||||||
private final AliPayRepository alipayRepository;
|
private final AliPayRepository alipayRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Cacheable(key = "'id:1'")
|
@Cacheable(key = "'config'")
|
||||||
public AlipayConfig find() {
|
public AlipayConfig find() {
|
||||||
Optional<AlipayConfig> alipayConfig = alipayRepository.findById(1L);
|
Optional<AlipayConfig> alipayConfig = alipayRepository.findById(1L);
|
||||||
return alipayConfig.orElseGet(AlipayConfig::new);
|
return alipayConfig.orElseGet(AlipayConfig::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@CachePut(key = "'id:1'")
|
@CachePut(key = "'config'")
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public AlipayConfig config(AlipayConfig alipayConfig) {
|
public AlipayConfig config(AlipayConfig alipayConfig) {
|
||||||
alipayConfig.setId(1L);
|
alipayConfig.setId(1L);
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class EmailServiceImpl implements EmailService {
|
||||||
private final EmailRepository emailRepository;
|
private final EmailRepository emailRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@CachePut(key = "'id:1'")
|
@CachePut(key = "'config'")
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public EmailConfig config(EmailConfig emailConfig, EmailConfig old) throws Exception {
|
public EmailConfig config(EmailConfig emailConfig, EmailConfig old) throws Exception {
|
||||||
emailConfig.setId(1L);
|
emailConfig.setId(1L);
|
||||||
|
@ -55,7 +55,7 @@ public class EmailServiceImpl implements EmailService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Cacheable(key = "'id:1'")
|
@Cacheable(key = "'config'")
|
||||||
public EmailConfig find() {
|
public EmailConfig find() {
|
||||||
Optional<EmailConfig> emailConfig = emailRepository.findById(1L);
|
Optional<EmailConfig> emailConfig = emailRepository.findById(1L);
|
||||||
return emailConfig.orElseGet(EmailConfig::new);
|
return emailConfig.orElseGet(EmailConfig::new);
|
||||||
|
|
|
@ -65,14 +65,14 @@ public class QiNiuServiceImpl implements QiNiuService {
|
||||||
private Long maxSize;
|
private Long maxSize;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Cacheable(key = "'id:1'")
|
@Cacheable(key = "'config'")
|
||||||
public QiniuConfig find() {
|
public QiniuConfig find() {
|
||||||
Optional<QiniuConfig> qiniuConfig = qiNiuConfigRepository.findById(1L);
|
Optional<QiniuConfig> qiniuConfig = qiNiuConfigRepository.findById(1L);
|
||||||
return qiniuConfig.orElseGet(QiniuConfig::new);
|
return qiniuConfig.orElseGet(QiniuConfig::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@CachePut(key = "'id:1'")
|
@CachePut(key = "'config'")
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public QiniuConfig config(QiniuConfig qiniuConfig) {
|
public QiniuConfig config(QiniuConfig qiniuConfig) {
|
||||||
qiniuConfig.setId(1L);
|
qiniuConfig.setId(1L);
|
||||||
|
|
|
@ -381,7 +381,7 @@ INSERT INTO `sys_menu` VALUES (15, 10, 0, 1, '富文本', 'Editor', 'components/
|
||||||
INSERT INTO `sys_menu` VALUES (16, 36, 2, 1, '图床管理', 'Pictures', 'tools/picture/index', 33, 'image', 'pictures', b'0', b'0', b'0', 'pictures:list', NULL, NULL, '2018-12-28 09:36:53', NULL);
|
INSERT INTO `sys_menu` VALUES (16, 36, 2, 1, '图床管理', 'Pictures', 'tools/picture/index', 33, 'image', 'pictures', b'0', b'0', b'0', 'pictures:list', NULL, NULL, '2018-12-28 09:36:53', NULL);
|
||||||
INSERT INTO `sys_menu` VALUES (18, 36, 3, 1, '存储管理', 'Storage', 'tools/storage/index', 34, 'qiniu', 'storage', b'0', b'0', b'0', 'storage:list', NULL, NULL, '2018-12-31 11:12:15', NULL);
|
INSERT INTO `sys_menu` VALUES (18, 36, 3, 1, '存储管理', 'Storage', 'tools/storage/index', 34, 'qiniu', 'storage', b'0', b'0', b'0', 'storage:list', NULL, NULL, '2018-12-31 11:12:15', NULL);
|
||||||
INSERT INTO `sys_menu` VALUES (19, 36, 0, 1, '支付宝工具', 'AliPay', 'tools/aliPay/index', 37, 'alipay', 'aliPay', b'0', b'0', b'0', NULL, NULL, NULL, '2018-12-31 14:52:38', NULL);
|
INSERT INTO `sys_menu` VALUES (19, 36, 0, 1, '支付宝工具', 'AliPay', 'tools/aliPay/index', 37, 'alipay', 'aliPay', b'0', b'0', b'0', NULL, NULL, NULL, '2018-12-31 14:52:38', NULL);
|
||||||
INSERT INTO `sys_menu` VALUES (21, NULL, 2, 0, '多级菜单', NULL, '', 900, 'menu', 'nested', b'0', b'0', b'1', NULL, NULL, NULL, '2019-01-04 16:22:03', NULL);
|
INSERT INTO `sys_menu` VALUES (21, NULL, 2, 0, '多级菜单', NULL, '', 900, 'menu', 'nested', b'0', b'0', b'0', NULL, NULL, NULL, '2019-01-04 16:22:03', NULL);
|
||||||
INSERT INTO `sys_menu` VALUES (22, 21, 2, 1, '二级菜单1', NULL, 'nested/menu1/index', 999, 'menu', 'menu1', b'0', b'0', b'0', NULL, NULL, NULL, '2019-01-04 16:23:29', NULL);
|
INSERT INTO `sys_menu` VALUES (22, 21, 2, 1, '二级菜单1', NULL, 'nested/menu1/index', 999, 'menu', 'menu1', b'0', b'0', b'0', NULL, NULL, NULL, '2019-01-04 16:23:29', NULL);
|
||||||
INSERT INTO `sys_menu` VALUES (23, 21, 0, 1, '二级菜单2', NULL, 'nested/menu2/index', 999, 'menu', 'menu2', b'0', b'0', b'0', NULL, NULL, NULL, '2019-01-04 16:23:57', NULL);
|
INSERT INTO `sys_menu` VALUES (23, 21, 0, 1, '二级菜单2', NULL, 'nested/menu2/index', 999, 'menu', 'menu2', b'0', b'0', b'0', NULL, NULL, NULL, '2019-01-04 16:23:57', NULL);
|
||||||
INSERT INTO `sys_menu` VALUES (24, 22, 0, 1, '三级菜单1', NULL, 'nested/menu1/menu1-1', 999, 'menu', 'menu1-1', b'0', b'0', b'0', NULL, NULL, NULL, '2019-01-04 16:24:48', NULL);
|
INSERT INTO `sys_menu` VALUES (24, 22, 0, 1, '三级菜单1', NULL, 'nested/menu1/menu1-1', 999, 'menu', 'menu1-1', b'0', b'0', b'0', NULL, NULL, NULL, '2019-01-04 16:24:48', NULL);
|
||||||
|
@ -584,6 +584,8 @@ INSERT INTO `sys_roles_menus` VALUES (19, 1);
|
||||||
INSERT INTO `sys_roles_menus` VALUES (21, 1);
|
INSERT INTO `sys_roles_menus` VALUES (21, 1);
|
||||||
INSERT INTO `sys_roles_menus` VALUES (22, 1);
|
INSERT INTO `sys_roles_menus` VALUES (22, 1);
|
||||||
INSERT INTO `sys_roles_menus` VALUES (23, 1);
|
INSERT INTO `sys_roles_menus` VALUES (23, 1);
|
||||||
|
INSERT INTO `sys_roles_menus` VALUES (24, 1);
|
||||||
|
INSERT INTO `sys_roles_menus` VALUES (27, 1);
|
||||||
INSERT INTO `sys_roles_menus` VALUES (28, 1);
|
INSERT INTO `sys_roles_menus` VALUES (28, 1);
|
||||||
INSERT INTO `sys_roles_menus` VALUES (30, 1);
|
INSERT INTO `sys_roles_menus` VALUES (30, 1);
|
||||||
INSERT INTO `sys_roles_menus` VALUES (32, 1);
|
INSERT INTO `sys_roles_menus` VALUES (32, 1);
|
||||||
|
|
Loading…
Reference in New Issue