Merge remote-tracking branch 'origin/master'

This commit is contained in:
flower 2019-01-28 23:16:28 +08:00
commit 1e350c0060
7 changed files with 78 additions and 75 deletions

View File

@ -165,7 +165,6 @@ public class ExamQuestionServiceImpl extends AbstractBaseServiceImpl<ExamQuestio
@Override @Override
public List<ExamQuestionVO> selectQuestionListByPracticeId(Map<String, Object> map) { public List<ExamQuestionVO> selectQuestionListByPracticeId(Map<String, Object> map) {
// startPage();
return examQuestionMapper.selectQuestionListByPracticeId(map); return examQuestionMapper.selectQuestionListByPracticeId(map);
} }

View File

@ -1,10 +1,12 @@
package com.ruoyi.framework.jwt; package com.ruoyi.framework.jwt;
import cn.hutool.core.util.StrUtil;
import com.auth0.jwt.JWT; import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier; import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm; import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTDecodeException; import com.auth0.jwt.exceptions.JWTDecodeException;
import com.auth0.jwt.interfaces.DecodedJWT; import com.auth0.jwt.interfaces.DecodedJWT;
import com.ruoyi.framework.web.exception.user.UserNotExistsException;
import com.ruoyi.framework.web.util.ServletUtils; import com.ruoyi.framework.web.util.ServletUtils;
import java.util.Date; import java.util.Date;
@ -49,10 +51,14 @@ public class JwtUtil {
try { try {
String token = ServletUtils.getRequest().getHeader("Authorization"); String token = ServletUtils.getRequest().getHeader("Authorization");
DecodedJWT jwt = JWT.decode(token); DecodedJWT jwt = JWT.decode(token);
String loginName = jwt.getClaim( "loginName" ).asString();
// jwt.getExpiresAt(); // jwt.getExpiresAt();
return jwt.getClaim("loginName").asString(); if (StrUtil.isBlank( loginName )) {
throw new UserNotExistsException();
}
return loginName;
} catch (JWTDecodeException e) { } catch (JWTDecodeException e) {
return null; throw new UserNotExistsException();
} }
} }

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
import org.apache.shiro.session.ExpiredSessionException; import org.apache.shiro.session.ExpiredSessionException;
import org.apache.shiro.session.InvalidSessionException; import org.apache.shiro.session.InvalidSessionException;
@ -24,51 +25,41 @@ import com.ruoyi.system.service.ISysUserOnlineService;
* *
* @author ruoyi * @author ruoyi
*/ */
public class OnlineWebSessionManager extends DefaultWebSessionManager public class OnlineWebSessionManager extends DefaultWebSessionManager {
{ private static final Logger log = LoggerFactory.getLogger( OnlineWebSessionManager.class );
private static final Logger log = LoggerFactory.getLogger(OnlineWebSessionManager.class);
@Override @Override
public void setAttribute(SessionKey sessionKey, Object attributeKey, Object value) throws InvalidSessionException public void setAttribute(SessionKey sessionKey, Object attributeKey, Object value) throws InvalidSessionException {
{ super.setAttribute( sessionKey, attributeKey, value );
super.setAttribute(sessionKey, attributeKey, value); if (value != null && needMarkAttributeChanged( attributeKey )) {
if (value != null && needMarkAttributeChanged(attributeKey)) OnlineSession s = (OnlineSession) doGetSession( sessionKey );
{
OnlineSession s = (OnlineSession) doGetSession(sessionKey);
s.markAttributeChanged(); s.markAttributeChanged();
} }
} }
private boolean needMarkAttributeChanged(Object attributeKey) private boolean needMarkAttributeChanged(Object attributeKey) {
{ if (attributeKey == null) {
if (attributeKey == null)
{
return false; return false;
} }
String attributeKeyStr = attributeKey.toString(); String attributeKeyStr = attributeKey.toString();
// 优化 flash属性没必要持久化 // 优化 flash属性没必要持久化
if (attributeKeyStr.startsWith("org.springframework")) if (attributeKeyStr.startsWith( "org.springframework" )) {
{
return false; return false;
} }
if (attributeKeyStr.startsWith("javax.servlet")) if (attributeKeyStr.startsWith( "javax.servlet" )) {
{
return false; return false;
} }
if (attributeKeyStr.equals(ShiroConstants.CURRENT_USERNAME)) if (attributeKeyStr.equals( ShiroConstants.CURRENT_USERNAME )) {
{
return false; return false;
} }
return true; return true;
} }
@Override @Override
public Object removeAttribute(SessionKey sessionKey, Object attributeKey) throws InvalidSessionException public Object removeAttribute(SessionKey sessionKey, Object attributeKey) throws InvalidSessionException {
{ Object removed = super.removeAttribute( sessionKey, attributeKey );
Object removed = super.removeAttribute(sessionKey, attributeKey); if (removed != null) {
if (removed != null) OnlineSession s = (OnlineSession) doGetSession( sessionKey );
{
OnlineSession s = (OnlineSession) doGetSession(sessionKey);
s.markAttributeChanged(); s.markAttributeChanged();
} }
@ -79,77 +70,60 @@ public class OnlineWebSessionManager extends DefaultWebSessionManager
* 验证session是否有效 用于删除过期session * 验证session是否有效 用于删除过期session
*/ */
@Override @Override
public void validateSessions() public void validateSessions() {
{ if (log.isInfoEnabled()) {
if (log.isInfoEnabled()) log.info( "invalidation sessions..." );
{
log.info("invalidation sessions...");
} }
int invalidCount = 0; int invalidCount = 0;
int timeout = (int) this.getGlobalSessionTimeout(); int timeout = (int) this.getGlobalSessionTimeout();
Date expiredDate = DateUtils.addMilliseconds(new Date(), 0 - timeout); Date expiredDate = DateUtils.addMilliseconds( new Date(), 0 - timeout );
ISysUserOnlineService userOnlineService = SpringUtils.getBean(ISysUserOnlineService.class); ISysUserOnlineService userOnlineService = SpringUtils.getBean( ISysUserOnlineService.class );
List<SysUserOnline> userOnlineList = userOnlineService.selectOnlineByExpired(expiredDate); List<SysUserOnline> userOnlineList = userOnlineService.selectOnlineByExpired( expiredDate );
// 批量过期删除 // 批量过期删除
List<String> needOfflineIdList = new ArrayList<String>(); List<String> needOfflineIdList = new ArrayList<String>();
for (SysUserOnline userOnline : userOnlineList) for (SysUserOnline userOnline : userOnlineList) {
{ try {
try SessionKey key = new DefaultSessionKey( userOnline.getSessionId() );
{ Session session = retrieveSession( key );
SessionKey key = new DefaultSessionKey(userOnline.getSessionId()); if (session != null) {
Session session = retrieveSession(key);
if (session != null)
{
throw new InvalidSessionException(); throw new InvalidSessionException();
} }
} } catch (InvalidSessionException e) {
catch (InvalidSessionException e) if (log.isDebugEnabled()) {
{
if (log.isDebugEnabled())
{
boolean expired = (e instanceof ExpiredSessionException); boolean expired = (e instanceof ExpiredSessionException);
String msg = "Invalidated session with id [" + userOnline.getSessionId() + "]" String msg = "Invalidated session with id [" + userOnline.getSessionId() + "]"
+ (expired ? " (expired)" : " (stopped)"); + (expired ? " (expired)" : " (stopped)");
log.debug(msg); log.debug( msg );
} }
invalidCount++; invalidCount++;
needOfflineIdList.add(userOnline.getSessionId()); needOfflineIdList.add( userOnline.getSessionId() );
} }
} }
if (needOfflineIdList.size() > 0) if (needOfflineIdList.size() > 0) {
{ try {
try userOnlineService.batchDeleteOnline( needOfflineIdList );
{ } catch (Exception e) {
userOnlineService.batchDeleteOnline(needOfflineIdList); log.error( "batch delete db session error.", e );
}
catch (Exception e)
{
log.error("batch delete db session error.", e);
} }
} }
if (log.isInfoEnabled()) if (log.isInfoEnabled()) {
{
String msg = "Finished invalidation session."; String msg = "Finished invalidation session.";
if (invalidCount > 0) if (invalidCount > 0) {
{
msg += " [" + invalidCount + "] sessions were stopped."; msg += " [" + invalidCount + "] sessions were stopped.";
} } else {
else
{
msg += " No sessions were stopped."; msg += " No sessions were stopped.";
} }
log.info(msg); log.info( msg );
} }
} }
@Override @Override
protected Collection<Session> getActiveSessions() protected Collection<Session> getActiveSessions() {
{ throw new UnsupportedOperationException( "getActiveSessions method not supported" );
throw new UnsupportedOperationException("getActiveSessions method not supported");
} }
} }

View File

@ -1,5 +1,6 @@
package com.ruoyi.framework.web.exception; package com.ruoyi.framework.web.exception;
import com.ruoyi.framework.web.exception.user.UserNotExistsException;
import org.apache.shiro.authz.AuthorizationException; import org.apache.shiro.authz.AuthorizationException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -39,7 +40,15 @@ public class DefaultExceptionHandler
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
return AjaxResult.error("不支持' " + e.getMethod() + "'请求"); return AjaxResult.error("不支持' " + e.getMethod() + "'请求");
} }
/**
* 拦截未知的运行时异常
*/
@ExceptionHandler(UserNotExistsException.class)
public AjaxResult userNotFound(UserNotExistsException e)
{
log.error("运行时异常:", e);
return AjaxResult.error(302,"运行时异常:" + e.getMessage());
}
/** /**
* 拦截未知的运行时异常 * 拦截未知的运行时异常
*/ */

