|
|
|
@ -2,7 +2,9 @@ package com.luoo.music.service;
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.IntStream;
|
|
|
|
|
|
|
|
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
|
|
@ -11,25 +13,35 @@ import javax.persistence.criteria.Predicate;
|
|
|
|
|
import javax.persistence.criteria.Root;
|
|
|
|
|
|
|
|
|
|
import api.Result;
|
|
|
|
|
import constants.Constants;
|
|
|
|
|
import enums.CollectTypeEnum;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -47,13 +59,20 @@ public class JournalService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private JournalSongDao journalSongDao;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IdWorker idWorker;
|
|
|
|
|
@Autowired
|
|
|
|
|
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<>();
|
|
|
|
|
/*
|
|
|
|
|
* public void updateState(String id) { journalDao.updateState(id); }
|
|
|
|
@ -100,18 +119,7 @@ public class JournalService {
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Journal findById(String id) {
|
|
|
|
|
|
|
|
|
|
Journal journal = (Journal) redisTemplate.opsForValue().get("journal_"+id);
|
|
|
|
|
|
|
|
|
|
if (journal==null) {
|
|
|
|
|
Optional<Journal> optional=journalDao.findById(id);
|
|
|
|
|
if(optional.isPresent()) {
|
|
|
|
|
journal =optional.get();
|
|
|
|
|
redisTemplate.opsForValue().set("journal_"+id,journal);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return journal;
|
|
|
|
|
return journalDao.findById(id).orElse(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -349,4 +357,37 @@ 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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public JournalRespDTO queryJournalById(String id) {
|
|
|
|
|
return (JournalRespDTO) this.cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_ID, id, key -> getJournalRespDTOById(id), false).getValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private JournalRespDTO getJournalRespDTOById(String id) {
|
|
|
|
|
Journal journal=this.findById(id);
|
|
|
|
|
if(null==journal) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return JournalMapper.getJournalRespDTO(journal,mongoTemplate,redisTemplate,commentDao);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|