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.TcNetworkSentiment;
import com.ruoyi.zongzhi.service.ITcNetworkSentimentService;
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-10
 */
@RestController
@RequestMapping("/zongzhi/sentiment")
@Api(tags = " 网络舆情")
public class TcNetworkSentimentController extends BaseController {
    @Autowired
    private ITcNetworkSentimentService tcNetworkSentimentService;

    /**
     * 查询网络舆情列表
     */

    @GetMapping("/list")
    public TableDataInfo list(TcNetworkSentiment tcNetworkSentiment) {
        startPage();
        List<TcNetworkSentiment> list = tcNetworkSentimentService.selectTcNetworkSentimentList(tcNetworkSentiment);
        return getDataTable(list);
    }

    /**
     * 导出网络舆情列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, TcNetworkSentiment tcNetworkSentiment) {
        List<TcNetworkSentiment> list = tcNetworkSentimentService.selectTcNetworkSentimentList(tcNetworkSentiment);
        ExcelUtil<TcNetworkSentiment> util = new ExcelUtil<TcNetworkSentiment>(TcNetworkSentiment.class);
        util.exportExcel(response, list, "网络舆情数据");
    }

    /**
     * 获取网络舆情详细信息
     */

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

    /**
     * 新增网络舆情
     */

    @PostMapping
    public AjaxResult add(@RequestBody TcNetworkSentiment tcNetworkSentiment) {
        tcNetworkSentiment.setIsStatus(true);
        return toAjax(tcNetworkSentimentService.insertTcNetworkSentiment(tcNetworkSentiment));
    }

    /**
     * 修改网络舆情
     */

    @PutMapping
    public AjaxResult edit(@RequestBody TcNetworkSentiment tcNetworkSentiment) {
        return toAjax(tcNetworkSentimentService.updateTcNetworkSentiment(tcNetworkSentiment));
    }

    /**
     * 删除网络舆情
     */

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