feat:my available comment detail list

main
wangqing 10 months ago
parent 6d67d4d60b
commit e8ff3810af

@ -0,0 +1,8 @@
package com.luoo.comment.dao;
import com.luoo.comment.pojo.CommentHis;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface CommentHisDao extends MongoRepository<CommentHis,String> {
}

@ -46,5 +46,7 @@ public class Comment implements Serializable {
private String journalId;
private String journalImage;
private boolean haveThumbup;
}

@ -0,0 +1,42 @@
package com.luoo.comment.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Data
public class CommentHis {
@Id
private String _id;
private String userId; // 被评论人userid;
private String content; // 被评论的内容;
private String commenterId; // 评论人userId
private String commenterAvatar; // 评论人头像
private String commentContent; //评论的内容
private String nickName; // 评论人昵称
private String journalId; // 期刊ID
private String journalImage; // 期刊封面
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
}

@ -14,4 +14,6 @@ public class CommentVo {
private String parentId;
private String journalId;
private String journalImage;
}

@ -2,7 +2,9 @@ package com.luoo.comment.service;
import com.luoo.comment.dao.CommentDao;
import com.luoo.comment.dao.CommentHisDao;
import com.luoo.comment.pojo.Comment;
import com.luoo.comment.pojo.CommentHis;
import constants.Constants;
import dto.UserLoginDto;
import dto.UserMessageDto;
@ -24,12 +26,14 @@ import java.util.Date;
import java.util.List;
@Service
@Transactional
public class CommentService {
@Autowired
private CommentDao commentDao;
@Autowired
private CommentHisDao commentHisDao;
@Autowired
private IdWorker idWorker;
@ -56,6 +60,20 @@ public class CommentService {
// 如果当前添加的评论,有父节点,那么父节点的评论回复数要加一
if (comment.getParentId()!=null && !"".equals(comment.getParentId())){
Comment parentComment = commentDao.findById(comment.getParentId()).get();
CommentHis commentHis = new CommentHis();
commentHis.set_id(idWorker.nextId()+"");
commentHis.setCommenterId(userLoginDto.getUserId());
commentHis.setUserId(parentComment.getUserId());
commentHis.setNickName(userLoginDto.getNickName());
commentHis.setCommentContent(comment.getContent());
commentHis.setContent(parentComment.getContent());
commentHis.setCommenterAvatar(Constants.RESOURCE_PREFIX+userLoginDto.getAvatar());
commentHis.setJournalId(parentComment.getJournalId());
commentHis.setJournalImage(parentComment.getJournalImage());
commentHis.setCreateTime(new Date());
commentHisDao.save(commentHis);
comment.setJournalId("");//如果有父节点,将期刊号置为空
Query query = new Query();
@ -64,7 +82,8 @@ public class CommentService {
update.inc("commentCount",1);
mongoTemplate.updateFirst(query,update,"comment");
Comment parentComment = commentDao.findById(comment.getParentId()).get();
/**
*
*/
@ -77,6 +96,9 @@ public class CommentService {
userMessageDto.setSendUserId(userLoginDto.getUserId());
userMessageDto.setSendUserNickName(userLoginDto.getNickName());
rabbitTemplate.convertAndSend("userMessage",userMessageDto);
}
commentDao.save(comment);

@ -9,9 +9,7 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import com.luoo.user.dto.TotalCommentVo;
import com.luoo.user.pojo.Feedback;
import com.luoo.user.pojo.PublicationLike;
import com.luoo.user.pojo.UserCollectInfo;
import com.luoo.user.pojo.*;
import com.luoo.user.service.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -38,7 +36,6 @@ import controller.BaseController;
import com.luoo.user.dto.UserInfoUpdateDto;
import com.luoo.user.dto.response.UserRespDTO;
import com.luoo.user.pojo.UserInfo;
import com.luoo.user.util.IpUtil;
import annotation.GlobalInterceptor;
@ -341,8 +338,8 @@ public class MyController extends BaseController {
return Result.unauthorized(null);
}
String userId = userLoginDto.getUserId();
myService.getMyCommentReplyList(userId);
return null;
Page<CommentHis> pageList = myService.getMyCommentReplyList(userId,page,size);
return Result.success(new PageResult<CommentHis>(pageList.getTotalElements(),pageList.getContent()));
}

@ -0,0 +1,13 @@
package com.luoo.user.dao;
import com.luoo.user.pojo.CommentHis;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface CommentHisDao extends MongoRepository<CommentHis,String> {
public Page<CommentHis> findByUserIdOrderByCreateTimeDesc(String userId, Pageable pageable);
}

@ -0,0 +1,42 @@
package com.luoo.user.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Data
public class CommentHis {
@Id
private String _id;
private String userId; // 被评论人userid;
private String content; // 被评论的内容;
private String commenterId; // 评论人userId
private String commenterAvatar; // 评论人头像
private String commentContent; //评论的内容
private String nickName; // 评论人昵称
private String journalId; // 期刊ID
private String journalImage; // 期刊封面
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
}

@ -1,7 +1,9 @@
package com.luoo.user.service;
import com.luoo.user.dao.CommentHisDao;
import com.luoo.user.dao.PublicationLikeDao;
import com.luoo.user.pojo.CommentHis;
import com.luoo.user.pojo.PublicationLike;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@ -13,19 +15,23 @@ import org.springframework.stereotype.Service;
@Service
public class MyService {
@Autowired
private MongoTemplate mongoTemplate;
@Autowired
private PublicationLikeDao publicationLikeDao;
@Autowired
private CommentHisDao commentHisDao;
/**
*
* @param userId
*/
public void getMyCommentReplyList(String userId) {
public Page<CommentHis> getMyCommentReplyList(String userId, int page, int size) {
Pageable pageable = PageRequest.of(page-1,size);
return commentHisDao.findByUserIdOrderByCreateTimeDesc(userId,pageable);
}

Loading…
Cancel
Save