package com.ruoyi.frequency.withdrawalrecord.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.withdrawalrecord.entity.WithdrawalRecord;
import com.ruoyi.frequency.withdrawalrecord.model.result.WithdrawalRecordCount;
import com.ruoyi.frequency.withdrawalrecord.service.WithdrawalRecordService;
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-07-20
 */
@RestController
@RequestMapping("/frequency/withdrawalrecord")
public class WithdrawalRecordController extends BaseController
{
    @Autowired
    private WithdrawalRecordService withdrawalRecordService;

    /**
     * 查询提现记录列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:withdrawalrecord:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody WithdrawalRecord withdrawalRecord)
    {
        startPage();
        List<WithdrawalRecord> list = withdrawalRecordService.selectWithdrawalRecordList(withdrawalRecord);
        return getDataTable(list);
    }

    /**
     * 统计
     */
    @PostMapping("/statistics")
    public AjaxResult statistics(@RequestBody WithdrawalRecord withdrawalRecord)
    {
        WithdrawalRecordCount count = withdrawalRecordService.statistics(withdrawalRecord);
        return AjaxResult.success(count);
    }


    /**
     * 导出提现记录列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:withdrawalrecord:export')")
    @Log(title = "提现记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WithdrawalRecord withdrawalRecord)
    {
        List<WithdrawalRecord> list = withdrawalRecordService.selectWithdrawalRecordList(withdrawalRecord);
        ExcelUtil<WithdrawalRecord> util = new ExcelUtil<WithdrawalRecord>(WithdrawalRecord.class);
        return util.exportExcel(list, "提现记录数据");
    }

    /**
     * 获取提现记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:withdrawalrecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(withdrawalRecordService.selectWithdrawalRecordById(id));
    }

    /**
     * 新增提现记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:withdrawalrecord:add')")
    @Log(title = "提现记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WithdrawalRecord withdrawalRecord)
    {
        return toAjax(withdrawalRecordService.insertWithdrawalRecord(withdrawalRecord));
    }

    /**
     * 修改提现记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:withdrawalrecord:edit')")
    @Log(title = "提现记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WithdrawalRecord withdrawalRecord)
    {
        return toAjax(withdrawalRecordService.updateWithdrawalRecord(withdrawalRecord));
    }

    /**
     * 删除提现记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:withdrawalrecord:remove')")
    @Log(title = "提现记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(withdrawalRecordService.deleteWithdrawalRecordByIds(ids));
    }


    /**
     * 提现审核
     */
    @PreAuthorize("@ss.hasPermi('frequency:withdrawalrecord:process')")
    @Log(title = "提现记录", businessType = BusinessType.UPDATE)
    @PostMapping("/process")
    public AjaxResult process(@RequestBody WithdrawalRecord withdrawalRecord)
    {
        return withdrawalRecordService.process(withdrawalRecord);
    }
}
