searchResponse = restHighLevelClient.search ( searchRequest ) ; } catch ( IOException e ) { e.printStackTrace ( ) ; } / / 获取搜索结果 SearchHits hits = searchResponse.getHits ( ) ; SearchHit[] searchHits = hits.getHits ( ) ; Map < String , CoursePub > map = new HashMap < > ( ) ; / / 数据列表 List < TeachplanMediaPub > teachplanMediaPubList = new ArrayList < > ( ) ; for ( SearchHit hit : searchHits ) { TeachplanMediaPub teachplanMediaPub = new TeachplanMediaPub ( ) ; Map < String , Object > sourceAsMap = hit.getSourceAsMap ( ) ; / / 取出课程计划媒资信息 String courseid = ( String ) sourceAsMap. get ( "courseid" ) ; String media_id = ( String ) sourceAsMap. get ( "media_id" ) ; String media_url = ( String ) sourceAsMap. get ( "media_url" ) ; String teachplan_id = ( String ) sourceAsMap. get ( "teachplan_id" ) ; String media_fileoriginalname = ( String ) sourceAsMap. get ( "media_fileoriginalname" ) ; teachplanMediaPub.setCourseId ( courseid ) ; teachplanMediaPub.setMediaUrl ( media_url ) ; teachplanMediaPub.setMediaFileOriginalName ( media_fileoriginalname ) ; teachplanMediaPub.setMediaId ( media_id ) ; teachplanMediaPub.setTeachplanId ( teachplan_id ) ; / / 将数据加入列表 teachplanMediaPubList. add ( teachplanMediaPub ) ; } / / 构建返回课程媒资信息对象 QueryResult < TeachplanMediaPub > queryResult = new QueryResult < > ( ) ; queryResult.setList ( teachplanMediaPubList ) ; QueryResponseResult < TeachplanMediaPub > queryResponseResult = new QueryResponseResult < TeachplanMediaPub > ( CommonCode.SUCCESS , queryResult ) ; return queryResponseResult; } @Override @GetMapping ( value = "/getmedia/{teachplanId}" ) public TeachplanMediaPub getmedia ( @PathVariable ( "teachplanId" ) String teachplanId ) { / / 将课程计划 id 放在数组中,为调用service作准备 String[] teachplanIds = new String[] { teachplanId } ; / / 通过service查询ES获取课程媒资信息 QueryResponseResult < TeachplanMediaPub > mediaPubQueryResponseResult = esCourseService.getmedia ( teachplanIds ) ; QueryResult < TeachplanMediaPub > queryResult = mediaPubQueryResponseResult.getQueryResult ( ) ; if ( queryResult! = null & & queryResult.getList ( ) ! = null & & queryResult.getList ( ) .size ( ) > 0 ) { / / 返回课程计划对应课程媒资 return queryResult.getList ( ) . get ( 0 ) ; } return new TeachplanMediaPub ( ) ; } |