@ -436,6 +436,75 @@ public class knowServiceImpl implements KnowService {
return ResultUtils . success ( knowPathVOList ) ;
return ResultUtils . success ( knowPathVOList ) ;
}
}
@Override
public BaseResponse < BaseKnowReturn > knowLearnPathGraph ( String corseId ) {
//查询第一个知识点-最后一个知识点
List < Long > knowIds = new ArrayList < > ( ) ;
List < Chapter > chapterList = chapterMapper . selectChapterPIDByCourseId ( corseId ) ;
for ( int i = 0 ; i < chapterList . size ( ) ; i + + ) {
List < Chapter > chapterList1 = chapterMapper . selectChapterChildrenOrderByNum ( chapterList . get ( i ) . getId ( ) ) ;
for ( int j = 0 ; j < chapterList1 . size ( ) ; j + + ) {
QueryWrapper queryWrapper = new QueryWrapper < Knowtmp > ( ) ;
queryWrapper . eq ( "chapterid" , chapterList1 . get ( j ) . getId ( ) ) ;
List < Knowtmp > knowtmp = knowtmpMapper . selectList ( queryWrapper ) ;
for ( int k = 0 ; k < knowtmp . size ( ) ; k + + ) {
Knowtmp knowtmp1 = knowtmp . get ( k ) ;
knowIds . add ( knowtmp1 . getId ( ) ) ;
}
}
}
// 生成学习路径
String str = "MATCH p = (:Know{knowId:" + knowIds . get ( 0 ) + "})-[*]->(:Know{knowId:" + knowIds . get ( knowIds . size ( ) - 1 ) + "}) WITH p, REDUCE(totalWeight = 0.0, r IN relationships(p) | totalWeight + r.weight) AS pathWeight " +
"RETURN nodes(p) as `p`,relationships(p) as `r`,pathWeight ORDER BY pathWeight desc;" ;
Collection < Map < String , Object > > result = neo4jClient . query ( str ) . fetch ( ) . all ( ) ;
Iterator < Map < String , Object > > iterator = result . iterator ( ) ;
Set < KnowVO > knowList = new HashSet < > ( ) ;
Set < Links > linksList = new HashSet < > ( ) ;
KnowVO knowVO ;
List node2 = new ArrayList < > ( ) ;
Links links ;
int p = 0 ;
while ( iterator . hasNext ( ) ) {
Map < String , Object > element = iterator . next ( ) ;
List list1 = ( List ) element . get ( "p" ) ;
for ( int i = 0 ; i < list1 . size ( ) ; i + + ) {
Node node1 = ( Node ) list1 . get ( i ) ;
Long id = node1 . id ( ) ;
String name = node1 . get ( "name" ) . asString ( ) ;
knowVO = new KnowVO ( ) ;
knowVO . setId ( id ) ;
knowVO . setLabel ( name ) ;
knowVO . setColor ( colorList [ 0 ] ) ;
knowList . add ( knowVO ) ;
}
List list2 = ( List ) element . get ( "r" ) ;
if ( ! list2 . isEmpty ( ) ) {
for ( int i = 0 ; i < list2 . size ( ) ; i + + ) {
InternalRelationship e = ( InternalRelationship ) list2 . get ( i ) ;
links = new Links ( ) ;
links . setId ( e . id ( ) ) ;
links . setSource ( e . startNodeId ( ) ) ;
links . setTarget ( e . endNodeId ( ) ) ;
if ( "contain" . equals ( e . type ( ) ) ) {
links . setLabel ( "包含" ) ;
} else if ( "order" . equals ( e . type ( ) ) ) {
links . setLabel ( "顺序" ) ;
} else if ( "dependent" . equals ( e . type ( ) ) ) {
links . setLabel ( "依赖" ) ;
}
linksList . add ( links ) ;
}
}
Double pathWeight = ( Double ) element . get ( "pathWeight" ) ;
}
BaseKnowReturn baseKnowReturn = new BaseKnowReturn ( knowList , linksList ) ;
return ResultUtils . success ( baseKnowReturn ) ;
}
@Override
@Override
public BaseResponse < String > updateLinks ( List < LinksVO > linksList ) {
public BaseResponse < String > updateLinks ( List < LinksVO > linksList ) {
for ( int i = 0 ; i < linksList . size ( ) ; i + + ) {
for ( int i = 0 ; i < linksList . size ( ) ; i + + ) {
@ -763,7 +832,8 @@ public class knowServiceImpl implements KnowService {
}
}
@Override
@Override
public BaseResponse < BaseKnowReturn > getRelsNodesByCourseId ( String courseId , List < String > types ) {
public BaseResponse < BaseKnowReturn > getRelsNodesByCourseId ( String courseId , Integer level , List < String > types ) {
String str = "match(n:Know)-[r:" ;
String str = "match(n:Know)-[r:" ;
for ( int i = 0 ; i < types . size ( ) ; i + + ) {
for ( int i = 0 ; i < types . size ( ) ; i + + ) {
if ( i = = types . size ( ) - 1 ) {
if ( i = = types . size ( ) - 1 ) {
@ -773,7 +843,11 @@ public class knowServiceImpl implements KnowService {
}
}
}
}
str = str + "]->(p:Know) where n.courseId = '" + courseId + "' return n as `n`,r as `r`,p as `p`,length(r) as `d`" ;
if ( level = = null | | level < = 0 ) {
str = str + "]->(p:Know) where n.courseId = '" + courseId + "' return n as `n`,r as `r`,p as `p`,length(r) as `d`" ;
} else {
str = str + "0.." + level + "]->(p:Know) where n.courseId = '" + courseId + "' return n as `n`,r as `r`,p as `p`,length(r) as `d`" ;
}
System . out . println ( str ) ;
System . out . println ( str ) ;
Collection < Map < String , Object > > all =
Collection < Map < String , Object > > all =
neo4jClient . query ( str ) . fetch ( ) . all ( ) ;
neo4jClient . query ( str ) . fetch ( ) . all ( ) ;
@ -812,6 +886,8 @@ public class knowServiceImpl implements KnowService {
links . setLabel ( "包含" ) ;
links . setLabel ( "包含" ) ;
} else if ( "order" . equals ( e . type ( ) ) ) {
} else if ( "order" . equals ( e . type ( ) ) ) {
links . setLabel ( "顺序" ) ;
links . setLabel ( "顺序" ) ;
} else if ( "dependent" . equals ( e . type ( ) ) ) {
links . setLabel ( "依赖" ) ;
}
}
linksList . add ( links ) ;
linksList . add ( links ) ;
}
}
@ -871,6 +947,8 @@ public class knowServiceImpl implements KnowService {
links . setLabel ( "包含" ) ;
links . setLabel ( "包含" ) ;
} else if ( "order" . equals ( e . type ( ) ) ) {
} else if ( "order" . equals ( e . type ( ) ) ) {
links . setLabel ( "顺序" ) ;
links . setLabel ( "顺序" ) ;
} else if ( "dependent" . equals ( e . type ( ) ) ) {
links . setLabel ( "依赖" ) ;
}
}
linksList . add ( links ) ;
linksList . add ( links ) ;
}
}