package com.ruoyi.web.controller.speak;

import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.speak.ZxSpeak;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IZxSpeakService;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 政协发言Controller
 *
 * @author boman
 * @date 2024-03-07
 */
@RestController
@RequestMapping("/zx/speak")
public class ZxSpeakController extends BaseController {
    @Autowired
    private IZxSpeakService zxSpeakService;

    /**
     * 查询政协发言列表
     */
    @PreAuthorize("@ss.hasPermi('zx:speak:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZxSpeak zxSpeak) {
        startPage();
        List<ZxSpeak> list = zxSpeakService.selectZxSpeakList(zxSpeak);
        return getDataTable(list);
    }

    /**
     * 导出政协发言列表
     */
    @PreAuthorize("@ss.hasPermi('zx:speak:export')")
    @Log(title = "政协发言", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZxSpeak zxSpeak) {
        List<ZxSpeak> list = zxSpeakService.selectZxSpeakList(zxSpeak);
        ExcelUtil<ZxSpeak> util = new ExcelUtil<ZxSpeak>(ZxSpeak.class);
        util.exportExcel(response, list, "政协发言数据");
    }

    /**
     * 获取政协发言详细信息
     */
    @PreAuthorize("@ss.hasPermi('zx:speak:query')")
    @GetMapping(value = "/{speakId}")
    public AjaxResult getInfo(@PathVariable("speakId") Long speakId) {
        return success(zxSpeakService.selectZxSpeakBySpeakId(speakId));
    }

    /**
     * 新增政协发言
     */
    @PreAuthorize("@ss.hasPermi('zx:speak:add')")
    @Log(title = "政协发言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZxSpeak zxSpeak) {
        return toAjax(zxSpeakService.insertZxSpeak(zxSpeak));
    }

    /**
     * 修改政协发言
     */
    @PreAuthorize("@ss.hasPermi('zx:speak:edit')")
    @Log(title = "政协发言", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody ZxSpeak zxSpeak) {
        return toAjax(zxSpeakService.updateZxSpeak(zxSpeak));
    }

    /**
     * 删除政协发言
     */
    @PreAuthorize("@ss.hasPermi('zx:speak:remove')")
    @Log(title = "政协发言", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{speakIds}")
    public AjaxResult remove(@PathVariable Long[] speakIds) {
        return toAjax(zxSpeakService.deleteZxSpeakBySpeakIds(speakIds));
    }
}
