package com.ruoyi.member.controller;

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

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
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.member.domain.MemberCard;
import com.ruoyi.member.service.IMemberCardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员开卡记录Controller
 *
 * @author pqz
 * @date 2025-03-17
 */
@RestController
@RequestMapping("/member/card")
public class MemberCardController extends BaseController
{
    @Autowired
    private IMemberCardService memberCardService;

    /**
     * 查询会员开卡记录列表
     */
    @PreAuthorize("@ss.hasPermi('member:card:list')")
    @GetMapping("/list")
    public AjaxResult list(MemberCard memberCard)
    {

        List<MemberCard> list = memberCardService.list();
        return success(list);
    }

    /**
     * 导出会员开卡记录列表
     */
    @PreAuthorize("@ss.hasPermi('member:card:export')")
    @Log(title = "会员开卡记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberCard memberCard)
    {
        List<MemberCard> list = memberCardService.list();
        ExcelUtil<MemberCard> util = new ExcelUtil<MemberCard>(MemberCard.class);
        util.exportExcel(response, list, "会员开卡记录数据");
    }

    /**
     * 获取会员开卡记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('member:card:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(memberCardService.getById(id));
    }

    /**
     * 新增会员开卡记录
     */
    @PreAuthorize("@ss.hasPermi('member:card:add')")
    @Log(title = "会员开卡记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberCard memberCard)
    {
        return toAjax(memberCardService.save(memberCard));
    }

    /**
     * 修改会员开卡记录
     */
    @PreAuthorize("@ss.hasPermi('member:card:edit')")
    @Log(title = "会员开卡记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberCard memberCard)
    {
        return toAjax(memberCardService.updateById(memberCard));
    }

    /**
     * 删除会员开卡记录
     */
    @PreAuthorize("@ss.hasPermi('member:card:remove')")
    @Log(title = "会员开卡记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        List<String> list = new ArrayList<>(Arrays.asList(ids));
        return toAjax(memberCardService.removeByIds(list));
    }

    /**
     * 查询当前用户的权益信息
     */

    @GetMapping("/selectMemberRights")
    public AjaxResult selectMemberRights()
    {
        return success( memberCardService.selectMemberRights(SecurityUtils.getUserId(),null));
    }

}
