package com.ruoyi.app.vip;

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

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.system.domain.InfoAddress;
import com.ruoyi.system.domain.PosOrder;
import com.ruoyi.system.utils.Auth;
import com.ruoyi.system.utils.JwtUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
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.system.domain.VipMembership;
import com.ruoyi.system.service.IVipMembershipService;
import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * viplistController
 * 
 * @author ruoyi
 * @date 2023-05-24
 */
@RestController
@RequestMapping("/system/membership")
public class VipMembershipController extends BaseController
{
    @Autowired
    private IVipMembershipService vipMembershipService;



    //获取在售会员卡列表
    @Anonymous
    @GetMapping("/getviplist")
    public AjaxResult getviplist()
    {
        QueryWrapper<VipMembership> queryWrapper= new QueryWrapper<>();
        queryWrapper.eq("state",0);
        List<VipMembership> list = vipMembershipService.list(queryWrapper);
        return success(MessageUtils.message("no.obtained.success"), list);
    }

    /**
     * 查询viplist列表
     */
    @PreAuthorize("@ss.hasPermi('system:membership:list')")
    @GetMapping("/list")
    public TableDataInfo list(VipMembership vipMembership)
    {
        startPage();
        List<VipMembership> list = vipMembershipService.selectVipMembershipList(vipMembership);
        return getDataTable(list);
    }

    /**
     * 导出viplist列表
     */
    @PreAuthorize("@ss.hasPermi('system:membership:export')")
    @Log(title = "viplist", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VipMembership vipMembership)
    {
        List<VipMembership> list = vipMembershipService.selectVipMembershipList(vipMembership);
        ExcelUtil<VipMembership> util = new ExcelUtil<VipMembership>(VipMembership.class);
        util.exportExcel(response, list, MessageUtils.message("no.export.excel.viplist"));
    }

    /**
     * 获取viplist详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:membership:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(vipMembershipService.selectVipMembershipById(id));
    }

    /**
     * 新增viplist
     */
    @PreAuthorize("@ss.hasPermi('system:membership:add')")
    @Log(title = "viplist", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VipMembership vipMembership)
    {
        return toAjax(vipMembershipService.insertVipMembership(vipMembership));
    }

    /**
     * 修改viplist
     */
    @PreAuthorize("@ss.hasPermi('system:membership:edit')")
    @Log(title = "viplist", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VipMembership vipMembership)
    {
        return toAjax(vipMembershipService.updateVipMembership(vipMembership));
    }

    /**
     * 删除viplist
     */
    @PreAuthorize("@ss.hasPermi('system:membership:remove')")
    @Log(title = "viplist", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(vipMembershipService.deleteVipMembershipByIds(ids));
    }
}
