package com.ruoyi.web.controller.system;

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 com.ruoyi.system.domain.PoOperLog;
import com.ruoyi.system.service.IPoOperLogService;
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;

/**
 * 操作日志记录Controller
 * @date 2023-01-15
 */
@RestController
@RequestMapping("/post/operlog")
public class PoOperLogController extends BaseController
{
    @Autowired
    private IPoOperLogService poOperLogService;

    /**
     * 查询操作日志记录列表
     */
    @PreAuthorize("@ss.hasPermi('post:operlog:list')")
    @GetMapping("/list")
    public TableDataInfo list(PoOperLog poOperLog)
    {
        startPage();
        List<PoOperLog> list = poOperLogService.selectPoOperLogList(poOperLog);
        return getDataTable(list);
    }

    /**
     * 导出操作日志记录列表
     */
    @PreAuthorize("@ss.hasPermi('post:operlog:export')")
    @Log(title = "操作日志记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PoOperLog poOperLog)
    {
        List<PoOperLog> list = poOperLogService.selectPoOperLogList(poOperLog);
        ExcelUtil<PoOperLog> util = new ExcelUtil<PoOperLog>(PoOperLog.class);
        util.exportExcel(response, list, "操作日志记录数据");
    }

    /**
     * 获取操作日志记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('post:operlog:query')")
    @GetMapping(value = "/{operId}")
    public AjaxResult getInfo(@PathVariable("operId") Long operId)
    {
        return success(poOperLogService.selectPoOperLogByOperId(operId));
    }

    /**
     * 新增操作日志记录
     */
    @PreAuthorize("@ss.hasPermi('post:operlog:add')")
    @Log(title = "操作日志记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody PoOperLog poOperLog)
    {
        return toAjax(poOperLogService.insertPoOperLog(poOperLog));
    }

    /**
     * 修改操作日志记录
     */
    @PreAuthorize("@ss.hasPermi('post:operlog:edit')")
    @Log(title = "操作日志记录", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody PoOperLog poOperLog)
    {
        return toAjax(poOperLogService.updatePoOperLog(poOperLog));
    }

    /**
     * 删除操作日志记录
     */
    @PreAuthorize("@ss.hasPermi('post:operlog:remove')")
    @Log(title = "操作日志记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{operIds}")
    public AjaxResult remove(@PathVariable Long[] operIds)
    {
        return toAjax(poOperLogService.deletePoOperLogByOperIds(operIds));
    }
}