package com.ruoyi.tcZz.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.tcZz.domain.TcYqyj;
import com.ruoyi.tcZz.domain.TcYqzs;
import com.ruoyi.tcZz.service.ITcYqzsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

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

/**
 * 舆情走势图Controller
 *
 * @author ruoyi
 * @date 2023-10-13
 */
@Api(tags = "舆情走势图")
@RestController
@RequestMapping("/tcZz/netWorkYq/yqzs")
public class TcYqzsController extends BaseController {
    @Autowired
    private ITcYqzsService tcYqzsService;


    /**
     * 导出舆情走势图列表
     */
    @ApiOperation("导出舆情走势图列表")
    @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, "舆情走势图数据");
    }

    /**
     * 获取舆情走势图详细信息
     */
    @ApiOperation("获取舆情走势图详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tcYqzsService.selectTcYqzsById(id));
    }

    /**
     * 新增舆情走势图
     */
    @ApiOperation("新增舆情走势图")
    @PostMapping
    public AjaxResult add(@RequestBody TcYqzs tcYqzs) {
        return toAjax(tcYqzsService.insertTcYqzs(tcYqzs));
    }

    /**
     * 修改舆情走势图
     */
    @ApiOperation("修改舆情走势图")
    @PutMapping
    public AjaxResult edit(@RequestBody TcYqzs tcYqzs) {
        return toAjax(tcYqzsService.updateTcYqzs(tcYqzs));
    }

    /**
     * 删除舆情走势图
     */
    @ApiOperation("删除舆情走势图")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tcYqzsService.deleteTcYqzsByIds(ids));
    }

    /**
     * 查询舆情走势图列表
     */
    @ApiOperation(value = "查询舆情走势图列表", response = TcYqzs.class)
    @GetMapping("/ListNoToken")
    public TableDataInfo ListNoToken(TcYqzs tcYqzs) {
        startPage();
        List<TcYqzs> list = tcYqzsService.selectTcYqzsList(tcYqzs);
        return getDataTable(list);
    }


    /**
     * 导入
     */
    @ApiOperation("通用导入excel信息")
    @PostMapping("/common/importExcel")
    public AjaxResult importExcel(MultipartFile file) throws Exception {
        ExcelUtil<TcYqzs> util = new ExcelUtil<TcYqzs>(TcYqzs.class);
        List<TcYqzs> tcYqzsList = util.importExcel(file.getInputStream());
        tcYqzsService.importUser(tcYqzsList);
        return AjaxResult.success();
    }
    /**
     * 批量启用禁用
     *
     * @param isStatus 启用禁用状态
     * @return
     */

    @ApiOperation("批量启用禁用")
    @GetMapping("/isStatus")
    public AjaxResult isStatus(@RequestParam("isStatus") Integer isStatus,@RequestParam("ids") List<String> ids) {
        tcYqzsService.updateByisStatus(isStatus,ids);
        return AjaxResult.success();
    }

    @ApiOperation("通用下载excel模板")
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<TcYqzs> util = new ExcelUtil<TcYqzs>(TcYqzs.class);
        util.importTemplateExcel(response, " 舆情走势图列表");
    }
}
