package com.ruoyi.interfaces.controller;

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

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.interfaces.domain.MdDataSetSql;
import com.ruoyi.interfaces.service.IMdDataSetSqlService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * sql数据集Controller
 * 
 * @author 朱得糠
 * @date 2025-09-02
 */
@RestController
@RequestMapping("/data/set/sql")
public class MdDataSetSqlController extends BaseController
{
    @Autowired
    private IMdDataSetSqlService mdDataSetSqlService;

    /**
     * 查询sql数据集列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MdDataSetSql mdDataSetSql)
    {
        startPage();
        List<MdDataSetSql> list = mdDataSetSqlService.selectMdDataSetSqlList(mdDataSetSql);
        return getDataTable(list);
    }

    /**
     * 导出sql数据集列表
     */
    @Log(title = "sql数据集", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MdDataSetSql mdDataSetSql)
    {
        List<MdDataSetSql> list = mdDataSetSqlService.selectMdDataSetSqlList(mdDataSetSql);
        ExcelUtil<MdDataSetSql> util = new ExcelUtil<MdDataSetSql>(MdDataSetSql.class);
        util.exportExcel(response, list, "sql数据集数据");
    }

    /**
     * 获取sql数据集详细信息
     */
    @GetMapping(value = "/{dcCode}")
    public AjaxResult getInfo(@PathVariable("dcCode") String dcCode)
    {

        return success(mdDataSetSqlService.selectMdDataSetSqlByDcCode(dcCode));
    }

    /**
     * 新增sql数据集
     */
    @PostMapping
    public AjaxResult add(@RequestBody MdDataSetSql mdDataSetSql)
    {
        mdDataSetSqlService.deleteMdDataSetSqlByDcCode(mdDataSetSql.getDcCode());
        return toAjax(mdDataSetSqlService.insertMdDataSetSql(mdDataSetSql));
    }

    /**
     * 修改sql数据集
     */
    @PutMapping
    public AjaxResult edit(@RequestBody MdDataSetSql mdDataSetSql)
    {
        return toAjax(mdDataSetSqlService.updateMdDataSetSql(mdDataSetSql));
    }

    /**
     * 删除sql数据集
     */
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mdDataSetSqlService.deleteMdDataSetSqlByIds(ids));
    }
}
