package com.imdroid.beidou.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.imdroid.beidou.service.CommonExcelService;
import com.imdroid.secapi.dto.OpLogMapper;
import com.imdroid.secapi.dto.OperationLog;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 消息摘要 控制器
 */
@Controller
@RequiredArgsConstructor
public class OpLogController extends BasicController implements CommonExcelService<OperationLog, OperationLog> {

    @Autowired
    OpLogMapper opLogMapper;

    /**** 推送页面  *****/
    @RequestMapping("/sys/oplog")
    public String opLog(Model m, HttpSession session) {
        initModel(m, session);
        return "/page/operation_log";
    }


    /**** 推送数据  *****/
    @RequestMapping("/sys/list_oplog")
    @ResponseBody
    public JSONObject listLog(HttpSession session, Integer page, Integer limit, String searchParams) {
        return this.pageList(session, page, limit, searchParams);
    }

    /**
     * 导出excel
     *
     * @param session      HttpSession
     * @param request HttpServletRequest
     * @param response     HttpServletResponse
     * @throws Exception
     */
    @RequestMapping("/sys/oplog/export")
    @ResponseBody
    public void exportData(HttpSession session, HttpServletRequest request, HttpServletResponse response) throws Exception {
        this.export(session, request, response);
    }

    /**
     * 获取实体类的class
     *
     * @return 实体类的class
     */
    @Override
    public Class<OperationLog> getEntityClass() {
        return OperationLog.class;
    }

    /**
     * 获取实体类对应的mybatis mapper
     *
     * @return 实体类对应的mybatis mapper
     */
    @Override
    public BaseMapper<OperationLog> getMapper() {
        return opLogMapper;
    }

    @Override
    public String getOrderByColumn() {
        return "op_time";
    }
}
