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

/**
 * 充值Controller
 * 
 * @author jin
 * @date 2024-12-01
 */
@RestController
@RequestMapping("/recovery/recharge")
public class WxRechargeController extends BaseController
{
    @Autowired
    private IWxRechargeService wxRechargeService;

    /**
     * 查询充值列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:recharge:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxRecharge wxRecharge)
    {
        startPage();
        List<WxRecharge> list = wxRechargeService.selectWxRechargeList(wxRecharge);
        return getDataTable(list);
    }

    /**
     * 导出充值列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:recharge:export')")
    @Log(title = "充值", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxRecharge wxRecharge)
    {
        List<WxRecharge> list = wxRechargeService.selectWxRechargeList(wxRecharge);
        ExcelUtil<WxRecharge> util = new ExcelUtil<WxRecharge>(WxRecharge.class);
        util.exportExcel(response, list, "充值数据");
    }

    /**
     * 获取充值详细信息
     */
    @PreAuthorize("@ss.hasPermi('recovery:recharge:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wxRechargeService.selectWxRechargeById(id));
    }

    /**
     * 新增充值
     */
    @PreAuthorize("@ss.hasPermi('recovery:recharge:add')")
    @Log(title = "充值", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxRecharge wxRecharge)
    {
        return toAjax(wxRechargeService.insertWxRecharge(wxRecharge));
    }

    /**
     * 修改充值
     */
    @PreAuthorize("@ss.hasPermi('recovery:recharge:edit')")
    @Log(title = "充值", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxRecharge wxRecharge)
    {
        return toAjax(wxRechargeService.updateWxRecharge(wxRecharge));
    }

    /**
     * 删除充值
     */
    @PreAuthorize("@ss.hasPermi('recovery:recharge:remove')")
    @Log(title = "充值", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wxRechargeService.deleteWxRechargeByIds(ids));
    }
}
