package org.diagbot.repository;

import org.diagbot.entity.node.Scale;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;

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

public interface ScaleRepository extends Neo4jRepository<Scale, Long> {
    List<Scale> findByNameContaining(String token);

    // 获取量表内容和评分标准
    @Query("MATCH (m:Scale)-[r1]->(n1)-[r2]->(n2)-[r3]->(n3) WHERE m.name= {0} " +
            "RETURN n1.name, n1.method, r1.score, n2.name, r2.score,n2.type, r2.p, " +
            "n3.name as n3name,r3.score as r3score, r3.p as r3p, n3.type as n3type " +
            "ORDER BY toInt(r2.p), n2.type union " +
            "MATCH (m:Scale)-[r1]->(n1)-[r2]->(n2) WHERE m.name= {0} " +
            "RETURN n1.name,n1.method, r1.score,n2.name,r2.score,n2.type,r2.p, " +
            "null as n3name, null as r3score, null as r3p, null as n3type ORDER BY toInt(r2.p),n2.type")
    List<Map<String, Object>> getScale(String tblname);

}
