新增[评论点赞]

This commit is contained in:
lxyer 2018-01-10 14:09:41 +08:00
parent cb3a29991e
commit 9e59872966
7 changed files with 76 additions and 6 deletions

View File

@ -1,6 +1,7 @@
package com.lxyer.controller;
import com.jfinal.aop.Before;
import com.jfinal.aop.Clear;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Page;
import com.lxyer.config.JBean;
@ -11,12 +12,14 @@ import com.lxyer.service.CommentService;
/**
* Created by JUECHENG at 2018/1/8 23:07.
*/
@Before(LoginInterceptor.class)
public class CommentController extends IController {
CommentService service = CommentService.me;
/**
* 评论列表
*/
@Clear(LoginInterceptor.class)
public void list(){
Kv kv = getParams("contentId");
Page<Comment> page = Comment.dao.findPage(getPn(), getPs(), kv);
@ -27,6 +30,7 @@ public class CommentController extends IController {
/**
* 评论详情
*/
@Clear(LoginInterceptor.class)
public void info(){
}
@ -43,16 +47,27 @@ public class CommentController extends IController {
}
/**
* todo:更新状态
* 更新状态
*/
public void update_status(){
}
/**
* todo:评论点赞
* 评论点赞
*/
public void support(){
JBean bean = new JBean(1);
Integer commentId = getParaToInt("commentId");
Integer ok = getParaToInt("ok");
try {
service.support(commentId, ok, getUserId());
} catch (Exception e) {
e.printStackTrace();
bean.setCode(-1, e.getMessage());
}
renderJson(bean);
}
}

View File

@ -31,7 +31,7 @@ public class JieController extends IController{
Content content = Content.dao.findFirst(Kv.by("contentId", contentId));
//评论
Page<Comment> comments = Comment.dao.findPage(getPn(), getPs(), Kv.by("contentId", contentId));
Page<Comment> comments = Comment.dao.findPage(getPn(), getPs(), Kv.by("contentId", contentId).set("login_user_id", getUserId()));
//热议
List<Content> hotReply = Content.dao.findPage(1, 8, Kv.by("order", "replyNum DESC")).getList();

View File

@ -1,5 +1,7 @@
package com.lxyer.model;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.lxyer.model.base.BaseComment;
/**
@ -18,4 +20,12 @@ public class Comment extends BaseComment<Comment> {
public Comment getDao() {
return dao;
}
/**
* 更新点赞数
* @param commentId
*/
public static void upSupportNum(Integer commentId) {
Db.update(Db.getSqlPara("comment.upSupportNum", Kv.by("commentId", commentId)));
}
}

View File

@ -1,5 +1,7 @@
package com.lxyer.service;
import com.jfinal.kit.Kv;
import com.lxyer.model.ActLog;
import com.lxyer.model.Comment;
import com.lxyer.model.Content;
@ -22,4 +24,34 @@ public class CommentService {
//更新评论数
Content.upReplyNum(comment.getContentId());
}
/**
* 评论点赞
* @param commentId
* @param ok
* @param userId
* @throws Exception
*/
public void support(Integer commentId, Integer ok, Integer userId) throws Exception {
Comment comment = Comment.dao.findById(commentId);
if (comment == null)
throw new Exception("操作失败,未查询到相关信息");
ActLog actLog = ActLog.dao.findFirst(Kv.by("userId", userId).set("tid", commentId).set("cate", 1));
if (actLog == null){
actLog = new ActLog();
actLog.setTid(commentId);
actLog.setUserId(userId);
actLog.setCate(1);
actLog.setStatus(1);
actLog.setCreateTime(System.currentTimeMillis());
actLog.save();
}else if (actLog.getStatus() != ok){
actLog.setStatus(ok == 1 ? 1 : -1);
actLog.setCreateTime(System.currentTimeMillis());
actLog.update();
}
Comment.upSupportNum(commentId);
}
}

View File

@ -1,8 +1,8 @@
### 帖子操作日志 para:[logid, cate, tid, userId, status]
#sql("actLog.list")
SELECT al.*
FROM `comment` al
WHERE al.status!=-1
FROM `act_log` al
WHERE 1=1
#if(logid)
AND al.`logid`=#(logid)
#end

View File

@ -2,6 +2,9 @@
#sql("comment.list")
SELECT c.*
,u.nickname,u.avatar
#if(login_user_id)
,(SELECT IFNULL((SELECT al.logid FROM act_log al WHERE al.userId=#(login_user_id) AND al.cate=1 AND al.status=1 AND al.tid=c.commentId),-1)) AS 'hadSupport'
#end
FROM `comment` c
LEFT JOIN user u ON c.userId=u.userId
WHERE c.status!=-1
@ -23,4 +26,14 @@
#if(status)
AND c.`status`=#(status)
#end
#end
### 更新点赞数 para:[contentId]
#sql("comment.upSupportNum")
UPDATE comment c SET c.supportNum=
(SELECT COUNT(*) FROM act_log WHERE tid=c.commentId AND status=1 AND cate=1)
#if(commentId)
WHERE c.commentId=#(commentId)
#end
#end

View File

@ -111,7 +111,7 @@
#(x.content)
</div>
<div class="jieda-reply">
#if(x.hadSupport == 1)
#if(x.hadSupport > 1)
<span class="jieda-zan zanok" type="zan"><i class="iconfont icon-zan"></i><em>#(x.supportNum)</em></span>
#else
<span class="jieda-zan" type="zan"><i class="iconfont icon-zan"></i><em>#(x.supportNum)</em></span>