package beilv.voucher.controller;

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 beilv.common.annotation.Log;
import beilv.common.enums.BusinessType;
import beilv.voucher.domain.BeilvVoucherMember;
import beilv.voucher.service.IBeilvVoucherMemberService;
import beilv.common.core.controller.BaseController;
import beilv.common.core.domain.AjaxResult;
import beilv.common.utils.poi.ExcelUtil;
import beilv.common.core.page.TableDataInfo;

/**
 * 代金券用户关系Controller
 *
 * @author ruoyi
 * @date 2025-11-20
 */
@Controller
@RequestMapping("/voucher/member")
public class BeilvVoucherMemberController extends BaseController {
    private String prefix = "voucher/member";

    @Autowired
    private IBeilvVoucherMemberService beilvVoucherMemberService;

    @GetMapping()
    public String member() {
        return prefix + "/voucher/member";
    }

    @GetMapping("/water/{id}")
    public String openDetails(@PathVariable("id") Long id, ModelMap mmap) {
        mmap.put("voucherId", id);
        return prefix + "/water";
    }

    /**
     * 查询代金券用户关系列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo couponWater(BeilvVoucherMember beilvVoucherMember) {
        startPage();
        List<BeilvVoucherMember> list = beilvVoucherMemberService.selectBeilvVoucherMemberList(beilvVoucherMember);
        return getDataTable(list);
    }

    /**
     * 新增代金券用户关系
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存代金券用户关系
     */
    @Log(title = "代金券用户关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BeilvVoucherMember beilvVoucherMember) {
        return toAjax(beilvVoucherMemberService.insertBeilvVoucherMember(beilvVoucherMember));
    }
}