package com.ruoyi.frequency.rechargecoin.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.frequency.rechargecoin.entity.RechargeCoin;
import com.ruoyi.frequency.rechargecoin.service.RechargeCoinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 充值包Controller
 * 
 * @author liwenlong
 * @date 2023-10-25
 */
@RestController
@RequestMapping("/frequency/rechargecoin")
public class RechargeCoinController extends BaseController
{
    @Autowired
    private RechargeCoinService rechargeCoinService;

    /**
     * 查询充值包列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:rechargecoin:list')")
    @PostMapping("/list")
    public TableDataInfo<RechargeCoin> list(@RequestBody RechargeCoin rechargeCoin)
    {
        startPage();
        List<RechargeCoin> list = rechargeCoinService.selectRechargeCoinList(rechargeCoin);
        return getDataTable(list);
    }

    /**
     * 导出充值包列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:rechargecoin:export')")
    @Log(title = "充值包", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RechargeCoin rechargeCoin)
    {
        List<RechargeCoin> list = rechargeCoinService.selectRechargeCoinList(rechargeCoin);
        ExcelUtil<RechargeCoin> util = new ExcelUtil<RechargeCoin>(RechargeCoin.class);
        return util.exportExcel(list, "充值包数据");
    }

    /**
     * 获取充值包详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:rechargecoin:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<RechargeCoin> getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(rechargeCoinService.selectRechargeCoinById(id));
    }

    /**
     * 新增充值包
     */
    @PreAuthorize("@ss.hasPermi('frequency:rechargecoin:add')")
    @Log(title = "充值包", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RechargeCoin rechargeCoin)
    {
        return toAjax(rechargeCoinService.insertRechargeCoin(rechargeCoin));
    }

    /**
     * 修改充值包
     */
    @PreAuthorize("@ss.hasPermi('frequency:rechargecoin:edit')")
    @Log(title = "充值包", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RechargeCoin rechargeCoin)
    {
        return toAjax(rechargeCoinService.updateRechargeCoin(rechargeCoin));
    }

    /**
     * 删除充值包
     */
    @PreAuthorize("@ss.hasPermi('frequency:rechargecoin:remove')")
    @Log(title = "充值包", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable("ids") String[] ids,@PathVariable("delFlag") Integer delFlag)
    {
        return toAjax(rechargeCoinService.deleteRechargeCoinByIds(ids,delFlag));
    }
}
