package com.ruoyi.web.controller.ss;

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

import com.ruoyi.ss.payBill.domain.dto.PayBillRefundDTO;
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.payBill.domain.PayBill;
import com.ruoyi.ss.payBill.domain.PayBillVO;
import com.ruoyi.ss.payBill.domain.PayBillQuery;
import com.ruoyi.ss.payBill.service.PayBillService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 支付订单Controller
 *
 * @author ruoyi
 * @date 2024-07-24
 */
@RestController
@RequestMapping("/ss/payBill")
public class PayBillController extends BaseController
{
    @Autowired
    private PayBillService payBillService;

    /**
     * 查询支付订单列表
     */
    @PreAuthorize("@ss.hasPermi('ss:payBill:list')")
    @GetMapping("/list")
    public TableDataInfo list(PayBillQuery query)
    {
        startPage();
        startOrderBy();
        List<PayBillVO> list = payBillService.selectPayBillList(query);
        return getDataTable(list);
    }

    /**
     * 导出支付订单列表
     */
    @PreAuthorize("@ss.hasPermi('ss:payBill:export')")
    @Log(title = "支付订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PayBillQuery query)
    {
        List<PayBillVO> list = payBillService.selectPayBillList(query);
        ExcelUtil<PayBillVO> util = new ExcelUtil<PayBillVO>(PayBillVO.class);
        util.exportExcel(response, list, "支付订单数据");
    }

    /**
     * 获取支付订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('ss:payBill:query')")
    @GetMapping(value = "/{payId}")
    public AjaxResult getInfo(@PathVariable("payId") Long payId)
    {
        return success(payBillService.selectPayBillByPayId(payId));
    }

    /**
     * 新增支付订单
     */
//    @PreAuthorize("@ss.hasPermi('ss:payBill:add')")
//    @Log(title = "支付订单", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody PayBill payBill)
//    {
//        return toAjax(payBillService.insertPayBill(payBill));
//    }

    /**
     * 修改支付订单
     */
//    @PreAuthorize("@ss.hasPermi('ss:payBill:edit')")
//    @Log(title = "支付订单", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody PayBill payBill)
//    {
//        return toAjax(payBillService.updatePayBill(payBill));
//    }

    /**
     * 删除支付订单
     */
//    @PreAuthorize("@ss.hasPermi('ss:payBill:remove')")
//    @Log(title = "支付订单", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{payIds}")
//    public AjaxResult remove(@PathVariable Long[] payIds)
//    {
//        return toAjax(payBillService.deletePayBillByPayIds(payIds));
//    }

    /**
     * 退款
     */
    @PreAuthorize("@ss.hasPermi('ss:payBill:refund')")
    @Log(title = "支付订单退款", businessType = BusinessType.OTHER)
	@PutMapping("/refund")
    public AjaxResult refund(@RequestBody PayBillRefundDTO dto)
    {
        return toAjax(payBillService.refund(dto));
    }


}
