package com.css.simulation.resource.server.adapter.controller.system_manage.log_manage;

import api.common.pojo.common.ResponseBodyVO;
import api.common.pojo.param.log.LogPageParam;
import api.common.pojo.po.log.LogLoginPO;
import api.common.pojo.po.log.LogOperationPO;
import api.common.pojo.po.log.LogSystemPO;
import com.css.simulation.resource.server.app.service.LogService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/log")
public class LogController {

    @Autowired
    LogService logService;

    @RequestMapping("/getLoginLogPageList")
    @ResponseBody
    @PreAuthorize("@AuthorityCheck.admin()")
    public ResponseBodyVO<PageInfo<LogLoginPO>> getLoginLogPageList(@RequestBody LogPageParam pageParam){
        ResponseBodyVO<PageInfo<LogLoginPO>> response = new ResponseBodyVO<PageInfo<LogLoginPO>>(ResponseBodyVO.Response.SUCCESS);
        response.setInfo(logService.getLoginLogPageList(pageParam));
        return response;
    }

    @RequestMapping("/getOperationLogPageList")
    @ResponseBody
    @PreAuthorize("@AuthorityCheck.adminAndUser()")
    public ResponseBodyVO<PageInfo<LogOperationPO>> getOperationLogPageList(@RequestBody LogPageParam pageParam){
        ResponseBodyVO<PageInfo<LogOperationPO>> response = new ResponseBodyVO<PageInfo<LogOperationPO>>(ResponseBodyVO.Response.SUCCESS);
        response.setInfo(logService.getOperationLogPageList(pageParam));
        return response;
    }

    @RequestMapping("/getSystemLogPageList")
    @ResponseBody
    @PreAuthorize("@AuthorityCheck.admin()")
    public ResponseBodyVO<PageInfo<LogSystemPO>> getSystemLogPageList(@RequestBody LogPageParam pageParam){
        ResponseBodyVO<PageInfo<LogSystemPO>> response = new ResponseBodyVO<PageInfo<LogSystemPO>>(ResponseBodyVO.Response.SUCCESS);
        response.setInfo(logService.getSystemLogPageList(pageParam));
        return response;
    }
}
