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.TbUserMember;
import com.ruoyi.business.service.ITbUserMemberService;
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/userMember")
public class TbUserMemberController extends BaseController
{
    private String prefix = "business/userMember";

    @Autowired
    private ITbUserMemberService tbUserMemberService;

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

    /**
     * 查询我的套餐
列表
     */
    @RequiresPermissions("business:userMember:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbUserMember tbUserMember)
    {
        startPage();
        List<TbUserMember> list = tbUserMemberService.selectTbUserMemberList(tbUserMember);
        return getDataTable(list);
    }

    /**
     * 导出我的套餐
列表
     */
    @RequiresPermissions("business:userMember:export")
    @Log(title = "我的套餐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbUserMember tbUserMember)
    {
        List<TbUserMember> list = tbUserMemberService.selectTbUserMemberList(tbUserMember);
        ExcelUtil<TbUserMember> util = new ExcelUtil<TbUserMember>(TbUserMember.class);
        return util.exportExcel(list, "我的套餐数据");
    }

    /**
     * 新增我的套餐

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

    /**
     * 新增保存我的套餐

     */
    @RequiresPermissions("business:userMember:add")
    @Log(title = "我的套餐", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbUserMember tbUserMember)
    {
        return toAjax(tbUserMemberService.insertTbUserMember(tbUserMember));
    }

    /**
     * 修改我的套餐

     */
    @RequiresPermissions("business:userMember:edit")
    @GetMapping("/edit/{userMemId}")
    public String edit(@PathVariable("userMemId") Long userMemId, ModelMap mmap)
    {
        TbUserMember tbUserMember = tbUserMemberService.selectTbUserMemberByUserMemId(userMemId);
        mmap.put("tbUserMember", tbUserMember);
        return prefix + "/edit";
    }

    /**
     * 修改保存我的套餐

     */
    @RequiresPermissions("business:userMember:edit")
    @Log(title = "我的套餐", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbUserMember tbUserMember)
    {
        return toAjax(tbUserMemberService.updateTbUserMember(tbUserMember));
    }

    /**
     * 删除我的套餐

     */
    @RequiresPermissions("business:userMember:remove")
    @Log(title = "我的套餐", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbUserMemberService.deleteTbUserMemberByUserMemIds(ids));
    }
}
