package com.yijia.coupon.controller;

import java.util.List;
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.yijia.common.annotation.Log;
import com.yijia.common.core.controller.BaseController;
import com.yijia.common.core.domain.AjaxResult;
import com.yijia.common.enums.BusinessType;
import com.yijia.coupon.domain.CouponInfo;
import com.yijia.coupon.service.ICouponInfoService;
import com.yijia.common.utils.poi.ExcelUtil;
import com.yijia.common.core.page.TableDataInfo;

/**
 * 优惠劵Controller
 * 
 * @author yijia
 * @date 2021-04-27
 */
@RestController
@RequestMapping("/coupon/info")
public class CouponInfoController extends BaseController
{
    @Autowired
    private ICouponInfoService couponInfoService;

    /**
     * 查询优惠劵列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CouponInfo couponInfo)
    {
        startPage();
        List<CouponInfo> list = couponInfoService.selectCouponInfoList(couponInfo);
        return getDataTable(list);
    }

    /**
     * 导出优惠劵列表
     */
    @Log(title = "优惠劵", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CouponInfo couponInfo)
    {
        List<CouponInfo> list = couponInfoService.selectCouponInfoList(couponInfo);
        ExcelUtil<CouponInfo> util = new ExcelUtil<CouponInfo>(CouponInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 获取优惠劵详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(couponInfoService.selectCouponInfoById(id));
    }

    /**
     * 新增优惠劵
     */
    @Log(title = "优惠劵", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CouponInfo couponInfo)
    {
        return toAjax(couponInfoService.insertCouponInfo(couponInfo));
    }

    /**
     * 修改优惠劵
     */
    @Log(title = "优惠劵", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CouponInfo couponInfo)
    {
        return toAjax(couponInfoService.updateCouponInfo(couponInfo));
    }

    /**
     * 删除优惠劵
     */
    @Log(title = "优惠劵", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(couponInfoService.deleteCouponInfoByIds(ids));
    }
}
