package com.ruoyi.cms.controller.cms;

import com.ruoyi.cms.domain.BussinessOperLog;
import com.ruoyi.cms.service.IBussinessOperLogService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 操作日志记录
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/cms/operlog")
@Api(tags = "后台：App用户操作日志")
public class BussinessOperlogController extends BaseController
{
    @Autowired
    private IBussinessOperLogService operLogService;

    @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
    @GetMapping("/list")
    @ApiOperation("日志列表")
    public TableDataInfo list(BussinessOperLog operLog)
    {
        startPage();
        List<BussinessOperLog> list = operLogService.selectOperLogList(operLog);
        return getDataTable(list);
    }

    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:export')")
    @PostMapping("/export")
    @ApiOperation("日志导出excel")
    public void export(HttpServletResponse response, BussinessOperLog operLog)
    {
        List<BussinessOperLog> list = operLogService.selectOperLogList(operLog);
        ExcelUtil<BussinessOperLog> util = new ExcelUtil<BussinessOperLog>(BussinessOperLog.class);
        util.exportExcel(response, list, "操作日志");
    }

    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/{operIds}")
    @ApiOperation("删除操作日志")
    public AjaxResult remove(@PathVariable Long[] operIds)
    {
        return toAjax(operLogService.deleteOperLogByIds(operIds));
    }

    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/clean")
    @ApiOperation("清空操作日志")
    public AjaxResult clean()
    {
        operLogService.cleanOperLog();
        return success();
    }
}
