package com.fs.live.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.ParseUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.live.domain.LiveOrderPayment;
import com.fs.live.service.ILiveOrderPaymentService;
import com.fs.live.vo.LiveOrderPaymentVo;
import com.fs.store.vo.FsStorePaymentVO;
import com.github.pagehelper.PageHelper;
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 fs
 * @date 2025-08-07
 */
@RestController
@RequestMapping("/live/order/payment")
public class LiveOrderPaymentController extends BaseController
{
    @Autowired
    private ILiveOrderPaymentService liveOrderPaymentService;

    /**
     * 查询支付明细列表
     */
    @PreAuthorize("@ss.hasPermi('live:order:payment:query')")
    @GetMapping("/list")
    public TableDataInfo list(LiveOrderPayment liveOrderPayment)
    {
        startPage();
        List<LiveOrderPayment> list = liveOrderPaymentService.selectLiveOrderPaymentList(liveOrderPayment);
        return getDataTable(list);
    }
    /**
     * 查询支付明细列表
     */
    @PreAuthorize("@ss.hasPermi('live:order:payment:query')")
    @GetMapping
    public TableDataInfo listNew(LiveOrderPaymentVo liveOrderPayment)
    {
        startPage();
        List<LiveOrderPaymentVo> list = liveOrderPaymentService.selectLiveOrderPaymentVoList(liveOrderPayment);
        for (LiveOrderPaymentVo vo : list){
            vo.setUserPhone(ParseUtils.parsePhone(vo.getUserPhone()));
        }
        return getDataTable(list);
    }

    /**
     * 导出支付明细列表
     */
    @PreAuthorize("@ss.hasPermi('live:order:payment:export')")
    @Log(title = "支付明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LiveOrderPaymentVo liveOrderPayment)
    {
        PageHelper.startPage(1, 10000, "");
        List<LiveOrderPaymentVo> list = liveOrderPaymentService.selectLiveOrderPaymentVoList(liveOrderPayment);
        for (LiveOrderPaymentVo vo : list){
            vo.setUserPhone(vo.getUserPhone() == null ? "" : vo.getUserPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
        }
        ExcelUtil<LiveOrderPaymentVo> util = new ExcelUtil<LiveOrderPaymentVo>(LiveOrderPaymentVo.class);
        return util.exportExcel(list, "直播订单支付记录");
    }

    /**
     * 获取支付明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('live:order:payment:query')")
    @GetMapping(value = "/{paymentId}")
    public AjaxResult getInfo(@PathVariable("paymentId") Long paymentId)
    {
        return AjaxResult.success(liveOrderPaymentService.selectLiveOrderPaymentByPaymentIdNew(paymentId));
    }

    /**
     * 新增支付明细
     */
    @PreAuthorize("@ss.hasPermi('live:order:payment:edit')")
    @Log(title = "支付明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LiveOrderPayment liveOrderPayment)
    {
        return toAjax(liveOrderPaymentService.insertLiveOrderPayment(liveOrderPayment));
    }

    /**
     * 修改支付明细
     */
    @PreAuthorize("@ss.hasPermi('live:order:payment:edit')")
    @Log(title = "支付明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LiveOrderPayment liveOrderPayment)
    {
        return toAjax(liveOrderPaymentService.updateLiveOrderPayment(liveOrderPayment));
    }

    /**
     * 删除支付明细
     */
    @PreAuthorize("@ss.hasPermi('live:order:payment:remove')")
    @Log(title = "支付明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{paymentIds}")
    public AjaxResult remove(@PathVariable Long[] paymentIds)
    {
        return toAjax(liveOrderPaymentService.deleteLiveOrderPaymentByPaymentIds(paymentIds));
    }
}
