|
|
|
@ -5,8 +5,10 @@ import api.Result;
|
|
|
|
|
import com.luoo.music.client.UserClient;
|
|
|
|
|
import com.luoo.music.dao.*;
|
|
|
|
|
import com.luoo.music.dto.request.cms.ArticleAddModel;
|
|
|
|
|
import com.luoo.music.dto.response.TotalCommentVo;
|
|
|
|
|
import com.luoo.music.dto.response.cms.ArticleRespDTO;
|
|
|
|
|
import com.luoo.music.pojo.Article;
|
|
|
|
|
import com.luoo.music.pojo.Comment;
|
|
|
|
|
import com.luoo.music.pojo.UserInfo;
|
|
|
|
|
import com.luoo.music.util.Constants;
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
@ -16,6 +18,10 @@ import org.springframework.data.domain.ExampleMatcher;
|
|
|
|
|
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.mongodb.core.aggregation.Aggregation;
|
|
|
|
|
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
|
|
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import util.IdWorker;
|
|
|
|
@ -43,6 +49,13 @@ public class CMSArticleService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserClient userClient;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MongoTemplate mongoTemplate;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private CommentDao commentDao;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Result add(ArticleAddModel paramAdd) {
|
|
|
|
|
String image = null;
|
|
|
|
|
if (StringUtils.isNotBlank(paramAdd.getImage())) {
|
|
|
|
@ -210,6 +223,35 @@ public class CMSArticleService {
|
|
|
|
|
return Result.success(null);
|
|
|
|
|
}else {
|
|
|
|
|
ArticleRespDTO response = ArticleRespDTO.convertPojo(article);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取文章总评论数 一级评论数加上父评论的总回复数
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
String totalString = "0";
|
|
|
|
|
|
|
|
|
|
totalString = "0";
|
|
|
|
|
Criteria criteria = Criteria.where("journalId").is(article.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();
|
|
|
|
|
// commentDTO.setTotalCommentReply("0");
|
|
|
|
|
List<Comment> list = commentDao.findByJournalId(article.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+";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
response.setTotalCommentReply(Long.valueOf(total));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Result.success(response);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|