|
|
@ -151,58 +151,92 @@ public class StatsGroupServiceImpl implements StatsGroupService { |
|
|
|
BeanUtils.copyProperties(timeDim,agencyResult); |
|
|
|
//机关下的所有网格(包括直属网格)
|
|
|
|
List<String> allGrid = this.getAllGrid(agencyId,customerId); |
|
|
|
String pidByAgencyId = dimAgencyService.getPidByAgencyId(agencyId); |
|
|
|
agencyResult.setPid(StringUtils.isBlank(pidByAgencyId)?"0":pidByAgencyId); |
|
|
|
// 1. 机关下有多少网格
|
|
|
|
List<GridIdListByCustomerResultDTO> customerGridIdList = customerGridService.getCustomerGridIdList(customerId, dateId); |
|
|
|
AtomicReference<Integer> 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<GridIdListByCustomerResultDTO> customerGridIdList = customerGridService.getCustomerGridIdList(customerId, dateId); |
|
|
|
AtomicReference<Integer> 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<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); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
agencyResult.setGridTotal(gridSize.get()); |
|
|
|
}else { |
|
|
|
agencyResult.setGridTotal(NumConstant.ZERO); |
|
|
|
} |
|
|
|
// 2. 机关下有多少小组,只算 state = ‘approved’
|
|
|
|
List<AgencyGroupTotalCountResultDTO> agencyGroupTotalCount = groupDataService.getAgencyGroupTotalCount(allGrid,dateId); |
|
|
|
Integer groupCount = agencyGroupTotalCount.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)); |
|
|
|
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()); |
|
|
|
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<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> 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()); |
|
|
|
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<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); |
|
|
|
} |
|
|
|
// 6. 机关下小组增量
|
|
|
|
List<AgencyGroupIncrResultDTO> agencyGroupIncr = groupDataService.selectAgencyGroupIncr(allGrid, dateId); |
|
|
|
Integer groupIncr = agencyGroupIncr.stream().collect(Collectors.summingInt(AgencyGroupIncrResultDTO::getGroupIncr)); |
|
|
|
agencyResult.setGroupIncr(groupIncr); |
|
|
|
result.add(agencyResult); |
|
|
|
}); |
|
|
|
return result; |
|
|
|