|  |  | @ -151,6 +151,7 @@ public class StatsGroupServiceImpl implements StatsGroupService { | 
			
		
	
		
			
				
					|  |  |  |             BeanUtils.copyProperties(timeDim,agencyResult); | 
			
		
	
		
			
				
					|  |  |  |             //机关下的所有网格(包括直属网格)
 | 
			
		
	
		
			
				
					|  |  |  |             List<String> allGrid = this.getAllGrid(agencyId,customerId); | 
			
		
	
		
			
				
					|  |  |  |             if (allGrid.size() != NumConstant.ZERO) { | 
			
		
	
		
			
				
					|  |  |  |                 String pidByAgencyId = dimAgencyService.getPidByAgencyId(agencyId); | 
			
		
	
		
			
				
					|  |  |  |                 agencyResult.setPid(StringUtils.isBlank(pidByAgencyId) ? "0" : pidByAgencyId); | 
			
		
	
		
			
				
					|  |  |  |                 // 1. 机关下有多少网格
 | 
			
		
	
	
		
			
				
					|  |  | @ -169,20 +170,44 @@ public class StatsGroupServiceImpl implements StatsGroupService { | 
			
		
	
		
			
				
					|  |  |  |                     agencyResult.setGridTotal(NumConstant.ZERO); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |                 // 2. 机关下有多少小组,只算   state = ‘approved’
 | 
			
		
	
		
			
				
					|  |  |  |             List<AgencyGroupTotalCountResultDTO> agencyGroupTotalCount = groupDataService.getAgencyGroupTotalCount(allGrid,dateId); | 
			
		
	
		
			
				
					|  |  |  |             Integer groupCount = agencyGroupTotalCount.stream().collect(Collectors.summingInt(AgencyGroupTotalCountResultDTO::getGridGroupCount)); | 
			
		
	
		
			
				
					|  |  |  |                 List<AgencyGroupTotalCountResultDTO> approvedResult = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |                 List<AgencyGroupTotalCountResultDTO> agencyGroupTotalCount = groupDataService.getAgencyGroupTotalCount(customerId, dateId); | 
			
		
	
		
			
				
					|  |  |  |                 allGrid.forEach(grid -> { | 
			
		
	
		
			
				
					|  |  |  |                     agencyGroupTotalCount.forEach(groupTotal -> { | 
			
		
	
		
			
				
					|  |  |  |                         if (grid.equals(groupTotal.getGridId())) { | 
			
		
	
		
			
				
					|  |  |  |                             approvedResult.add(groupTotal); | 
			
		
	
		
			
				
					|  |  |  |                         } | 
			
		
	
		
			
				
					|  |  |  |                     }); | 
			
		
	
		
			
				
					|  |  |  |                 }); | 
			
		
	
		
			
				
					|  |  |  |                 Integer groupCount = approvedResult.stream().collect(Collectors.summingInt(AgencyGroupTotalCountResultDTO::getGridGroupCount)); | 
			
		
	
		
			
				
					|  |  |  |                 agencyResult.setGroupTotalCount(groupCount); | 
			
		
	
		
			
				
					|  |  |  |                 // 3. 机关下所有组内人数和(不需要去重) 人员状态 != "removed"
 | 
			
		
	
		
			
				
					|  |  |  |             List<AgencyGridGroupPeopleTotalResultDTO> agencyGridGroupPeopleTotal = groupDataService.selectAgencyGridGroupPeopleTotal(allGrid,dateId); | 
			
		
	
		
			
				
					|  |  |  |             Integer groupPeopleCount = agencyGridGroupPeopleTotal.stream().collect(Collectors.summingInt(AgencyGridGroupPeopleTotalResultDTO::getGridGroupPeopleTotal)); | 
			
		
	
		
			
				
					|  |  |  |                 List<AgencyGridGroupPeopleTotalResultDTO> peopleTotal = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |                 List<AgencyGridGroupPeopleTotalResultDTO> 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<AgencyGridGroupPeopleResultDTO> agencyGridGroupPeople = groupDataService.selectAgencyEveryGroupPeopleCount(allGrid,dateId); | 
			
		
	
		
			
				
					|  |  |  |             List<AgencyGridGroupPeopleResultDTO> sorted = agencyGridGroupPeople.stream().sorted(Comparator.comparing(AgencyGridGroupPeopleResultDTO::getGroupCount).reversed()).collect(Collectors.toList()); | 
			
		
	
		
			
				
					|  |  |  |                 List<AgencyGridGroupPeopleResultDTO> groupPeople = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |                 List<AgencyGridGroupPeopleResultDTO> agencyGridGroupPeople = groupDataService.selectAgencyEveryGroupPeopleCount(customerId, dateId); | 
			
		
	
		
			
				
					|  |  |  |                 allGrid.forEach(grid -> { | 
			
		
	
		
			
				
					|  |  |  |                     agencyGridGroupPeople.forEach(group -> { | 
			
		
	
		
			
				
					|  |  |  |                         if (grid.equals(group.getGridId())) { | 
			
		
	
		
			
				
					|  |  |  |                             groupPeople.add(group); | 
			
		
	
		
			
				
					|  |  |  |                         } | 
			
		
	
		
			
				
					|  |  |  |                     }); | 
			
		
	
		
			
				
					|  |  |  |                 }); | 
			
		
	
		
			
				
					|  |  |  |                 List<AgencyGridGroupPeopleResultDTO> 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()); | 
			
		
	
	
		
			
				
					|  |  | @ -200,9 +225,18 @@ public class StatsGroupServiceImpl implements StatsGroupService { | 
			
		
	
		
			
				
					|  |  |  |                     agencyResult.setMinMemberGroupId(sorted.get(sorted.size() - NumConstant.ONE).getGroupId()); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |                 // 6. 机关下小组增量
 | 
			
		
	
		
			
				
					|  |  |  |             List<AgencyGroupIncrResultDTO> agencyGroupIncr = groupDataService.selectAgencyGroupIncr(allGrid, dateId); | 
			
		
	
		
			
				
					|  |  |  |             Integer groupIncr = agencyGroupIncr.stream().collect(Collectors.summingInt(AgencyGroupIncrResultDTO::getGroupIncr)); | 
			
		
	
		
			
				
					|  |  |  |             agencyResult.setGroupIncr(groupIncr); | 
			
		
	
		
			
				
					|  |  |  |                 List<AgencyGroupIncrResultDTO> groupIncr = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |                 List<AgencyGroupIncrResultDTO> 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); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             result.add(agencyResult); | 
			
		
	
		
			
				
					|  |  |  |         }); | 
			
		
	
		
			
				
					|  |  |  |         return result; | 
			
		
	
	
		
			
				
					|  |  | 
 |