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.TbMember;
import com.ruoyi.business.service.ITbMemberService;
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/member")
public class TbMemberController extends BaseController
{
    private String prefix = "business/member";

    @Autowired
    private ITbMemberService tbMemberService;

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

    /**
     * 查询套餐列表
     */
    @RequiresPermissions("business:member:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbMember tbMember)
    {
        startPage();
        List<TbMember> list = tbMemberService.selectTbMemberList(tbMember);
        return getDataTable(list);
    }

    /**
     * 导出套餐列表
     */
    @RequiresPermissions("business:member:export")
    @Log(title = "套餐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbMember tbMember)
    {
        List<TbMember> list = tbMemberService.selectTbMemberList(tbMember);
        ExcelUtil<TbMember> util = new ExcelUtil<TbMember>(TbMember.class);
        return util.exportExcel(list, "套餐数据");
    }

    /**
     * 新增套餐
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存套餐
     */
    @RequiresPermissions("business:member:add")
    @Log(title = "套餐", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbMember tbMember)
    {
        return toAjax(tbMemberService.insertTbMember(tbMember));
    }

    /**
     * 修改套餐
     */
    @RequiresPermissions("business:member:edit")
    @GetMapping("/edit/{memId}")
    public String edit(@PathVariable("memId") Long memId, ModelMap mmap)
    {
        TbMember tbMember = tbMemberService.selectTbMemberByMemId(memId);
        mmap.put("tbMember", tbMember);
        return prefix + "/edit";
    }

    /**
     * 修改保存套餐
     */
    @RequiresPermissions("business:member:edit")
    @Log(title = "套餐", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbMember tbMember)
    {
        return toAjax(tbMemberService.updateTbMember(tbMember));
    }

    /**
     * 删除套餐
     */
    @RequiresPermissions("business:member:remove")
    @Log(title = "套餐", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbMemberService.deleteTbMemberByMemIds(ids));
    }
}
