package com.ruoyi.web.bst;

import com.ruoyi.bst.refund.domain.RefundQuery;
import com.ruoyi.bst.refund.domain.RefundVO;
import com.ruoyi.bst.refund.service.RefundService;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 退款Controller
 *
 * @author ruoyi
 * @date 2025-03-28
 */
@RestController
@RequestMapping("/bst/refund")
public class RefundController extends BaseController
{
    @Autowired
    private RefundService refundService;

    /**
     * 查询退款列表
     */
    @PreAuthorize("@ss.hasPermi('bst:refund:list')")
    @GetMapping("/list")
    public TableDataInfo list(RefundQuery query)
    {
        startPage();
        startOrderBy();
        List<RefundVO> list = refundService.selectRefundList(query);
        return getDataTable(list);
    }

    /**
     * 导出退款列表
     */
    @PreAuthorize("@ss.hasPermi('bst:refund:export')")
    @Log(title = "退款", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RefundQuery query)
    {
        List<RefundVO> list = refundService.selectRefundList(query);
        ExcelUtil<RefundVO> util = new ExcelUtil<RefundVO>(RefundVO.class);
        util.exportExcel(response, list, "退款数据");
    }

    /**
     * 获取退款详细信息
     */
    @PreAuthorize("@ss.hasPermi('bst:refund:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(refundService.selectRefundById(id));
    }

}
