fix article total CommentReply

main
wangqing 10 months ago
parent 7aa04bdddb
commit aed8faee29

@ -48,7 +48,7 @@ public class ArticleRespDTO implements Serializable {
private String autoPush;
@ApiModelProperty(value = "总评论数,大于99显示99+")
private Long commitsNum;
private Long totalCommentReply;
@ApiModelProperty(value = "总阅览数,大于99显示99+")
private Long vistisNum;
@ -68,7 +68,7 @@ public class ArticleRespDTO implements Serializable {
response.setUserId(article.getUserId());
response.setUserName(article.getUserName());
response.setDate(article.getUpdateTime().format(Constants.formatter));
response.setCommitsNum(article.getComment());
response.setTotalCommentReply(article.getComment());
response.setVistisNum(article.getVisits());
response.setIsScheduled(article.getIsScheduled());
response.setPubTime(article.getPubTime().format(Constants.formatter));

@ -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);
}
}

Loading…
Cancel
Save