package com.ruoyi.web.controller.school;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbNotice;
import com.ruoyi.system.service.ITbNoticeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 通知公告Controller
 * 
 * @author ruoyi
 * @date 2022-10-18
 */
@Controller
@RequestMapping("/business/notice")
public class TbNoticeController extends BaseController
{
    private String prefix = "business/notice";

    @Autowired
    private ITbNoticeService tbNoticeService;

    @RequiresPermissions("business:notice:view")
    @GetMapping()
    public String notice()
    {
        return prefix + "/notice";
    }

    /**
     * 查询通知公告列表
     */
    @RequiresPermissions("business:notice:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbNotice tbNotice)
    {
        startPage();
        List<TbNotice> list = tbNoticeService.selectTbNoticeList(tbNotice);
        return getDataTable(list);
    }

    /**
     * 导出通知公告列表
     */
    @RequiresPermissions("business:notice:export")
    @Log(title = "通知公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbNotice tbNotice)
    {
        List<TbNotice> list = tbNoticeService.selectTbNoticeList(tbNotice);
        ExcelUtil<TbNotice> util = new ExcelUtil<TbNotice>(TbNotice.class);
        return util.exportExcel(list, "通知公告数据");
    }

    /**
     * 新增通知公告
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存通知公告
     */
    @RequiresPermissions("business:notice:add")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbNotice tbNotice)
    {
        tbNotice.setCreator(getUserId());
        return toAjax(tbNoticeService.insertTbNotice(tbNotice));
    }

    /**
     * 修改通知公告
     */
    @RequiresPermissions("business:notice:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbNotice tbNotice = tbNoticeService.selectTbNoticeById(id);
        mmap.put("tbNotice", tbNotice);
        return prefix + "/edit";
    }

    /**
     * 修改保存通知公告
     */
    @RequiresPermissions("business:notice:edit")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbNotice tbNotice)
    {
        tbNotice.setModifiedBy(getUserId());
        return toAjax(tbNoticeService.updateTbNotice(tbNotice));
    }

    /**
     * 删除通知公告
     */
    @RequiresPermissions("business:notice:remove")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbNoticeService.deleteTbNoticeByIds(ids));
    }
}
