Search in sources :

Example 1 with SysUserOnline

use of com.ruoyi.system.domain.SysUserOnline 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 SysUserOnline

use of com.ruoyi.system.domain.SysUserOnline 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)

Example 3 with SysUserOnline

use of com.ruoyi.system.domain.SysUserOnline in project RuoYi-Cloud-Oracle by yangzongzhuan.

the class SysUserOnlineServiceImpl method loginUserToUserOnline.

/**
 * 设置在线用户信息
 *
 * @param user 用户信息
 * @return 在线用户
 */
@Override
public SysUserOnline loginUserToUserOnline(LoginUser user) {
    if (StringUtils.isNull(user)) {
        return null;
    }
    SysUserOnline sysUserOnline = new SysUserOnline();
    sysUserOnline.setTokenId(user.getToken());
    sysUserOnline.setUserName(user.getUsername());
    sysUserOnline.setIpaddr(user.getIpaddr());
    sysUserOnline.setLoginTime(user.getLoginTime());
    return sysUserOnline;
}
Also used : SysUserOnline(com.ruoyi.system.domain.SysUserOnline)

Example 4 with SysUserOnline

use of com.ruoyi.system.domain.SysUserOnline in project RuoYi-Cloud-Oracle by yangzongzhuan.

the class SysUserOnlineController method list.

@RequiresPermissions("monitor:online:list")
@GetMapping("/list")
public TableDataInfo list(String ipaddr, String userName) {
    Collection<String> keys = redisService.keys(CacheConstants.LOGIN_TOKEN_KEY + "*");
    List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>();
    for (String key : keys) {
        LoginUser user = redisService.getCacheObject(key);
        if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) {
            if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) {
                userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user));
            }
        } else if (StringUtils.isNotEmpty(ipaddr)) {
            if (StringUtils.equals(ipaddr, user.getIpaddr())) {
                userOnlineList.add(userOnlineService.selectOnlineByIpaddr(ipaddr, user));
            }
        } else if (StringUtils.isNotEmpty(userName)) {
            if (StringUtils.equals(userName, user.getUsername())) {
                userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user));
            }
        } else {
            userOnlineList.add(userOnlineService.loginUserToUserOnline(user));
        }
    }
    Collections.reverse(userOnlineList);
    userOnlineList.removeAll(Collections.singleton(null));
    return getDataTable(userOnlineList);
}
Also used : SysUserOnline(com.ruoyi.system.domain.SysUserOnline) ArrayList(java.util.ArrayList) LoginUser(com.ruoyi.system.api.model.LoginUser) RequiresPermissions(com.ruoyi.common.security.annotation.RequiresPermissions) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 5 with SysUserOnline

use of com.ruoyi.system.domain.SysUserOnline in project wumei-smart by kerwincui.

the class SysUserOnlineController method list.

@PreAuthorize("@ss.hasPermi('monitor:online:list')")
@GetMapping("/list")
public TableDataInfo list(String ipaddr, String userName) {
    Collection<String> keys = redisCache.keys(Constants.LOGIN_TOKEN_KEY + "*");
    List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>();
    for (String key : keys) {
        LoginUser user = redisCache.getCacheObject(key);
        if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) {
            if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) {
                userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user));
            }
        } else if (StringUtils.isNotEmpty(ipaddr)) {
            if (StringUtils.equals(ipaddr, user.getIpaddr())) {
                userOnlineList.add(userOnlineService.selectOnlineByIpaddr(ipaddr, user));
            }
        } else if (StringUtils.isNotEmpty(userName) && StringUtils.isNotNull(user.getUser())) {
            if (StringUtils.equals(userName, user.getUsername())) {
                userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user));
            }
        } else {
            userOnlineList.add(userOnlineService.loginUserToUserOnline(user));
        }
    }
    Collections.reverse(userOnlineList);
    userOnlineList.removeAll(Collections.singleton(null));
    return getDataTable(userOnlineList);
}
Also used : SysUserOnline(com.ruoyi.system.domain.SysUserOnline) ArrayList(java.util.ArrayList) LoginUser(com.ruoyi.common.core.domain.model.LoginUser) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

SysUserOnline (com.ruoyi.system.domain.SysUserOnline)12 ArrayList (java.util.ArrayList)5 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 LoginUser (com.ruoyi.common.core.domain.model.LoginUser)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 Log (com.ruoyi.common.annotation.Log)2 RequiresPermissions (com.ruoyi.common.security.annotation.RequiresPermissions)2 OnlineSession (com.ruoyi.framework.shiro.session.OnlineSession)2 LoginUser (com.ruoyi.system.api.model.LoginUser)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