package com.ruoyi.framework.recovery.controller;

import java.util.List;
import jakarta.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.framework.recovery.domain.WxCoupons;
import com.ruoyi.framework.recovery.service.IWxCouponsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 微信优惠卷Controller
 * 
 * @author jin
 * @date 2024-12-08
 */
@RestController
@RequestMapping("/recovery/coupons")
public class WxCouponsController extends BaseController
{
    @Autowired
    private IWxCouponsService wxCouponsService;

    /**
     * 查询微信优惠卷列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:coupons:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxCoupons wxCoupons)
    {
        startPage();
        List<WxCoupons> list = wxCouponsService.selectWxCouponsList(wxCoupons);
        return getDataTable(list);
    }

    /**
     * 导出微信优惠卷列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:coupons:export')")
    @Log(title = "微信优惠卷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxCoupons wxCoupons)
    {
        List<WxCoupons> list = wxCouponsService.selectWxCouponsList(wxCoupons);
        ExcelUtil<WxCoupons> util = new ExcelUtil<WxCoupons>(WxCoupons.class);
        util.exportExcel(response, list, "微信优惠卷数据");
    }

    /**
     * 获取微信优惠卷详细信息
     */
    @PreAuthorize("@ss.hasPermi('recovery:coupons:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wxCouponsService.selectWxCouponsById(id));
    }

    /**
     * 新增微信优惠卷
     */
    @PreAuthorize("@ss.hasPermi('recovery:coupons:add')")
    @Log(title = "微信优惠卷", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxCoupons wxCoupons)
    {
        return toAjax(wxCouponsService.insertWxCoupons(wxCoupons));
    }

    /**
     * 修改微信优惠卷
     */
    @PreAuthorize("@ss.hasPermi('recovery:coupons:edit')")
    @Log(title = "微信优惠卷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxCoupons wxCoupons)
    {
        return toAjax(wxCouponsService.updateWxCoupons(wxCoupons));
    }

    /**
     * 删除微信优惠卷
     */
    @PreAuthorize("@ss.hasPermi('recovery:coupons:remove')")
    @Log(title = "微信优惠卷", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wxCouponsService.deleteWxCouponsByIds(ids));
    }
}
