Browse Source

【五大图层】修复分页情况下total不对的问题

feature/teamB_zz_wgh
wangxianzhang 3 years ago
parent
commit
d001345063
  1. 8
      epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/controller/CoverageController.java
  2. 5
      epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/CoverageService.java
  3. 50
      epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/impl/CoverageServiceImpl.java

8
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -34,13 +35,12 @@ public class CoverageController {
List<String> coverageTypes = input.getCoverageTypes(); List<String> coverageTypes = input.getCoverageTypes();
List<String> categoryKeys = input.getCategoryKeys(); List<String> categoryKeys = input.getCategoryKeys();
if (CollectionUtils.isEmpty(coverageTypes)) { if (CollectionUtils.isEmpty(coverageTypes)) {
return new Result(); return new Result().ok(new PageData<>(new ArrayList<>(), 0));
} }
List<CoverageAnalisisDataListResultDTO> l = coverageService.analysisDataList(coverageTypes, categoryKeys, PageData<CoverageAnalisisDataListResultDTO> page = coverageService.analysisDataList(coverageTypes, categoryKeys,
input.getSearch(), input.getPageNo(), input.getPageSize(), input.getIsPage()); input.getSearch(), input.getPageNo(), input.getPageSize(), input.getIsPage());
PageInfo<CoverageAnalisisDataListResultDTO> pageInfo = new PageInfo<>(l); return new Result<PageData<CoverageAnalisisDataListResultDTO>>().ok(page);
return new Result<PageData<CoverageAnalisisDataListResultDTO>>().ok(new PageData<>(l, pageInfo.getTotal()));
} }
} }

5
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; package com.epmet.dataaggre.service;
import com.epmet.commons.tools.page.PageData;
import com.epmet.dataaggre.dto.govorg.result.CoverageAnalisisDataListResultDTO; import com.epmet.dataaggre.dto.govorg.result.CoverageAnalisisDataListResultDTO;
import java.util.List; import java.util.List;
@ -17,6 +18,6 @@ public interface CoverageService {
* @param pageSize 页面大小 * @param pageSize 页面大小
* @return * @return
*/ */
List<CoverageAnalisisDataListResultDTO> analysisDataList(List<String> coverageTypes, List<String> categoryKeys, PageData<CoverageAnalisisDataListResultDTO> analysisDataList(List<String> coverageTypes, List<String> categoryKeys,
String search, Integer pageNo, Integer pageSize, Boolean isPage); String search, Integer pageNo, Integer pageSize, Boolean isPage);
} }

50
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.dto.result.CustomerStaffInfoCacheResult;
import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.EpmetException; 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.CustomerStaffRedis;
import com.epmet.commons.tools.redis.common.bean.BuildingInfoCache; import com.epmet.commons.tools.redis.common.bean.BuildingInfoCache;
import com.epmet.commons.tools.utils.EpmetRequestHolder; import com.epmet.commons.tools.utils.EpmetRequestHolder;
@ -75,8 +76,8 @@ public class CoverageServiceImpl implements CoverageService {
* @return * @return
*/ */
@Override @Override
public List<CoverageAnalisisDataListResultDTO> analysisDataList(List<String> coverageTypes, List<String> categoryKeys, public PageData<CoverageAnalisisDataListResultDTO> analysisDataList(List<String> coverageTypes, List<String> categoryKeys,
String search, Integer pageNo, Integer pageSize, Boolean isPage) { String search, Integer pageNo, Integer pageSize, Boolean isPage) {
String customerId = EpmetRequestHolder.getLoginUserCustomerId(); String customerId = EpmetRequestHolder.getLoginUserCustomerId();
String staffId = EpmetRequestHolder.getLoginUserId(); String staffId = EpmetRequestHolder.getLoginUserId();
@ -109,8 +110,16 @@ public class CoverageServiceImpl implements CoverageService {
// 总共查询了多少个了 // 总共查询了多少个了
int lastTotalCount = 0; int lastTotalCount = 0;
int totalCount = 0; int totalCount = 0;
// 是否出现要展示的数据
boolean dataAppear = false; boolean dataAppear = false;
// 是否是第一次出现需要展示的数据
boolean firstTimeDataAppear = false;
// 数据是否够了,够了就不再查询数据
boolean isDataEnough = false;
// 结果集 // 结果集
List<CoverageAnalisisDataListResultDTO> rls = new ArrayList<>(); List<CoverageAnalisisDataListResultDTO> rls = new ArrayList<>();
for (String coverageType : coverageTypes) { for (String coverageType : coverageTypes) {
@ -119,7 +128,11 @@ public class CoverageServiceImpl implements CoverageService {
continue; continue;
} }
for (GovOrgCoverageService.CategoryCoverageMapping e : ccm) { 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) { if (!isPage) {
// 不分页,查询所有 // 不分页,查询所有
@ -131,19 +144,18 @@ public class CoverageServiceImpl implements CoverageService {
continue; continue;
} }
// 查询当前category有多少个 if (totalCount > start) {
if (!dataAppear) { if (!dataAppear) {
Integer tempCount = doDataListCount(EpmetRequestHolder.getLoginUserCustomerId(), agencyId, staffPids, e.getPlaceType(),
e.getCategoryKey(), search);
lastTotalCount = totalCount;
totalCount += tempCount;
if (totalCount > start) {
dataAppear = true; dataAppear = true;
firstTimeDataAppear = true; firstTimeDataAppear = true;
} else {
continue;
} }
} else {
continue;
}
if (isDataEnough) {
// 数据够了,则不再查询数据列表,只检索数量,用于分页条显示
continue;
} }
// 检索数据 // 检索数据
@ -153,19 +165,23 @@ public class CoverageServiceImpl implements CoverageService {
if (firstTimeDataAppear) { if (firstTimeDataAppear) {
rls.addAll(dataSegment.subList(start - lastTotalCount, dataSegment.size())); rls.addAll(dataSegment.subList(start - lastTotalCount, dataSegment.size()));
firstTimeDataAppear = false;
} else { } else {
rls.addAll(dataSegment); rls.addAll(dataSegment);
} }
firstTimeDataAppear = false;
// 最后,将多余的数据裁剪掉 // 最后,将多余的数据裁剪掉
if (rls.size() >= pageSize) { 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);
}
} }
/** /**

Loading…
Cancel
Save