|
|
@@ -23,10 +23,8 @@ import io.jpress.interceptor.UCodeInterceptor;
|
|
|
import io.jpress.model.Comment;
|
|
|
import io.jpress.model.Content;
|
|
|
import io.jpress.model.User;
|
|
|
-import io.jpress.model.Vote;
|
|
|
import io.jpress.model.query.CommentQuery;
|
|
|
import io.jpress.model.query.UserQuery;
|
|
|
-import io.jpress.model.query.VoteQuery;
|
|
|
import io.jpress.router.RouterMapping;
|
|
|
import io.jpress.router.RouterNotAllowConvert;
|
|
|
import io.jpress.template.TemplateManager;
|
|
|
@@ -34,9 +32,7 @@ import io.jpress.utils.JsoupUtils;
|
|
|
import io.jpress.utils.StringUtils;
|
|
|
|
|
|
import java.math.BigInteger;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
|
|
|
@RouterMapping(url = "/admin/comment", viewPath = "/WEB-INF/admin/comment")
|
|
|
@Before(ActionCacheClearInterceptor.class)
|
|
|
@@ -245,125 +241,7 @@ public class _CommentController extends JBaseCRUDController<Comment> {
|
|
|
renderAjaxResultForError("restore error!");
|
|
|
}
|
|
|
}
|
|
|
- @Before(UCodeInterceptor.class)
|
|
|
- public void lazyLoad() {
|
|
|
- Page<Comment> page = CommentQuery.me().uuHelperPaginateByContentId(getParaToInt("pagenumber"), getParaToInt("pagesize"), getParaToBigInteger("contId"), "uuhelper");
|
|
|
- List<Comment> list = page.getList();
|
|
|
- StringBuilder htmlBuilder = new StringBuilder();
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
- for (int i = 0; i< list.size() ;i ++) {
|
|
|
- Comment comment = list.get(i);
|
|
|
- htmlBuilder.append("<div class=\"message\">");
|
|
|
- htmlBuilder.append("<div class=\"left\">");
|
|
|
- htmlBuilder.append("<div class=\"img\">");
|
|
|
- htmlBuilder.append("<img src=\"/jpress/static/jpress/admin/image/dot.png\" alt=\"用户头像\">");
|
|
|
- htmlBuilder.append("</div>");
|
|
|
- htmlBuilder.append("</div>");
|
|
|
- htmlBuilder.append("<div class=\"right\">");
|
|
|
- htmlBuilder.append("<div class=\"detail\">");
|
|
|
- htmlBuilder.append("<div class=\"title\">");
|
|
|
- htmlBuilder.append("<span>"+ comment.getAuthor() +"<em>" + sdf.format(comment.getCreated()) + "</em></span>");
|
|
|
- htmlBuilder.append("<span><img src=\"/jpress/static/jpress/admin/image/hands.png\" alt=\"\" onclick=\"vote("+ comment.getId()+")\"><em>" + comment.getVoteUp() + "</em></span>");
|
|
|
- htmlBuilder.append("</div>");
|
|
|
- htmlBuilder.append("<p>"+comment.getText()+"</p>");
|
|
|
- if (comment.getlatestSon(comment.getId()) != null) {
|
|
|
- Comment sonComment = comment.getlatestSon(comment.getId());
|
|
|
- htmlBuilder.append("<div class=\"title reply\">");
|
|
|
- htmlBuilder.append("<span>作者回复: <em>" + sdf.format(sonComment.getCreated()) + "</em></span>");
|
|
|
- htmlBuilder.append("<span><img src=\"/jpress/static/jpress/admin/image/hands.png\" alt=\"\" onclick=\"vote("+ sonComment.getId()+")\"><em>" + sonComment.getVoteUp() + "</em></span>");
|
|
|
- htmlBuilder.append("</div>");
|
|
|
- htmlBuilder.append("<p>"+sonComment.getText()+"</p>");
|
|
|
- }
|
|
|
- htmlBuilder.append("</div>\n" + "</div>\n" + " </div>");
|
|
|
- }
|
|
|
-
|
|
|
- renderAjaxResultForSuccess(htmlBuilder.toString());
|
|
|
- }
|
|
|
-
|
|
|
- //新增点赞
|
|
|
- private void voteUp(Comment comment,BigInteger userId,BigInteger uuUserId){
|
|
|
-// BigInteger commentId = getParaToBigInteger("comment_id");
|
|
|
-// Comment comment = CommentQuery.me().findById(commentId);
|
|
|
-// BigInteger userId = getParaToBigInteger("user_id");
|
|
|
-// BigInteger uuUserId = getParaToBigInteger("uu_user_id");
|
|
|
- Vote vote = getModel(Vote.class);
|
|
|
- vote.setCommentId(comment.getId());
|
|
|
- vote.setUserId(userId);
|
|
|
- vote.setUuUserId(uuUserId);
|
|
|
- vote.setUp(true);
|
|
|
- vote.setDown(null);
|
|
|
- vote.setIp(getIPAddress());
|
|
|
- vote.setAgent(getUserAgent());
|
|
|
- vote.setStatus(Vote.STATUS_NORMAL);
|
|
|
- vote.setCreated(new Date());
|
|
|
-
|
|
|
- if (vote.save()) {
|
|
|
- //更新对应评论的点赞数
|
|
|
- comment.updateVoteUpCount();
|
|
|
- renderAjaxResultForSuccess();
|
|
|
- } else {
|
|
|
- renderAjaxResultForError();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- //取消赞
|
|
|
- private void cancelVoteUp(Comment comment,Vote vote){
|
|
|
-// BigInteger commentId = getParaToBigInteger("comment_id");
|
|
|
-// Comment comment = CommentQuery.me().findById(commentId);
|
|
|
-// BigInteger userId = getParaToBigInteger("user_id");
|
|
|
-// BigInteger uuUserId = getParaToBigInteger("uu_user_id");
|
|
|
- vote.setUp(null);
|
|
|
- if (vote.update()) {
|
|
|
- //更新对应评论的点赞数
|
|
|
- comment.updateVoteUpCount();
|
|
|
- renderAjaxResultForSuccess();
|
|
|
- } else {
|
|
|
- renderAjaxResultForError();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //再次赞
|
|
|
- private void againVoteUp(Comment comment,Vote vote){
|
|
|
-// BigInteger commentId = getParaToBigInteger("comment_id");
|
|
|
-// Comment comment = CommentQuery.me().findById(commentId);
|
|
|
-// BigInteger userId = getParaToBigInteger("user_id");
|
|
|
-// BigInteger uuUserId = getParaToBigInteger("uu_user_id");
|
|
|
- vote.setUp(true);
|
|
|
- if (vote.update()) {
|
|
|
- //更新对应评论的点赞数
|
|
|
- comment.updateVoteUpCount();
|
|
|
- renderAjaxResultForSuccess();
|
|
|
- } else {
|
|
|
- renderAjaxResultForError();
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- //点赞接口
|
|
|
- public void vote() {
|
|
|
- BigInteger commentId = getParaToBigInteger("comment_id");
|
|
|
- Comment comment = CommentQuery.me().findById(commentId);
|
|
|
- BigInteger userId = getParaToBigInteger("user_id");
|
|
|
- BigInteger uuUserId = getParaToBigInteger("uu_user_id");
|
|
|
- if ("0".equals(userId.toString())) {
|
|
|
- userId = null;
|
|
|
- }
|
|
|
- if ("0".equals(uuUserId.toString())) {
|
|
|
- uuUserId = null;
|
|
|
- }
|
|
|
-
|
|
|
- Vote vote = VoteQuery.me().findVote(commentId,userId,uuUserId);
|
|
|
- //判断此用户是否给此评论点过赞
|
|
|
- if (vote != null) {
|
|
|
- if (vote.getUp() == null) {
|
|
|
- againVoteUp(comment,vote);
|
|
|
- } else {
|
|
|
- cancelVoteUp(comment,vote);
|
|
|
- }
|
|
|
- } else {
|
|
|
- voteUp(comment,userId,uuUserId);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
|
|
|
}
|