From e770818cee5844f8b1fff8a38e1f9a98e8f04001 Mon Sep 17 00:00:00 2001 From: DaveBoy1994 Date: Mon, 2 Mar 2020 19:47:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=BB=E5=8A=A1=E7=BB=84?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aria/core/download/DownloadReceiver.java | 10 +----- .../com/arialyy/aria/orm/DelegateFind.java | 31 ++++++++++++++++--- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java index cc71525b..6987c90c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java @@ -417,15 +417,7 @@ public class DownloadReceiver extends AbsReceiver { * @return 如果没有任务组列表,则返回null */ public List getGroupTaskList() { - List wrappers = DbEntity.findRelationData(DGEntityWrapper.class); - if (wrappers == null || wrappers.isEmpty()) { - return null; - } - List entities = new ArrayList<>(); - for (DGEntityWrapper wrapper : wrappers) { - entities.add(wrapper.groupEntity); - } - return entities; + return getGroupTaskList(1,10); } /** diff --git a/PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateFind.java b/PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateFind.java index 4f0ba511..1128376f 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateFind.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateFind.java @@ -215,12 +215,15 @@ class DelegateFind extends AbsDelegate { } else { sql = sb.toString(); } + boolean paged=false; if (page != -1 && num != -1) { - sql = sql.concat(String.format(" LIMIT %s,%s", (page - 1) * num, num)); + paged=true; + sql = sql.concat(String.format(" Group by %s LIMIT %s,%s", pTableName.concat(".").concat(m.parentColumn()), (page - 1) * num, num)); } Cursor cursor = db.rawQuery(sql, null); List data = - newInstanceEntity(wrapperClazz, parentClazz, childClazz, cursor, pColumn, cColumn); + newInstanceEntity(wrapperClazz, parentClazz, childClazz, cursor, pColumn, cColumn,paged, db,m.entityColumn(),m.parentColumn()); + closeCursor(cursor); return data; } catch (ClassNotFoundException e) { @@ -243,7 +246,7 @@ class DelegateFind extends AbsDelegate { Class wrapperClazz, Class

parentClazz, Class childClazz, Cursor cursor, - List pColumn, List cColumn) { + List pColumn, List cColumn,boolean paged,SQLiteDatabase db,String entityColumn,String parentColumn) { List wrappers = new ArrayList<>(); SparseArray> childs = new SparseArray<>(); // 所有子表数据 SparseArray parents = new SparseArray<>(); // 所有父表数据 @@ -255,7 +258,12 @@ class DelegateFind extends AbsDelegate { childs.put(pRowId, new ArrayList()); parents.put(pRowId, createParent(pRowId, parentClazz, pColumn, cursor)); } - childs.get(pRowId).add(createChild(childClazz, cColumn, cursor)); + if(paged){ + childs.get(pRowId).addAll(createChildren(db,childClazz,pColumn,entityColumn,parentColumn,parents.get(pRowId))); + } + else { + childs.get(pRowId).add(createChild(childClazz, cColumn, cursor)); + } } List wFields = SqlUtil.getAllNotIgnoreField(wrapperClazz); @@ -285,7 +293,22 @@ class DelegateFind extends AbsDelegate { return wrappers; } + /** + * 创建子对象集合 + */ + private List createChildren(SQLiteDatabase db,Class childClazz, List pColumn, + String entityColumn,String parentColumn,DbEntity parents) + throws IllegalAccessException { + for (Field field : pColumn) { + field.setAccessible(true); + if(field.getName().equals(parentColumn)){ + Object o = field.get(parents); + return findData(db,childClazz,entityColumn+"='"+o+"'"); + } + } + return new ArrayList(); + } /** * 创建子对象 */