package com.ruoyi.web.controller.ss;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.ValidGroup;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ss.vipLevel.domain.VipLevel;
import com.ruoyi.ss.vipLevel.domain.VipLevelVO;
import com.ruoyi.ss.vipLevel.domain.VipLevelQuery;
import com.ruoyi.ss.vipLevel.service.VipLevelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员等级Controller
 *
 * @author ruoyi
 * @date 2024-12-09
 */
@RestController
@RequestMapping("/ss/vipLevel")
public class VipLevelController extends BaseController
{
    @Autowired
    private VipLevelService vipLevelService;

    /**
     * 查询会员等级列表
     */
    @PreAuthorize("@ss.hasPermi('ss:vipLevel:list')")
    @GetMapping("/list")
    public TableDataInfo list(VipLevelQuery query)
    {
        startPage();
        startOrderBy();
        List<VipLevelVO> list = vipLevelService.selectVipLevelList(query);
        return getDataTable(list);
    }

    /**
     * 查询会员等级列表
     */
    @PreAuthorize("@ss.hasPermi('ss:vipLevel:list')")
    @PostMapping("/listByIds")
    public AjaxResult list(@RequestBody List<Long> ids)
    {
        VipLevelQuery query = new VipLevelQuery();
        query.setIds(ids);
        List<VipLevelVO> list = vipLevelService.selectVipLevelList(query);
        return success(list);
    }

    /**
     * 导出会员等级列表
     */
    @PreAuthorize("@ss.hasPermi('ss:vipLevel:export')")
    @Log(title = "会员等级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VipLevelQuery query)
    {
        List<VipLevelVO> list = vipLevelService.selectVipLevelList(query);
        ExcelUtil<VipLevelVO> util = new ExcelUtil<VipLevelVO>(VipLevelVO.class);
        util.exportExcel(response, list, "会员等级数据");
    }

    /**
     * 获取会员等级详细信息
     */
    @PreAuthorize("@ss.hasPermi('ss:vipLevel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(vipLevelService.selectVipLevelById(id));
    }

    /**
     * 新增会员等级
     */
    @PreAuthorize("@ss.hasPermi('ss:vipLevel:add')")
    @Log(title = "会员等级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated(ValidGroup.Create.class) VipLevel vipLevel)
    {
        return toAjax(vipLevelService.insertVipLevel(vipLevel));
    }

    /**
     * 修改会员等级
     */
    @PreAuthorize("@ss.hasPermi('ss:vipLevel:edit')")
    @Log(title = "会员等级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated(ValidGroup.Update.class) VipLevel vipLevel)
    {
        return toAjax(vipLevelService.updateVipLevel(vipLevel));
    }

    /**
     * 删除会员等级
     */
    @PreAuthorize("@ss.hasPermi('ss:vipLevel:remove')")
    @Log(title = "会员等级", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(vipLevelService.deleteVipLevelByIds(ids));
    }
}
