package com.ruoyi.web.controller.system;

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

import com.ruoyi.system.domain.ReportQueryLog;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IReportQueryLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 查询日志Controller
 * 
 * @author boman
 * @date 2021-12-27
 */
@RestController
@RequestMapping("/system/queryLog")
public class ReportQueryLogController extends BaseController
{
    @Autowired
    private IReportQueryLogService reportQueryLogService;

    /**
     * 查询查询日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:queryLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReportQueryLog reportQueryLog)
    {
        startPage();
        List<ReportQueryLog> list = reportQueryLogService.selectReportQueryLogList(reportQueryLog);
        return getDataTable(list);
    }

    /**
     * 导出查询日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:queryLog:export')")
    @Log(title = "查询日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReportQueryLog reportQueryLog)
    {
        List<ReportQueryLog> list = reportQueryLogService.selectReportQueryLogList(reportQueryLog);
        ExcelUtil<ReportQueryLog> util = new ExcelUtil<ReportQueryLog>(ReportQueryLog.class);
        util.exportExcel(response, list, "查询日志数据");
    }

    /**
     * 获取查询日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:queryLog:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId)
    {
        return AjaxResult.success(reportQueryLogService.selectReportQueryLogByLogId(logId));
    }

    /**
     * 新增查询日志
     */
    @PreAuthorize("@ss.hasPermi('system:queryLog:add')")
    @Log(title = "查询日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReportQueryLog reportQueryLog)
    {
        reportQueryLog.setCreateBy(getUsername());
        return toAjax(reportQueryLogService.insertReportQueryLog(reportQueryLog));
    }

    /**
     * 修改查询日志
     */
    @PreAuthorize("@ss.hasPermi('system:queryLog:edit')")
    @Log(title = "查询日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReportQueryLog reportQueryLog)
    {
        reportQueryLog.setUpdateBy(getUsername());
        return toAjax(reportQueryLogService.updateReportQueryLog(reportQueryLog));
    }

    /**
     * 删除查询日志
     */
    @PreAuthorize("@ss.hasPermi('system:queryLog:remove')")
    @Log(title = "查询日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds)
    {
        return toAjax(reportQueryLogService.deleteReportQueryLogByLogIds(logIds));
    }
}
