package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.domain.QueryConfig;
import com.ruoyi.system.service.IQueryConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 查询配置Controller
 * 
 * @author 博曼
 * @date 2021-12-27
 */
@RestController
@RequestMapping("/system/queryConfig")
public class QueryConfigController extends BaseController
{
    @Autowired
    private IQueryConfigService queryConfigService;

    /**
     * 查询查询配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:queryConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(QueryConfig queryConfig)
    {
        startPage();
        List<QueryConfig> list = queryConfigService.selectQueryConfigList(queryConfig);
        return getDataTable(list);
    }

    /**
     * 导出查询配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:queryConfig:export')")
    @Log(title = "查询配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QueryConfig queryConfig)
    {
        List<QueryConfig> list = queryConfigService.selectQueryConfigList(queryConfig);
        ExcelUtil<QueryConfig> util = new ExcelUtil<QueryConfig>(QueryConfig.class);
        util.exportExcel(response, list, "查询配置数据");
    }

    /**
     * 获取查询配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:queryConfig:query')")
    @GetMapping(value = "/{configId}")
    public AjaxResult getInfo(@PathVariable("configId") Long configId)
    {
        return AjaxResult.success(queryConfigService.selectQueryConfigByConfigId(configId));
    }

    /**
     * 新增查询配置
     */
    @PreAuthorize("@ss.hasPermi('system:queryConfig:add')")
    @Log(title = "查询配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QueryConfig queryConfig)
    {
        queryConfig.setCreateBy(getUsername());
        return queryConfigService.insertQueryConfig(queryConfig);
    }

    /**
     * 修改查询配置
     */
    @PreAuthorize("@ss.hasPermi('system:queryConfig:edit')")
    @Log(title = "查询配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QueryConfig queryConfig)
    {
        queryConfig.setUpdateBy(getUsername());
        return queryConfigService.updateQueryConfig(queryConfig);
    }

    /**
     * 删除查询配置
     */
    @PreAuthorize("@ss.hasPermi('system:queryConfig:remove')")
    @Log(title = "查询配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{configIds}")
    public AjaxResult remove(@PathVariable Long[] configIds)
    {
        return toAjax(queryConfigService.deleteQueryConfigByConfigIds(configIds));
    }
}
