package com.qiaoba.module.log.controller;

import com.qiaoba.api.job.annotation.Log;
import com.qiaoba.api.job.enums.BusinessType;
import com.qiaoba.common.base.result.AjaxResult;
import com.qiaoba.common.database.entity.PageQuery;
import com.qiaoba.common.database.entity.TableDataInfo;
import com.qiaoba.common.poi.util.ExcelUtil;
import com.qiaoba.module.log.entity.SysUseLog;
import com.qiaoba.module.log.entity.param.SysUseLogParam;
import com.qiaoba.module.log.service.SysUserLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

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

/**
 * 操作日志 web层
 *
 * @author ailanyin
 * @version 1.0
 * @since 2022-09-22 04:20:28
 */
@RestController
@RequestMapping("/monitor/use-log")
@RequiredArgsConstructor
public class SysUseLogController {

    private final SysUserLogService sysUserLogService;


    @GetMapping("/list")
    public TableDataInfo list(SysUseLogParam param, PageQuery pageQuery) {
        return sysUserLogService.selectPageList(param, pageQuery);
    }

    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUseLogParam param) {
        List<SysUseLog> list = sysUserLogService.selectList(param);
        ExcelUtil.exportExcel(list, SysUseLog.class, "操作日志", response);
    }

    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public AjaxResult clean() {
        sysUserLogService.cleanUseLog();
        return AjaxResult.success();
    }
}
