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.TcYqZs;
import com.ruoyi.zongzhi.service.ITcYqZsService;
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/zs")
@Api(tags = " 舆情走势图")
public class TcYqZsController extends BaseController {
    @Autowired
    private ITcYqZsService tcYqZsService;

    /**
     * 查询舆情走势图列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TcYqZs tcYqZs) {
        startPage();
        List<TcYqZs> list = tcYqZsService.selectTcYqZsList(tcYqZs);
        return getDataTable(list);
    }

    /**
     * 导出舆情走势图列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, TcYqZs tcYqZs) {
        List<TcYqZs> list = tcYqZsService.selectTcYqZsList(tcYqZs);
        ExcelUtil<TcYqZs> util = new ExcelUtil<TcYqZs>(TcYqZs.class);
        util.exportExcel(response, list, "舆情走势图数据");
    }

    /**
     * 获取舆情走势图详细信息
     */

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

    /**
     * 新增舆情走势图
     */

    @PostMapping
    public AjaxResult add(@RequestBody TcYqZs tcYqZs) {
        tcYqZs.setIsStatus(true);
        return toAjax(tcYqZsService.insertTcYqZs(tcYqZs));
    }

    /**
     * 修改舆情走势图
     */

    @PutMapping
    public AjaxResult edit(@RequestBody TcYqZs tcYqZs) {
        return toAjax(tcYqZsService.updateTcYqZs(tcYqZs));
    }

    /**
     * 删除舆情走势图
     */

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