package com.cyl.manager.marketing.controller;

import java.util.List;

import com.cyl.manager.marketing.domain.WechatMemberCoupon;
import com.cyl.manager.marketing.pojo.SendCouponRequest;
import com.cyl.manager.marketing.service.IWechatMemberCouponService;
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.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员券发放记录Controller
 * 
 * @author daixiande
 * @date 2024-04-26
 */
@RestController
@RequestMapping("/mall/wechatMemberCoupon")
public class WechatMemberCouponController extends BaseController {
    @Autowired
    private IWechatMemberCouponService wechatMemberCouponService;

    /**
     * 查询会员券发放记录列表
     */
    @PreAuthorize("@ss.hasPermi('mall:wechatMemberCoupon:list')")
    @GetMapping("/list")
    public TableDataInfo list(WechatMemberCoupon wechatMemberCoupon) {
        startPage();
        List<WechatMemberCoupon> list = wechatMemberCouponService.selectWechatMemberCouponList(wechatMemberCoupon);
        return getDataTable(list);
    }

    /**
     * 导出会员券发放记录列表
     */
    @PreAuthorize("@ss.hasPermi('mall:wechatMemberCoupon:export')")
    @Log(title = "会员券发放记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WechatMemberCoupon wechatMemberCoupon) {
        List<WechatMemberCoupon> list = wechatMemberCouponService.selectWechatMemberCouponList(wechatMemberCoupon);
        ExcelUtil<WechatMemberCoupon> util = new ExcelUtil<WechatMemberCoupon>(WechatMemberCoupon.class);
        return util.exportExcel(list, "会员券发放记录数据");
    }

    /**
     * 获取会员券发放记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:wechatMemberCoupon:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(wechatMemberCouponService.selectWechatMemberCouponById(id));
    }

    /**
     * 新增会员券发放记录
     */
    @PreAuthorize("@ss.hasPermi('mall:wechatMemberCoupon:add')")
    @Log(title = "会员券发放记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WechatMemberCoupon wechatMemberCoupon) {
        return toAjax(wechatMemberCouponService.insertWechatMemberCoupon(wechatMemberCoupon));
    }

    /**
     * 修改会员券发放记录
     */
    @PreAuthorize("@ss.hasPermi('mall:wechatMemberCoupon:edit')")
    @Log(title = "会员券发放记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WechatMemberCoupon wechatMemberCoupon) {
        return toAjax(wechatMemberCouponService.updateWechatMemberCoupon(wechatMemberCoupon));
    }

    /**
     * 删除会员券发放记录
     */
    @PreAuthorize("@ss.hasPermi('mall:wechatMemberCoupon:remove')")
    @Log(title = "会员券发放记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(wechatMemberCouponService.deleteWechatMemberCouponByIds(ids));
    }

    /**
     * 发放会员券
     */
    @PreAuthorize("@ss.hasPermi('mall:wechatMemberCoupon:add')")
    @Log(title = "发放会员券", businessType = BusinessType.INSERT)
    @PostMapping("/send")
    public AjaxResult sendCoupon(@RequestBody SendCouponRequest sendCouponRequest) {
        return toAjax(wechatMemberCouponService.sendCoupon(sendCouponRequest));
    }
}
