com.ruoyi.common.enums.OnlineStatus Java Examples

The following examples show how to use com.ruoyi.common.enums.OnlineStatus. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SysUserOnlineController.java    From RuoYi with Apache License 2.0 6 votes vote down vote up
private String logout(String sessionId) {
    SysUserOnline online = userOnlineService.selectOnlineById(sessionId);
    if (sessionId.equals(ShiroUtils.getSessionId())) {
        return "当前登陆用户无法强退";
    }
    if (online == null) {
        return "用户已下线";
    }
    OnlineSession onlineSession = (OnlineSession) onlineSessionDAO.readSession(online.getSessionId());
    if (onlineSession == null) {
        return "用户已下线";
    }
    onlineSession.setStatus(OnlineStatus.OFF_LINE);
    online.setStatus(OnlineStatus.OFF_LINE);
    userOnlineService.saveOnline(online);
    return null;
}
 
Example #2
Source File: SysUserOnlineController.java    From ruoyiplus with MIT License 6 votes vote down vote up
@RequiresPermissions("monitor:online:forceLogout")
@Log(title = "在线用户", businessType = BusinessType.FORCE)
@PostMapping("/forceLogout")
@ResponseBody
public AjaxResult forceLogout(String sessionId)
{
    SysUserOnline online = userOnlineService.selectOnlineById(sessionId);
    if (sessionId.equals(ShiroUtils.getSessionId()))
    {
        return error("当前登陆用户无法强退");
    }
    if (online == null)
    {
        return error("用户已下线");
    }
    OnlineSession onlineSession = (OnlineSession) onlineSessionDAO.readSession(online.getSessionId());
    if (onlineSession == null)
    {
        return error("用户已下线");
    }
    onlineSession.setStatus(OnlineStatus.off_line);
    online.setStatus(OnlineStatus.off_line);
    userOnlineService.saveOnline(online);
    return success();
}
 
Example #3
Source File: SysUserOnlineController.java    From supplierShop with MIT License 6 votes vote down vote up
@RequiresPermissions("monitor:online:forceLogout")
@Log(title = "在线用户", businessType = BusinessType.FORCE)
@PostMapping("/forceLogout")
@ResponseBody
public AjaxResult forceLogout(String sessionId)
{
    SysUserOnline online = userOnlineService.selectOnlineById(sessionId);
    if (sessionId.equals(ShiroUtils.getSessionId()))
    {
        return error("当前登陆用户无法强退");
    }
    if (online == null)
    {
        return error("用户已下线");
    }
    OnlineSession onlineSession = (OnlineSession) onlineSessionDAO.readSession(online.getSessionId());
    if (onlineSession == null)
    {
        return error("用户已下线");
    }
    onlineSession.setStatus(OnlineStatus.off_line);
    onlineSessionDAO.update(onlineSession);
    online.setStatus(OnlineStatus.off_line);
    userOnlineService.saveOnline(online);
    return success();
}
 
Example #4
Source File: OnlineSessionDAO.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 当会话过期/停止(如用户退出时)属性等会调用
 */
@Override
protected void doDelete(Session session) {
    OnlineSession onlineSession = (OnlineSession) session;
    if (null == onlineSession) {
        return;
    }
    onlineSession.setStatus(OnlineStatus.OFF_LINE);
    sysShiroService.deleteSession(onlineSession);
}
 
Example #5
Source File: OnlineSessionDAO.java    From supplierShop with MIT License 5 votes vote down vote up
/**
 * 当会话过期/停止(如用户退出时)属性等会调用
 */
@Override
protected void doDelete(Session session)
{
    OnlineSession onlineSession = (OnlineSession) session;
    if (null == onlineSession)
    {
        return;
    }
    onlineSession.setStatus(OnlineStatus.off_line);
    sysShiroService.deleteSession(onlineSession);
}
 
Example #6
Source File: OnlineSessionFilter.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 表示是否允许访问;mappedValue就是[urls]配置中拦截器参数部分,如果允许访问返回true,否则false;
 */
