package org.diagbot.repository;

import org.diagbot.entity.relation.base.BaseRelation;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;

import java.util.List;
import java.util.Map;

public interface RelationRepository extends Neo4jRepository<BaseRelation, Long> {

    // get Relation by Nodes
    @Query("MATCH P=((s{name:{0}})-[*..1]-(e{name:{2}})) RETURN P")
    Iterable<Map<String, Object>> getRelationByNodes(String start_name, String start_type, String end_name, String end_type);

    // get Relation by EndNode
    @Query("MATCH P=((e{name:{0}})<-[*..1]-(s)) RETURN P")
    Iterable<Map<String, Object>> getOneLevelRelationByEndNode(String end_name, String end_type);

    // get Node by Relation
    @Query("MATCH (s{name:{0}})-[r]->(e) WHERE type(r)={2} RETURN s,e")
    Iterable<Map<String, Object>> getNodeByRelation(String start_name, String start_type, String relation);

    // 获取推荐项目
    @Query("MATCH (d:Disease)-[r:推荐]->(lp) where d.name in {0} RETURN DISTINCT d.name as name, labels(lp)[0] as type, lp.name as item")
    List<Map<String, Object>> getRecommendItem(List<String> DiseaseList);
}
