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.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.vipOrder.domain.VipOrderQuery;
import com.ruoyi.bst.vipOrder.domain.VipOrderVO;
import com.ruoyi.bst.vipOrder.service.VipOrderService;
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;

/**
 * 卡券订单Controller
 *
 * @author ruoyi
 * @date 2025-05-24
 */
@RestController
@RequestMapping("/bst/vipOrder")
public class VipOrderController extends BaseController
{
    @Autowired
    private VipOrderService vipOrderService;

    /**
     * 查询卡券订单列表
     */
    @PreAuthorize("@ss.hasPermi('bst:vipOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(VipOrderQuery query)
    {
        startPage();
        startOrderBy();
        query.setScope(true);
        query.addAreaPermission(AreaJoinPermission.VIP_ORDER_VIEW.getCode());
        List<VipOrderVO> list = vipOrderService.selectVipOrderList(query);
        return getDataTable(list);
    }

    /**
     * 导出卡券订单列表
     */
    @PreAuthorize("@ss.hasPermi('bst:vipOrder:export')")
    @Log(title = "卡券订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VipOrderQuery query)
    {
        query.setScope(true);
        query.addAreaPermission(AreaJoinPermission.VIP_ORDER_VIEW.getCode());
        List<VipOrderVO> list = vipOrderService.selectVipOrderList(query);
        ExcelUtil<VipOrderVO> util = new ExcelUtil<VipOrderVO>(VipOrderVO.class);
        util.exportExcel(response, list, "卡券订单数据");
    }

    /**
     * 获取卡券订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('bst:vipOrder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(vipOrderService.selectVipOrderById(id, true));
    }

}
