@ -1,6 +1,7 @@
package com.luoo.music.service ;
package com.luoo.music.service ;
import java.util.* ;
import java.util.* ;
import java.util.function.Function ;
import java.util.regex.Pattern ;
import java.util.regex.Pattern ;
import java.util.stream.Collectors ;
import java.util.stream.Collectors ;
import javax.persistence.criteria.CriteriaBuilder ;
import javax.persistence.criteria.CriteriaBuilder ;
@ -14,6 +15,8 @@ import constants.Constants;
import enums.JournalPublishEnum ;
import enums.JournalPublishEnum ;
import enums.JournalStatusEnum ;
import enums.JournalStatusEnum ;
import net.oschina.j2cache.CacheChannel ;
import net.oschina.j2cache.CacheChannel ;
import net.oschina.j2cache.CacheObject ;
import org.apache.commons.lang.StringUtils ;
import org.apache.commons.lang.StringUtils ;
import org.apache.commons.lang3.tuple.Pair ;
import org.apache.commons.lang3.tuple.Pair ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
@ -57,6 +60,9 @@ public class JournalService {
@Autowired
@Autowired
private JournalSongDao journalSongDao ;
private JournalSongDao journalSongDao ;
@Autowired
private JournalMapper journalMapper ;
@Autowired
@Autowired
private JournalTagDao journalTagDao ;
private JournalTagDao journalTagDao ;
@Autowired
@Autowired
@ -228,8 +234,6 @@ public class JournalService {
return Collections . emptyList ( ) ;
return Collections . emptyList ( ) ;
}
}
public boolean isLatest10ByJournalNo ( String journalNo ) {
public boolean isLatest10ByJournalNo ( String journalNo ) {
return null ! = journalDao . isLatest10ByJournalNo ( journalNo ) ;
return null ! = journalDao . isLatest10ByJournalNo ( journalNo ) ;
}
}
@ -349,23 +353,38 @@ public class JournalService {
return journalDao . orderByField ( recommendIds ) ;
return journalDao . orderByField ( recommendIds ) ;
}
}
public List < String > orderByJournalIdField ( List < String > jouranlIds ) {
public List < String > orderByJournalIdField ( List < String > jouranlIds ) {
return journalSongDao . orderByJournalIdField ( jouranlIds ) ;
return CollectionUtils . isEmpty ( jouranlIds ) ? Collections . emptyList ( )
: journalSongDao . orderByJournalIdField ( jouranlIds ) ;
}
}
@SuppressWarnings ( "unchecked" )
public List < JournalRespDTO > queryJournalByPage ( JournalQueryReq queryReq ) {
public List < JournalRespDTO > queryJournalByPage ( JournalQueryReq queryReq ) {
if ( StringTools . isEmpty ( queryReq . getCategoryId ( ) ) & & StringTools . isEmpty ( queryReq . getJournalNoRange ( ) ) ) {
if ( StringTools . isEmpty ( queryReq . getCategoryId ( ) ) & & StringTools . isEmpty ( queryReq . getJournalNoRange ( ) ) ) {
return ( List < JournalRespDTO > ) this . cacheChannel . get ( Constants . J2CACHE_REGION_JOURNAL_QUERY_PAGE , queryReq . toString ( ) , key - > getJournalRespDTOWithComment ( queryReq ) , false ) . getValue ( ) ;
return queryJournalByPage ( queryReq , key - > getJournalRespDTOWithComment ( queryReq ) ) ;
}
}
List < JournalRespDTO > list = ( List < JournalRespDTO > ) this . cacheChannel . get ( Constants . J2CACHE_REGION_JOURNAL_QUERY_PAGE , queryReq . toString ( ) , key - > getJournalRespDTO ( queryReq ) , false ) . getValue ( ) ;
List < JournalRespDTO > list = queryJournalByPage ( queryReq , key - > getJournalRespDTO ( queryReq ) ) ;
list . parallelStream ( ) . forEach ( j - > {
list . parallelStream ( ) . forEach ( j - > {
updateComment ( j ) ;
updateComment ( j ) ;
} ) ;
} ) ;
return list ;
return list ;
}
}
@SuppressWarnings ( "unchecked" )
private List < JournalRespDTO > queryJournalByPage ( JournalQueryReq queryReq ,
Function < JournalQueryReq , List < JournalRespDTO > > function ) {
CacheObject cacheObject = this . cacheChannel . get ( Constants . J2CACHE_REGION_JOURNAL_QUERY_PAGE , queryReq . toString ( ) ) ;
if ( null = = cacheObject | | null = = cacheObject . getValue ( ) ) {
List < JournalRespDTO > result = function . apply ( queryReq ) ;
if ( CollectionUtils . isEmpty ( result ) ) {
return Collections . emptyList ( ) ;
}
this . cacheChannel . set ( Constants . J2CACHE_REGION_JOURNAL_QUERY_PAGE , queryReq . toString ( ) , result ) ;
return result ;
}
return ( List < JournalRespDTO > ) cacheObject . getValue ( ) ;
}
private void updateComment ( JournalRespDTO journalRespDTO ) {
private void updateComment ( JournalRespDTO journalRespDTO ) {
CommentDTO commentDTO = CommentMapper . getCommentDTO ( journalRespDTO . getId ( ) , mongoTemplate , commentDao ,
CommentDTO commentDTO = CommentMapper . getCommentDTO ( journalRespDTO . getId ( ) , mongoTemplate , commentDao ,
redisTemplate , userClient , cacheChannel ) ;
redisTemplate , userClient , cacheChannel ) ;
@ -378,12 +397,12 @@ public class JournalService {
private List < JournalRespDTO > getJournalRespDTO ( JournalQueryReq queryReq ) {
private List < JournalRespDTO > getJournalRespDTO ( JournalQueryReq queryReq ) {
List < Journal > pageList = queryPage ( queryReq ) ;
List < Journal > pageList = queryPage ( queryReq ) ;
return pageList . stream ( ) . map ( a - >
return pageList . stream ( ) . map ( a - >
J ournalMapper. getJournalRespDTO ( a ) ) . collect ( Collectors . toList ( ) ) ;
j ournalMapper. getJournalRespDTO ( a ) ) . collect ( Collectors . toList ( ) ) ;
}
}
private List < JournalRespDTO > getJournalRespDTOWithComment ( JournalQueryReq queryReq ) {
private List < JournalRespDTO > getJournalRespDTOWithComment ( JournalQueryReq queryReq ) {
List < Journal > pageList = queryPage ( queryReq ) ;
List < Journal > pageList = queryPage ( queryReq ) ;
return pageList . stream ( ) . map ( journal - > JournalMapper. getJournalRespDTO ( journal , mongoTemplate , redisTemplate , commentDao , userClient , cacheChanne l) ) . collect ( Collectors . toList ( ) ) ;
return pageList . stream ( ) . map ( journal - > journalMapper. getJournalRespDTOWithComment ( journa l) ) . collect ( Collectors . toList ( ) ) ;
}
}
@ -397,7 +416,7 @@ public class JournalService {
if ( null = = journal ) {
if ( null = = journal ) {
return null ;
return null ;
}
}
return JournalMapper. getJournalRespDTO ( journal , mongoTemplate , redisTemplate , commentDao , userClient , cacheChanne l) ;
return journalMapper. getJournalRespDTOWithComment ( journa l) ;
}
}
public JournalRespDTO queryJournalByJournalNo ( String journalNo ) {
public JournalRespDTO queryJournalByJournalNo ( String journalNo ) {
@ -409,7 +428,7 @@ public class JournalService {
if ( null = = journal ) {
if ( null = = journal ) {
return null ;
return null ;
}
}
return JournalMapper. getJournalRespDTO ( journal , mongoTemplate , redisTemplate , commentDao , userClient , cacheChanne l) ;
return journalMapper. getJournalRespDTOWithComment ( journa l) ;
}
}
public JournalFilterDTO getJournalFilterDTO ( ) {
public JournalFilterDTO getJournalFilterDTO ( ) {