package com.ruoyi.model.controller;

import java.io.IOException;
import java.util.List;
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.model.domain.Wallet;
import com.ruoyi.model.service.IWalletService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 钱包Controller
 * 
 * @author ruoyi
 * @date 2025-03-05
 */
@RestController
@RequestMapping("/model/Wallet")
public class WalletController extends BaseController
{
    @Autowired
    private IWalletService walletService;

    /**
     * 查询钱包列表
     */
    @PreAuthorize("@ss.hasPermi('model:Wallet:list')")
    @GetMapping("/list")
    public TableDataInfo list(Wallet wallet)
    {
        startPage();
        List<Wallet> list = walletService.selectWalletList(wallet);
        return getDataTable(list);
    }

    /**
     * 导出钱包列表
     */
    @PreAuthorize("@ss.hasPermi('model:Wallet:export')")
    @Log(title = "钱包", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Wallet wallet) throws IOException {
        List<Wallet> list = walletService.selectWalletList(wallet);
        ExcelUtil<Wallet> util = new ExcelUtil<Wallet>(Wallet.class);
        util.exportExcel(response, list, "钱包数据");
    }

    /**
     * 获取钱包详细信息
     */
    @PreAuthorize("@ss.hasPermi('model:Wallet:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(walletService.selectWalletById(id));
    }

    /**
     * 新增钱包
     */
    @PreAuthorize("@ss.hasPermi('model:Wallet:add')")
    @Log(title = "钱包", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Wallet wallet)
    {
        return toAjax(walletService.insertWallet(wallet));
    }

    /**
     * 修改钱包
     */
    @PreAuthorize("@ss.hasPermi('model:Wallet:edit')")
    @Log(title = "钱包", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Wallet wallet)
    {
        return toAjax(walletService.updateWallet(wallet));
    }

    /**
     * 删除钱包
     */
    @PreAuthorize("@ss.hasPermi('model:Wallet:remove')")
    @Log(title = "钱包", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(walletService.deleteWalletByIds(ids));
    }
}
