新增[评论点赞]
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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();
|
||||
|
@@ -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)));
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user