View File

@ -1,9 +1,12 @@
package com.ruoyi.system.service.impl; package com.ruoyi.system.service.impl;
import java.nio.file.attribute.UserPrincipalNotFoundException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.ruoyi.framework.web.base.AbstractBaseServiceImpl; import com.ruoyi.framework.web.base.AbstractBaseServiceImpl;
import com.ruoyi.framework.web.exception.user.UserException;
import com.ruoyi.framework.web.exception.user.UserNotExistsException;
import com.ruoyi.system.domain.*; import com.ruoyi.system.domain.*;
import com.ruoyi.system.mapper.*; import com.ruoyi.system.mapper.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -57,6 +60,7 @@ public class SysUserServiceImpl extends AbstractBaseServiceImpl<SysUserMapper, S
*/ */
@Override @Override
public SysUser selectUserByLoginName(String userName) { public SysUser selectUserByLoginName(String userName) {
return userMapper.selectUserByLoginName( userName ); return userMapper.selectUserByLoginName( userName );
} }

View File

@ -10,6 +10,15 @@ public class VipUserOrdersVO extends VipUserOrders {
private String vipUserName; private String vipUserName;
private String trainCourseName; private String trainCourseName;
private String trainCourseCover;
public String getTrainCourseCover() {
return trainCourseCover;
}
public void setTrainCourseCover(String trainCourseCover) {
this.trainCourseCover = trainCourseCover;
}
public String getVipUserName() { public String getVipUserName() {
return vipUserName; return vipUserName;

View File

@ -17,6 +17,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="delFlag" column="del_flag" /> <result property="delFlag" column="del_flag" />
<result property="vipUserName" column="vipUserName" /> <result property="vipUserName" column="vipUserName" />
<result property="trainCourseName" column="trainCourseName" /> <result property="trainCourseName" column="trainCourseName" />
<result property="trainCourseCover" column="trainCourseCover" />
</resultMap> </resultMap>
<sql id="selectVipUserOrdersVo"> <sql id="selectVipUserOrdersVo">
@ -26,7 +28,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectVipUserOrdersList" parameterType="VipUserOrdersVO" resultMap="VipUserOrdersResult"> <select id="selectVipUserOrdersList" parameterType="VipUserOrdersVO" resultMap="VipUserOrdersResult">
select select
<include refid="selectVipUserOrdersVo"/>, <include refid="selectVipUserOrdersVo"/>,
u.user_name vipUserName,c.name trainCourseName u.user_name vipUserName,c.name trainCourseName,c.cover trainCourseCover
from vip_user_orders o from vip_user_orders o
join sys_user u on u.user_id=o.vip_user_id join sys_user u on u.user_id=o.vip_user_id
join train_course c on c.id=o.train_course_id join train_course c on c.id=o.train_course_id