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.ss.commandLog.domain.CommandLog;
import com.ruoyi.ss.commandLog.service.ICommandLogService;
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
 *
 * @author 邱贞招
 * @date 2024-07-06
 */
@RestController
@RequestMapping("/system/commandLog")
public class CommandLogController extends BaseController
{
    @Autowired
    private ICommandLogService etCommandLogService;

    /**
     * 查询命令日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:commandLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommandLog eCommandLog)
    {
        startPage();
        List<CommandLog> list = etCommandLogService.selectEtCommandLogList(eCommandLog);
        return getDataTable(list);
    }

    /**
     * 导出命令日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:commandLog:export')")
    @Log(title = "命令日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommandLog eCommandLog)
    {
        List<CommandLog> list = etCommandLogService.selectEtCommandLogList(eCommandLog);
        ExcelUtil<CommandLog> util = new ExcelUtil<CommandLog>(CommandLog.class);
        util.exportExcel(response, list, "命令日志数据");
    }

    /**
     * 获取命令日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:commandLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(etCommandLogService.selectEtCommandLogById(id));
    }

    /**
     * 新增命令日志
     */
    @PreAuthorize("@ss.hasPermi('system:commandLog:add')")
    @Log(title = "命令日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommandLog eCommandLog)
    {
        return toAjax(etCommandLogService.insertEtCommandLog(eCommandLog));
    }

    /**
     * 修改命令日志
     */
    @PreAuthorize("@ss.hasPermi('system:commandLog:edit')")
    @Log(title = "命令日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommandLog eCommandLog)
    {
        return toAjax(etCommandLogService.updateEtCommandLog(eCommandLog));
    }

    /**
     * 删除命令日志
     */
    @PreAuthorize("@ss.hasPermi('system:commandLog:remove')")
    @Log(title = "命令日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(etCommandLogService.deleteEtCommandLogByIds(ids));
    }
}
