@ -4,21 +4,10 @@ import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject ;
import cn.hutool.json.JSONObject ;
import cn.hutool.json.JSONUtil ;
import cn.hutool.json.JSONUtil ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.fasterxml.jackson.core.JsonProcessingException ;
import com.fasterxml.jackson.databind.JsonMappingException ;
import com.fasterxml.jackson.databind.JsonNode ;
import com.fasterxml.jackson.databind.ObjectMapper ;
import com.fasterxml.jackson.databind.node.ArrayNode ;
import com.fasterxml.jackson.databind.node.ObjectNode ;
import com.google.gson.Gson ;
import com.google.gson.GsonBuilder ;
import com.google.gson.JsonObject ;
import com.teaching.backend.common.BaseResponse ;
import com.teaching.backend.common.BaseResponse ;
import com.teaching.backend.common.ErrorCode ;
import com.teaching.backend.common.ErrorCode ;
import com.teaching.backend.common.ResultUtils ;
import com.teaching.backend.common.ResultUtils ;
import com.teaching.backend.controller.Know.Edge ;
import com.teaching.backend.controller.Know.KnowPathVO ;
import com.teaching.backend.controller.Know.KnowJson ;
import com.teaching.backend.controller.Know.KnowJsonListVO ;
import com.teaching.backend.mapper.Knowtemp.KnowstrMapper ;
import com.teaching.backend.mapper.Knowtemp.KnowstrMapper ;
import com.teaching.backend.mapper.Knowtemp.KnowtmpMapper ;
import com.teaching.backend.mapper.Knowtemp.KnowtmpMapper ;
import com.teaching.backend.mapper.chapter.ChapterMapper ;
import com.teaching.backend.mapper.chapter.ChapterMapper ;
@ -29,24 +18,17 @@ import com.teaching.backend.model.entity.chapter.Chapter;
import com.teaching.backend.model.entity.courses.Courses ;
import com.teaching.backend.model.entity.courses.Courses ;
import com.teaching.backend.model.entity.know.* ;
import com.teaching.backend.model.entity.know.* ;
import com.teaching.backend.model.entity.knowtmp.Knowtmp ;
import com.teaching.backend.model.entity.knowtmp.Knowtmp ;
import com.teaching.backend.model.entity.resource.Resources ;
import com.teaching.backend.model.vo.knowGraph.KnowVO ;
import com.teaching.backend.model.vo.knowGraph.KnowVO ;
import com.teaching.backend.model.vo.knowGraph.KnowVO1 ;
import com.teaching.backend.service.Know.KnowService ;
import com.teaching.backend.service.Know.KnowService ;
import com.teaching.backend.service.knowtmp.KnowtmpService ;
import com.teaching.backend.service.knowtmp.KnowtmpService ;
import org.neo4j.driver.internal.InternalRelationship ;
import org.neo4j.driver.internal.InternalRelationship ;
import org.neo4j.driver.types.Node ;
import org.neo4j.driver.types.Node ;
import org.springframework.beans.BeanUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.data.neo4j.core.Neo4jClient ;
import org.springframework.data.neo4j.core.Neo4jClient ;
import org.springframework.data.neo4j.core.Neo4jTemplate ;
import org.springframework.stereotype.Service ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import javax.annotation.Resource ;
import javax.annotation.Resource ;
import java.io.IOException ;
import java.util.* ;
import java.util.* ;
import java.util.stream.Collectors ;
/ * *
/ * *
* @Author : youhang
* @Author : youhang
@ -169,7 +151,85 @@ public class knowServiceImpl implements KnowService {
return ResultUtils . success ( baseKnowReturn ) ;
return ResultUtils . success ( baseKnowReturn ) ;
}
}
public BaseResponse < BaseKnowReturn > getDepthNodeByCourseId ( String courseId , Long depth ) {
Collection < Map < String , Object > > all =
neo4jClient . query ( "match(n:Know)-[r:contain*0.." + depth + "]->(p:Know) where n.courseId = '" + courseId + "' return n as `n`,r as `r`,p as `p`,length(r) as `d`" ) . fetch ( ) . all ( ) ;
Collection < Map < String , Object > > all2 =
neo4jClient . query ( "match(n:Know)-[r*0.." + depth + "]->(p:Know) where n.courseId = '" + courseId + "' return r as `r`" ) . fetch ( ) . all ( ) ;
Iterator < Map < String , Object > > iterator = all . iterator ( ) ;
Iterator < Map < String , Object > > iterator2 = all2 . 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 ( ) ;
knowVO = new KnowVO ( ) ;
Node node1 = ( Node ) element . get ( "p" ) ;
Long group = ( Long ) element . get ( "d" ) ;
knowVO . setColor ( colorChoose . get ( group ) ) ;
if ( node1 ! = null ) {
Long id1 = node1 . id ( ) ;
String name1 = node1 . get ( "name" ) . asString ( ) ;
knowVO . setId ( id1 ) ;
knowVO . setLabel ( name1 ) ;
knowList . add ( knowVO ) ;
knowVO . setColor ( colorChoose . get ( group ) ) ;
}
node2 = ( List ) element . get ( "r" ) ;
if ( ! node2 . isEmpty ( ) ) {
for ( int i = 0 ; i < node2 . size ( ) ; i + + ) {
InternalRelationship e = ( InternalRelationship ) node2 . 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 ) ;
}
}
}
while ( iterator2 . hasNext ( ) ) {
Map < String , Object > element = iterator2 . next ( ) ;
node2 = ( List ) element . get ( "r" ) ;
if ( ! node2 . isEmpty ( ) ) {
for ( int i = 0 ; i < node2 . size ( ) ; i + + ) {
InternalRelationship e = ( InternalRelationship ) node2 . 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 ) ;
}
}
}
BaseKnowReturn baseKnowReturn = new BaseKnowReturn ( knowList , linksList ) ;
return ResultUtils . success ( baseKnowReturn ) ;
}
@Override
@Override
public BaseResponse < String > showGraphJson ( String courseId ) {
public BaseResponse < String > showGraphJson ( String courseId ) {
// 创建 JSON 对象数组
// 创建 JSON 对象数组
@ -337,7 +397,8 @@ public class knowServiceImpl implements KnowService {
}
}
@Override
@Override
public BaseResponse < BaseKnowReturn > knowLearnPath ( String corseId ) {
public BaseResponse < List < KnowPathVO > > knowLearnPath ( String corseId ) {
//查询第一个知识点-最后一个知识点
//查询第一个知识点-最后一个知识点
List < Long > knowIds = new ArrayList < > ( ) ;
List < Long > knowIds = new ArrayList < > ( ) ;
List < Chapter > chapterList = chapterMapper . selectChapterPIDByCourseId ( corseId ) ;
List < Chapter > chapterList = chapterMapper . selectChapterPIDByCourseId ( corseId ) ;
@ -354,59 +415,25 @@ public class knowServiceImpl implements KnowService {
}
}
}
}
// 生成学习路径
BaseKnowReturn baseKnowReturn = new BaseKnowReturn ( ) ;
// 生成学习路径
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 " +
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 " +
"RETURN [x IN nodes(p)|x.name] AS path,pathWeight ORDER BY pathWeight desc;" ;
"ORDER BY pathWeight DESC LIMIT 1;" ;
Collection < Map < String , Object > > result = neo4jClient . query ( str ) . fetch ( ) . all ( ) ;
Collection < Map < String , Object > > result = neo4jClient . query ( str ) . fetch ( ) . all ( ) ;
Iterator < Map < String , Object > > iterator = result . iterator ( ) ;
Iterator < Map < String , Object > > iterator = result . iterator ( ) ;
Set < KnowVO > knowList = new HashSet < > ( ) ;
List < KnowPathVO > knowPathVOList = new ArrayList < > ( ) ;
Set < Links > linksList = new HashSet < > ( ) ;
KnowPathVO knowPathVO ;
while ( iterator . hasNext ( ) ) {
while ( iterator . hasNext ( ) ) {
Map < String , Object > element = iterator . next ( ) ;
Map < String , Object > element = iterator . next ( ) ;
KnowVO knowVO ;
knowPathVO = new KnowPathVO ( ) ;
List node1 = new ArrayList < > ( ) ;
List list = new ArrayList < > ( ) ;
node1 = ( List ) element . get ( "p" ) ;
list = ( List ) element . get ( "path" ) ;
knowPathVO . setNodeList ( list ) ;
if ( node1 ! = null ) {
Double pathWeight = ( Double ) element . get ( "pathWeight" ) ;
for ( int i = 0 ; i < node1 . size ( ) ; i + + ) {
knowPathVO . setWeight ( pathWeight ) ;
Node e = ( Node ) node1 . get ( i ) ;
knowPathVOList . add ( knowPathVO ) ;
Long id1 = e . id ( ) ;
}
String name1 = e . get ( "name" ) . asString ( ) ;
return ResultUtils . success ( knowPathVOList ) ;
knowVO = new KnowVO ( ) ;
knowVO . setId ( id1 ) ;
knowVO . setLabel ( name1 ) ;
knowVO . setColor ( colorList [ 0 ] ) ;
knowList . add ( knowVO ) ;
}
}
List node2 = new ArrayList < > ( ) ;
node2 = ( List ) element . get ( "r" ) ;
if ( ! node2 . isEmpty ( ) ) {
for ( int i = 0 ; i < node2 . size ( ) ; i + + ) {
InternalRelationship e = ( InternalRelationship ) node2 . get ( i ) ;
Links 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 ) ;
}
}
}
baseKnowReturn . setKnowList ( knowList ) ;
baseKnowReturn . setLinksList ( linksList ) ;
return ResultUtils . success ( baseKnowReturn ) ;
}
}
@Override
@Override