package com.ruoyi.frequency.rechargeorder.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.rechargeorder.entity.RechargeOrder;
import com.ruoyi.frequency.rechargeorder.model.result.RechargeOrderCount;
import com.ruoyi.frequency.rechargeorder.service.RechargeOrderService;
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/rechargeorder")
public class RechargeOrderController extends BaseController
{
    @Autowired
    private RechargeOrderService rechargeOrderService;

    /**
     * 查询充值余额订单列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:rechargeorder:list')")
    @PostMapping("/list")
    public TableDataInfo<RechargeOrder> list(@RequestBody RechargeOrder rechargeOrder)
    {
        startPage();
        List<RechargeOrder> list = rechargeOrderService.selectRechargeOrderList(rechargeOrder);
        return getDataTable(list);
    }

    /**
     * 统计
     */
    @PostMapping("/statistics")
    public AjaxResult statistics(@RequestBody RechargeOrder rechargeOrder)
    {
        RechargeOrderCount count = rechargeOrderService.statistics(rechargeOrder);
        return AjaxResult.success(count);
    }

    /**
     * 导出充值余额订单列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:rechargeorder:export')")
    @Log(title = "充值余额订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RechargeOrder rechargeOrder)
    {
        List<RechargeOrder> list = rechargeOrderService.selectRechargeOrderList(rechargeOrder);
        ExcelUtil<RechargeOrder> util = new ExcelUtil<RechargeOrder>(RechargeOrder.class);
        return util.exportExcel(list, "充值余额订单数据");
    }

    /**
     * 获取充值余额订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:rechargeorder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<RechargeOrder> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(rechargeOrderService.selectRechargeOrderById(id));
    }

    /**
     * 新增充值余额订单
     */
    @PreAuthorize("@ss.hasPermi('frequency:rechargeorder:add')")
    @Log(title = "充值余额订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RechargeOrder rechargeOrder)
    {
        return toAjax(rechargeOrderService.insertRechargeOrder(rechargeOrder));
    }

    /**
     * 修改充值余额订单
     */
    @PreAuthorize("@ss.hasPermi('frequency:rechargeorder:edit')")
    @Log(title = "充值余额订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RechargeOrder rechargeOrder)
    {
        return toAjax(rechargeOrderService.updateRechargeOrder(rechargeOrder));
    }

    /**
     * 删除充值余额订单
     */
    @PreAuthorize("@ss.hasPermi('frequency:rechargeorder:remove')")
    @Log(title = "充值余额订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rechargeOrderService.deleteRechargeOrderByIds(ids));
    }
}
