package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.ss.cardOrder.domain.CardOrder;
import com.ruoyi.ss.cardOrder.domain.CardOrderVO;
import com.ruoyi.ss.cardOrder.domain.CardOrderQuery;
import com.ruoyi.ss.cardOrder.service.ICardOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 卡券订单Controller
 *
 * @author qzz
 * @date 2025-03-20
 */
@RestController
@RequestMapping("/system/cardOrder")
public class CardOrderController extends BaseController
{
    @Autowired
    private ICardOrderService cardOrderService;

    /**
     * 查询卡券订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:cardOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(CardOrderQuery query)
    {
        startPage();
        startOrderBy();
        List<CardOrderVO> list = cardOrderService.selectCardOrderList(query);
        return getDataTable(list);
    }

    /**
     * 导出卡券订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:cardOrder:export')")
    @Log(title = "卡券订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CardOrderQuery query)
    {
        List<CardOrderVO> list = cardOrderService.selectCardOrderList(query);
        ExcelUtil<CardOrderVO> util = new ExcelUtil<CardOrderVO>(CardOrderVO.class);
        util.exportExcel(response, list, "卡券订单数据");
    }

    /**
     * 获取卡券订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cardOrder:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return success(cardOrderService.selectCardOrderByOrderId(orderId));
    }

    /**
     * 新增卡券订单
     */
    @PreAuthorize("@ss.hasPermi('system:cardOrder:add')")
    @Log(title = "卡券订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CardOrder cardOrder)
    {
        return toAjax(cardOrderService.insertCardOrder(cardOrder));
    }

    /**
     * 修改卡券订单
     */
    @PreAuthorize("@ss.hasPermi('system:cardOrder:edit')")
    @Log(title = "卡券订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CardOrder cardOrder)
    {
        return toAjax(cardOrderService.updateCardOrder(cardOrder));
    }

    /**
     * 删除卡券订单
     */
    @PreAuthorize("@ss.hasPermi('system:cardOrder:remove')")
    @Log(title = "卡券订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(cardOrderService.deleteCardOrderByOrderIds(orderIds));
    }
}
