package com.crm.pay.dao.repository;

import com.crm.rely.backend.dao.repository.BaseRepository;
import com.crm.rely.backend.model.pojo.table.FinanceDepositTable;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.stereotype.Repository;

import javax.persistence.LockModeType;
import java.util.Date;
import java.util.List;

/**
 * @author: houn
 */
@Repository
public interface FinanceDepositRepository extends BaseRepository<FinanceDepositTable> {

    /**
     * 根据入金流水号获取入金信息(加锁-行级锁)
     *
     * @param serial
     * @return
     */
    @Lock(LockModeType.PESSIMISTIC_WRITE)
    FinanceDepositTable findFirstBySerial(String serial);

    FinanceDepositTable getFirstBySerial(String serial);

    List<FinanceDepositTable> getAllByCustomId(Long customId);

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    FinanceDepositTable findFirstById(Long id);

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    List<FinanceDepositTable> findAllByIdIn(List<Long> ids);

    FinanceDepositTable getFirstByChannelSerial(String ticket);

    boolean existsByCustomIdAndPayTypeAndAddTimeGreaterThanEqual(Long customId, String payType, Date date);

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    FinanceDepositTable findFirstByChannelSerial(String ticket);

}
