Search in sources :

Example 1 with OnlineSession

use of com.ruoyi.framework.shiro.session.OnlineSession in project Rental-Information-Platform by who1sBruce.

the class SysUserOnlineController method forceLogout.

@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();
}
Also used : SysUserOnline(com.ruoyi.system.domain.SysUserOnline) OnlineSession(com.ruoyi.framework.shiro.session.OnlineSession) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) PostMapping(org.springframework.web.bind.annotation.PostMapping) Log(com.ruoyi.common.annotation.Log) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with OnlineSession

use of com.ruoyi.framework.shiro.session.OnlineSession in project Rental-Information-Platform by who1sBruce.

the class SysUserOnlineController method batchForceLogout.

@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();
}
Also used : SysUserOnline(com.ruoyi.system.domain.SysUserOnline) OnlineSession(com.ruoyi.framework.shiro.session.OnlineSession) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) PostMapping(org.springframework.web.bind.annotation.PostMapping) Log(com.ruoyi.common.annotation.Log) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Log (com.ruoyi.common.annotation.Log)2 OnlineSession (com.ruoyi.framework.shiro.session.OnlineSession)2 SysUserOnline (com.ruoyi.system.domain.SysUserOnline)2 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2