package com.chushang.system.controller;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import com.chushang.common.core.constant.CacheConstants;
import com.chushang.common.core.web.AjaxResult;
import com.chushang.common.log.annotation.SysLog;
import com.chushang.common.log.enums.BusinessType;
import com.chushang.common.mybatis.page.CommonParam;
import com.chushang.common.mybatis.utils.PageResult;
import com.chushang.security.annotation.RequiresPermissions;
import com.chushang.security.auth.AuthUtil;
import com.chushang.security.entity.vo.LoginUser;
import com.chushang.system.entity.vo.SysUserOnline;
import com.chushang.system.service.ISysUserOnlineService;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 在线用户监控
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/online")
public class SysUserOnlineController
{
    @Autowired
    private ISysUserOnlineService userOnlineService;

    @RequiresPermissions("monitor:online:list")
    @GetMapping("/list")
    public AjaxResult list(String ipaddr, String userName)
    {
        CommonParam commonParam = CommonParam.buildPageRequest();
        PageResult pageResult = userOnlineService.selectOnlineByIpaddr(ipaddr, userName, commonParam);
        return AjaxResult.success(pageResult);
    }

    /**
     * 强退用户
     */
    @RequiresPermissions("monitor:online:forceLogout")
    @SysLog(value = "在线用户", businessType = BusinessType.FORCE)
    @DeleteMapping("/{tokenId}")
    public AjaxResult forceLogout(@PathVariable String tokenId)
    {
        userOnlineService.forceLogout(tokenId);
        return AjaxResult.success();
    }
}
