|
|
@ -11,24 +11,31 @@ import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
|
|
|
|
|
import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
|
|
|
|
|
|
|
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
|
|
|
|
|
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
|
|
|
|
|
|
|
|
|
import com.apifan.common.random.RandomSource;
|
|
|
|
import com.apifan.common.random.RandomSource;
|
|
|
|
import com.apifan.common.random.entity.Poem;
|
|
|
|
import com.apifan.common.random.entity.Poem;
|
|
|
|
import com.luoo.music.dao.CommentDao;
|
|
|
|
import com.luoo.music.dao.CommentDao;
|
|
|
|
import com.luoo.music.dto.response.CommentDTO;
|
|
|
|
|
|
|
|
import com.luoo.music.dto.response.JournalRespDTO;
|
|
|
|
import com.luoo.music.dto.response.JournalRespDTO;
|
|
|
|
|
|
|
|
import com.luoo.music.dto.response.TotalCommentVo;
|
|
|
|
|
|
|
|
import com.luoo.music.pojo.Comment;
|
|
|
|
import com.luoo.music.pojo.Journal;
|
|
|
|
import com.luoo.music.pojo.Journal;
|
|
|
|
import constants.Constants;
|
|
|
|
import constants.Constants;
|
|
|
|
import enums.DateTimePatternEnum;
|
|
|
|
import enums.DateTimePatternEnum;
|
|
|
|
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
import util.DateUtil;
|
|
|
|
import util.DateUtil;
|
|
|
|
import util.StringTools;
|
|
|
|
import util.StringTools;
|
|
|
|
|
|
|
|
|
|
|
|
public class JournalMapper {
|
|
|
|
public class JournalMapper {
|
|
|
|
// mock data
|
|
|
|
// mock data
|
|
|
|
private static final List<String> DEFAULT_TAGS=Arrays.asList("暂无标签");
|
|
|
|
|
|
|
|
private static final String JOURNAL_TAG_FILE_PATH = "journalTags.txt";
|
|
|
|
private static final String JOURNAL_TAG_FILE_PATH = "journalTags.txt";
|
|
|
|
private static final Map<String, List<String>> journalTagMap = new HashMap<>();
|
|
|
|
private static final Map<String, List<String>> journalTagMap = new HashMap<>();
|
|
|
|
private static final String[] EDITOR = new String[] { "左岸以西", "落在低处" };
|
|
|
|
private static final String[] EDITOR = new String[] { "左岸以西", "落在低处" };
|
|
|
@ -52,9 +59,9 @@ public class JournalMapper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static JournalRespDTO getJournalRespDTO(Journal journal) {
|
|
|
|
public static JournalRespDTO getJournalRespDTO(Journal journal) {
|
|
|
|
return getJournalRespDTO(journal, Collections.emptySet());
|
|
|
|
return getJournalRespDTO(journal,Collections.emptySet());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static JournalRespDTO getJournalRespDTO(Journal journal, Set<String> journalCollectSet) {
|
|
|
|
public static JournalRespDTO getJournalRespDTO(Journal journal, Set<String> journalCollectSet) {
|
|
|
|
JournalRespDTO journalRespDTO = new JournalRespDTO();
|
|
|
|
JournalRespDTO journalRespDTO = new JournalRespDTO();
|
|
|
|
journalRespDTO.setId(journal.getId());
|
|
|
|
journalRespDTO.setId(journal.getId());
|
|
|
@ -78,13 +85,58 @@ public class JournalMapper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return journalRespDTO;
|
|
|
|
return journalRespDTO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static JournalRespDTO getJournalRespDTO(Journal journal, Set<String> journalCollectSet,
|
|
|
|
public static JournalRespDTO getJournalRespDTO(Journal journal, Set<String> journalCollectSet,
|
|
|
|
MongoTemplate mongoTemplate, CommentDao commentDao) {
|
|
|
|
MongoTemplate mongoTemplate, RedisTemplate redisTemplate,CommentDao commentDao) {
|
|
|
|
JournalRespDTO journalRespDTO = getJournalRespDTO(journal, journalCollectSet);
|
|
|
|
JournalRespDTO journalRespDTO = getJournalRespDTO(journal,journalCollectSet);
|
|
|
|
CommentDTO commentDTO = CommentMapper.getCommentDTO(journalRespDTO.getId(), mongoTemplate, commentDao);
|
|
|
|
|
|
|
|
journalRespDTO.setCommentList(commentDTO.getCommentList());
|
|
|
|
/**
|
|
|
|
journalRespDTO.setTotalCommentReply(commentDTO.getTotalCommentReply());
|
|
|
|
* 显示期刊点赞最多5条评论,该五条评论随机显示,每次进入刷新新,超过部分显示为“...”点击评论进入期刊详情页并自动定位到该评论,点击用户头像同上,若为空数据则显示“暂无评论,快去抢沙发吧!
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Comment> commentList = (List<Comment>) redisTemplate.opsForValue().get("JOURNAL_TOP5_COMMENT___"+journal.getId());
|
|
|
|
|
|
|
|
if (null!= commentList) {
|
|
|
|
|
|
|
|
journalRespDTO.setCommentList(commentList);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
commentList = commentDao.findTop5ByJournalIdOrderByThumbupCountDesc(journal.getId());
|
|
|
|
|
|
|
|
journalRespDTO.setCommentList(commentList);
|
|
|
|
|
|
|
|
redisTemplate.opsForValue().set("JOURNAL_TOP5_COMMENT___"+journal.getId(),commentList,6, TimeUnit.HOURS);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// List<Comment> commentList = commentDao.findTop5ByJournalIdOrderByThumbupCountDesc(journal.getId());
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// journalRespDTO.setCommentList(commentList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取期刊总评论数 一级评论数加上父评论的总回复数
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String totalString = (String) redisTemplate.opsForValue().get("JOURNAL_TATAL_COMMENT_COUNT___"+journal.getId());
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(totalString)) {
|
|
|
|
|
|
|
|
journalRespDTO.setTotalCommentReply(totalString);
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
totalString = "0";
|
|
|
|
|
|
|
|
Criteria criteria = Criteria.where("journalId").is(journal.getId());
|
|
|
|
|
|
|
|
Aggregation agg = Aggregation.newAggregation(Aggregation.match(criteria), // 匹配条件
|
|
|
|
|
|
|
|
Aggregation.group().sum("commentCount").as("totalComment"));
|
|
|
|
|
|
|
|
AggregationResults<TotalCommentVo> results = mongoTemplate.aggregate(agg, "comment", TotalCommentVo.class);
|
|
|
|
|
|
|
|
TotalCommentVo totalCommentVo = results.getUniqueMappedResult();
|
|
|
|
|
|
|
|
journalRespDTO.setTotalCommentReply("0");
|
|
|
|
|
|
|
|
List<Comment> list = commentDao.findByJournalId(journal.getId());
|
|
|
|
|
|
|
|
int total = 0;
|
|
|
|
|
|
|
|
if (null != list && list.size() > 0) {
|
|
|
|
|
|
|
|
total = list.size();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (null != totalCommentVo) {
|
|
|
|
|
|
|
|
total = total + totalCommentVo.getTotalComment();
|
|
|
|
|
|
|
|
totalString = total +"";
|
|
|
|
|
|
|
|
if (total > 99) {
|
|
|
|
|
|
|
|
totalString = "99+";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
journalRespDTO.setTotalCommentReply(totalString);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return journalRespDTO;
|
|
|
|
return journalRespDTO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -94,7 +146,7 @@ public class JournalMapper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static List<String> getTags(String journalNo) {
|
|
|
|
private static List<String> getTags(String journalNo) {
|
|
|
|
return journalTagMap.getOrDefault(journalNo, DEFAULT_TAGS);
|
|
|
|
return journalTagMap.getOrDefault(journalNo, Collections.emptyList());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static String getEditDate(Journal journal) {
|
|
|
|
private static String getEditDate(Journal journal) {
|
|
|
|