|
|
@@ -15,14 +15,13 @@
|
|
|
*/
|
|
|
package io.jpress.model.query;
|
|
|
|
|
|
-import java.math.BigInteger;
|
|
|
-import java.util.LinkedList;
|
|
|
-
|
|
|
import com.jfinal.plugin.activerecord.Page;
|
|
|
import com.jfinal.plugin.ehcache.IDataLoader;
|
|
|
-
|
|
|
import io.jpress.model.Comment;
|
|
|
|
|
|
+import java.math.BigInteger;
|
|
|
+import java.util.LinkedList;
|
|
|
+
|
|
|
public class CommentQuery extends JBaseQuery {
|
|
|
|
|
|
protected static final Comment DAO = new Comment();
|
|
|
@@ -90,6 +89,42 @@ public class CommentQuery extends JBaseQuery {
|
|
|
return DAO.paginate(pageNumber, pageSize, select, fromBuilder.toString(), params.toArray());
|
|
|
}
|
|
|
|
|
|
+ public Page<Comment> paginateWithContentAndSon(int pageNumber, int pageSize, String module, String type,
|
|
|
+ BigInteger contentId, BigInteger parentCommentId, Boolean hasSon) {
|
|
|
+
|
|
|
+ String select = " select c.*,content.title content_title,u.username,u.nickname,u.avatar, "
|
|
|
+ + "quote_comment.text qc_content,quote_comment.author qc_author,"
|
|
|
+ + "quote_user.username qc_username,quote_user.nickname qc_nickname,quote_user.avatar qc_avatar ";
|
|
|
+
|
|
|
+ StringBuilder fromBuilder = new StringBuilder(" from comment c");
|
|
|
+ fromBuilder.append(" left join content on c.content_id = content.id");
|
|
|
+ fromBuilder.append(" left join user u on c.user_id = u.id ");
|
|
|
+ fromBuilder.append(" left join comment quote_comment on c.parent_id = quote_comment.id");
|
|
|
+ fromBuilder.append(" left join user quote_user on quote_comment.user_id = quote_user.id ");
|
|
|
+
|
|
|
+ fromBuilder.append(" WHERE c.status <> '" + Comment.STATUS_DELETE + "' ");
|
|
|
+
|
|
|
+ if (hasSon == true) {
|
|
|
+ fromBuilder.append("and c.parent_id is not null ");
|
|
|
+ } else {
|
|
|
+ //不找作者本身的回复
|
|
|
+ fromBuilder.append("and c.parent_id is null and quote_user.user_id != content.user_id ");
|
|
|
+ }
|
|
|
+
|
|
|
+ LinkedList<Object> params = new LinkedList<Object>();
|
|
|
+ appendIfNotEmpty(fromBuilder, " c.`type`", type, params, false);
|
|
|
+ appendIfNotEmpty(fromBuilder, " c.content_module", module, params, false);
|
|
|
+ appendIfNotEmpty(fromBuilder, " c.parent_id", parentCommentId, params, false);
|
|
|
+ appendIfNotEmpty(fromBuilder, " content.id", contentId, params, false);
|
|
|
+
|
|
|
+ fromBuilder.append("order by c.created desc");
|
|
|
+
|
|
|
+ if (params.isEmpty()) {
|
|
|
+ return DAO.paginate(pageNumber, pageSize, select, fromBuilder.toString());
|
|
|
+ }
|
|
|
+ return DAO.paginate(pageNumber, pageSize, select, fromBuilder.toString(), params.toArray());
|
|
|
+ }
|
|
|
+
|
|
|
public Page<Comment> paginateByContentId(int pageNumber, int pageSize, BigInteger contentId) {
|
|
|
return paginateWithContent(pageNumber, pageSize, null, null, contentId, null, Comment.STATUS_NORMAL);
|
|
|
}
|
|
|
@@ -139,4 +174,14 @@ public class CommentQuery extends JBaseQuery {
|
|
|
return DAO.doFindCount("content_module = ? and status=?", module, status);
|
|
|
}
|
|
|
|
|
|
+ public long findCountByModuleAndSon(String module, boolean parent) {
|
|
|
+ Long count = new Long(0);
|
|
|
+ if (parent == true) {
|
|
|
+ count = DAO.doFindCount("content_module = ? and parent_id is not null", module);
|
|
|
+ } else {
|
|
|
+ count = DAO.doFindCount("content_module = ? and parent_id is null", module);
|
|
|
+ }
|
|
|
+
|
|
|
+ return count;
|
|
|
+ }
|
|
|
}
|