package com.xhkjedu.sapi.controller.system;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.sapi.model.system.TUserLog;
import com.xhkjedu.sapi.service.system.UserLogService;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.utils.PageUtil;
import com.xhkjedu.vo.PageResult;
import com.xhkjedu.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author ywx
 * @classname UserLogController
 * @description 
 * @date 2020/6/17 17:38
 **/
@RestController
@RequestMapping("log")
public class UserLogController {
    @Autowired
    private UserLogService userLogService;

    /**
     * 登录日志列表
     * @Param [log]
     * @Author ywx
     * @Date 2020/6/17 17:22
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_log")
    public ResultVo listLog(@RequestBody TUserLog log){
        Integer page = log.getPage();
        Integer pageSize = log.getPageSize();
        N_Utils.validation(new Object[]{page,"显示页码",1,pageSize,"显示条数",1});
        PageHelper.startPage(page, pageSize);
        List<TUserLog> logs = userLogService.listLog(log);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo(logs));
        return new ResultVo(0, "获取登录日志列表成功", pageResult);
    }

    /**
     * @Description 区域登录日志列表
     * @Date 2023/1/16 16:54
     * @Author wn
     * * @param log
     * * @return ResultVo
     **/
    @PostMapping("/list_qy")
    public ResultVo listLogQy(@RequestBody TUserLog log){
        Integer page = log.getPage();
        Integer pageSize = log.getPageSize();
        N_Utils.validation(new Object[]{page,"显示页码",1,pageSize,"显示条数",1});
        PageHelper.startPage(page, pageSize);
        List<Map> logs = userLogService.listLogQy(log);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo(logs));
        return new ResultVo(0, "获取登录日志列表成功", pageResult);
    }
}
