package com.ruoyi.frequency.rechargerecord.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.rechargerecord.entity.RechargeRecord;
import com.ruoyi.frequency.rechargerecord.service.RechargeRecordService;
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/rechargerecord")
public class RechargeRecordController extends BaseController
{
    @Autowired
    private RechargeRecordService rechargeRecordService;

    /**
     * 查询充值记录列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:rechargerecord:list')")
    @PostMapping("/list")
    public TableDataInfo<RechargeRecord> list(@RequestBody RechargeRecord rechargeRecord)
    {
        startPage();
        List<RechargeRecord> list = rechargeRecordService.selectRechargeRecordList(rechargeRecord);
        return getDataTable(list);
    }

    /**
     * 导出充值记录列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:rechargerecord:export')")
    @Log(title = "充值记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RechargeRecord rechargeRecord)
    {
        List<RechargeRecord> list = rechargeRecordService.selectRechargeRecordList(rechargeRecord);
        ExcelUtil<RechargeRecord> util = new ExcelUtil<RechargeRecord>(RechargeRecord.class);
        return util.exportExcel(list, "充值记录数据");
    }

    /**
     * 获取充值记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:rechargerecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<RechargeRecord> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(rechargeRecordService.selectRechargeRecordById(id));
    }

    /**
     * 新增充值记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:rechargerecord:add')")
    @Log(title = "充值记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RechargeRecord rechargeRecord)
    {
        return toAjax(rechargeRecordService.insertRechargeRecord(rechargeRecord));
    }

    /**
     * 修改充值记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:rechargerecord:edit')")
    @Log(title = "充值记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RechargeRecord rechargeRecord)
    {
        return toAjax(rechargeRecordService.updateRechargeRecord(rechargeRecord));
    }

    /**
     * 删除充值记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:rechargerecord:remove')")
    @Log(title = "充值记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rechargeRecordService.deleteRechargeRecordByIds(ids));
    }
}
