package com.ruoyi.web.controller.monitor;

import com.easy.mongodb.core.biz.PageInfo;
import com.easy.mongodb.core.toolkit.Wraps;
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.domain.entity.SysOperLog;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.service.ISysOperLogService;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
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;

/**
 * ProjectName: RuoYi-Vue-MongoDB
 * Description: 操作日志记录
 * Author: 86631561@163.coom
 * Date: 2022/7/20 17:04:00
 * UpdateUser: 86631561@163.coom
 * UpdateDate: 2022/7/20 17:04:00
 * UpdateRemark: The modified content
 * Version: 1.0
 * <p>
 * Copyright © 2022 86631561@163.coom Technologies Inc. All Rights Reserved
 **/
@RestController
@RequestMapping("/monitor/operlog")
public class SysOperlogController extends BaseController {
    @Autowired
    private ISysOperLogService operLogService;

    @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysOperLog operLog, Integer pageNum, Integer pageSize) {
        startPage();
        PageInfo<SysOperLog> pageInfo = this.operLogService.page(Wraps.lbQ(operLog), pageNum, pageSize);
//        List<SysOperLog> list = this.operLogService.selectOperLogList(operLog);
        return getDataTable(pageInfo);
    }

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

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

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