package com.ruoyi.web.controller.ss;

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;
import com.ruoyi.ss.vipOrder.domain.VipOrderQuery;
import com.ruoyi.ss.vipOrder.domain.VipOrderVO;
import com.ruoyi.ss.vipOrder.service.VipOrderAssembler;
import com.ruoyi.ss.vipOrder.service.VipOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 会员订单Controller
 *
 * @author ruoyi
 * @date 2025-01-16
 */
@RestController
@RequestMapping("/ss/vipOrder")
public class VipOrderController extends BaseController
{
    @Autowired
    private VipOrderService vipOrderService;

    @Autowired
    private VipOrderAssembler vipOrderAssembler;

    /**
     * 查询会员订单列表
     */
    @PreAuthorize("@ss.hasPermi('ss:vipOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(VipOrderQuery query)
    {
        startPage();
        startOrderBy();
        List<VipOrderVO> list = vipOrderService.selectVipOrderList(query);
        return getDataTable(list);
    }

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

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

    /**
     * 刷新支付结果
     */
    @PreAuthorize("@ss.hasPermi('ss:vipOrder:refreshPayResult')")
    @Log(title = "会员订单", businessType = BusinessType.UPDATE)
    @PutMapping("/refreshPayResult")
    public AjaxResult refreshPayResult(Long id) {
        return toAjax(vipOrderService.refreshPayResult(id));
    }


}
