评论
This commit is contained in:
@@ -6,8 +6,10 @@ import com.lovenav.dao.CommentDao;
|
||||
import com.lovenav.dao.UserDao;
|
||||
import com.lovenav.entity.Comment;
|
||||
import com.lovenav.entity.CommentNode;
|
||||
import com.lovenav.entity.CommentUser;
|
||||
import com.lovenav.entity.User;
|
||||
import com.lovenav.service.CommentService;
|
||||
import io.swagger.models.auth.In;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.HashMap;
|
||||
@@ -66,16 +68,10 @@ public class CommentServiceImpl implements CommentService {
|
||||
return JSON.toJSONString(hashMap);
|
||||
}
|
||||
|
||||
// 显示一级评论和用户信息
|
||||
// 显示评论和用户信息
|
||||
public String View_comment(){
|
||||
List<Comment> list_comment = commentDao.selectAllComment();
|
||||
HashMap<Comment, User> result = new HashMap<>();
|
||||
for(int i=0;i<list_comment.size();++i){
|
||||
int user_id = list_comment.get(i).getUserId();
|
||||
User user = userDao.selectByPrimaryKey(user_id);
|
||||
result.put(list_comment.get(i),user );
|
||||
}
|
||||
return JSON.toJSONString(result);
|
||||
return JSON.toJSONString(list_comment);
|
||||
}
|
||||
|
||||
// 显示回复
|
||||
@@ -85,6 +81,54 @@ public class CommentServiceImpl implements CommentService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 功能描述:根据博客id,查询此博客的所有评论信息
|
||||
*
|
||||
* @param UrlId 博客id
|
||||
* @return 博客的评论信息
|
||||
*/
|
||||
@Override
|
||||
public List<CommentNode> queryCommentByUrlId ( Integer UrlId ) {
|
||||
//所有未处理的一级评论集合
|
||||
List<CommentNode> firstCommentList = commentDao.queryFirstCommentList(UrlId);
|
||||
//所有未处理的二级评论集合
|
||||
List<CommentNode> secondCommentList = commentDao.querySecondCommentList(UrlId);
|
||||
//将二级评论用链表的方式添加到一级评论
|
||||
List<CommentNode> list = addAllNode(firstCommentList, secondCommentList);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 功能描述:根据评论id查询用户信息
|
||||
*
|
||||
* @param id 评论id
|
||||
* @return 评论信息,携带用户信息
|
||||
*/
|
||||
@Override
|
||||
public CommentUser queryCommentUserById ( Integer id ) {
|
||||
Comment comment = commentDao.selectByPrimaryKey(id);
|
||||
User user = userDao.selectByPrimaryKey(comment.getUserId());
|
||||
CommentUser commentUser = new CommentUser();
|
||||
commentUser.setComment(comment);
|
||||
commentUser.setUser(user);
|
||||
return commentUser;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 功能描述:将单个node添加到链表中
|
||||
*
|
||||
* @param firstList 第一层评论集合(链表)
|
||||
* @param commentNode 非第一层评论的回复信息
|
||||
* @return 是否添加
|
||||
*/
|
||||
|
||||
private boolean addNode (List<CommentNode> firstList, CommentNode commentNode ) {
|
||||
//循环添加
|
||||
for (CommentNode node : firstList) {
|
||||
@@ -106,7 +150,7 @@ public class CommentServiceImpl implements CommentService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能描述:将查出来的lastId不为null的回复都添加到第一层Node集合中
|
||||
* 功能描述:将查出来的rootId不为null的回复都添加到第一层Node集合中
|
||||
*
|
||||
* @param firstList 第一层评论集合(链表)
|
||||
* @param thenList 非第一层评论集合(链表)
|
||||
@@ -126,14 +170,4 @@ public class CommentServiceImpl implements CommentService {
|
||||
return firstList;
|
||||
}
|
||||
|
||||
public List<CommentNode> queryObserveByBlogId ( Integer UrlId ) {
|
||||
//所有未处理的一级评论集合
|
||||
List<CommentNode> firstCommentList = commentDao.queryFirstCommentList(UrlId);
|
||||
//所有未处理的二级评论集合
|
||||
List<CommentNode> secondCommentList = commentDao.querySecondCommentList(UrlId);
|
||||
|
||||
//将二级评论用链表的方式添加到一级评论
|
||||
List<CommentNode> list = addAllNode(firstCommentList, secondCommentList);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user