package common.repository;

import common.model.ContractRelation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;


/**
 * 合同 关联信息
 */
public interface ContractRelationRepository extends JpaRepository<ContractRelation, Long> {

    @Query(value = "select  relation_id id from contract_relation where main_contract  = ?1 union all select  main_contract id from contract_relation where  relation_id  = ?1",nativeQuery = true)
    List<Long> findRelationIds(String contractId);

    @Query(value = "select * from contract_relation where main_contract = ?1 and relation_id = ?2 and platform = ?3",nativeQuery = true)
    ContractRelation findByRelationData(Long mainContract, Long relationId, String platform);

    @Query(value = "select  * from contract_relation where main_contract  = ?1 ",nativeQuery = true)
    List<ContractRelation> findRelationIdsMain(String contractId);
}
