Ver Fonte

获取上一篇下一篇逻辑修改

huangct há 8 anos atrás
pai
commit
cfe69d3e64

+ 19 - 24
jpress-model/src/main/java/io/jpress/model/query/ContentQuery.java

@@ -131,7 +131,7 @@ public class ContentQuery extends JBaseQuery {
 
 
 		}
 		}
 
 
-		sql.append(" WHERE c.status != 'normal' ");
+		sql.append(" WHERE c.status = 'normal' ");
 
 
 		appendIfNotEmpty(sql, "c.module", module, params, false);
 		appendIfNotEmpty(sql, "c.module", module, params, false);
 
 
@@ -288,7 +288,7 @@ public class ContentQuery extends JBaseQuery {
 		}
 		}
 
 
 		else if ("created".equals(orderBy)) {
 		else if ("created".equals(orderBy)) {
-			fromBuilder.append(" ORDER BY c.created DESC");
+			fromBuilder.append(" ORDER BY c.created ");
 		}
 		}
 
 
 		else if ("vote_up".equals(orderBy)) {
 		else if ("vote_up".equals(orderBy)) {
@@ -563,7 +563,7 @@ public class ContentQuery extends JBaseQuery {
                     new IDataLoader() {
                     new IDataLoader() {
                         @Override
                         @Override
                         public Object load() {
                         public Object load() {
-                            StringBuilder sqlBuilder = new StringBuilder(" select c.* from content c ,mapping m, taxonomy t where c.module='news' and c.status!='normal' and m.content_id=c.id and m.taxonomy_id=t.id and t.type = 'category' ");
+                            StringBuilder sqlBuilder = new StringBuilder(" select c.* from content c ,mapping m, taxonomy t where c.module='news' and c.status='normal' and m.content_id=c.id and m.taxonomy_id=t.id and t.type = 'category' ");
                             List<Taxonomy> taxonomys =  currentContent.getTaxonomys();
                             List<Taxonomy> taxonomys =  currentContent.getTaxonomys();
                             for (int i = 0; i < taxonomys.size(); i++) {
                             for (int i = 0; i < taxonomys.size(); i++) {
                                 String slug = taxonomys.get(i).getSlug();
                                 String slug = taxonomys.get(i).getSlug();
@@ -571,19 +571,17 @@ public class ContentQuery extends JBaseQuery {
                                     sqlBuilder.append(" and t.slug = '" + slug +"'");
                                     sqlBuilder.append(" and t.slug = '" + slug +"'");
                                 }
                                 }
                             }
                             }
-                            sqlBuilder.append(" order by c.created asc");
+							sqlBuilder.append(" and c.created < '" + currentContent.getCreated().toString() +"'" );
+							sqlBuilder.append(" order by c.created desc limit 1");
 
 
                             return DAO.find(sqlBuilder.toString());
                             return DAO.find(sqlBuilder.toString());
                         }
                         }
                     });
                     });
-            int index = 0;
-            for(int i=0;i<list.size();i++){
-                if (list.get(i).getId().toString().equals(currentContent.getId().toString())){
-                    index = i;
-                }
-            }
-            if(index==list.size()-1){return null;}
-            content = list.get(index+1);
+			if (list != null && list.size() != 0) {
+				return list.get(0);
+			} else {
+				return null;
+			}
         } else{
         } else{
 			content = DAO.getFromListCache(buildKey(currentContent.getModule(), "next:" + currentContent.getId()),
 			content = DAO.getFromListCache(buildKey(currentContent.getModule(), "next:" + currentContent.getId()),
 					new IDataLoader() {
 					new IDataLoader() {
@@ -652,7 +650,7 @@ public class ContentQuery extends JBaseQuery {
                     new IDataLoader() {
                     new IDataLoader() {
                         @Override
                         @Override
                         public Object load() {
                         public Object load() {
-                            StringBuilder sqlBuilder = new StringBuilder(" select c.* from content c ,mapping m, taxonomy t where c.module='news' and c.status!='normal' and m.content_id=c.id and m.taxonomy_id=t.id and t.type = 'category' ");
+                            StringBuilder sqlBuilder = new StringBuilder(" select c.* from content c ,mapping m, taxonomy t where c.module='news' and c.status='normal' and m.content_id=c.id and m.taxonomy_id=t.id and t.type = 'category' ");
                             List<Taxonomy> taxonomys =  currentContent.getTaxonomys();
                             List<Taxonomy> taxonomys =  currentContent.getTaxonomys();
                             for (int i = 0; i < taxonomys.size(); i++) {
                             for (int i = 0; i < taxonomys.size(); i++) {
                                 String slug = taxonomys.get(i).getSlug();
                                 String slug = taxonomys.get(i).getSlug();
@@ -660,21 +658,18 @@ public class ContentQuery extends JBaseQuery {
                                     sqlBuilder.append(" and t.slug = '" + slug +"'");
                                     sqlBuilder.append(" and t.slug = '" + slug +"'");
                                 }
                                 }
                             }
                             }
-                            sqlBuilder.append(" order by c.created asc");
+
+							sqlBuilder.append(" and c.created > '" + currentContent.getCreated().toString() +"'" );
+                            sqlBuilder.append(" order by c.created asc limit 1");
 
 
                             return DAO.find(sqlBuilder.toString());
                             return DAO.find(sqlBuilder.toString());
                         }
                         }
                     });
                     });
-            int index = 0;
-            for (int i = 0; i < list.size(); i++) {
-                if (list.get(i).getId().toString().equals(currentContent.getId().toString())) {
-                    index = i;
-                }
-            }
-            if (index == 0) {
-                return null;
-            }
-            content = list.get(index - 1);
+			if (list != null && list.size() != 0) {
+				return list.get(0);
+			} else {
+				return null;
+			}
         } else{
         } else{
 			content = DAO.getFromListCache(buildKey(currentContent.getModule(), "previous:" + currentContent.getId()),
 			content = DAO.getFromListCache(buildKey(currentContent.getModule(), "previous:" + currentContent.getId()),
 					new IDataLoader() {
 					new IDataLoader() {