package com.ruoyi.szxc.controller;

import com.ruoyi.common.annotation.Log;
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.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.szxc.domain.SzxcNews;
import com.ruoyi.szxc.service.ISzxcNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 公告资讯Controller
 * 
 * @author hs
 * @date 2024-03-16
 */
@RestController
@RequestMapping("/szxc/news")
public class SzxcNewsController extends BaseController
{
    @Autowired
    private ISzxcNewsService szxcNewsService;

    /**
     * 查询公告资讯列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:news:list')")
    @GetMapping("/list")
    public TableDataInfo list(SzxcNews szxcNews)
    {
        startPage();
        List<SzxcNews> list = szxcNewsService.selectSzxcNewsList(szxcNews);
        return getDataTable(list);
    }

    /**
     * 导出公告资讯列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:news:export')")
    @Log(title = "公告资讯", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SzxcNews szxcNews)
    {
        List<SzxcNews> list = szxcNewsService.selectSzxcNewsList(szxcNews);
        ExcelUtil<SzxcNews> util = new ExcelUtil<SzxcNews>(SzxcNews.class);
        util.exportExcel(response, list, "公告资讯数据");
    }

    /**
     * 获取公告资讯详细信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:news:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(szxcNewsService.selectSzxcNewsById(id));
    }

    /**
     * 新增公告资讯
     */
    @PreAuthorize("@ss.hasPermi('szxc:news:add')")
    @Log(title = "公告资讯", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SzxcNews szxcNews)
    {
        return toAjax(szxcNewsService.insertSzxcNews(szxcNews));
    }

    /**
     * 修改公告资讯
     */
    @PreAuthorize("@ss.hasPermi('szxc:news:edit')")
    @Log(title = "公告资讯", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SzxcNews szxcNews)
    {
        return toAjax(szxcNewsService.updateSzxcNews(szxcNews));
    }

    /**
     * 删除公告资讯
     */
    @PreAuthorize("@ss.hasPermi('szxc:news:remove')")
    @Log(title = "公告资讯", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(szxcNewsService.deleteSzxcNewsByIds(ids));
    }
}
