package com.dcsoft.system.consume.controller;

import com.dcsoft.common.core.utils.poi.ExcelUtil;
import com.dcsoft.common.core.web.controller.BaseController;
import com.dcsoft.common.core.web.domain.AjaxResult;
import com.dcsoft.common.core.web.page.TableDataInfo;
import com.dcsoft.common.log.annotation.Log;
import com.dcsoft.common.log.enums.BusinessType;
import com.dcsoft.common.security.annotation.RequiresPermissions;
import com.dcsoft.system.consume.domain.ConsumeRechargeRecord;
import com.dcsoft.system.consume.service.IConsumeRechargeRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 充值记录Controller
 *
 * @author dcsoft
 * @date 2023-09-12
 */
@RestController
@RequestMapping("/rechargeRecord")
public class ConsumeRechargeRecordController extends BaseController
{
    @Autowired
    private IConsumeRechargeRecordService consumeRechargeRecordService;

    /**
     * 查询充值记录列表
     */
    @RequiresPermissions("consume:rechargeRecord:list")
    @GetMapping("/list")
    public TableDataInfo list(ConsumeRechargeRecord consumeRechargeRecord)
    {
        startPage();
        List<ConsumeRechargeRecord> list = consumeRechargeRecordService.selectConsumeRechargeRecordList(consumeRechargeRecord);
        return getDataTable(list);
    }

    /**
     * 导出充值记录列表
     */
    @RequiresPermissions("consume:rechargeRecord:export")
    @Log(title = "充值记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ConsumeRechargeRecord consumeRechargeRecord)
    {
        List<ConsumeRechargeRecord> list = consumeRechargeRecordService.selectConsumeRechargeRecordList(consumeRechargeRecord);
        ExcelUtil<ConsumeRechargeRecord> util = new ExcelUtil<ConsumeRechargeRecord>(ConsumeRechargeRecord.class);
        util.exportExcel(response, list, "充值记录数据");
    }

    /**
     * 获取充值记录详细信息
     */
    @RequiresPermissions("consume:rechargeRecord:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(consumeRechargeRecordService.selectConsumeRechargeRecordById(id));
    }

    /**
     * 新增充值记录
     */
    @RequiresPermissions("consume:rechargeRecord:add")
    @Log(title = "充值记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConsumeRechargeRecord consumeRechargeRecord)
    {
        return toAjax(consumeRechargeRecordService.insertConsumeRechargeRecord(consumeRechargeRecord));
    }

    /**
     * 修改充值记录
     */
    @RequiresPermissions("consume:rechargeRecord:edit")
    @Log(title = "充值记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConsumeRechargeRecord consumeRechargeRecord)
    {
        return toAjax(consumeRechargeRecordService.updateConsumeRechargeRecord(consumeRechargeRecord));
    }

    /**
     * 删除充值记录
     */
    @RequiresPermissions("consume:rechargeRecord:remove")
    @Log(title = "充值记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(consumeRechargeRecordService.deleteConsumeRechargeRecordByIds(ids));
    }
}
