package com.fjs.scenic.controller.system;

import javax.servlet.http.HttpServletRequest;

import com.fjs.scenic.annotation.LoggerManage;
import com.fjs.scenic.dto.LogsVo;
import com.fjs.scenic.entity.user.UserStatistical;
import com.fjs.scenic.service.system.impl.LogsService;
import com.fjs.scenic.utils.ReturnResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/logs")
public class LogsController {

    @Autowired
    private LogsService logsService;

    @RequestMapping("/index")
    public ModelAndView index(HttpServletRequest request) {
        return new ModelAndView("system/logs");
    }


    @PostMapping("/page")
    @ResponseBody
    public ReturnResult page(LogsVo record, int currentPage, int pageSize) {
        currentPage = (currentPage == 0) ? 1 : currentPage;
        pageSize = (pageSize == 0) ? 10 : pageSize;
        PageHelper.startPage(currentPage, pageSize);
        List<HashMap<String, Object>> userStatisticals = logsService.page(record);
        PageInfo<HashMap<String, Object>> pageInfo = new PageInfo<HashMap<String, Object>>(userStatisticals);
        return ReturnResult.ok(pageInfo);
    }

}
