From 1c4798d086a7e3fa2a85a68354fe7a21b3b44fe4 Mon Sep 17 00:00:00 2001 From: zxc <954985706@qq.com> Date: Mon, 29 Jun 2020 13:45:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BB=9F=E8=AE=A1=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/dao/group/GroupDataDao.java | 8 +- .../group/impl/GroupDataServiceImpl.java | 32 ++--- .../service/impl/StatsGroupServiceImpl.java | 130 +++++++++++------- .../resources/mapper/group/GroupDataDao.xml | 16 +-- 4 files changed, 106 insertions(+), 80 deletions(-) diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/group/GroupDataDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/group/GroupDataDao.java index 28703e70e9..db1bc08318 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/group/GroupDataDao.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/group/GroupDataDao.java @@ -50,21 +50,21 @@ public interface GroupDataDao { * @param * @author zxc */ - List getAgencyGroupTotalCount(@Param("allGrid") List allGrid,@Param("dateId")String dateId); + List getAgencyGroupTotalCount(@Param("customerId") String customerId,@Param("dateId")String dateId); /** * @Description 查询机关下网格内的小组人数 【待优化】 * @param * @author zxc */ - List selectAgencyGridGroupPeopleTotal(@Param("allGrid") List allGrid,@Param("dateId")String dateId); + List selectAgencyGridGroupPeopleTotal(@Param("customerId") String customerId,@Param("dateId")String dateId); /** * @Description 查询机关下每个小组的人数 【待优化】 * @param * @author zxc */ - List selectAgencyEveryGroupPeopleCount(@Param("allGrid") List allGrid,@Param("dateId")String dateId); + List selectAgencyEveryGroupPeopleCount(@Param("customerId") String customerId,@Param("dateId")String dateId); /** * @Description 查询机关下的小组日增数 【待优化】 @@ -72,7 +72,7 @@ public interface GroupDataDao { * @param dateId * @author zxc */ - List selectAgencyGroupIncr(@Param("allGrid") List allGrid,@Param("dateId")String dateId); + List selectAgencyGroupIncr(@Param("customerId") String customerId,@Param("dateId")String dateId); /** * @Description 查询机关下所有网格小组人数 diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/group/impl/GroupDataServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/group/impl/GroupDataServiceImpl.java index 1cdc3acdcf..cd4a68f97a 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/group/impl/GroupDataServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/group/impl/GroupDataServiceImpl.java @@ -133,11 +133,11 @@ public class GroupDataServiceImpl implements GroupDataService { * @param * @author zxc */ - public List getAgencyGroupTotalCount(List allGrid,String dateId){ - if (allGrid.size() == NumConstant.ZERO){ + public List getAgencyGroupTotalCount(String customerId,String dateId){ + /*if (allGrid.size() == NumConstant.ZERO){ return new ArrayList<>(); - } - return groupDataDao.getAgencyGroupTotalCount(allGrid,dateId); + }*/ + return groupDataDao.getAgencyGroupTotalCount(customerId,dateId); } /** @@ -146,11 +146,11 @@ public class GroupDataServiceImpl implements GroupDataService { * @author zxc */ @Override - public List selectAgencyGridGroupPeopleTotal(List allGrid,String dateId) { - if (allGrid.size() == NumConstant.ZERO){ + public List selectAgencyGridGroupPeopleTotal(String customerId,String dateId) { + /*if (allGrid.size() == NumConstant.ZERO){ return new ArrayList<>(); - } - return groupDataDao.selectAgencyGridGroupPeopleTotal(allGrid,dateId); + }*/ + return groupDataDao.selectAgencyGridGroupPeopleTotal(customerId,dateId); } /** @@ -158,11 +158,11 @@ public class GroupDataServiceImpl implements GroupDataService { * @param * @author zxc */ - public List selectAgencyEveryGroupPeopleCount(List allGrid,String dateId){ - if (allGrid.size() == NumConstant.ZERO){ + public List selectAgencyEveryGroupPeopleCount(String customerId,String dateId){ + /*if (allGrid.size() == NumConstant.ZERO){ return new ArrayList<>(); - } - return groupDataDao.selectAgencyEveryGroupPeopleCount(allGrid,dateId); + }*/ + return groupDataDao.selectAgencyEveryGroupPeopleCount(customerId,dateId); } /** @@ -171,11 +171,11 @@ public class GroupDataServiceImpl implements GroupDataService { * @param dateId * @author zxc */ - public List selectAgencyGroupIncr(List allGrid,String dateId){ - if (allGrid.size() == NumConstant.ZERO){ + public List selectAgencyGroupIncr(String customerId,String dateId){ + /*if (allGrid.size() == NumConstant.ZERO){ return new ArrayList<>(); - } - return groupDataDao.selectAgencyGroupIncr(allGrid, dateId); + }*/ + return groupDataDao.selectAgencyGroupIncr(customerId, dateId); } /** diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsGroupServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsGroupServiceImpl.java index 8fc87943da..5e86bc0bbb 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsGroupServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsGroupServiceImpl.java @@ -151,58 +151,92 @@ public class StatsGroupServiceImpl implements StatsGroupService { BeanUtils.copyProperties(timeDim,agencyResult); //机关下的所有网格(包括直属网格) List allGrid = this.getAllGrid(agencyId,customerId); - String pidByAgencyId = dimAgencyService.getPidByAgencyId(agencyId); - agencyResult.setPid(StringUtils.isBlank(pidByAgencyId)?"0":pidByAgencyId); - // 1. 机关下有多少网格 - List customerGridIdList = customerGridService.getCustomerGridIdList(customerId, dateId); - AtomicReference gridSize = new AtomicReference<>(0); - if (customerGridIdList.size() != NumConstant.ZERO){ - customerGridIdList.forEach(gridId -> { - allGrid.forEach(allAgencyGrid -> { - if (gridId.getGridId().equals(allAgencyGrid)){ - gridSize.updateAndGet(v -> v + NumConstant.ONE); + if (allGrid.size() != NumConstant.ZERO) { + String pidByAgencyId = dimAgencyService.getPidByAgencyId(agencyId); + agencyResult.setPid(StringUtils.isBlank(pidByAgencyId) ? "0" : pidByAgencyId); + // 1. 机关下有多少网格 + List customerGridIdList = customerGridService.getCustomerGridIdList(customerId, dateId); + AtomicReference gridSize = new AtomicReference<>(0); + if (customerGridIdList.size() != NumConstant.ZERO) { + customerGridIdList.forEach(gridId -> { + allGrid.forEach(allAgencyGrid -> { + if (gridId.getGridId().equals(allAgencyGrid)) { + gridSize.updateAndGet(v -> v + NumConstant.ONE); + } + }); + }); + agencyResult.setGridTotal(gridSize.get()); + } else { + agencyResult.setGridTotal(NumConstant.ZERO); + } + // 2. 机关下有多少小组,只算 state = ‘approved’ + List approvedResult = new ArrayList<>(); + List agencyGroupTotalCount = groupDataService.getAgencyGroupTotalCount(customerId, dateId); + allGrid.forEach(grid -> { + agencyGroupTotalCount.forEach(groupTotal -> { + if (grid.equals(groupTotal.getGridId())) { + approvedResult.add(groupTotal); } }); }); - agencyResult.setGridTotal(gridSize.get()); - }else { - agencyResult.setGridTotal(NumConstant.ZERO); - } - // 2. 机关下有多少小组,只算 state = ‘approved’ - List agencyGroupTotalCount = groupDataService.getAgencyGroupTotalCount(allGrid,dateId); - Integer groupCount = agencyGroupTotalCount.stream().collect(Collectors.summingInt(AgencyGroupTotalCountResultDTO::getGridGroupCount)); - agencyResult.setGroupTotalCount(groupCount); - // 3. 机关下所有组内人数和(不需要去重) 人员状态 != "removed" - List agencyGridGroupPeopleTotal = groupDataService.selectAgencyGridGroupPeopleTotal(allGrid,dateId); - Integer groupPeopleCount = agencyGridGroupPeopleTotal.stream().collect(Collectors.summingInt(AgencyGridGroupPeopleTotalResultDTO::getGridGroupPeopleTotal)); - agencyResult.setGroupMemberTotalCount(groupPeopleCount); - // 4. 机关下小组平均人数 - agencyResult.setGroupMemberAvgCount( - agencyResult.getGroupTotalCount() == NumConstant.ZERO ? NumConstant.ZERO : - agencyResult.getGroupMemberTotalCount()/agencyResult.getGroupTotalCount()); - // 5. 机关下小组人数中位数 小组最大(小)成员数、最多(少)成员小组ID - List agencyGridGroupPeople = groupDataService.selectAgencyEveryGroupPeopleCount(allGrid,dateId); - List sorted = agencyGridGroupPeople.stream().sorted(Comparator.comparing(AgencyGridGroupPeopleResultDTO::getGroupCount).reversed()).collect(Collectors.toList()); - Integer groupPeopleMedian; - if (sorted.size() == NumConstant.ONE){ - agencyResult.setGroupMemberMaxCount(sorted.get(NumConstant.ZERO).getGroupCount()); - agencyResult.setMaxMemberGroupId(sorted.get(NumConstant.ZERO).getGroupId()); - agencyResult.setGroupMemberMinCount(sorted.get(NumConstant.ZERO).getGroupCount()); - agencyResult.setMinMemberGroupId(sorted.get(NumConstant.ZERO).getGroupId()); - }else if (sorted.size() >= NumConstant.TWO){ - groupPeopleMedian = sorted.size() % NumConstant.TWO == NumConstant.ZERO ? - (sorted.get(sorted.size() / NumConstant.TWO - NumConstant.ONE).getGroupCount() + sorted.get(sorted.size() / 2).getGroupCount()) / 2 : - sorted.get(sorted.size() / NumConstant.TWO).getGroupCount(); - agencyResult.setGroupMedian(groupPeopleMedian); - agencyResult.setGroupMemberMaxCount(sorted.get(NumConstant.ZERO).getGroupCount()); - agencyResult.setMaxMemberGroupId(sorted.get(NumConstant.ZERO).getGroupId()); - agencyResult.setGroupMemberMinCount(sorted.get(sorted.size() - NumConstant.ONE).getGroupCount()); - agencyResult.setMinMemberGroupId(sorted.get(sorted.size() - NumConstant.ONE).getGroupId()); + Integer groupCount = approvedResult.stream().collect(Collectors.summingInt(AgencyGroupTotalCountResultDTO::getGridGroupCount)); + agencyResult.setGroupTotalCount(groupCount); + // 3. 机关下所有组内人数和(不需要去重) 人员状态 != "removed" + List peopleTotal = new ArrayList<>(); + List agencyGridGroupPeopleTotal = groupDataService.selectAgencyGridGroupPeopleTotal(customerId, dateId); + allGrid.forEach(grid -> { + agencyGridGroupPeopleTotal.forEach(people -> { + if (grid.equals(people.getGridId())) { + peopleTotal.add(people); + } + }); + }); + Integer groupPeopleCount = peopleTotal.stream().collect(Collectors.summingInt(AgencyGridGroupPeopleTotalResultDTO::getGridGroupPeopleTotal)); + agencyResult.setGroupMemberTotalCount(groupPeopleCount); + // 4. 机关下小组平均人数 + agencyResult.setGroupMemberAvgCount( + agencyResult.getGroupTotalCount() == NumConstant.ZERO ? NumConstant.ZERO : + agencyResult.getGroupMemberTotalCount() / agencyResult.getGroupTotalCount()); + // 5. 机关下小组人数中位数 小组最大(小)成员数、最多(少)成员小组ID + List groupPeople = new ArrayList<>(); + List agencyGridGroupPeople = groupDataService.selectAgencyEveryGroupPeopleCount(customerId, dateId); + allGrid.forEach(grid -> { + agencyGridGroupPeople.forEach(group -> { + if (grid.equals(group.getGridId())) { + groupPeople.add(group); + } + }); + }); + List sorted = groupPeople.stream().sorted(Comparator.comparing(AgencyGridGroupPeopleResultDTO::getGroupCount).reversed()).collect(Collectors.toList()); + Integer groupPeopleMedian; + if (sorted.size() == NumConstant.ONE) { + agencyResult.setGroupMemberMaxCount(sorted.get(NumConstant.ZERO).getGroupCount()); + agencyResult.setMaxMemberGroupId(sorted.get(NumConstant.ZERO).getGroupId()); + agencyResult.setGroupMemberMinCount(sorted.get(NumConstant.ZERO).getGroupCount()); + agencyResult.setMinMemberGroupId(sorted.get(NumConstant.ZERO).getGroupId()); + } else if (sorted.size() >= NumConstant.TWO) { + groupPeopleMedian = sorted.size() % NumConstant.TWO == NumConstant.ZERO ? + (sorted.get(sorted.size() / NumConstant.TWO - NumConstant.ONE).getGroupCount() + sorted.get(sorted.size() / 2).getGroupCount()) / 2 : + sorted.get(sorted.size() / NumConstant.TWO).getGroupCount(); + agencyResult.setGroupMedian(groupPeopleMedian); + agencyResult.setGroupMemberMaxCount(sorted.get(NumConstant.ZERO).getGroupCount()); + agencyResult.setMaxMemberGroupId(sorted.get(NumConstant.ZERO).getGroupId()); + agencyResult.setGroupMemberMinCount(sorted.get(sorted.size() - NumConstant.ONE).getGroupCount()); + agencyResult.setMinMemberGroupId(sorted.get(sorted.size() - NumConstant.ONE).getGroupId()); + } + // 6. 机关下小组增量 + List groupIncr = new ArrayList<>(); + List agencyGroupIncr = groupDataService.selectAgencyGroupIncr(customerId, dateId); + allGrid.forEach(grid -> { + agencyGroupIncr.forEach(incr -> { + if (grid.equals(incr.getGridId())) { + groupIncr.add(incr); + } + }); + }); + Integer groupIncrCount = groupIncr.stream().collect(Collectors.summingInt(AgencyGroupIncrResultDTO::getGroupIncr)); + agencyResult.setGroupIncr(groupIncrCount); } - // 6. 机关下小组增量 - List agencyGroupIncr = groupDataService.selectAgencyGroupIncr(allGrid, dateId); - Integer groupIncr = agencyGroupIncr.stream().collect(Collectors.summingInt(AgencyGroupIncrResultDTO::getGroupIncr)); - agencyResult.setGroupIncr(groupIncr); result.add(agencyResult); }); return result; diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/group/GroupDataDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/group/GroupDataDao.xml index 968ca9d83d..0ed8f428fe 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/group/GroupDataDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/group/GroupDataDao.xml @@ -73,7 +73,6 @@