From 48954ddb04d3d288f5b103edefbdb556a081548e Mon Sep 17 00:00:00 2001 From: sjm <2431685932@qq.com> Date: Sun, 24 Dec 2023 23:07:41 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=B8=80=E7=BA=A7?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E5=92=8C=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/lovenav/dao/CommentDao.java | 5 ++ .../serviceImpl/CommentServiceImpl.java | 67 ++++++++++++++++++- .../service/serviceImpl/QRCServiceImpl.java | 14 +++- src/main/resources/mybatis/CommentDao.xml | 35 ++++++++++ 4 files changed, 116 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/lovenav/dao/CommentDao.java b/src/main/java/com/lovenav/dao/CommentDao.java index 3bc1f61..c27d800 100644 --- a/src/main/java/com/lovenav/dao/CommentDao.java +++ b/src/main/java/com/lovenav/dao/CommentDao.java @@ -1,12 +1,14 @@ package com.lovenav.dao; import com.lovenav.entity.Comment; +import com.lovenav.entity.CommentNode; import org.apache.ibatis.annotations.Mapper; import org.mybatis.spring.annotation.MapperScan; import org.springframework.stereotype.Repository; import java.util.List; + @Repository @Mapper public interface CommentDao { @@ -25,4 +27,7 @@ public interface CommentDao { List selectAllComment(); List selectByAllReply(int id); + List queryFirstCommentList(int urlid); + + List querySecondCommentList(int UrlId); } \ No newline at end of file diff --git a/src/main/java/com/lovenav/service/serviceImpl/CommentServiceImpl.java b/src/main/java/com/lovenav/service/serviceImpl/CommentServiceImpl.java index d82491b..096e4bf 100644 --- a/src/main/java/com/lovenav/service/serviceImpl/CommentServiceImpl.java +++ b/src/main/java/com/lovenav/service/serviceImpl/CommentServiceImpl.java @@ -5,6 +5,8 @@ import com.alibaba.fastjson2.JSONObject; import com.lovenav.dao.CommentDao; import com.lovenav.dao.UserDao; import com.lovenav.entity.Comment; +import com.lovenav.entity.CommentNode; +import com.lovenav.entity.User; import com.lovenav.service.CommentService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -64,10 +66,16 @@ public class CommentServiceImpl implements CommentService { return JSON.toJSONString(hashMap); } -// 显示评论 +// 显示一级评论和用户信息 public String View_comment(){ - List list = commentDao.selectAllComment(); - return JSON.toJSONString(list); + List list_comment = commentDao.selectAllComment(); + HashMap result = new HashMap<>(); + for(int i=0;i list = commentDao.selectByAllReply(id); return JSON.toJSONString(list); } + + + private boolean addNode (List firstList, CommentNode commentNode ) { + //循环添加 + for (CommentNode node : firstList) { + //判断留言的上一段是否是这条留言(判断这条回复,是否是当前评论的回复) + if (node.getId().equals(commentNode.getRootCommentId())) { + //是,添加,返回true + node.getNextNodes().add(commentNode); + return true; + } else { + //否则递归继续判断 + if (node.getNextNodes().size() != 0) { + if (addNode(node.getNextNodes(), commentNode)) { + return true; + } + } + } + } + return false; + } + + /** + * 功能描述:将查出来的lastId不为null的回复都添加到第一层Node集合中 + * + * @param firstList 第一层评论集合(链表) + * @param thenList 非第一层评论集合(链表) + * @return 所有评论集合(非第一层评论集合对应添加到第一层评论集合,返回) + */ + private List addAllNode ( List firstList, List thenList ) { + while (thenList.size() != 0) { + int size = thenList.size(); + for (int i = 0; i < size; i++) { + if (addNode(firstList, new CommentNode(thenList.get(i)))) { + thenList.remove(i); + i--; + size--; + } + } + } + return firstList; + } + + public List queryObserveByBlogId ( Integer UrlId ) { + //所有未处理的一级评论集合 + List firstCommentList = commentDao.queryFirstCommentList(UrlId); + //所有未处理的二级评论集合 + List secondCommentList = commentDao.querySecondCommentList(UrlId); + + //将二级评论用链表的方式添加到一级评论 + List list = addAllNode(firstCommentList, secondCommentList); + return list; + } } diff --git a/src/main/java/com/lovenav/service/serviceImpl/QRCServiceImpl.java b/src/main/java/com/lovenav/service/serviceImpl/QRCServiceImpl.java index b4b1373..e409851 100644 --- a/src/main/java/com/lovenav/service/serviceImpl/QRCServiceImpl.java +++ b/src/main/java/com/lovenav/service/serviceImpl/QRCServiceImpl.java @@ -32,7 +32,7 @@ public class QRCServiceImpl implements QRCService{ List list = collectIconListDao.selectByUrlid(collect.getUrl_id()); if(list.size()==0){ - if(urlList != null){ + if(urlList != null && collect.getIcon_url()!=null){ // 将icon下载到本地并存储本地路径 String icon_url = QRCodeUtil.downloadPicture(collect.getIcon_url()); collect.setIcon_url(icon_url); @@ -45,7 +45,17 @@ public class QRCServiceImpl implements QRCService{ collectIconListDao.insert(collect); String base64 = QRCodeUtil.ImageToBase64(url_wait); return JSON.toJSONString(base64); - }else{ + }else if(urlList != null && collect.getIcon_url()==null){ +// 获取网址url + String url = urlList.getUrl(); + String url_wait = QRCodeUtil.encode(url, logoPath, destPath, true); +// 为collect设置二维码本地路径 + collect.setQr_url(url_wait); + collectIconListDao.insert(collect); + String base64 = QRCodeUtil.ImageToBase64(url_wait); + return JSON.toJSONString(base64); + } + else{ HashMap result = new HashMap<>(); result.put("code",500); result.put("msg", "找不到对应网址"); diff --git a/src/main/resources/mybatis/CommentDao.xml b/src/main/resources/mybatis/CommentDao.xml index 12f7f52..39cdf8c 100644 --- a/src/main/resources/mybatis/CommentDao.xml +++ b/src/main/resources/mybatis/CommentDao.xml @@ -159,4 +159,39 @@ from ln_comment where root_comment_id = #{rootCommentId,jdbcType=INTEGER} and comment_status = 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From c48b8e000c3c446ae6ae1ce73c91a0402b6307d3 Mon Sep 17 00:00:00 2001 From: sjm <2431685932@qq.com> Date: Sun, 24 Dec 2023 23:12:15 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=B8=80=E7=BA=A7?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E5=92=8C=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/lovenav/entity/CommentNode.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/main/java/com/lovenav/entity/CommentNode.java diff --git a/src/main/java/com/lovenav/entity/CommentNode.java b/src/main/java/com/lovenav/entity/CommentNode.java new file mode 100644 index 0000000..ff7d1bb --- /dev/null +++ b/src/main/java/com/lovenav/entity/CommentNode.java @@ -0,0 +1,44 @@ +package com.lovenav.entity; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.ArrayList; +import java.util.List; + +/** + * 功能描述:封装博客评论的BO
+ * 采用链表结构实现 + **/ +@EqualsAndHashCode(callSuper = true) +@Data +@NoArgsConstructor +public class CommentNode extends Comment { + + /** + * 评论的用户信息 + */ + private User user; + + /** + * 下一条回复 + */ + private List nextNodes = new ArrayList<>(); + + public CommentNode ( CommentNode commentNode ) { + super(); + setId(commentNode.getId()); + setUrlId(commentNode.getUrlId()); + setUserId(commentNode.getUserId()); + setContent(commentNode.getContent()); + setRootCommentId(commentNode.getRootCommentId()); + setCommentStatus(commentNode.getCommentStatus()); + setCommentTime(commentNode.getCommentTime()); + setUpdateTime(commentNode.getUpdateTime()); + setRating(commentNode.getRating()); + setLikeCount(commentNode.getLikeCount()); + this.user = commentNode.getUser(); + } +} From 812b226943e089f2a0a3e4d12e56d3ffb87b39c4 Mon Sep 17 00:00:00 2001 From: sjm <2431685932@qq.com> Date: Mon, 25 Dec 2023 01:13:02 +0800 Subject: [PATCH 3/3] QRC --- .../com/lovenav/service/serviceImpl/QRCServiceImpl.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/com/lovenav/service/serviceImpl/QRCServiceImpl.java b/src/main/java/com/lovenav/service/serviceImpl/QRCServiceImpl.java index e409851..5a74bcd 100644 --- a/src/main/java/com/lovenav/service/serviceImpl/QRCServiceImpl.java +++ b/src/main/java/com/lovenav/service/serviceImpl/QRCServiceImpl.java @@ -55,12 +55,6 @@ public class QRCServiceImpl implements QRCService{ String base64 = QRCodeUtil.ImageToBase64(url_wait); return JSON.toJSONString(base64); } - else{ - HashMap result = new HashMap<>(); - result.put("code",500); - result.put("msg", "找不到对应网址"); - return JSON.toJSONString(result); - } }else{ String url_wait = list.get(0).getQr_url(); String base64 = QRCodeUtil.ImageToBase64(url_wait);