diff --git a/luoo_comment/pom.xml b/luoo_comment/pom.xml
index 2671b27..b92079d 100644
--- a/luoo_comment/pom.xml
+++ b/luoo_comment/pom.xml
@@ -21,6 +21,13 @@
org.springframework.boot
spring-boot-starter-data-mongodb
+
+
+ com.spring4all
+ mongodb-plus-spring-boot-starter
+ 1.0.0.RELEASE
+
+
org.springframework.boot
spring-boot-starter-data-redis
diff --git a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java
index 77ec602..b190e4d 100644
--- a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java
+++ b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java
@@ -12,6 +12,8 @@ import dto.UserLoginDto;
import dto.UserMessageDto;
import enums.MessageTypeEnum;
import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils;
@@ -57,8 +59,11 @@ public class CommentController extends BaseController {
* ,页面在请求添加评论的时候,当给评论添加子评论的时候,父评论parentID有值,就无法添加子评论并且不显示回复2字,控制到两级
* @return
*/
- @GetMapping("/{journalId}/{page}/{size}")
@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) {
Page pageData = commentService.findByJournalId(journalId,page,size);
@@ -84,6 +89,7 @@ public class CommentController extends BaseController {
BeanUtils.copyProperties(commentVo, comment);
comment.setUserId(userId);
comment.setNickName(userLoginDto.getNickName());
+ comment.setAvatar(Constants.RESOURCE_PREFIX+userLoginDto.getAvatar());
comment.setLocation(getIpAddr(request));
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}")
public Result findByParentId(@PathVariable String parentId,@PathVariable int page,@PathVariable int size) {
diff --git a/luoo_comment/src/main/java/com/luoo/comment/pojo/Comment.java b/luoo_comment/src/main/java/com/luoo/comment/pojo/Comment.java
index 73a192a..df26ffe 100644
--- a/luoo_comment/src/main/java/com/luoo/comment/pojo/Comment.java
+++ b/luoo_comment/src/main/java/com/luoo/comment/pojo/Comment.java
@@ -21,6 +21,8 @@ public class Comment implements Serializable {
private String nickName;
+ private String avatar;
+
// 点赞数
private Integer thumbupCount;
// 转发数
diff --git a/luoo_comment/target/classes/iplocal/IP2LOCATION-LITE-DB11.BIN b/luoo_comment/target/classes/iplocal/IP2LOCATION-LITE-DB11.BIN
deleted file mode 100644
index ef74243..0000000
Binary files a/luoo_comment/target/classes/iplocal/IP2LOCATION-LITE-DB11.BIN and /dev/null differ
diff --git a/luoo_music/pom.xml b/luoo_music/pom.xml
index 275b800..e6fbef3 100644
--- a/luoo_music/pom.xml
+++ b/luoo_music/pom.xml
@@ -11,7 +11,13 @@
org.springframework.boot
spring-boot-starter-data-mongodb
-
+
+ com.spring4all
+ mongodb-plus-spring-boot-starter
+ 1.0.0.RELEASE
+
+
+
org.springframework.boot
spring-boot-starter-data-jpa
diff --git a/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java b/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java
index d1b3780..b38ab90 100644
--- a/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java
+++ b/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java
@@ -18,13 +18,20 @@ import javax.annotation.PostConstruct;
import com.apifan.common.random.RandomSource;
import com.apifan.common.random.entity.Poem;
+import com.luoo.music.dao.CommentDao;
import com.luoo.music.dao.TagDao;
import com.luoo.music.dto.request.JournalQueryReq;
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.core.io.ClassPathResource;
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 com.luoo.music.pojo.Journal;
import com.luoo.music.pojo.Tag;
@@ -68,6 +75,13 @@ public class JournalController {
@Autowired
private JwtUtil jwtUtil;
+
+ @Autowired
+ private MongoTemplate mongoTemplate;
+
+ @Autowired
+ private CommentDao commentDao;
+
// mock data
private static final String JOURNAL_TAG_FILE_PATH = "journalTags.txt";
private Map> journalTagMap = new HashMap<>();
@@ -172,6 +186,38 @@ public class JournalController {
journalRespDTO.setEditor(editor);
}
+ /**
+ *显示期刊点赞最多5条评论,该五条评论随机显示,每次进入刷新新,超过部分显示为“...”点击评论进入期刊详情页并自动定位到该评论,点击用户头像同上,若为空数据则显示“暂无评论,快去抢沙发吧!
+ */
+
+ List 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 results = mongoTemplate.aggregate(agg,"comment", TotalCommentVo.class);
+ TotalCommentVo totalCommentVo = results.getUniqueMappedResult();
+ journalRespDTO.setTotalCommentReply("0");
+ List 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;
}
diff --git a/luoo_music/src/main/java/com/luoo/music/dao/CommentDao.java b/luoo_music/src/main/java/com/luoo/music/dao/CommentDao.java
new file mode 100644
index 0000000..5568882
--- /dev/null
+++ b/luoo_music/src/main/java/com/luoo/music/dao/CommentDao.java
@@ -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 {
+
+ public Page findByParentId(String parentId, Pageable pageable);
+ public Page findByJournalId(String journalId, Pageable pageable);
+
+ public List findTop5ByJournalIdOrderByThumbupCountDesc(String journalId);
+
+ public List findByJournalId(String journalId);
+
+}
diff --git a/luoo_music/src/main/java/com/luoo/music/dto/response/JournalRespDTO.java b/luoo_music/src/main/java/com/luoo/music/dto/response/JournalRespDTO.java
index 9882678..24cd850 100644
--- a/luoo_music/src/main/java/com/luoo/music/dto/response/JournalRespDTO.java
+++ b/luoo_music/src/main/java/com/luoo/music/dto/response/JournalRespDTO.java
@@ -2,6 +2,7 @@ package com.luoo.music.dto.response;
import java.util.List;
+import com.luoo.music.pojo.Comment;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -27,4 +28,10 @@ public class JournalRespDTO {
private String ipLocation;
@ApiModelProperty(value = "已收藏")
private boolean haveCollect;
+
+ @ApiModelProperty(value = "期刊评论top5")
+ private List commentList;
+
+ @ApiModelProperty(value = "期刊总评论数,大于99,显示99+")
+ private String totalCommentReply;
}
diff --git a/luoo_music/src/main/java/com/luoo/music/dto/response/TotalCommentVo.java b/luoo_music/src/main/java/com/luoo/music/dto/response/TotalCommentVo.java
new file mode 100644
index 0000000..000facf
--- /dev/null
+++ b/luoo_music/src/main/java/com/luoo/music/dto/response/TotalCommentVo.java
@@ -0,0 +1,13 @@
+package com.luoo.music.dto.response;
+
+import lombok.Data;
+
+@Data
+public class TotalCommentVo {
+
+
+
+ private Integer totalComment;
+
+ private String journalId;
+}
diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/Comment.java b/luoo_music/src/main/java/com/luoo/music/pojo/Comment.java
new file mode 100644
index 0000000..0784883
--- /dev/null
+++ b/luoo_music/src/main/java/com/luoo/music/pojo/Comment.java
@@ -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;
+}
diff --git a/luoo_user/pom.xml b/luoo_user/pom.xml
index a388fc2..c5d4f03 100644
--- a/luoo_user/pom.xml
+++ b/luoo_user/pom.xml
@@ -13,6 +13,11 @@
org.springframework.boot
spring-boot-starter-data-mongodb
+
+ com.spring4all
+ mongodb-plus-spring-boot-starter
+ 1.0.0.RELEASE
+
org.springframework.boot
spring-boot-starter-data-jpa
diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/Comment.java b/luoo_user/src/main/java/com/luoo/user/pojo/Comment.java
index 75f41ae..6f90cce 100644
--- a/luoo_user/src/main/java/com/luoo/user/pojo/Comment.java
+++ b/luoo_user/src/main/java/com/luoo/user/pojo/Comment.java
@@ -21,6 +21,8 @@ public class Comment implements Serializable {
private String nickName;
+ private String avatar;
+
// 点赞数
private Integer thumbupCount;
// 转发数