package com.ruoyi.web.controller.business;

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.business.domain.TbUserMsg;
import com.ruoyi.business.service.ITbUserMsgService;
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 xiatao
 * @date 2022-01-18
 */
@Controller
@RequestMapping("/business/userMsg")
public class TbUserMsgController extends BaseController
{
    private String prefix = "business/userMsg";

    @Autowired
    private ITbUserMsgService tbUserMsgService;

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

    /**
     * 查询消息中心列表
     */
    @RequiresPermissions("business:userMsg:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbUserMsg tbUserMsg)
    {
        startPage();
        List<TbUserMsg> list = tbUserMsgService.selectTbUserMsgList(tbUserMsg);
        return getDataTable(list);
    }

    /**
     * 导出消息中心列表
     */
    @RequiresPermissions("business:userMsg:export")
    @Log(title = "消息中心", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbUserMsg tbUserMsg)
    {
        List<TbUserMsg> list = tbUserMsgService.selectTbUserMsgList(tbUserMsg);
        ExcelUtil<TbUserMsg> util = new ExcelUtil<TbUserMsg>(TbUserMsg.class);
        return util.exportExcel(list, "消息中心数据");
    }

    /**
     * 新增消息中心
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存消息中心

     */
    @RequiresPermissions("business:userMsg:add")
    @Log(title = "消息中心", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbUserMsg tbUserMsg)
    {
        return toAjax(tbUserMsgService.insertTbUserMsg(tbUserMsg));
    }

    /**
     * 修改消息中心
     */
    @RequiresPermissions("business:userMsg:edit")
    @GetMapping("/edit/{msgId}")
    public String edit(@PathVariable("msgId") Long msgId, ModelMap mmap)
    {
        TbUserMsg tbUserMsg = tbUserMsgService.selectTbUserMsgByMsgId(msgId);
        mmap.put("tbUserMsg", tbUserMsg);
        return prefix + "/edit";
    }

    /**
     * 修改保存消息中心
     */
    @RequiresPermissions("business:userMsg:edit")
    @Log(title = "消息中心", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbUserMsg tbUserMsg)
    {
        return toAjax(tbUserMsgService.updateTbUserMsg(tbUserMsg));
    }

    /**
     * 删除消息中心
     */
    @RequiresPermissions("business:userMsg:remove")
    @Log(title = "消息中心", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbUserMsgService.deleteTbUserMsgByMsgIds(ids));
    }
}
