package com.ruoyi.web.controller.ss;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ss.vipLevel.domain.VipLevel;
import com.ruoyi.ss.vipLevel.domain.VipLevelQuery;
import com.ruoyi.ss.vipLevel.domain.VipLevelVO;
import com.ruoyi.ss.vipLevel.service.VipLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * VIP等级Controller
 *
 * @author ruoyi
 * @date 2025-01-16
 */
@RestController
@RequestMapping("/ss/vipLevel")
public class VipLevelController extends BaseController
{
    @Autowired
    private VipLevelService vipLevelService;

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

    /**
     * 导出VIP等级列表
     */
    @PreAuthorize("@ss.hasPermi('ss:vipLevel:export')")
    @Log(title = "VIP等级", 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, "VIP等级数据");
    }

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

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

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

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