package com.ruoyi.web.controller.ss;

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

import com.ruoyi.ss.refund.domain.RefundQuery;
import com.ruoyi.ss.refund.domain.RefundVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ss.refund.domain.Refund;
import com.ruoyi.ss.refund.service.RefundService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 退款订单Controller
 *
 * @author ruoyi
 * @date 2024-07-09
 */
@RestController
@RequestMapping("/ss/refund")
public class RefundController extends BaseController
{
    @Autowired
    private RefundService refundService;

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

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

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

    @PreAuthorize("@ss.hasPermi('ss:refund:refresh')")
    @PutMapping(value = "/refresh/{refundId}")
    public AjaxResult refreshResult(@PathVariable("refundId") Long refundId)
    {
        return success(refundService.refreshResult(refundId));
    }
}
