From 9616152d18c8218dd66d510dfc6457ffaeaec35e Mon Sep 17 00:00:00 2001 From: wangxianzhang Date: Mon, 13 Dec 2021 15:43:02 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=201.=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=BF=97=E6=84=BF=E8=80=85=E5=88=86=E5=B8=83=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/heart/HeartVolunteerService.java | 2 +- .../heart/impl/HeartVolunteerServiceImpl.java | 12 ++-- .../epmet/service/impl/DemandServiceImpl.java | 59 ++++++++----------- 3 files changed, 31 insertions(+), 42 deletions(-) diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/HeartVolunteerService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/HeartVolunteerService.java index abccaae1e6..b8e4414f60 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/HeartVolunteerService.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/HeartVolunteerService.java @@ -11,5 +11,5 @@ import java.util.List; *@Date 2021/12/8 */ public interface HeartVolunteerService { - List listVolunteersPage(String customerId, Date endCreateTime, Integer pageNum, Integer pageSize); + List listVolunteers(String customerId, Date endCreateTime); } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/impl/HeartVolunteerServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/impl/HeartVolunteerServiceImpl.java index c95fd094fe..d9a931072b 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/impl/HeartVolunteerServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/impl/HeartVolunteerServiceImpl.java @@ -29,12 +29,10 @@ public class HeartVolunteerServiceImpl implements HeartVolunteerService { private VolunteerInfoDao volunteerInfoDao; @Override - public List listVolunteersPage(String customerId, Date endCreateTime, Integer pageNum, Integer pageSize) { - return PageHelper.startPage(pageNum, pageSize).doSelectPage(() -> { - LambdaQueryWrapper query = new LambdaQueryWrapper<>(); - query.eq(VolunteerInfoEntity::getCustomerId, customerId); - query.lt(VolunteerInfoEntity::getCreatedTime, endCreateTime); - volunteerInfoDao.selectList(query); - }); + public List listVolunteers(String customerId, Date endCreateTime) { + LambdaQueryWrapper query = new LambdaQueryWrapper<>(); + query.eq(VolunteerInfoEntity::getCustomerId, customerId); + query.lt(VolunteerInfoEntity::getCreatedTime, endCreateTime); + volunteerInfoDao.selectList(query); } } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/DemandServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/DemandServiceImpl.java index 7782226923..e165e95a75 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/DemandServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/DemandServiceImpl.java @@ -67,11 +67,12 @@ public class DemandServiceImpl implements DemandService { /** * 清理旧数据 - * @param yestoday + * @param targetDate 要清理哪天的数据 + * @param customerIds 要清理哪些客户的 */ - private void clearOldDatas(List customerIds, Date yestoday) { + private void clearOldDatas(List customerIds, Date targetDate) { - String dateDimId = DimIdGenerator.getDateDimId(yestoday); + String dateDimId = DimIdGenerator.getDateDimId(targetDate); demandStatsService.clearVolunteerDemandServiceDailyStats(customerIds, dateDimId); @@ -90,50 +91,40 @@ public class DemandServiceImpl implements DemandService { // 居民志愿者数量 Integer resiVolunteerCount = 0; + // 党员志愿者用户id列表 List partymemberVolunteerUserIds = new ArrayList<>(16); - int pageNum = 1; - int volunteerPageSize = 5; + List volunteers = heartVolunteerService.listVolunteers(customerId, endTime); - while (true) { - - int shardingStartIndex = 0; - int shardingSize = 2; + volunteerTotalCount = volunteers.size(); - List volunteersPage = heartVolunteerService.listVolunteersPage(customerId, endTime, pageNum, volunteerPageSize); + // 分片开始下标 + int shardingStartIndex = 0; + // 分片大小(条数) + int shardingSize = 2; + + // 分片去确定党员身份,防止in条件过大 + while (true) { + int realShardingSize = Math.min(shardingSize, volunteerTotalCount - shardingStartIndex); - // 如果查询结果为0,说明没有更多的志愿者了 - if (volunteersPage.size() == 0) { + if (realShardingSize <= 0) { break; } - volunteerTotalCount += volunteersPage.size(); - - // 分片去确定党员身份 - while (true) { - int realShardingSize = Math.min(shardingSize, volunteersPage.size() - shardingStartIndex); + int shardingEndIndex = shardingStartIndex + realShardingSize; + List volunteerUserIds = volunteers.subList(shardingStartIndex, shardingEndIndex) + .stream() + .map((volunteerInfoEntity) -> volunteerInfoEntity.getUserId()) + .collect(Collectors.toList()); - if (realShardingSize == 0) { - break; - } - - int shardingEndIndex = shardingStartIndex + realShardingSize; - List volunteerUserIds = volunteersPage.subList(shardingStartIndex, shardingEndIndex) - .stream() - .map((volunteerInfoEntity) -> volunteerInfoEntity.getUserId()) - .collect(Collectors.toList()); - - List tempPartymemberUserIds = userService.filterUserIds(volunteerUserIds, EpmetRoleKeyConstant.PARTYMEMBER); + List tempPartymemberUserIds = userService.filterUserIds(volunteerUserIds, EpmetRoleKeyConstant.PARTYMEMBER); - partymemberVolunteerUserIds.addAll(tempPartymemberUserIds); - - shardingStartIndex = shardingEndIndex; - } + partymemberVolunteerUserIds.addAll(tempPartymemberUserIds); - pageNum++; + shardingStartIndex = shardingEndIndex; } - partymemberVolunteerCount += partymemberVolunteerUserIds.size(); + partymemberVolunteerCount = partymemberVolunteerUserIds.size(); resiVolunteerCount = volunteerTotalCount - partymemberVolunteerCount; //2. 查询志愿者服务次数 From b5d1790bff3f6a67d51fd264faff66755e879b72 Mon Sep 17 00:00:00 2001 From: wangxianzhang Date: Mon, 13 Dec 2021 15:57:28 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=201.=E5=BF=97?= =?UTF-8?q?=E6=84=BF=E8=80=85=E5=88=86=E5=B8=83=E5=8F=82=E6=95=B0=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/dto/result/VolunteerDistributionResultDTO.java | 2 +- .../main/java/com/epmet/service/impl/VolunteerServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/VolunteerDistributionResultDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/VolunteerDistributionResultDTO.java index c1bb3d866c..94a4d4ac88 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/VolunteerDistributionResultDTO.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/VolunteerDistributionResultDTO.java @@ -27,7 +27,7 @@ public class VolunteerDistributionResultDTO { @Data public static class Distribution { - private Set volunteerTypes; + private Set volunteerCategories; private String epmetUserId; private String icResiUserId; private String longitude; diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/VolunteerServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/VolunteerServiceImpl.java index f0e2796a98..d259315211 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/VolunteerServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/VolunteerServiceImpl.java @@ -162,7 +162,7 @@ public class VolunteerServiceImpl implements VolunteerService, ResultDataResolve ServiceConstant.GOV_ORG_SERVER, EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), msg, msg); - distribution.setVolunteerTypes(volunteerTypes); + distribution.setVolunteerCategories(volunteerTypes); distribution.setEpmetUserId(userBaseInfo.getUserId()); distribution.setIcResiUserId(icResiUserInfo.getId()); Optional.of(building).ifPresent(b -> { From 302c72d7bbc0f578478b5f22776eb790e44a79f8 Mon Sep 17 00:00:00 2001 From: wangxianzhang Date: Mon, 13 Dec 2021 15:58:59 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=201.=E5=BF=97?= =?UTF-8?q?=E6=84=BF=E8=80=85=E5=88=86=E5=B8=83=E5=8F=82=E6=95=B0=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/service/heart/impl/HeartVolunteerServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/impl/HeartVolunteerServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/impl/HeartVolunteerServiceImpl.java index d9a931072b..902a6a8713 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/impl/HeartVolunteerServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/impl/HeartVolunteerServiceImpl.java @@ -33,6 +33,6 @@ public class HeartVolunteerServiceImpl implements HeartVolunteerService { LambdaQueryWrapper query = new LambdaQueryWrapper<>(); query.eq(VolunteerInfoEntity::getCustomerId, customerId); query.lt(VolunteerInfoEntity::getCreatedTime, endCreateTime); - volunteerInfoDao.selectList(query); + return volunteerInfoDao.selectList(query); } }