package com.crm.pay.dao.repository;

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

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

/**
 * @author: houn
 */
@Repository
public interface SysRemitChannelRepository extends BaseRepository<SysRemitChannelTable> {

    /**
     * 根据是否启用获取所有通道信息
     *
     * @param valid
     * @return
     */
    List<SysRemitChannelTable> getAllByValidOrderBySubIndex(Integer valid);

    List<SysRemitChannelTable> getAllByValidAndCodeInOrderBySubIndex(Integer valid, List<String> codes);

    /**
     * 根据code获取通道信息
     *
     * @param code
     * @param valid
     * @return
     */
    SysRemitChannelTable getFirstByCodeAndValid(String code, Integer valid);

    SysRemitChannelTable getFirstByCode(String code);

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

    SysRemitChannelTable getFirstById(Long id);

    boolean existsByCode(String code);

    List<SysRemitChannelTable> getAllByIdNotNull();

    /**
     * 根据code和快速到账获取通道信息
     *
     * @param code
     * @param valid
     * @return
     */
    SysRemitChannelTable getFirstByCodeAndValidAndFastChannel(String code, Integer valid, Integer fastChannel);

    List<SysRemitChannelTable> getAllByRemitApi(Integer remitApi);

}
