package com.ruoyi.zongzhi.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zongzhi.domain.TcDtSx;
import com.ruoyi.zongzhi.service.ITcDtSxService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 动态筛选Controller
 *
 * @author ruoyi
 * @date 2023-08-28
 */
@RestController
@RequestMapping("/zongzhi/sx")
@Api(tags = " 动态筛选")
public class TcDtSxController extends BaseController {
    @Autowired
    private ITcDtSxService tcDtSxService;

    /**
     * 查询动态筛选列表
     */

    @GetMapping("/list")
    public TableDataInfo list(TcDtSx tcDtSx) {
        startPage();
        List<TcDtSx> list = tcDtSxService.selectTcDtSxList(tcDtSx);
        return getDataTable(list);
    }

    /**
     * 导出动态筛选列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, TcDtSx tcDtSx) {
        List<TcDtSx> list = tcDtSxService.selectTcDtSxList(tcDtSx);
        ExcelUtil<TcDtSx> util = new ExcelUtil<TcDtSx>(TcDtSx.class);
        util.exportExcel(response, list, "动态筛选数据");
    }

    /**
     * 获取动态筛选详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tcDtSxService.selectTcDtSxById(id));
    }

    /**
     * 新增动态筛选
     */

    @PostMapping
    public AjaxResult add(@RequestBody TcDtSx tcDtSx) {
        tcDtSx.setIsStatus(true);
        return toAjax(tcDtSxService.insertTcDtSx(tcDtSx));
    }

    /**
     * 修改动态筛选
     */

    @PutMapping
    public AjaxResult edit(@RequestBody TcDtSx tcDtSx) {
        return toAjax(tcDtSxService.updateTcDtSx(tcDtSx));
    }

    /**
     * 删除动态筛选
     */

    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tcDtSxService.deleteTcDtSxByIds(ids));
    }
}
