会话检查优化

pull/56/head
RuoYi 6 years ago
parent c404de1773
commit 1de73da333

@ -0,0 +1,62 @@
package com.ruoyi.framework.shiro.service;
import java.io.Serializable;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.shiro.session.OnlineSession;
import com.ruoyi.system.domain.SysUserOnline;
import com.ruoyi.system.service.ISysUserOnlineService;
/**
* db
*
* @author ruoyi
*/
@Component
public class SysShiroService
{
@Autowired
private ISysUserOnlineService onlineService;
/**
*
*
* @param onlineSession
*/
public void deleteSession(OnlineSession onlineSession)
{
onlineService.deleteOnlineById(String.valueOf(onlineSession.getId()));
}
/**
*
*
* @param sessionId
* @return
*/
public Session getSession(Serializable sessionId)
{
SysUserOnline userOnline = onlineService.selectOnlineById(String.valueOf(sessionId));
return StringUtils.isNull(userOnline) ? null : createSession(userOnline);
}
public Session createSession(SysUserOnline userOnline)
{
OnlineSession onlineSession = new OnlineSession();
if (StringUtils.isNotNull(userOnline))
{
onlineSession.setId(userOnline.getSessionId());
onlineSession.setHost(userOnline.getIpaddr());
onlineSession.setBrowser(userOnline.getBrowser());
onlineSession.setOs(userOnline.getOs());
onlineSession.setDeptName(userOnline.getDeptName());
onlineSession.setLoginName(userOnline.getLoginName());
onlineSession.setStartTimestamp(userOnline.getStartTimestamp());
onlineSession.setLastAccessTime(userOnline.getLastAccessTime());
onlineSession.setTimeout(userOnline.getExpireTime());
}
return onlineSession;
}
}

@ -9,8 +9,7 @@ import org.springframework.beans.factory.annotation.Value;
import com.ruoyi.common.enums.OnlineStatus;
import com.ruoyi.framework.manager.AsyncManager;
import com.ruoyi.framework.manager.factory.AsyncFactory;
import com.ruoyi.system.domain.SysUserOnline;
import com.ruoyi.system.service.ISysUserOnlineService;
import com.ruoyi.framework.shiro.service.SysShiroService;
/**
* ShiroSessiondb
@ -31,7 +30,7 @@ public class OnlineSessionDAO extends EnterpriseCacheSessionDAO
private static final String LAST_SYNC_DB_TIMESTAMP = OnlineSessionDAO.class.getName() + "LAST_SYNC_DB_TIMESTAMP";
@Autowired
private ISysUserOnlineService onlineService;
private SysShiroService sysShiroService;
public OnlineSessionDAO()
{
@ -52,12 +51,7 @@ public class OnlineSessionDAO extends EnterpriseCacheSessionDAO
@Override
protected Session doReadSession(Serializable sessionId)
{
SysUserOnline userOnline = onlineService.selectOnlineById(String.valueOf(sessionId));
if (userOnline == null)
{
return null;
}
return super.doReadSession(sessionId);
return sysShiroService.getSession(sessionId);
}
/**
@ -109,6 +103,6 @@ public class OnlineSessionDAO extends EnterpriseCacheSessionDAO
return;
}
onlineSession.setStatus(OnlineStatus.off_line);
onlineService.deleteOnlineById(String.valueOf(onlineSession.getId()));
sysShiroService.deleteSession(onlineSession);
}
}

Loading…
Cancel
Save