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.TcYqFl;
import com.ruoyi.zongzhi.service.ITcYqFlService;
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/fl")
@Api(tags = " 舆情分类")
public class TcYqFlController extends BaseController {
    @Autowired
    private ITcYqFlService tcYqFlService;

    /**
     * 查询舆情分类列表
     */

    @GetMapping("/list")
    public TableDataInfo list(TcYqFl tcYqFl) {
        startPage();
        List<TcYqFl> list = tcYqFlService.selectTcYqFlList(tcYqFl);
        return getDataTable(list);
    }

    /**
     * 导出舆情分类列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, TcYqFl tcYqFl) {
        List<TcYqFl> list = tcYqFlService.selectTcYqFlList(tcYqFl);
        ExcelUtil<TcYqFl> util = new ExcelUtil<TcYqFl>(TcYqFl.class);
        util.exportExcel(response, list, "舆情分类数据");
    }

    /**
     * 获取舆情分类详细信息
     */

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

    /**
     * 新增舆情分类
     */

    @PostMapping
    public AjaxResult add(@RequestBody TcYqFl tcYqFl) {
        tcYqFl.setIsStatus(true);
        return toAjax(tcYqFlService.insertTcYqFl(tcYqFl));
    }

    /**
     * 修改舆情分类
     */

    @PutMapping
    public AjaxResult edit(@RequestBody TcYqFl tcYqFl) {
        return toAjax(tcYqFlService.updateTcYqFl(tcYqFl));
    }

    /**
     * 删除舆情分类
     */

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