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.WxLottery;
import com.ruoyi.framework.recovery.service.IWxLotteryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 微信抽奖Controller
 * 
 * @author jin
 * @date 2024-12-17
 */
@RestController
@RequestMapping("/recovery/lottery")
public class WxLotteryController extends BaseController
{
    @Autowired
    private IWxLotteryService wxLotteryService;

    /**
     * 查询微信抽奖列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:lottery:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxLottery wxLottery)
    {
        startPage();
        List<WxLottery> list = wxLotteryService.selectWxLotteryList(wxLottery);
        return getDataTable(list);
    }

    /**
     * 导出微信抽奖列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:lottery:export')")
    @Log(title = "微信抽奖", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxLottery wxLottery)
    {
        List<WxLottery> list = wxLotteryService.selectWxLotteryList(wxLottery);
        ExcelUtil<WxLottery> util = new ExcelUtil<WxLottery>(WxLottery.class);
        util.exportExcel(response, list, "微信抽奖数据");
    }

    /**
     * 获取微信抽奖详细信息
     */
    @PreAuthorize("@ss.hasPermi('recovery:lottery:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wxLotteryService.selectWxLotteryById(id));
    }

    /**
     * 新增微信抽奖
     */
    @PreAuthorize("@ss.hasPermi('recovery:lottery:add')")
    @Log(title = "微信抽奖", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxLottery wxLottery)
    {
        return toAjax(wxLotteryService.insertWxLottery(wxLottery));
    }

    /**
     * 修改微信抽奖
     */
    @PreAuthorize("@ss.hasPermi('recovery:lottery:edit')")
    @Log(title = "微信抽奖", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxLottery wxLottery)
    {
        return toAjax(wxLotteryService.updateWxLottery(wxLottery));
    }

    /**
     * 删除微信抽奖
     */
    @PreAuthorize("@ss.hasPermi('recovery:lottery:remove')")
    @Log(title = "微信抽奖", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wxLotteryService.deleteWxLotteryByIds(ids));
    }
}
