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.TcTb;
import com.ruoyi.zongzhi.service.ITcTbService;
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-16
 */
@RestController
@RequestMapping("/zongzhi/tb")
@Api(tags = " 通报")
public class TcTbController extends BaseController {
    @Autowired
    private ITcTbService tcTbService;

    /**
     * 查询通报列表
     */

    @GetMapping("/list")
    public TableDataInfo list(TcTb tcTb) {
        startPage();
        List<TcTb> list = tcTbService.selectTcTbList(tcTb);
        return getDataTable(list);
    }

    /**
     * 导出通报列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, TcTb tcTb) {
        List<TcTb> list = tcTbService.selectTcTbList(tcTb);
        ExcelUtil<TcTb> util = new ExcelUtil<TcTb>(TcTb.class);
        util.exportExcel(response, list, "通报数据");
    }

    /**
     * 获取通报详细信息
     */

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

    /**
     * 新增通报
     */

    @PostMapping
    public AjaxResult add(@RequestBody TcTb tcTb) {
        tcTb.setIsStatus(true);
        return toAjax(tcTbService.insertTcTb(tcTb));
    }

    /**
     * 修改通报
     */

    @PutMapping
    public AjaxResult edit(@RequestBody TcTb tcTb) {
        return toAjax(tcTbService.updateTcTb(tcTb));
    }

    /**
     * 删除通报
     */

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