package com.ruoyi.mall.controller;

import java.util.List;
import javax.annotation.Resource;
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.mall.domain.UserCoupon;
import com.ruoyi.mall.service.IUserCouponService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 优惠卷发放Controller
 *
 * @author ruoyi
 * @date 2023-11-07
 */
@RestController
@RequestMapping("/mall/userCoupon")
public class UserCouponController extends BaseController
{
    @Resource
    private IUserCouponService userCouponService;

    /**
     * 查询优惠卷发放列表
     */
    @PreAuthorize("@ss.hasPermi('mall:userCoupon:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserCoupon userCoupon)
    {
        startPage();
        List<UserCoupon> list = userCouponService.selectUserCouponList(userCoupon);
        return getDataTable(list);
    }

    /**
     * 导出优惠卷发放列表
     */
    @PreAuthorize("@ss.hasPermi('mall:userCoupon:export')")
    @Log(title = "优惠卷发放", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserCoupon userCoupon)
    {
        List<UserCoupon> list = userCouponService.selectUserCouponList(userCoupon);
        ExcelUtil<UserCoupon> util = new ExcelUtil<UserCoupon>(UserCoupon.class);
        util.exportExcel(response, list, "优惠卷发放数据");
    }

    /**
     * 获取优惠卷发放详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:userCoupon:query')")
    @GetMapping(value = "/{cuId}")
    public AjaxResult getInfo(@PathVariable("cuId") Long cuId)
    {
        return AjaxResult.success(userCouponService.selectUserCouponByCuId(cuId));
    }

    /**
     * 新增优惠卷发放
     */
    @PreAuthorize("@ss.hasPermi('mall:userCoupon:add')")
    @Log(title = "优惠卷发放", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserCoupon userCoupon)
    {
        return toAjax(userCouponService.insertUserCoupon(userCoupon));
    }

    /**
     * 修改优惠卷发放
     */
    @PreAuthorize("@ss.hasPermi('mall:userCoupon:edit')")
    @Log(title = "优惠卷发放", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserCoupon userCoupon)
    {
        return toAjax(userCouponService.updateUserCoupon(userCoupon));
    }

    /**
     * 删除优惠卷发放
     */
    @PreAuthorize("@ss.hasPermi('mall:userCoupon:remove')")
    @Log(title = "优惠卷发放", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cuIds}")
    public AjaxResult remove(@PathVariable Long[] cuIds)
    {
        return toAjax(userCouponService.deleteUserCouponByCuIds(cuIds));
    }
}
