Merge remote-tracking branch 'origin/master'

This commit is contained in:
landaiqing 2023-12-25 02:02:42 +08:00
commit ee639e7f4a
5 changed files with 158 additions and 9 deletions

View File

@ -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<Comment> selectAllComment();
List<Comment> selectByAllReply(int id);
List<CommentNode> queryFirstCommentList(int urlid);
List<CommentNode> querySecondCommentList(int UrlId);
}

View File

@ -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 <br>
* 采用链表结构实现
**/
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
public class CommentNode extends Comment {
/**
* 评论的用户信息
*/
private User user;
/**
* 下一条回复
*/
private List<CommentNode> 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();
}
}

View File

@ -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<Comment> list = commentDao.selectAllComment();
return JSON.toJSONString(list);
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);
}
// 显示回复
@ -75,4 +83,57 @@ public class CommentServiceImpl implements CommentService {
List<Comment> list = commentDao.selectByAllReply(id);
return JSON.toJSONString(list);
}
private boolean addNode (List<CommentNode> 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<CommentNode> addAllNode ( List<CommentNode> firstList, List<CommentNode> 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<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,7 +32,7 @@ public class QRCServiceImpl implements QRCService{
List<CollectIconList> 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,11 +45,15 @@ public class QRCServiceImpl implements QRCService{
collectIconListDao.insert(collect);
String base64 = QRCodeUtil.ImageToBase64(url_wait);
return JSON.toJSONString(base64);
}else{
HashMap<String,Object> result = new HashMap<>();
result.put("code",500);
result.put("msg", "找不到对应网址");
return JSON.toJSONString(result);
}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{
String url_wait = list.get(0).getQr_url();

View File

@ -159,4 +159,39 @@
from ln_comment
where root_comment_id = #{rootCommentId,jdbcType=INTEGER} and comment_status = 0
</select>
<select id="queryFirstCommentList" parameterType="java.lang.Integer" resultMap="ResultMap">
SELECT * FROM ln_comment o LEFT JOIN ln_user u
ON o.user_id=u.id
WHERE o.url_id=#{urlId,jdbcType=INTEGER} AND o.root_comment_id is null
</select>
<resultMap id="ResultMap" type="com.lovenav.entity.Comment">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="url_id" jdbcType="INTEGER" property="urlId" />
<result column="user_id" jdbcType="INTEGER" property="userId" />
<result column="content" jdbcType="VARCHAR" property="content" />
<result column="root_comment_id" jdbcType="INTEGER" property="rootCommentId" />
<result column="like_count" jdbcType="BIGINT" property="likeCount" />
<result column="comment_time" jdbcType="TIMESTAMP" property="commentTime" />
<result column="comment_status" jdbcType="TINYINT" property="commentStatus" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="rating" jdbcType="INTEGER" property="rating" />
</resultMap>
<select id="querySecondCommentList" parameterType="java.lang.Integer" resultMap="ResultMap">
SELECT * FROM ln_comment o LEFT JOIN ln_user u
ON o.user_id=u.id
WHERE o.url_id=#{urlId,jdbcType=INTEGER} AND o.root_comment_id is not null
</select>
</mapper>