@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue){
    Subject subject = getSubject(request, response);
    if (subject == null || subject.getSession() == null) {
        return true;
    }
    Session session = onlineSessionDAO.readSession(subject.getSession().getId());
    if (session instanceof OnlineSession) {
        OnlineSession onlineSession = (OnlineSession) session;
        request.setAttribute(ShiroConstants.ONLINE_SESSION, onlineSession);
        // 把user对象设置进去
        boolean isGuest = onlineSession.getUserId() == null || onlineSession.getUserId() == 0L;
        if (isGuest) {
            SysUser user = ShiroUtils.getSysUser();
            if (user != null) {
                onlineSession.setUserId(user.getUserId());
                onlineSession.setLoginName(user.getLoginName());
                onlineSession.setAvatar(user.getAvatar());
                onlineSession.setDeptName(user.getDept().getDeptName());
                onlineSession.markAttributeChanged();
            }
        }

        return onlineSession.getStatus() != OnlineStatus.OFF_LINE;
    }
    return true;
}
 
Example #7
Source File: SysUserOnlineController.java    From supplierShop with MIT License 5 votes vote down vote up
@RequiresPermissions("monitor:online:batchForceLogout")
@Log(title = "在线用户", businessType = BusinessType.FORCE)
@PostMapping("/batchForceLogout")
@ResponseBody
public AjaxResult batchForceLogout(@RequestParam("ids[]") String[] ids)
{
    for (String sessionId : ids)
    {
        SysUserOnline online = userOnlineService.selectOnlineById(sessionId);
        if (online == null)
        {
            return error("用户已下线");
        }
        OnlineSession onlineSession = (OnlineSession) onlineSessionDAO.readSession(online.getSessionId());
        if (onlineSession == null)
        {
            return error("用户已下线");
        }
        if (sessionId.equals(ShiroUtils.getSessionId()))
        {
            return error("当前登陆用户无法强退");
        }
        onlineSession.setStatus(OnlineStatus.off_line);
        onlineSessionDAO.update(onlineSession);
        online.setStatus(OnlineStatus.off_line);
        userOnlineService.saveOnline(online);
    }
    return success();
}
 
Example #8
Source File: OnlineSessionFilter.java    From ruoyiplus with MIT License 5 votes vote down vote up
/**
 * 表示是否允许访问;mappedValue就是[urls]配置中拦截器参数部分,如果允许访问返回true,否则false;
 */
@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue)
        throws Exception
{
    Subject subject = getSubject(request, response);
    if (subject == null || subject.getSession() == null)
    {
        return true;
    }
    Session session = onlineSessionDAO.readSession(subject.getSession().getId());
    if (session != null && session instanceof OnlineSession)
    {
        OnlineSession onlineSession = (OnlineSession) session;
        request.setAttribute(ShiroConstants.ONLINE_SESSION, onlineSession);
        // 把user对象设置进去
        boolean isGuest = onlineSession.getUserId() == null || onlineSession.getUserId() == 0L;
        if (isGuest == true)
        {
            SysUser user = ShiroUtils.getSysUser();
            if (user != null)
            {
                onlineSession.setUserId(user.getUserId());
                onlineSession.setLoginName(user.getLoginName());
                onlineSession.setDeptName(user.getDept().getDeptName());
                onlineSession.markAttributeChanged();
            }
        }

        if (onlineSession.getStatus() == OnlineStatus.off_line)
        {
            return false;
        }
    }
    return true;
}
 
Example #9
Source File: OnlineSessionFilter.java    From supplierShop with MIT License 5 votes vote down vote up
/**
 * 表示是否允许访问;mappedValue就是[urls]配置中拦截器参数部分,如果允许访问返回true,否则false;
 */
