package com.ruoyi.frequency.mallrefund.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.mallrefund.entity.MallRefund;
import com.ruoyi.frequency.mallrefund.service.MallRefundService;
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 2024-01-25
 */
@RestController
@RequestMapping("/frequency/mallrefund")
public class MallRefundController extends BaseController
{
    @Autowired
    private MallRefundService mallRefundService;

    /**
     * 查询订单退款列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallrefund:list')")
    @PostMapping("/list")
    public TableDataInfo<MallRefund> list(@RequestBody MallRefund mallRefund)
    {
        startPage();
        List<MallRefund> list = mallRefundService.selectMallRefundList(mallRefund);
        return getDataTable(list);
    }

    /**
     * 导出订单退款列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallrefund:export')")
    @Log(title = "订单退款", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallRefund mallRefund)
    {
        List<MallRefund> list = mallRefundService.selectMallRefundList(mallRefund);
        ExcelUtil<MallRefund> util = new ExcelUtil<MallRefund>(MallRefund.class);
        return util.exportExcel(list, "订单退款数据");
    }

    /**
     * 获取订单退款详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallrefund:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<MallRefund> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallRefundService.selectMallRefundById(id));
    }

    /**
     * 新增订单退款
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallrefund:add')")
    @Log(title = "订单退款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallRefund mallRefund)
    {
        return toAjax(mallRefundService.insertMallRefund(mallRefund));
    }

    /**
     * 修改订单退款
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallrefund:edit')")
    @Log(title = "订单退款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallRefund mallRefund)
    {
        return toAjax(mallRefundService.updateMallRefund(mallRefund));
    }

    /**
     * 删除订单退款
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallrefund:remove')")
    @Log(title = "订单退款", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids,@PathVariable("delFlag") Integer delFlag)
    {
        return toAjax(mallRefundService.deleteMallRefundByIds(ids,delFlag));
    }
}
