@ -1,8 +1,10 @@
package com.luoo.music.controller ;
package com.luoo.music.controller ;
import java.util.Arrays ;
import java.util.Collections ;
import java.util.Collections ;
import java.util.HashSet ;
import java.util.HashSet ;
import java.util.List ;
import java.util.List ;
import java.util.Map ;
import java.util.Set ;
import java.util.Set ;
import java.util.stream.Collectors ;
import java.util.stream.Collectors ;
@ -84,7 +86,8 @@ public class JournalController {
List < String > ids = pageList . stream ( ) . map ( Journal : : getId ) . collect ( Collectors . toList ( ) ) ;
List < String > ids = pageList . stream ( ) . map ( Journal : : getId ) . collect ( Collectors . toList ( ) ) ;
Set < String > journalCollectSet = null = = user ? Collections . emptySet ( )
Set < String > journalCollectSet = null = = user ? Collections . emptySet ( )
: userCollectInfoService . getCollectSet ( user . getUserId ( ) , ids , CollectTypeEnum . JOURNAL ) ;
: userCollectInfoService . getCollectSet ( user . getUserId ( ) , ids , CollectTypeEnum . JOURNAL ) ;
List < JournalRespDTO > list = pageList . stream ( ) . map ( a - > JournalMapper . getJournalRespDTO ( a , journalCollectSet , mongoTemplate , redisTemplate , commentDao ) )
Map < String , List < String > > tagMap = tagService . getTagMap ( ids ) ;
List < JournalRespDTO > list = pageList . stream ( ) . map ( a - > JournalMapper . getJournalRespDTO ( a , journalCollectSet , mongoTemplate , redisTemplate , commentDao , tagMap ) )
. collect ( Collectors . toList ( ) ) ;
. collect ( Collectors . toList ( ) ) ;
return Result . success ( new PageResult < JournalRespDTO > ( Long . valueOf ( list . size ( ) ) , list ) ) ;
return Result . success ( new PageResult < JournalRespDTO > ( Long . valueOf ( list . size ( ) ) , list ) ) ;
}
}
@ -107,7 +110,8 @@ public class JournalController {
}
}
List < Journal > pageList = journalService . orderByField ( objectIds ) ;
List < Journal > pageList = journalService . orderByField ( objectIds ) ;
Set < String > journalCollectSet = new HashSet < > ( objectIds ) ;
Set < String > journalCollectSet = new HashSet < > ( objectIds ) ;
List < JournalRespDTO > list = pageList . stream ( ) . map ( a - > JournalMapper . getJournalRespDTO ( a , journalCollectSet , mongoTemplate , redisTemplate , commentDao ) )
Map < String , List < String > > tagMap = tagService . getTagMap ( objectIds ) ;
List < JournalRespDTO > list = pageList . stream ( ) . map ( a - > JournalMapper . getJournalRespDTO ( a , journalCollectSet , mongoTemplate , redisTemplate , commentDao , tagMap ) )
. collect ( Collectors . toList ( ) ) ;
. collect ( Collectors . toList ( ) ) ;
return Result . success ( new PageResult < JournalRespDTO > ( Long . valueOf ( list . size ( ) ) , list ) ) ;
return Result . success ( new PageResult < JournalRespDTO > ( Long . valueOf ( list . size ( ) ) , list ) ) ;
}
}
@ -123,7 +127,8 @@ public class JournalController {
return Result . unauthorized ( null ) ;
return Result . unauthorized ( null ) ;
}
}
Journal journal = journalService . findById ( id ) ;
Journal journal = journalService . findById ( id ) ;
JournalRespDTO journalRespDTO = JournalMapper . getJournalRespDTO ( journal , Collections . emptySet ( ) , mongoTemplate , redisTemplate , commentDao ) ;
Map < String , List < String > > tagMap = tagService . getTagMap ( Arrays . asList ( id ) ) ;
JournalRespDTO journalRespDTO = JournalMapper . getJournalRespDTO ( journal , Collections . emptySet ( ) , mongoTemplate , redisTemplate , commentDao , tagMap ) ;
boolean isCollect = null = = user ? false : userCollectInfoService . isCollect ( user . getUserId ( ) , id , CollectTypeEnum . JOURNAL ) ;
boolean isCollect = null = = user ? false : userCollectInfoService . isCollect ( user . getUserId ( ) , id , CollectTypeEnum . JOURNAL ) ;
journalRespDTO . setHaveCollect ( isCollect ) ;
journalRespDTO . setHaveCollect ( isCollect ) ;
return Result . success ( journalRespDTO ) ;
return Result . success ( journalRespDTO ) ;
@ -139,7 +144,7 @@ public class JournalController {
if ( null = = user & & ! journalService . isLatest10ByJournalId ( id ) ) {
if ( null = = user & & ! journalService . isLatest10ByJournalId ( id ) ) {
return Result . unauthorized ( null ) ;
return Result . unauthorized ( null ) ;
}
}
return Result . success ( CommentMapper . getCommentDTO ( id , mongoTemplate , commentDao )) ;
return Result . success ( CommentMapper . getCommentDTO ( id , mongoTemplate , commentDao ,redisTemplate )) ;
}
}
@ApiOperation ( value = "4.获取期刊筛选条件" )
@ApiOperation ( value = "4.获取期刊筛选条件" )
@ -154,6 +159,29 @@ public class JournalController {
journalFilterDTO . setStyleList ( tagService . getStyleList ( ) . stream ( ) . map ( this : : getTagDTO ) . collect ( Collectors . toList ( ) ) ) ;
journalFilterDTO . setStyleList ( tagService . getStyleList ( ) . stream ( ) . map ( this : : getTagDTO ) . collect ( Collectors . toList ( ) ) ) ;
return Result . success ( journalFilterDTO ) ;
return Result . success ( journalFilterDTO ) ;
}
}
@ApiOperation ( value = "5.根据当前期刊的标签推荐6期类似期刊" )
@GetMapping ( "/recommend/{id}" )
@GlobalInterceptor
public Result < List < JournalRespDTO > > recommendById (
@RequestHeader ( value = "Authorization" , required = false ) String authorization ,
@PathVariable @VerifyParam ( required = true ) String id ) {
UserLoginDto user = jwtUtil . getUserLoginDto ( authorization ) ;
if ( null = = user & & ! journalService . isLatest10ByJournalId ( id ) ) {
return Result . unauthorized ( null ) ;
}
List < Journal > journals = journalService . recommendById ( id ) ;
List < String > ids = journals . stream ( ) . map ( Journal : : getId ) . collect ( Collectors . toList ( ) ) ;
Set < String > journalCollectSet = null = = user ? Collections . emptySet ( )
: userCollectInfoService . getCollectSet ( user . getUserId ( ) , ids , CollectTypeEnum . JOURNAL ) ;
Map < String , List < String > > tagMap = tagService . getTagMap ( ids ) ;
List < JournalRespDTO > list = journals . stream ( ) . map ( a - > JournalMapper . getJournalRespDTO ( a , journalCollectSet , mongoTemplate , redisTemplate , commentDao , tagMap ) )
. collect ( Collectors . toList ( ) ) ;
return Result . success ( list ) ;
}
private TagDTO getTagDTO ( Tag tag ) {
private TagDTO getTagDTO ( Tag tag ) {
TagDTO tagDTO = new TagDTO ( ) ;
TagDTO tagDTO = new TagDTO ( ) ;
tagDTO . setName ( tag . getNameCh ( ) ) ;
tagDTO . setName ( tag . getNameCh ( ) ) ;