@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue)
        throws Exception
{
    Subject subject = getSubject(request, response);
    if (subject == null || subject.getSession() == null)
    {
        return true;
    }
    Session session = onlineSessionDAO.readSession(subject.getSession().getId());
    if (session != null && session instanceof OnlineSession)
    {
        OnlineSession onlineSession = (OnlineSession) session;
        request.setAttribute(ShiroConstants.ONLINE_SESSION, onlineSession);
        // 把user对象设置进去
        boolean isGuest = onlineSession.getUserId() == null || onlineSession.getUserId() == 0L;
        if (isGuest == true)
        {
            SysUser user = ShiroUtils.getSysUser();
            if (user != null)
            {
                onlineSession.setUserId(user.getUserId());
                onlineSession.setLoginName(user.getLoginName());
	onlineSession.setAvatar(user.getAvatar());
                onlineSession.setDeptName(user.getDept().getDeptName());
                onlineSession.markAttributeChanged();
            }
        }

        if (onlineSession.getStatus() == OnlineStatus.off_line)
        {
            return false;
        }
    }
    return true;
}
 
Example #10
Source File: SysUserOnlineController.java    From ruoyiplus with MIT License 5 votes vote down vote up
@RequiresPermissions("monitor:online:batchForceLogout")
@Log(title = "在线用户", businessType = BusinessType.FORCE)
@PostMapping("/batchForceLogout")
@ResponseBody
public AjaxResult batchForceLogout(@RequestParam("ids[]") String[] ids)
{
    for (String sessionId : ids)
    {
        SysUserOnline online = userOnlineService.selectOnlineById(sessionId);
        if (online == null)
        {
            return error("用户已下线");
        }
        OnlineSession onlineSession = (OnlineSession) onlineSessionDAO.readSession(online.getSessionId());
        if (onlineSession == null)
        {
            return error("用户已下线");
        }
        if (sessionId.equals(ShiroUtils.getSessionId()))
        {
            return error("当前登陆用户无法强退");
        }
        onlineSession.setStatus(OnlineStatus.off_line);
        online.setStatus(OnlineStatus.off_line);
        userOnlineService.saveOnline(online);
    }
    return success();
}
 
Example #11
Source File: OnlineSessionDAO.java    From ruoyiplus with MIT License 5 votes vote down vote up
/**
 * 当会话过期/停止(如用户退出时)属性等会调用
 */
@Override
protected void doDelete(Session session)
{
    OnlineSession onlineSession = (OnlineSession) session;
    if (null == onlineSession)
    {
        return;
    }
    onlineSession.setStatus(OnlineStatus.off_line);
    sysShiroService.deleteSession(onlineSession);
}
 
Example #12
Source File: OnlineSession.java    From ruoyiplus with MIT License 4 votes vote down vote up
public OnlineStatus getStatus()
{
    return status;
}
 
Example #13
Source File: SysUserOnline.java    From ruoyiplus with MIT License 4 votes vote down vote up
public void setStatus(OnlineStatus status)
{
    this.status = status;
}
 
Example #14
Source File: SysUserOnline.java    From ruoyiplus with MIT License 4 votes vote down vote up
public OnlineStatus getStatus()
{
    return status;
}
 
Example #15
Source File: OnlineSession.java    From ruoyiplus with MIT License 4 votes vote down vote up
public void setStatus(OnlineStatus status)
{
    this.status = status;
}
 
Example #16
Source File: SysUserOnline.java    From supplierShop with MIT License 4 votes vote down vote up
public void setStatus(OnlineStatus status)
{
    this.status = status;
}
 
Example #17
Source File: SysUserOnline.java    From supplierShop with MIT License 4 votes vote down vote up
public OnlineStatus getStatus()
{
    return status;
}
 
Example #18
Source File: OnlineSession.java    From supplierShop with MIT License 4 votes vote down vote up
public void setStatus(OnlineStatus status)
{
    this.status = status;
}
 
Example #19
Source File: OnlineSession.java    From supplierShop with MIT License 4 votes vote down vote up
public OnlineStatus getStatus()
{
    return status;
}