package com.ruoyi.web.controller.dragForm;

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

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.entity.TableSql;
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.ITableSqlService;

import com.ruoyi.common.core.page.TableDataInfo;

/**
 * table 联合查询sql存储Controller
 * 
 * @author ruoyi
 * @date 2023-07-19
 */
@RestController
@RequestMapping("/system/sql")
public class TableSqlController extends BaseController
{
    @Autowired
    private ITableSqlService tableSqlService;

    /**
     * 查询table 联合查询sql存储列表
     */
    @PreAuthorize("@ss.hasPermi('system:sql:list')")
    @GetMapping("/list")
    public TableDataInfo list(TableSql tableSql)
    {
        startPage();
        List<TableSql> list = tableSqlService.selectTableSqlList(tableSql);
        return getDataTable(list);
    }

    /**
     * 导出table 联合查询sql存储列表
     */
    @PreAuthorize("@ss.hasPermi('system:sql:export')")
    @Log(title = "table 联合查询sql存储", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TableSql tableSql)
    {
        List<TableSql> list = tableSqlService.selectTableSqlList(tableSql);
        ExcelUtil<TableSql> util = new ExcelUtil<TableSql>(TableSql.class);
        util.exportExcel(response, list, "table 联合查询sql存储数据");
    }

    /**
     * 获取table 联合查询sql存储详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sql:query')")
    @GetMapping(value = "/{tId}")
    public AjaxResult getInfo(@PathVariable("tId") Long tId)
    {
        return success(tableSqlService.selectTableSqlByTId(tId));
    }

    /**
     * 新增table 联合查询sql存储
     */
    @PreAuthorize("@ss.hasPermi('system:sql:add')")
    @Log(title = "table 联合查询sql存储", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TableSql tableSql)
    {
        return toAjax(tableSqlService.insertTableSql(tableSql));
    }

    /**
     * 修改table 联合查询sql存储
     */
    @PreAuthorize("@ss.hasPermi('system:sql:edit')")
    @Log(title = "table 联合查询sql存储", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TableSql tableSql)
    {
        return toAjax(tableSqlService.updateTableSql(tableSql));
    }

    /**
     * 删除table 联合查询sql存储
     */
    @PreAuthorize("@ss.hasPermi('system:sql:remove')")
    @Log(title = "table 联合查询sql存储", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tIds}")
    public AjaxResult remove(@PathVariable Long[] tIds)
    {
        return toAjax(tableSqlService.deleteTableSqlByTIds(tIds));
    }
}
