package com.ruoyi.web.controller.notice;

import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.notice.ZxNotice;
import com.ruoyi.system.service.IZxNoticeService;
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.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 政协通知公告Controller
 *
 * @author boman
 * @date 2024-03-05
 */
@RestController
@RequestMapping("/zxNotice/notice")
public class ZxNoticeController extends BaseController {
    @Autowired
    private IZxNoticeService zxNoticeService;

    /**
     * 查询政协通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('zxNotice:notice:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZxNotice zxNotice) {
        startPage();
        List<ZxNotice> list = zxNoticeService.selectZxNoticeList(zxNotice);
        return getDataTable(list);
    }

    /**
     * 导出政协通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('zxNotice:notice:export')")
    @Log(title = "政协通知公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZxNotice zxNotice) {
        List<ZxNotice> list = zxNoticeService.selectZxNoticeList(zxNotice);
        ExcelUtil<ZxNotice> util = new ExcelUtil<ZxNotice>(ZxNotice.class);
        util.exportExcel(response, list, "政协通知公告数据");
    }

    /**
     * 获取政协通知公告详细信息
     */
    @PreAuthorize("@ss.hasPermi('zxNotice:notice:query')")
    @GetMapping(value = "/{zxNoticeId}")
    public AjaxResult getInfo(@PathVariable("zxNoticeId") Long zxNoticeId) {
        return success(zxNoticeService.selectZxNoticeByZxNoticeId(zxNoticeId));
    }

    /**
     * 新增政协通知公告
     */
    @PreAuthorize("@ss.hasPermi('zxNotice:notice:add')")
    @Log(title = "政协通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZxNotice zxNotice) {
        return toAjax(zxNoticeService.insertZxNotice(zxNotice));
    }

    /**
     * 修改政协通知公告
     */
    @PreAuthorize("@ss.hasPermi('zxNotice:notice:edit')")
    @Log(title = "政协通知公告", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody ZxNotice zxNotice) {
        return toAjax(zxNoticeService.updateZxNotice(zxNotice));
    }

    /**
     * 删除政协通知公告
     */
    @PreAuthorize("@ss.hasPermi('zxNotice:notice:remove')")
    @Log(title = "政协通知公告", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{zxNoticeIds}")
    public AjaxResult remove(@PathVariable Long[] zxNoticeIds) {
        return toAjax(zxNoticeService.deleteZxNoticeByZxNoticeIds(zxNoticeIds));
    }
}
