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

/**
 * 微信中奖记录Controller
 * 
 * @author jin
 * @date 2024-12-17
 */
@RestController
@RequestMapping("/recovery/user/lottery")
public class WxUserLotteryController extends BaseController
{
    @Autowired
    private IWxUserLotteryService wxUserLotteryService;

    /**
     * 查询微信中奖记录列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:lottery:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxUserLottery wxUserLottery)
    {
        startPage();
        List<WxUserLottery> list = wxUserLotteryService.selectWxUserLotteryList(wxUserLottery);
        return getDataTable(list);
    }

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

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

    /**
     * 新增微信中奖记录
     */
    @PreAuthorize("@ss.hasPermi('recovery:lottery:add')")
    @Log(title = "微信中奖记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxUserLottery wxUserLottery)
    {
        return toAjax(wxUserLotteryService.insertWxUserLottery(wxUserLottery));
    }

    /**
     * 修改微信中奖记录
     */
    @PreAuthorize("@ss.hasPermi('recovery:lottery:edit')")
    @Log(title = "微信中奖记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxUserLottery wxUserLottery)
    {
        return toAjax(wxUserLotteryService.updateWxUserLottery(wxUserLottery));
    }

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