会话检查优化

dep_wangsr
RuoYi 6 years ago committed by Limy
parent 8f94d100fa
commit 5319972062

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

Loading…
Cancel
Save