From d0013450633ef4b3fa1e3d4b347c9c0d8f3bed02 Mon Sep 17 00:00:00 2001 From: wangxianzhang Date: Thu, 23 Jun 2022 09:47:42 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BA=94=E5=A4=A7=E5=9B=BE=E5=B1=82?= =?UTF-8?q?=E3=80=91=E4=BF=AE=E5=A4=8D=E5=88=86=E9=A1=B5=E6=83=85=E5=86=B5?= =?UTF-8?q?=E4=B8=8Btotal=E4=B8=8D=E5=AF=B9=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CoverageController.java | 8 +-- .../dataaggre/service/CoverageService.java | 5 +- .../service/impl/CoverageServiceImpl.java | 50 ++++++++++++------- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/controller/CoverageController.java b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/controller/CoverageController.java index 98c4885046..27563e2134 100644 --- a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/controller/CoverageController.java +++ b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/controller/CoverageController.java @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.ArrayList; import java.util.List; /** @@ -34,13 +35,12 @@ public class CoverageController { List coverageTypes = input.getCoverageTypes(); List categoryKeys = input.getCategoryKeys(); if (CollectionUtils.isEmpty(coverageTypes)) { - return new Result(); + return new Result().ok(new PageData<>(new ArrayList<>(), 0)); } - List l = coverageService.analysisDataList(coverageTypes, categoryKeys, + PageData page = coverageService.analysisDataList(coverageTypes, categoryKeys, input.getSearch(), input.getPageNo(), input.getPageSize(), input.getIsPage()); - PageInfo pageInfo = new PageInfo<>(l); - return new Result>().ok(new PageData<>(l, pageInfo.getTotal())); + return new Result>().ok(page); } } diff --git a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/CoverageService.java b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/CoverageService.java index 446afa9e48..8734dcabd2 100644 --- a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/CoverageService.java +++ b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/CoverageService.java @@ -1,5 +1,6 @@ package com.epmet.dataaggre.service; +import com.epmet.commons.tools.page.PageData; import com.epmet.dataaggre.dto.govorg.result.CoverageAnalisisDataListResultDTO; import java.util.List; @@ -17,6 +18,6 @@ public interface CoverageService { * @param pageSize 页面大小 * @return */ - List analysisDataList(List coverageTypes, List categoryKeys, - String search, Integer pageNo, Integer pageSize, Boolean isPage); + PageData analysisDataList(List coverageTypes, List categoryKeys, + String search, Integer pageNo, Integer pageSize, Boolean isPage); } \ No newline at end of file diff --git a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/impl/CoverageServiceImpl.java b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/impl/CoverageServiceImpl.java index 6a1341a785..890665efe0 100644 --- a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/impl/CoverageServiceImpl.java +++ b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/impl/CoverageServiceImpl.java @@ -3,6 +3,7 @@ package com.epmet.dataaggre.service.impl; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.EpmetException; +import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.redis.common.CustomerStaffRedis; import com.epmet.commons.tools.redis.common.bean.BuildingInfoCache; import com.epmet.commons.tools.utils.EpmetRequestHolder; @@ -75,8 +76,8 @@ public class CoverageServiceImpl implements CoverageService { * @return */ @Override - public List analysisDataList(List coverageTypes, List categoryKeys, - String search, Integer pageNo, Integer pageSize, Boolean isPage) { + public PageData analysisDataList(List coverageTypes, List categoryKeys, + String search, Integer pageNo, Integer pageSize, Boolean isPage) { String customerId = EpmetRequestHolder.getLoginUserCustomerId(); String staffId = EpmetRequestHolder.getLoginUserId(); @@ -109,8 +110,16 @@ public class CoverageServiceImpl implements CoverageService { // 总共查询了多少个了 int lastTotalCount = 0; int totalCount = 0; + + // 是否出现要展示的数据 boolean dataAppear = false; + // 是否是第一次出现需要展示的数据 + boolean firstTimeDataAppear = false; + + // 数据是否够了,够了就不再查询数据 + boolean isDataEnough = false; + // 结果集 List rls = new ArrayList<>(); for (String coverageType : coverageTypes) { @@ -119,7 +128,11 @@ public class CoverageServiceImpl implements CoverageService { continue; } for (GovOrgCoverageService.CategoryCoverageMapping e : ccm) { - boolean firstTimeDataAppear = false; + + Integer tempCount = doDataListCount(EpmetRequestHolder.getLoginUserCustomerId(), agencyId, staffPids, e.getPlaceType(), + e.getCategoryKey(), search); + lastTotalCount = totalCount; + totalCount += tempCount; if (!isPage) { // 不分页,查询所有 @@ -131,19 +144,18 @@ public class CoverageServiceImpl implements CoverageService { continue; } - // 查询当前category有多少个 - if (!dataAppear) { - Integer tempCount = doDataListCount(EpmetRequestHolder.getLoginUserCustomerId(), agencyId, staffPids, e.getPlaceType(), - e.getCategoryKey(), search); - - lastTotalCount = totalCount; - totalCount += tempCount; - if (totalCount > start) { + if (totalCount > start) { + if (!dataAppear) { dataAppear = true; firstTimeDataAppear = true; - } else { - continue; } + } else { + continue; + } + + if (isDataEnough) { + // 数据够了,则不再查询数据列表,只检索数量,用于分页条显示 + continue; } // 检索数据 @@ -153,19 +165,23 @@ public class CoverageServiceImpl implements CoverageService { if (firstTimeDataAppear) { rls.addAll(dataSegment.subList(start - lastTotalCount, dataSegment.size())); + firstTimeDataAppear = false; } else { rls.addAll(dataSegment); } - firstTimeDataAppear = false; - // 最后,将多余的数据裁剪掉 if (rls.size() >= pageSize) { - return rls.subList(0, pageSize); + isDataEnough = true; } } } - return rls; + + if (isPage && rls.size() >= pageSize) { + return new PageData<>(rls.subList(0, pageSize), totalCount); + } else { + return new PageData<>(rls, totalCount); + } } /**