package com.jeesharp.business.modules.finance.payorder.mapper;

import com.jeesharp.business.modules.finance.payorder.entity.PayOrder;
import com.jeesharp.business.modules.finance.payorder.vo.PayOrderQueryVO;
import com.jeesharp.framework.mybatis.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

/**
 * 支付单表 Mapper；自定义 SQL 见同包 {@code xml/PayOrderMapper.xml}。
 *
 * @author jeesharp
 * @since 2026-05-08
 */
@Mapper
public interface PayOrderMapper extends BaseMapper<PayOrder, PayOrderQueryVO> {

    /**
     * 将同一业务单下未终态的支付单置为已关闭，便于用户多次点「去支付」生成新单号。
     */
    int closePendingByBiz(@Param("bizOrderId") String bizOrderId, @Param("bizScene") String bizScene);

    /**
     * 查询同一业务单下最近一条待预支付/已生成预支付的支付单（用于幂等复用）。
     */
    PayOrder findLatestPendingForBiz(@Param("bizOrderId") String bizOrderId, @Param("bizScene") String bizScene);

    PayOrder findLatestSuccessByBiz(@Param("bizOrderId") String bizOrderId, @Param("bizScene") String bizScene);

    PayOrder getByCombineOutTradeNo(@Param("combineOutTradeNo") String combineOutTradeNo);

    java.util.List<PayOrder> findPendingListByBiz(@Param("bizOrderId") String bizOrderId, @Param("bizScene") String bizScene);
}
