package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
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.domain.XiaoyuanNotice;
import com.ruoyi.system.service.IXiaoyuanNoticeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 校园新闻Controller
 * 
 * @author boman
 * @date 2023-06-05
 */
@RestController
@RequestMapping("/xiaoYuan/notice")
public class XiaoyuanNoticeController extends BaseController
{
    @Autowired
    private IXiaoyuanNoticeService xiaoyuanNoticeService;

    /**
     * 查询校园新闻列表
     */
    @PreAuthorize("@ss.hasPermi('xiaoYuan:notice:list')")
    @GetMapping("/list")
    public TableDataInfo list(XiaoyuanNotice xiaoyuanNotice)
    {
        List<XiaoyuanNotice> list = xiaoyuanNoticeService.selectXiaoyuanNoticeList(xiaoyuanNotice);
        return getDataTable(list);
    }

    /**
     * 我的校园新闻列表
     */
    @GetMapping("/myList")
    public TableDataInfo myList(XiaoyuanNotice xiaoyuanNotice)
    {
        startPage();
        List<XiaoyuanNotice> list = xiaoyuanNoticeService.selectXiaoyuanNoticeMyList(xiaoyuanNotice);
        return getDataTable(list);
    }
    /**
     * 我的收藏
     */
    @GetMapping("/collect")
    public TableDataInfo myCollect(XiaoyuanNotice xiaoyuanNotice)
    {
        startPage();
        List<XiaoyuanNotice> list = xiaoyuanNoticeService.myCollect(xiaoyuanNotice);
        return getDataTable(list);
    }

    /**
     * 导出校园新闻列表
     */
    @PreAuthorize("@ss.hasPermi('xiaoYuan:notice:export')")
    @Log(title = "校园新闻", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XiaoyuanNotice xiaoyuanNotice)
    {
        List<XiaoyuanNotice> list = xiaoyuanNoticeService.selectXiaoyuanNoticeList(xiaoyuanNotice);
        ExcelUtil<XiaoyuanNotice> util = new ExcelUtil<XiaoyuanNotice>(XiaoyuanNotice.class);
        util.exportExcel(response, list, "校园新闻数据");
    }

    /**
     * 获取校园新闻详细信息
     */
    @PreAuthorize("@ss.hasPermi('xiaoYuan:notice:query')")
    @GetMapping(value = "/{noticeId}")
    public AjaxResult getInfo(@PathVariable("noticeId") Integer noticeId)
    {
        return success(xiaoyuanNoticeService.selectXiaoyuanNoticeByNoticeId(noticeId));
    }

    /**
     * 新增校园新闻
     */
    @PreAuthorize("@ss.hasPermi('xiaoYuan:notice:add')")
    @Log(title = "校园新闻", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XiaoyuanNotice xiaoyuanNotice)
    {
        return toAjax(xiaoyuanNoticeService.insertXiaoyuanNotice(xiaoyuanNotice));
    }

    /**
     * 修改校园新闻
     */
    @PreAuthorize("@ss.hasPermi('xiaoYuan:notice:edit')")
    @Log(title = "校园新闻", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody XiaoyuanNotice xiaoyuanNotice)
    {
        return toAjax(xiaoyuanNoticeService.updateXiaoyuanNotice(xiaoyuanNotice));
    }

    /**
     * 删除校园新闻
     */
    @PreAuthorize("@ss.hasPermi('xiaoYuan:notice:remove')")
    @Log(title = "校园新闻", businessType = BusinessType.DELETE)
	@GetMapping("/delete/{noticeIds}")
    public AjaxResult remove(@PathVariable Integer[] noticeIds)
    {
        return toAjax(xiaoyuanNoticeService.deleteXiaoyuanNoticeByNoticeIds(noticeIds));
    }
}
