mirror of https://github.com/halo-dev/halo
👽 Update comment system
parent
7e258b8196
commit
ad0290c3cf
|
@ -77,9 +77,7 @@ public class Comment implements Serializable {
|
||||||
/**
|
/**
|
||||||
* 上一级
|
* 上一级
|
||||||
*/
|
*/
|
||||||
//@OneToOne
|
private Long commentParent = 0L;
|
||||||
//@JoinColumn(name = "comment_id")
|
|
||||||
//private Comment commentParent;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 评论状态,0:正常,1:待审核,2:回收站
|
* 评论状态,0:正常,1:待审核,2:回收站
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package cc.ryanc.halo.web.controller.admin;
|
package cc.ryanc.halo.web.controller.admin;
|
||||||
|
|
||||||
import cc.ryanc.halo.model.domain.Comment;
|
import cc.ryanc.halo.model.domain.Comment;
|
||||||
|
import cc.ryanc.halo.model.domain.Post;
|
||||||
import cc.ryanc.halo.model.dto.HaloConst;
|
import cc.ryanc.halo.model.dto.HaloConst;
|
||||||
import cc.ryanc.halo.service.CommentService;
|
import cc.ryanc.halo.service.CommentService;
|
||||||
import cc.ryanc.halo.service.MailService;
|
import cc.ryanc.halo.service.MailService;
|
||||||
import cc.ryanc.halo.service.UserService;
|
import cc.ryanc.halo.service.UserService;
|
||||||
|
import cc.ryanc.halo.util.HaloUtil;
|
||||||
import cc.ryanc.halo.web.controller.BaseController;
|
import cc.ryanc.halo.web.controller.BaseController;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -15,11 +17,14 @@ import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
import javax.websocket.server.PathParam;
|
import javax.websocket.server.PathParam;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -151,4 +156,43 @@ public class CommentController extends BaseController{
|
||||||
}
|
}
|
||||||
return "redirect:/admin/comments?status="+status;
|
return "redirect:/admin/comments?status="+status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理员回复评论
|
||||||
|
*
|
||||||
|
* @param commentId 被回复的评论
|
||||||
|
* @param commentContent 回复的内容
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
@PostMapping("/reply")
|
||||||
|
public String replyComment(@RequestParam("commentId") Long commentId,
|
||||||
|
@RequestParam("postId") Long postId,
|
||||||
|
@RequestParam("commentContent") String commentContent,
|
||||||
|
@RequestParam("userAgent") String userAgent,
|
||||||
|
HttpServletRequest request){
|
||||||
|
try {
|
||||||
|
Post post = new Post();
|
||||||
|
post.setPostId(postId);
|
||||||
|
|
||||||
|
//保存评论
|
||||||
|
Comment comment = new Comment();
|
||||||
|
comment.setPost(post);
|
||||||
|
comment.setCommentAuthor(userService.findAllUser().get(0).getUserDisplayName());
|
||||||
|
comment.setCommentAuthorEmail(userService.findAllUser().get(0).getUserEmail());
|
||||||
|
comment.setCommentAuthorUrl(HaloConst.OPTIONS.get("site_url"));
|
||||||
|
comment.setCommentAuthorIp(HaloUtil.getIpAddr(request));
|
||||||
|
comment.setCommentAuthorAvatarMd5(HaloUtil.getMD5(userService.findAllUser().get(0).getUserEmail()));
|
||||||
|
comment.setCommentDate(new Date());
|
||||||
|
String at = "<a href='#'>@"+commentService.findCommentById(commentId).get().getCommentAuthor()+"</a>";
|
||||||
|
comment.setCommentContent(at+commentContent);
|
||||||
|
comment.setCommentAgent(userAgent);
|
||||||
|
comment.setCommentParent(commentId);
|
||||||
|
comment.setCommentStatus(0);
|
||||||
|
commentService.saveByComment(comment);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("回复评论失败!"+e.getMessage());
|
||||||
|
}
|
||||||
|
return "redirect:/admin/comments";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# 端口配置
|
# 端口配置
|
||||||
server:
|
server:
|
||||||
port: 8080
|
port: 8090
|
||||||
spring:
|
spring:
|
||||||
# 数据源配置 使用druid数据源
|
# 数据源配置 使用druid数据源
|
||||||
datasource:
|
datasource:
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
<td>
|
<td>
|
||||||
<#switch comment.commentStatus>
|
<#switch comment.commentStatus>
|
||||||
<#case 0>
|
<#case 0>
|
||||||
<button class="btn btn-info btn-sm btn-flat" onclick="modelShow()">回复</button>
|
<button class="btn btn-info btn-sm btn-flat" onclick="replyShow('${comment.commentId}','${comment.post.postId}')">回复</button>
|
||||||
<button class="btn btn-danger btn-sm btn-flat" onclick="modelShow('/admin/comments/throw?commentId=${comment.commentId}','确定移动到回收站?')">丢弃</button>
|
<button class="btn btn-danger btn-sm btn-flat" onclick="modelShow('/admin/comments/throw?commentId=${comment.commentId}','确定移动到回收站?')">丢弃</button>
|
||||||
<#break >
|
<#break >
|
||||||
<#case 1>
|
<#case 1>
|
||||||
|
@ -90,7 +90,7 @@
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<!-- 删除确认弹出层 -->
|
<!-- 删除确认弹出层 -->
|
||||||
<div class="modal fade" id="removePostModal">
|
<div class="modal fade" id="removeCommentModal">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
<div class="modal-content message_align">
|
<div class="modal-content message_align">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
|
@ -108,16 +108,46 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- 回复弹出层 -->
|
||||||
|
<div class="modal fade" id="commentReplyModal">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content message_align">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||||
|
<h4 class="modal-title">回复</h4>
|
||||||
|
</div>
|
||||||
|
<form method="post" action="/admin/comments/reply">
|
||||||
|
<div class="modal-body">
|
||||||
|
<textarea class="form-control" rows="5" id="commentContent" name="commentContent" style="resize: none"></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<input type="hidden" id="commentId" name="commentId" value=""/>
|
||||||
|
<input type="hidden" id="userAgent" name="userAgent" value=""/>
|
||||||
|
<input type="hidden" id="postId" name="postId" value="" />
|
||||||
|
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
|
||||||
|
<button type="submit" class="btn btn-primary">确定</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<script>
|
<script>
|
||||||
function modelShow(url,message) {
|
function modelShow(url,message) {
|
||||||
$('#url').val(url);
|
$('#url').val(url);
|
||||||
$('#message').html(message);
|
$('#message').html(message);
|
||||||
$('#removePostModal').modal();
|
$('#removeCommentModal').modal();
|
||||||
}
|
}
|
||||||
function removeIt(){
|
function removeIt(){
|
||||||
var url=$.trim($("#url").val());
|
var url=$.trim($("#url").val());
|
||||||
window.location.href=url;
|
window.location.href=url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function replyShow(commentId,postId) {
|
||||||
|
$('#userAgent').val(navigator.userAgent);
|
||||||
|
$('#commentId').val(commentId);
|
||||||
|
$('#postId').val(postId);
|
||||||
|
$('#commentReplyModal').modal();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
<#include "module/_footer.ftl">
|
<#include "module/_footer.ftl">
|
||||||
|
|
Loading…
Reference in New Issue