package com.ruoyi.abuwx.controller;

import com.ruoyi.abuwx.domain.CardRedeption;
import com.ruoyi.abuwx.service.ICardRedeptionService;
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 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 lujie
 * @date 2025-01-07
 */
@RestController
@RequestMapping("/card/redeption")
public class CardRedeptionController extends BaseController {
    @Autowired
    private ICardRedeptionService cardRedeptionService;

    /**
     * 查询卡券兑换列表
     */
    @PreAuthorize("@ss.hasPermi('card:redeption:list')")
    @GetMapping("/list")
    public TableDataInfo list(CardRedeption cardRedeption) {
        startPage();
        List<CardRedeption> list = cardRedeptionService.selectCardRedeptionList(cardRedeption);
        return getDataTable(list);
    }

    /**
     * 导出卡券兑换列表
     */
    @PreAuthorize("@ss.hasPermi('card:redeption:export')")
    @Log(title = "卡券兑换", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CardRedeption cardRedeption) {
        List<CardRedeption> list = cardRedeptionService.selectCardRedeptionList(cardRedeption);
        ExcelUtil<CardRedeption> util = new ExcelUtil<CardRedeption>(CardRedeption.class);
        util.exportExcel(response, list, "卡券兑换数据");
    }

    /**
     * 获取卡券兑换详细信息
     */
    @PreAuthorize("@ss.hasPermi('card:redeption:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(cardRedeptionService.selectCardRedeptionById(id));
    }

    /**
     * 新增卡券兑换
     */
    @PreAuthorize("@ss.hasPermi('card:redeption:add')")
    @Log(title = "卡券兑换", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CardRedeption cardRedeption) {
        return toAjax(cardRedeptionService.insertCardRedeption(cardRedeption));
    }

    /**
     * 修改卡券兑换
     */
    @PreAuthorize("@ss.hasPermi('card:redeption:edit')")
    @Log(title = "卡券兑换", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CardRedeption cardRedeption) {
        return toAjax(cardRedeptionService.updateCardRedeption(cardRedeption));
    }

    /**
     * 删除卡券兑换
     */
    @PreAuthorize("@ss.hasPermi('card:redeption:remove')")
    @Log(title = "卡券兑换", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cardRedeptionService.deleteCardRedeptionByIds(ids));
    }
}
