package com.ruoyi.abuwx.controller;

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.abuwx.domain.CardCoupons;
import com.ruoyi.abuwx.service.ICardCouponsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 卡券管理Controller
 *
 * @author lujie
 * @date 2025-01-07
 */
@RestController
@RequestMapping("/card/coupons")
public class CardCouponsController extends BaseController {
    @Autowired
    private ICardCouponsService cardCouponsService;

    /**
     * 查询卡券管理列表
     */
    @PreAuthorize("@ss.hasPermi('card:coupons:list')")
    @GetMapping("/list")
    public TableDataInfo list(CardCoupons cardCoupons) {
        startPage();
        List<CardCoupons> list = cardCouponsService.selectCardCouponsList(cardCoupons);
        return getDataTable(list);
    }

    /**
     * 导出卡券管理列表
     */
    @PreAuthorize("@ss.hasPermi('card:coupons:export')")
    @Log(title = "卡券管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CardCoupons cardCoupons) {
        List<CardCoupons> list = cardCouponsService.selectCardCouponsList(cardCoupons);
        ExcelUtil<CardCoupons> util = new ExcelUtil<CardCoupons>(CardCoupons.class);
        util.exportExcel(response, list, "卡券管理数据");
    }

    /**
     * 获取卡券管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('card:coupons:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(cardCouponsService.selectCardCouponsById(id));
    }

    /**
     * 新增卡券管理
     */
    @PreAuthorize("@ss.hasPermi('card:coupons:add')")
    @Log(title = "卡券管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CardCoupons cardCoupons) {
        return toAjax(cardCouponsService.insertCardCoupons(cardCoupons));
    }

    /**
     * 修改卡券管理
     */
    @PreAuthorize("@ss.hasPermi('card:coupons:edit')")
    @Log(title = "卡券管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CardCoupons cardCoupons) {
        return toAjax(cardCouponsService.updateCardCoupons(cardCoupons));
    }

    /**
     * 删除卡券管理
     */
    @PreAuthorize("@ss.hasPermi('card:coupons:remove')")
    @Log(title = "卡券管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cardCouponsService.deleteCardCouponsByIds(ids));
    }
}
