评论
This commit is contained in:
parent
1f9388cba4
commit
8efe35f13b
@ -1,10 +1,17 @@
|
|||||||
package com.lovenav.controller;
|
package com.lovenav.controller;
|
||||||
|
|
||||||
import com.lovenav.entity.Comment;
|
import com.lovenav.entity.Comment;
|
||||||
|
import com.lovenav.entity.CommentNode;
|
||||||
|
import com.lovenav.entity.CommentUser;
|
||||||
import com.lovenav.service.CommentService;
|
import com.lovenav.service.CommentService;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
import io.swagger.models.auth.In;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/comment")
|
@RequestMapping("/comment")
|
||||||
@ -34,13 +41,40 @@ public class CommentController {
|
|||||||
|
|
||||||
// 显示评论
|
// 显示评论
|
||||||
@RequestMapping(method = RequestMethod.GET, value = "/view_comment")
|
@RequestMapping(method = RequestMethod.GET, value = "/view_comment")
|
||||||
public String View_comment(){
|
public ResponseEntity<List<CommentNode>> queryObserveByBlogId (
|
||||||
return commentService.View_comment();
|
@ApiParam(name = "url_id", value = "id", required = true) @PathVariable Integer url_id
|
||||||
}
|
) {
|
||||||
|
return ResponseEntity.ok(commentService.queryCommentByUrlId(url_id));
|
||||||
|
}
|
||||||
|
|
||||||
// 显示回复
|
// 显示回复
|
||||||
@RequestMapping(method = RequestMethod.GET, value = "/view_reply")
|
@RequestMapping(method = RequestMethod.GET, value = "/view_reply")
|
||||||
public String View_reply(int id){
|
public String View_reply(int id){
|
||||||
return commentService.View_Reply(id);
|
return commentService.View_Reply(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 功能描述:根据博客id,查询此博客的所有评论信息(链表类型的数据)
|
||||||
|
* @param UrlId 博客id
|
||||||
|
* @return 博客的评论信息
|
||||||
|
*/
|
||||||
|
@GetMapping("/UrlId")
|
||||||
|
public ResponseEntity<List<CommentNode>> queryCommentByUrlId (
|
||||||
|
@ApiParam(name = "UrlId", value = "urlid", required = true) @PathVariable Integer UrlId
|
||||||
|
) {
|
||||||
|
return ResponseEntity.ok(commentService.queryCommentByUrlId(UrlId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 功能描述:根据评论id查询用户信息(评论信息,携带用户信息)
|
||||||
|
* @param Id 评论id
|
||||||
|
* @return 评论信息,携带用户信息
|
||||||
|
*/
|
||||||
|
@GetMapping("/Id")
|
||||||
|
public ResponseEntity<CommentUser> queryObserveUserById (
|
||||||
|
@ApiParam(name = "Id", value = "评论id", required = true)@PathVariable Integer Id
|
||||||
|
) {
|
||||||
|
return ResponseEntity.ok(commentService.queryCommentUserById(Id));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,8 @@ package com.lovenav.dao;
|
|||||||
|
|
||||||
import com.lovenav.entity.Comment;
|
import com.lovenav.entity.Comment;
|
||||||
import com.lovenav.entity.CommentNode;
|
import com.lovenav.entity.CommentNode;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.*;
|
||||||
|
import org.apache.ibatis.mapping.FetchType;
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@ -27,7 +28,55 @@ public interface CommentDao {
|
|||||||
List<Comment> selectAllComment();
|
List<Comment> selectAllComment();
|
||||||
|
|
||||||
List<Comment> selectByAllReply(int id);
|
List<Comment> selectByAllReply(int id);
|
||||||
List<CommentNode> queryFirstCommentList(int urlid);
|
|
||||||
|
|
||||||
List<CommentNode> querySecondCommentList(int UrlId);
|
@Select("SELECT * FROM ln_comment o LEFT JOIN ln_user u"+
|
||||||
|
"ON o.user_id=u.id"+
|
||||||
|
"WHERE o.user_id = #{userId,jdbcType=INTEGER} AND o.root_comment_id = 0")
|
||||||
|
@Results({
|
||||||
|
@Result(id = true, column = "id", property = "id"),
|
||||||
|
@Result(column = "url_id", property = "urlId"),
|
||||||
|
@Result(column = "user_id", property = "userId"),
|
||||||
|
@Result(column = "content", property = "content"),
|
||||||
|
@Result(column = "content", property = "user",
|
||||||
|
one = @One(select = "com.lovenav.dao.UserDao.queryUserForComment",
|
||||||
|
fetchType = FetchType.EAGER)),
|
||||||
|
@Result(column = "root_comment_id", property = "rootCommentId"),
|
||||||
|
@Result(column = "comment_status", property = "commentStatus"),
|
||||||
|
@Result(column = "comment_time", property = "commentTime"),
|
||||||
|
@Result(column = "update_time", property = "updateTime"),
|
||||||
|
@Result(column = "like_count", property = "likeCount"),
|
||||||
|
@Result(column = "rating", property = "rating")
|
||||||
|
|
||||||
|
})
|
||||||
|
List<CommentNode> queryFirstCommentList (@Param("urlId") Integer UrlId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 功能描述:根据博客id和lastId不为空,查询所有的二级评论信息集合
|
||||||
|
* @param UrlId 博客id
|
||||||
|
* @return 二级评论信息集合
|
||||||
|
* @author RenShiWei
|
||||||
|
* Date: 2020/4/16 10:37
|
||||||
|
*/
|
||||||
|
@Select("SELECT * FROM ln_comment o LEFT JOIN ln_user u " +
|
||||||
|
"ON o.user_id=u.id " +
|
||||||
|
"WHERE o.user_id = #{userId,jdbcType=INTEGER} AND o.last_id != 0 ")
|
||||||
|
@Results({
|
||||||
|
@Result(id = true, column = "id", property = "id"),
|
||||||
|
@Result(column = "url_id", property = "urlId"),
|
||||||
|
@Result(column = "user_id", property = "userId"),
|
||||||
|
@Result(column = "content", property = "content"),
|
||||||
|
@Result(column = "content", property = "user",
|
||||||
|
one = @One(select = "com.lovenav.dao.UserDao.queryUserForComment",
|
||||||
|
fetchType = FetchType.EAGER)),
|
||||||
|
@Result(column = "root_comment_id", property = "rootCommentId"),
|
||||||
|
@Result(column = "comment_status", property = "commentStatus"),
|
||||||
|
@Result(column = "comment_time", property = "commentTime"),
|
||||||
|
@Result(column = "update_time", property = "updateTime"),
|
||||||
|
@Result(column = "like_count", property = "likeCount"),
|
||||||
|
@Result(column = "rating", property = "rating")
|
||||||
|
|
||||||
|
})
|
||||||
|
List<CommentNode> querySecondCommentList(@Param("urlId")Integer UrlId);
|
||||||
}
|
}
|
@ -1,9 +1,8 @@
|
|||||||
package com.lovenav.dao;
|
package com.lovenav.dao;
|
||||||
|
|
||||||
import com.lovenav.entity.User;
|
import com.lovenav.entity.User;
|
||||||
import org.apache.ibatis.annotations.MapKey;
|
import io.swagger.models.auth.In;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.*;
|
||||||
import org.apache.ibatis.annotations.Select;
|
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -32,4 +31,28 @@ public interface UserDao {
|
|||||||
@MapKey("id")
|
@MapKey("id")
|
||||||
HashMap<Integer,Object> selectAllUsers();
|
HashMap<Integer,Object> selectAllUsers();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 功能描述:根据主键id查询用户信息
|
||||||
|
* (在observe中一对一关系使用)
|
||||||
|
*
|
||||||
|
* @param id 用户id
|
||||||
|
* @return 用户信息
|
||||||
|
* @author RenShiWei
|
||||||
|
* Date: 2020/4/16 10:43
|
||||||
|
*/
|
||||||
|
@Select("SELECT * FROM ln_user WHERE id=#{id}")
|
||||||
|
@Results({
|
||||||
|
@Result(id = true, column = "id", property = "id"),
|
||||||
|
@Result(column = "root_comment_id", property = "rootCommentId"),
|
||||||
|
@Result(column = "comment_status", property = "commentStatus"),
|
||||||
|
@Result(column = "comment_time", property = "commentTime"),
|
||||||
|
@Result(column = "update_time", property = "updateTime"),
|
||||||
|
@Result(column = "like_count", property = "likeCount"),
|
||||||
|
@Result(column = "rating", property = "rating")
|
||||||
|
|
||||||
|
})
|
||||||
|
User queryUserForComment (@Param("id") Integer id );
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -143,5 +143,8 @@ public class Comment implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Integer rating;
|
private Integer rating;
|
||||||
|
|
||||||
|
public interface UpdateGroup {
|
||||||
|
}
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
}
|
}
|
26
src/main/java/com/lovenav/entity/CommentUser.java
Normal file
26
src/main/java/com/lovenav/entity/CommentUser.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package com.lovenav.entity;
|
||||||
|
|
||||||
|
public class CommentUser {
|
||||||
|
/**
|
||||||
|
* 评论的用户信息
|
||||||
|
*/
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
private Comment comment;
|
||||||
|
|
||||||
|
public Comment getComment() {
|
||||||
|
return comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setComment(Comment comment) {
|
||||||
|
this.comment = comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(User user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,13 @@
|
|||||||
package com.lovenav.service;
|
package com.lovenav.service;
|
||||||
|
|
||||||
import com.lovenav.entity.Comment;
|
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 org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
public interface CommentService {
|
public interface CommentService {
|
||||||
// 点赞
|
// 点赞
|
||||||
@ -17,4 +22,8 @@ public interface CommentService {
|
|||||||
String View_comment();
|
String View_comment();
|
||||||
// 显示回复
|
// 显示回复
|
||||||
String View_Reply(int id);
|
String View_Reply(int id);
|
||||||
|
|
||||||
|
List<CommentNode> queryCommentByUrlId (Integer UrlId );
|
||||||
|
|
||||||
|
CommentUser queryCommentUserById(Integer id);
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,10 @@ import com.lovenav.dao.CommentDao;
|
|||||||
import com.lovenav.dao.UserDao;
|
import com.lovenav.dao.UserDao;
|
||||||
import com.lovenav.entity.Comment;
|
import com.lovenav.entity.Comment;
|
||||||
import com.lovenav.entity.CommentNode;
|
import com.lovenav.entity.CommentNode;
|
||||||
|
import com.lovenav.entity.CommentUser;
|
||||||
import com.lovenav.entity.User;
|
import com.lovenav.entity.User;
|
||||||
import com.lovenav.service.CommentService;
|
import com.lovenav.service.CommentService;
|
||||||
|
import io.swagger.models.auth.In;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -66,16 +68,10 @@ public class CommentServiceImpl implements CommentService {
|
|||||||
return JSON.toJSONString(hashMap);
|
return JSON.toJSONString(hashMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 显示一级评论和用户信息
|
// 显示评论和用户信息
|
||||||
public String View_comment(){
|
public String View_comment(){
|
||||||
List<Comment> list_comment = commentDao.selectAllComment();
|
List<Comment> list_comment = commentDao.selectAllComment();
|
||||||
HashMap<Comment, User> result = new HashMap<>();
|
return JSON.toJSONString(list_comment);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 显示回复
|
// 显示回复
|
||||||
@ -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 ) {
|
private boolean addNode (List<CommentNode> firstList, CommentNode commentNode ) {
|
||||||
//循环添加
|
//循环添加
|
||||||
for (CommentNode node : firstList) {
|
for (CommentNode node : firstList) {
|
||||||
@ -106,7 +150,7 @@ public class CommentServiceImpl implements CommentService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 功能描述:将查出来的lastId不为null的回复都添加到第一层Node集合中
|
* 功能描述:将查出来的rootId不为null的回复都添加到第一层Node集合中
|
||||||
*
|
*
|
||||||
* @param firstList 第一层评论集合(链表)
|
* @param firstList 第一层评论集合(链表)
|
||||||
* @param thenList 非第一层评论集合(链表)
|
* @param thenList 非第一层评论集合(链表)
|
||||||
@ -126,14 +170,4 @@ public class CommentServiceImpl implements CommentService {
|
|||||||
return firstList;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -32,10 +32,12 @@ public class QRCServiceImpl implements QRCService{
|
|||||||
if (list.size() == 0) {
|
if (list.size() == 0) {
|
||||||
// 如果icon是url
|
// 如果icon是url
|
||||||
if(QRCodeUtil.notBase64(collect.getIcon_url())){
|
if(QRCodeUtil.notBase64(collect.getIcon_url())){
|
||||||
|
|
||||||
String icon_url = QRCodeUtil.downloadPicture(collect.getIcon_url());
|
String icon_url = QRCodeUtil.downloadPicture(collect.getIcon_url());
|
||||||
collect.setIcon_url(icon_url);
|
collect.setIcon_url(icon_url);
|
||||||
String url = urlList.getUrl();
|
|
||||||
// 将网址生成二维码并返回本地路径
|
// 将网址生成二维码并返回本地路径
|
||||||
|
String url = urlList.getUrl();
|
||||||
String url_wait = QRCodeUtil.encode(url, logoPath, destPath, true);
|
String url_wait = QRCodeUtil.encode(url, logoPath, destPath, true);
|
||||||
collect.setQr_url(url_wait);
|
collect.setQr_url(url_wait);
|
||||||
String base64 = QRCodeUtil.ImageToBase64(url_wait);
|
String base64 = QRCodeUtil.ImageToBase64(url_wait);
|
||||||
|
Loading…
Reference in New Issue
Block a user