package com.younike.admin.controller.system.monitor;

import com.younike.common.bean.APIResult;
import com.younike.common.bean.ResultGenerator;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.page.TableResult;
import com.younike.service.pojo.SysUserOnline;
import com.younike.service.service.ISysUserOnlineService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author chenpengfei
 */
@RestController
@RequestMapping("/monitor/online")
public class SysUserOnlineController extends BaseController {

    @Autowired
    private ISysUserOnlineService sysUserOnlineService;

    /**
     * 在线用户一览
     */
    @GetMapping("/list")
    public TableResult list(SysUserOnline userOnline) {
        startPage();
        List<SysUserOnline> selectRoleList = sysUserOnlineService.selectUserOnlineList(userOnline);
        return getDataTable(selectRoleList);
    }

    /**
     * 强退用户
     */
    @DeleteMapping(value = "/{sessionId}")
    public APIResult deleteUsers(@PathVariable String sessionId) {
        try {
            sysUserOnlineService.deleteOnlineById(sessionId);
        } catch (Exception e) {
            return ResultGenerator.getFailResult(e.getMessage());
        }
        return ResultGenerator.getSuccessResult();
    }


}
