package com.sundot.airport.web.controller.system;

import com.sundot.airport.common.annotation.Log;
import com.sundot.airport.common.core.controller.BaseController;
import com.sundot.airport.common.core.domain.AjaxResult;
import com.sundot.airport.common.core.page.TableDataInfo;
import com.sundot.airport.common.enums.BusinessType;
import com.sundot.airport.common.utils.poi.ExcelUtil;
import com.sundot.airport.system.domain.SysDynamicSql;
import com.sundot.airport.system.service.ISysDynamicSqlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 动态sql执行configController
 *
 * @author ruoyi
 * @date 2025-06-20
 */
@RestController
@RequestMapping("/system/sql")
public class SysDynamicSqlController extends BaseController {
    @Autowired
    private ISysDynamicSqlService sysDynamicSqlService;

    /**
     * 查询动态sql执行config列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysDynamicSql sysDynamicSql) {
        startPage();
        List<SysDynamicSql> list = sysDynamicSqlService.selectSysDynamicSqlList(sysDynamicSql);
        return getDataTable(list);
    }

    /**
     * 导出动态sql执行config列表
     */
    @Log(title = "动态sql执行config", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDynamicSql sysDynamicSql) {
        List<SysDynamicSql> list = sysDynamicSqlService.selectSysDynamicSqlList(sysDynamicSql);
        ExcelUtil<SysDynamicSql> util = new ExcelUtil<SysDynamicSql>(SysDynamicSql.class);
        util.exportExcel(response, list, "动态sql执行config数据");
    }

    /**
     * 获取动态sql执行config详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysDynamicSqlService.selectSysDynamicSqlById(id));
    }

    /**
     * 新增动态sql执行config
     */
    @Log(title = "动态sql执行config", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDynamicSql sysDynamicSql) {
        return toAjax(sysDynamicSqlService.insertSysDynamicSql(sysDynamicSql));
    }

    /**
     * 修改动态sql执行config
     */
    @Log(title = "动态sql执行config", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDynamicSql sysDynamicSql) {
        return toAjax(sysDynamicSqlService.updateSysDynamicSql(sysDynamicSql));
    }

    /**
     * 删除动态sql执行config
     */
    @Log(title = "动态sql执行config", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysDynamicSqlService.deleteSysDynamicSqlByIds(ids));
    }

    /**
     * 删除动态sql执行config
     */
    @PostMapping("/executeSqlByKeyAndParam/{sqlKey}")
    public AjaxResult executeSqlByKeyAndParam(@PathVariable(name = "sqlKey") String sqlkey, @RequestBody Map<String, Object> params) {
        return success(sysDynamicSqlService.executeSqlByKeyAndParam(sqlkey, params));
    }
}
