|
|
|
@ -3,6 +3,7 @@ package com.luoo.music.service;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.IntStream;
|
|
|
|
|
|
|
|
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
|
|
@ -11,25 +12,34 @@ import javax.persistence.criteria.Predicate;
|
|
|
|
|
import javax.persistence.criteria.Root;
|
|
|
|
|
|
|
|
|
|
import api.Result;
|
|
|
|
|
import constants.Constants;
|
|
|
|
|
import enums.JournalPublishEnum;
|
|
|
|
|
import enums.JournalStatusEnum;
|
|
|
|
|
import net.oschina.j2cache.CacheChannel;
|
|
|
|
|
import net.oschina.j2cache.CacheObject;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import util.IdWorker;
|
|
|
|
|
import util.StringTools;
|
|
|
|
|
|
|
|
|
|
import com.luoo.music.dao.CommentDao;
|
|
|
|
|
import com.luoo.music.dao.JournalDao;
|
|
|
|
|
import com.luoo.music.dao.JournalSongDao;
|
|
|
|
|
import com.luoo.music.dao.JournalTagDao;
|
|
|
|
|
import com.luoo.music.dao.TagDao;
|
|
|
|
|
import com.luoo.music.dto.mapper.JournalMapper;
|
|
|
|
|
import com.luoo.music.dto.request.JournalQueryReq;
|
|
|
|
|
import com.luoo.music.dto.response.JournalRespDTO;
|
|
|
|
|
import com.luoo.music.pojo.Journal;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -53,6 +63,15 @@ public class JournalService {
|
|
|
|
|
private JournalTagDao journalTagDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private RedisTemplate redisTemplate;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private CacheChannel cacheChannel;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MongoTemplate mongoTemplate;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private CommentDao commentDao;
|
|
|
|
|
|
|
|
|
|
private Map<Integer,List<String>> JOURNAL_RANGE_MAP=new HashMap<>();
|
|
|
|
|
/*
|
|
|
|
@ -349,4 +368,23 @@ public class JournalService {
|
|
|
|
|
public List<String> orderByJournalIdField(List<String> jouranlIds) {
|
|
|
|
|
return journalSongDao.orderByJournalIdField(jouranlIds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
public List<JournalRespDTO> queryJournalByPage(JournalQueryReq queryReq) {
|
|
|
|
|
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) , true).getValue() ;
|
|
|
|
|
}
|
|
|
|
|
return (List<JournalRespDTO>) this.cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_QUERY_PAGE, queryReq.toString(), key -> getJournalRespDTO(queryReq) , true).getValue() ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<JournalRespDTO> getJournalRespDTO(JournalQueryReq queryReq) {
|
|
|
|
|
List<Journal> pageList = queryPage(queryReq);
|
|
|
|
|
return pageList.stream().map(a ->
|
|
|
|
|
JournalMapper.getJournalRespDTO(a)).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<JournalRespDTO> getJournalRespDTOWithComment(JournalQueryReq queryReq) {
|
|
|
|
|
List<Journal> pageList = queryPage(queryReq);
|
|
|
|
|
return pageList.stream().map(journal -> JournalMapper.getJournalRespDTO(journal,mongoTemplate,redisTemplate,commentDao)).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|