From b22c93b89339795d85b563126c5ce6f349f7ea53 Mon Sep 17 00:00:00 2001 From: zhaoguangwei Date: Mon, 21 Oct 2019 15:04:32 +0800 Subject: [PATCH] add the calFromIndexAndCountDescend(); --- .../ledger/core/LedgerQueryService.java | 6 +++--- .../peer/web/LedgerQueryController.java | 6 +++--- .../java/com/jd/blockchain/utils/QueryUtil.java | 17 +++++++++++++++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerQueryService.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerQueryService.java index 55b989d5..41e70138 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerQueryService.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerQueryService.java @@ -392,7 +392,7 @@ public class LedgerQueryService implements BlockchainQueryService { checkLedgerHash(ledgerHash); LedgerBlock block = ledger.getLatestBlock(); UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); - int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) userAccountSet.getTotal()); + int pages[] = QueryUtil.calFromIndexAndCountDescend(fromIndex, count, (int) userAccountSet.getTotal()); return userAccountSet.getHeaders(pages[0], pages[1]); } @@ -401,7 +401,7 @@ public class LedgerQueryService implements BlockchainQueryService { checkLedgerHash(ledgerHash); LedgerBlock block = ledger.getLatestBlock(); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); - int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccountSet.getTotal()); + int pages[] = QueryUtil.calFromIndexAndCountDescend(fromIndex, count, (int) dataAccountSet.getTotal()); return dataAccountSet.getHeaders(pages[0], pages[1]); } @@ -410,7 +410,7 @@ public class LedgerQueryService implements BlockchainQueryService { checkLedgerHash(ledgerHash); LedgerBlock block = ledger.getLatestBlock(); ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); - int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) contractAccountSet.getTotal()); + int pages[] = QueryUtil.calFromIndexAndCountDescend(fromIndex, count, (int) contractAccountSet.getTotal()); return contractAccountSet.getHeaders(pages[0], pages[1]); } diff --git a/source/peer/src/main/java/com/jd/blockchain/peer/web/LedgerQueryController.java b/source/peer/src/main/java/com/jd/blockchain/peer/web/LedgerQueryController.java index ad5f3aeb..741594ce 100644 --- a/source/peer/src/main/java/com/jd/blockchain/peer/web/LedgerQueryController.java +++ b/source/peer/src/main/java/com/jd/blockchain/peer/web/LedgerQueryController.java @@ -474,7 +474,7 @@ public class LedgerQueryController implements BlockchainQueryService { LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerBlock block = ledger.getLatestBlock(); UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); - int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) userAccountSet.getTotal()); + int pages[] = QueryUtil.calFromIndexAndCountDescend(fromIndex, count, (int) userAccountSet.getTotal()); return userAccountSet.getHeaders(pages[0], pages[1]); } @@ -494,7 +494,7 @@ public class LedgerQueryController implements BlockchainQueryService { LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerBlock block = ledger.getLatestBlock(); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); - int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccountSet.getTotal()); + int pages[] = QueryUtil.calFromIndexAndCountDescend(fromIndex, count, (int) dataAccountSet.getTotal()); return dataAccountSet.getHeaders(pages[0], pages[1]); } @@ -506,7 +506,7 @@ public class LedgerQueryController implements BlockchainQueryService { LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerBlock block = ledger.getLatestBlock(); ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); - int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) contractAccountSet.getTotal()); + int pages[] = QueryUtil.calFromIndexAndCountDescend(fromIndex, count, (int) contractAccountSet.getTotal()); return contractAccountSet.getHeaders(pages[0], pages[1]); } diff --git a/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/QueryUtil.java b/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/QueryUtil.java index 6af57e64..16021427 100644 --- a/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/QueryUtil.java +++ b/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/QueryUtil.java @@ -45,10 +45,23 @@ public class QueryUtil { } rtn[0] = fromIndex; rtn[1] = count; + return rtn; + } + + /** + * cal the data by descend; + * @param fromIndex + * @param count + * @param maxNum + * @return + */ + public static int[] calFromIndexAndCountDescend(int fromIndex, int count, int maxNum){ + int rtn[] = new int[2]; + int results[] = calFromIndexAndCount(fromIndex,count,maxNum); //now use descend; first show the latest record; - rtn[0] = maxNum - fromIndex - count; - rtn[1] = count; + rtn[0] = maxNum - results[0] - results[1]; + rtn[1] = results[1]; return rtn; } }