This commit is contained in:
sjm
2023-12-25 16:09:14 +08:00
parent 1f9388cba4
commit 8efe35f13b
8 changed files with 209 additions and 29 deletions

View File

@@ -1,8 +1,13 @@
package com.lovenav.service;
import com.lovenav.entity.Comment;
import com.lovenav.entity.CommentNode;
import com.lovenav.entity.CommentUser;
import com.lovenav.entity.User;
import org.springframework.stereotype.Service;
import java.util.List;
public interface CommentService {
// 点赞
@@ -17,4 +22,8 @@ public interface CommentService {
String View_comment();
// 显示回复
String View_Reply(int id);
List<CommentNode> queryCommentByUrlId (Integer UrlId );
CommentUser queryCommentUserById(Integer id);
}

View File

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

View File

@@ -32,10 +32,12 @@ public class QRCServiceImpl implements QRCService{
if (list.size() == 0) {
// 如果icon是url
if(QRCodeUtil.notBase64(collect.getIcon_url())){
String icon_url = QRCodeUtil.downloadPicture(collect.getIcon_url());
collect.setIcon_url(icon_url);
String url = urlList.getUrl();
// 将网址生成二维码并返回本地路径
String url = urlList.getUrl();
String url_wait = QRCodeUtil.encode(url, logoPath, destPath, true);
collect.setQr_url(url_wait);
String base64 = QRCodeUtil.ImageToBase64(url_wait);