package com.ruoyi.web.controller.system.check;

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.TdNotify;
import com.ruoyi.system.service.ITdNotifyService;
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 2024-05-06
 */
@Controller
@RequestMapping("/system/notify")
public class TdNotifyController extends BaseController
{
    private String prefix = "system/notify";

    @Autowired
    private ITdNotifyService tdNotifyService;

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

    /**
     * 查询检查通知列表
     */
    @RequiresPermissions("system:notify:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TdNotify tdNotify)
    {
        startPage();
        List<TdNotify> list = tdNotifyService.selectTdNotifyList(tdNotify);
        return getDataTable(list);
    }

    /**
     * 导出检查通知列表
     */
    @RequiresPermissions("system:notify:export")
    @Log(title = "检查通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TdNotify tdNotify)
    {
        List<TdNotify> list = tdNotifyService.selectTdNotifyList(tdNotify);
        ExcelUtil<TdNotify> util = new ExcelUtil<TdNotify>(TdNotify.class);
        return util.exportExcel(list, "检查通知数据");
    }

    /**
     * 新增检查通知
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("sysuser", getSysUser());
        return prefix + "/add";
    }

    /**
     * 新增保存检查通知
     */
    @RequiresPermissions("system:notify:add")
    @Log(title = "检查通知", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TdNotify tdNotify)
    {
        return toAjax(tdNotifyService.insertTdNotify(tdNotify));
    }

    /**
     * 修改检查通知
     */
    @RequiresPermissions("system:notify:edit")
    @GetMapping("/edit/{notifyId}")
    public String edit(@PathVariable("notifyId") Long notifyId, ModelMap mmap)
    {
        TdNotify tdNotify = tdNotifyService.selectTdNotifyByNotifyId(notifyId);
        mmap.put("tdNotify", tdNotify);
        return prefix + "/edit";
    }

    /**
     * 修改保存检查通知
     */
    @RequiresPermissions("system:notify:edit")
    @Log(title = "检查通知", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TdNotify tdNotify)
    {
        return toAjax(tdNotifyService.updateTdNotify(tdNotify));
    }

    /**
     * 删除检查通知
     */
    @RequiresPermissions("system:notify:remove")
    @Log(title = "检查通知", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tdNotifyService.deleteTdNotifyByNotifyIds(ids));
    }
}
