package com.ebts.web.controller.monitor;

import com.ebts.common.annotation.Log;
import com.ebts.common.core.controller.BaseController;
import com.ebts.common.core.entity.Result;
import com.ebts.common.enums.BusinessType;
import com.ebts.common.utils.poi.ExcelUtil;
import com.ebts.system.entity.OperLog;
import com.ebts.system.service.OperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * 操作日志记录
 *
 * @author binlin
 */
@RestController
@RequestMapping("/monitor/operlog")
public class OperlogController extends BaseController {

    @Autowired
    private OperLogService operLogService;

    @PreAuthorize("@ebts.hasPermi('monitor:operlog:list')")
    @GetMapping("/list")
    public Serializable list(OperLog operLog) {
        startPage();
        List<OperLog> list = operLogService.selectOperLogList(operLog);
        return getDataTable(list);
    }

    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ebts.hasPermi('monitor:operlog:export')")
    @GetMapping("/export")
    public Result<OperLog> export(OperLog operLog) {
        List<OperLog> list = operLogService.selectOperLogList(operLog);
        ExcelUtil<OperLog> util = new ExcelUtil<OperLog>(OperLog.class);
        return util.exportExcel(list, "操作日志");
    }

    @PreAuthorize("@ebts.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/{operIds}")
    public Result<Integer> remove(@PathVariable Long[] operIds) {
        return toResult(operLogService.deleteOperLogByIds(operIds));
    }

    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @PreAuthorize("@ebts.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/clean")
    public Result<Integer> clean() {
        operLogService.cleanOperLog();
        return Result.ok();
    }
}
