add comment info to journal List

main
wangqing 10 months ago
parent f84f7047c4
commit fd9a0d2929

@ -21,6 +21,13 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId> <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>mongodb-plus-spring-boot-starter</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId> <artifactId>spring-boot-starter-data-redis</artifactId>

@ -12,6 +12,8 @@ import dto.UserLoginDto;
import dto.UserMessageDto; import dto.UserMessageDto;
import enums.MessageTypeEnum; import enums.MessageTypeEnum;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
@ -57,8 +59,11 @@ public class CommentController extends BaseController {
* ,parentID2 * ,parentID2
* @return * @return
*/ */
@GetMapping("/{journalId}/{page}/{size}")
@ApiOperation(value = "根据期刊ID获取分布评论列表",notes = "根据期刊ID获取根节点评论分页列表 数据库中保存的有期刊号的都是根节点期刊号为空的代表有父评论且parentID一定有值拿到当然根节点评论列表每个根评论有 commentCount字段页面可以显示有 280个回复然后根据 @GetMapping(\"/comment/{parentId}/{page}/{size}\") 接口分页拿到该评论下的子评论列表页面在请求添加评论的时候当给评论添加子评论的时候父评论parentID有值就无法添加子评论并且不显示回复2字控制到两级") @ApiOperation(value = "根据期刊ID获取分布评论列表",notes = "根据期刊ID获取根节点评论分页列表 数据库中保存的有期刊号的都是根节点期刊号为空的代表有父评论且parentID一定有值拿到当然根节点评论列表每个根评论有 commentCount字段页面可以显示有 280个回复然后根据 @GetMapping(\"/comment/{parentId}/{page}/{size}\") 接口分页拿到该评论下的子评论列表页面在请求添加评论的时候当给评论添加子评论的时候父评论parentID有值就无法添加子评论并且不显示回复2字控制到两级")
@ApiImplicitParams({@ApiImplicitParam(name = "journalId", value = "剘刊id", required = true),
@ApiImplicitParam(name = "page", value = "分页: 页码以1开始", required = true),
@ApiImplicitParam(name = "size", value = "分页: 每页数量", required = true)})
@GetMapping("/{journalId}/{page}/{size}")
public Result findAllByJournalId(@PathVariable String journalId,@PathVariable int page,@PathVariable int size) { public Result findAllByJournalId(@PathVariable String journalId,@PathVariable int page,@PathVariable int size) {
Page<Comment> pageData = commentService.findByJournalId(journalId,page,size); Page<Comment> pageData = commentService.findByJournalId(journalId,page,size);
@ -84,6 +89,7 @@ public class CommentController extends BaseController {
BeanUtils.copyProperties(commentVo, comment); BeanUtils.copyProperties(commentVo, comment);
comment.setUserId(userId); comment.setUserId(userId);
comment.setNickName(userLoginDto.getNickName()); comment.setNickName(userLoginDto.getNickName());
comment.setAvatar(Constants.RESOURCE_PREFIX+userLoginDto.getAvatar());
comment.setLocation(getIpAddr(request)); comment.setLocation(getIpAddr(request));
commentService.save(comment,userLoginDto); commentService.save(comment,userLoginDto);
@ -107,6 +113,10 @@ public class CommentController extends BaseController {
@ApiOperation(value = "获取评论下的子评论列表")
@ApiImplicitParams({@ApiImplicitParam(name = "parentId", value = "父评论id", required = true),
@ApiImplicitParam(name = "page", value = "分页: 页码以1开始", required = true),
@ApiImplicitParam(name = "size", value = "分页: 每页数量", required = true)})
@GetMapping("/comment/{parentId}/{page}/{size}") @GetMapping("/comment/{parentId}/{page}/{size}")
public Result findByParentId(@PathVariable String parentId,@PathVariable int page,@PathVariable int size) { public Result findByParentId(@PathVariable String parentId,@PathVariable int page,@PathVariable int size) {

@ -21,6 +21,8 @@ public class Comment implements Serializable {
private String nickName; private String nickName;
private String avatar;
// 点赞数 // 点赞数
private Integer thumbupCount; private Integer thumbupCount;
// 转发数 // 转发数

@ -11,6 +11,12 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId> <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>mongodb-plus-spring-boot-starter</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>

@ -18,13 +18,20 @@ import javax.annotation.PostConstruct;
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.TagDao; import com.luoo.music.dao.TagDao;
import com.luoo.music.dto.request.JournalQueryReq; import com.luoo.music.dto.request.JournalQueryReq;
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 org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
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.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.luoo.music.pojo.Journal; import com.luoo.music.pojo.Journal;
import com.luoo.music.pojo.Tag; import com.luoo.music.pojo.Tag;
@ -68,6 +75,13 @@ public class JournalController {
@Autowired @Autowired
private JwtUtil jwtUtil; private JwtUtil jwtUtil;
@Autowired
private MongoTemplate mongoTemplate;
@Autowired
private CommentDao commentDao;
// mock data // mock data
private static final String JOURNAL_TAG_FILE_PATH = "journalTags.txt"; private static final String JOURNAL_TAG_FILE_PATH = "journalTags.txt";
private Map<String, List<String>> journalTagMap = new HashMap<>(); private Map<String, List<String>> journalTagMap = new HashMap<>();
@ -172,6 +186,38 @@ public class JournalController {
journalRespDTO.setEditor(editor); journalRespDTO.setEditor(editor);
} }
/**
*5...
*/
List<Comment> commentList = commentDao.findTop5ByJournalIdOrderByThumbupCountDesc(journal.getId());
journalRespDTO.setCommentList(commentList);
/**
*
*/
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();
journalRespDTO.setTotalCommentReply(total+"");
if (total>99) {
journalRespDTO.setTotalCommentReply("99+");
}
}
return journalRespDTO; return journalRespDTO;
} }

@ -0,0 +1,19 @@
package com.luoo.music.dao;
import com.luoo.music.pojo.Comment;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List;
public interface CommentDao extends MongoRepository<Comment,String> {
public Page<Comment> findByParentId(String parentId, Pageable pageable);
public Page<Comment> findByJournalId(String journalId, Pageable pageable);
public List<Comment> findTop5ByJournalIdOrderByThumbupCountDesc(String journalId);
public List<Comment> findByJournalId(String journalId);
}

@ -2,6 +2,7 @@ package com.luoo.music.dto.response;
import java.util.List; import java.util.List;
import com.luoo.music.pojo.Comment;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@ -27,4 +28,10 @@ public class JournalRespDTO {
private String ipLocation; private String ipLocation;
@ApiModelProperty(value = "已收藏") @ApiModelProperty(value = "已收藏")
private boolean haveCollect; private boolean haveCollect;
@ApiModelProperty(value = "期刊评论top5")
private List<Comment> commentList;
@ApiModelProperty(value = "期刊总评论数,大于99显示99+")
private String totalCommentReply;
} }

@ -0,0 +1,13 @@
package com.luoo.music.dto.response;
import lombok.Data;
@Data
public class TotalCommentVo {
private Integer totalComment;
private String journalId;
}

@ -0,0 +1,44 @@
package com.luoo.music.pojo;
import lombok.Data;
import org.springframework.data.annotation.Id;
import java.io.Serializable;
import java.util.Date;
@Data
public class Comment implements Serializable {
@Id
private String _id;
// 评论内容
private String content;
// 发布时间
private Date publishTime;
private String userId;
private String nickName;
private String avatar;
// 点赞数
private Integer thumbupCount;
// 转发数
// private Integer share;
// 评论数量
private Integer commentCount;
// 状态
private Integer state;
private String location; //归属地
/**
* ID
*/
private String parentId;
private String journalId;
}

@ -13,6 +13,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId> <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>mongodb-plus-spring-boot-starter</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>

@ -21,6 +21,8 @@ public class Comment implements Serializable {
private String nickName; private String nickName;
private String avatar;
// 点赞数 // 点赞数
private Integer thumbupCount; private Integer thumbupCount;
// 转发数 // 转发数

Loading…
Cancel
Save