package com.ruoyi.web.bst;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
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.RestController;

import com.ruoyi.bst.areaJoin.domain.enums.AreaJoinPermission;
import com.ruoyi.bst.vipUser.domain.VipUserQuery;
import com.ruoyi.bst.vipUser.domain.VipUserVO;
import com.ruoyi.bst.vipUser.service.VipUserService;
import com.ruoyi.bst.vipUser.service.VipUserValidator;
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.ServiceUtil;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 用户卡券Controller
 *
 * @author ruoyi
 * @date 2025-05-26
 */
@RestController
@RequestMapping("/bst/vipUser")
public class VipUserController extends BaseController
{
    @Autowired
    private VipUserService vipUserService;

    @Autowired
    private VipUserValidator vipUserValidator;

    /**
     * 查询用户卡券列表
     */
    @PreAuthorize("@ss.hasPermi('bst:vipUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(VipUserQuery query)
    {
        startPage();
        startOrderBy();
        query.setScope(true);
        query.addAreaPermission(AreaJoinPermission.VIP_USER_VIEW.getCode());
        List<VipUserVO> list = vipUserService.selectVipUserList(query);
        return getDataTable(list);
    }

    /**
     * 导出用户卡券列表
     */
    @PreAuthorize("@ss.hasPermi('bst:vipUser:export')")
    @Log(title = "用户卡券", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VipUserQuery query)
    {
        query.setScope(true);
        query.addAreaPermission(AreaJoinPermission.VIP_USER_VIEW.getCode());
        List<VipUserVO> list = vipUserService.selectVipUserList(query);
        ExcelUtil<VipUserVO> util = new ExcelUtil<VipUserVO>(VipUserVO.class);
        util.exportExcel(response, list, "用户卡券数据");
    }

    /**
     * 获取用户卡券详细信息
     */
    @PreAuthorize("@ss.hasPermi('bst:vipUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(vipUserService.selectVipUserById(id, true));
    }

    /**
     * 删除用户卡券
     */
    @PreAuthorize("@ss.hasPermi('bst:vipUser:remove')")
    @Log(title = "用户卡券", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        ServiceUtil.assertion(!vipUserValidator.canEdit(ids), "您无权操作ID为%s的用户卡券", ids);
        return toAjax(vipUserService.logicDel(ids));
    }
}
