|
|
@@ -15,21 +15,20 @@
|
|
|
*/
|
|
|
package io.jpress.model.query;
|
|
|
|
|
|
-import java.math.BigInteger;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.LinkedList;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
import com.jfinal.plugin.activerecord.Page;
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
import com.jfinal.plugin.ehcache.IDataLoader;
|
|
|
-
|
|
|
import io.jpress.model.Content;
|
|
|
import io.jpress.model.core.Jdb;
|
|
|
import io.jpress.model.vo.Archive;
|
|
|
import io.jpress.template.TemplateManager;
|
|
|
import io.jpress.utils.StringUtils;
|
|
|
|
|
|
+import java.math.BigInteger;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.LinkedList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
public class ContentQuery extends JBaseQuery {
|
|
|
|
|
|
protected static final Content DAO = new Content();
|
|
|
@@ -108,7 +107,7 @@ public class ContentQuery extends JBaseQuery {
|
|
|
}
|
|
|
|
|
|
public Page<Content> paginateInNormal(int page, int pagesize, String module, BigInteger[] taxonomyIds,
|
|
|
- String orderBy) {
|
|
|
+ String orderBy) {
|
|
|
|
|
|
LinkedList<Object> params = new LinkedList<Object>();
|
|
|
|
|
|
@@ -118,10 +117,17 @@ public class ContentQuery extends JBaseQuery {
|
|
|
sql.append(" left join mapping m on c.id = m.`content_id`");
|
|
|
sql.append(" left join taxonomy t on m.`taxonomy_id` = t.id");
|
|
|
|
|
|
+ /*ContentPageTag源码只支持meta:date这种写法,固定desc。修改源码之后格式meta:date asc,asc可不写,默认desc*/
|
|
|
if (orderBy != null && orderBy.startsWith("meta:")) {
|
|
|
sql.append(
|
|
|
" left join metadata meta on meta.`object_type`='content' and meta.`object_id`=c.id and meta.`meta_key`=? ");
|
|
|
- params.add(orderBy.substring("meta:".length()));
|
|
|
+ String[] orderByArr = orderBy.split(" ");
|
|
|
+ if (orderByArr.length > 1) {
|
|
|
+ params.add(orderByArr[0].substring("meta:".length()));
|
|
|
+ } else {
|
|
|
+ params.add(orderBy.substring("meta:".length()));
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
sql.append(" WHERE c.status = 'normal' ");
|
|
|
@@ -141,7 +147,14 @@ public class ContentQuery extends JBaseQuery {
|
|
|
sql.append(" group by c.id");
|
|
|
|
|
|
if (orderBy != null && orderBy.startsWith("meta:")) {
|
|
|
- sql.append(" order by meta.`meta_value` + 0 desc ");
|
|
|
+ //将源码固定desc排序方式改为动态获取
|
|
|
+ String[] orderArr = orderBy.split(" ");
|
|
|
+ String orderWay = "desc";
|
|
|
+ if (orderArr.length > 1) {
|
|
|
+ orderWay = orderArr[orderArr.length-1];
|
|
|
+ }
|
|
|
+ //sql.append(" order by meta.`meta_value` + 0 desc ");
|
|
|
+ sql.append(" order by meta.`meta_value` " + orderWay);
|
|
|
} else {
|
|
|
buildOrderBy(orderBy, sql);
|
|
|
}
|
|
|
@@ -246,6 +259,18 @@ public class ContentQuery extends JBaseQuery {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ //contentsTag标签增加按元数据排序
|
|
|
+ if (orderBy.startsWith("meta:")) {
|
|
|
+ //将源码固定desc排序方式改为动态获取
|
|
|
+ String[] orderArr = orderBy.split(" ");
|
|
|
+ String orderWay = "desc";
|
|
|
+ if (orderArr.length > 1) {
|
|
|
+ orderWay = orderArr[orderArr.length-1];
|
|
|
+ }
|
|
|
+ fromBuilder.append(" order by d.`meta_value` " + orderWay);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
// maybe orderby == "view_count desc";
|
|
|
String orderbyInfo[] = orderBy.trim().split("\\s+");
|
|
|
orderBy = orderbyInfo[0];
|
|
|
@@ -342,6 +367,9 @@ public class ContentQuery extends JBaseQuery {
|
|
|
sql.append(" left join mapping m on c.id = m.`content_id`");
|
|
|
sql.append(" left join taxonomy t on m.`taxonomy_id` = t.id");
|
|
|
|
|
|
+ //连接元数据表
|
|
|
+ sql.append(" left join metadata d on c.id = d.`object_id`");
|
|
|
+
|
|
|
sql.append(" where c.status = 'normal' ");
|
|
|
LinkedList<Object> params = new LinkedList<Object>();
|
|
|
appendIfNotEmpty(sql, "m.taxonomy_id", typeIds, params, false);
|