package org.wfc.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wfc.common.core.utils.poi.ExcelUtil;
import org.wfc.common.core.web.controller.BaseController;
import org.wfc.common.core.web.domain.AjaxResult;
import org.wfc.common.core.web.page.TableDataInfo;
import org.wfc.common.log.annotation.Log;
import org.wfc.common.log.enums.BusinessType;
import org.wfc.common.security.annotation.InnerAuth;
import org.wfc.common.security.annotation.RequiresPermissions;
import org.wfc.user.api.domain.UOperLog;
import org.wfc.user.service.IUOperLogService;

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

/**
 * 操作日志记录
 * 
 * @author wfc
 */
@RestController
@RequestMapping("/operlog")
public class UOperlogController extends BaseController
{
    @Autowired
    private IUOperLogService operLogService;

    @RequiresPermissions("Utem:operlog:list")
    @GetMapping("/list")
    public TableDataInfo list(UOperLog operLog)
    {
        startPage();
        List<UOperLog> list = operLogService.selectOperLogList(operLog);
        return getDataTable(list);
    }

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

    // @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @RequiresPermissions("Utem:operlog:remove")
    @DeleteMapping("/{operIds}")
    public AjaxResult remove(@PathVariable Long[] operIds)
    {
        return toAjax(operLogService.deleteOperLogByIds(operIds));
    }

    @RequiresPermissions("Utem:operlog:remove")
    // @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public AjaxResult clean()
    {
        operLogService.cleanOperLog();
        return success();
    }

    @InnerAuth
    @PostMapping
    public AjaxResult add(@RequestBody UOperLog operLog)
    {
        return toAjax(operLogService.insertOperlog(operLog));
    }
}
