|
1 | 1 | package com.dduckddak.domain.data.service;
|
2 | 2 |
|
3 |
| -import com.dduckddak.domain.data.dto.PopulationByDistrictResponse; |
4 |
| -import com.dduckddak.domain.data.dto.PopulationByQuarterDto; |
5 |
| -import com.dduckddak.domain.data.dto.PopulationsTop10Response; |
6 |
| -import com.dduckddak.domain.data.dto.TimelyDto; |
| 3 | +import com.dduckddak.domain.data.dto.*; |
| 4 | +import com.dduckddak.domain.data.dto.PopulationTransitionResponse.PopulationData; |
7 | 5 | import com.dduckddak.domain.data.model.Population;
|
8 | 6 | import com.dduckddak.domain.data.model.PopulationType;
|
9 | 7 | import com.dduckddak.domain.data.repository.PopulationRepository;
|
|
12 | 10 | import org.springframework.stereotype.Service;
|
13 | 11 | import org.springframework.transaction.annotation.Transactional;
|
14 | 12 |
|
| 13 | +import java.util.ArrayList; |
15 | 14 | import java.util.Comparator;
|
16 | 15 | import java.util.List;
|
17 | 16 |
|
@@ -74,4 +73,35 @@ else if(age.equals("60"))
|
74 | 73 | System.out.println(columnName);
|
75 | 74 | return populationRepository.findPopulationsTop10(columnName, orderCriteria, "'residentPopulation'");
|
76 | 75 | }
|
| 76 | + |
| 77 | + public PopulationTransitionResponse getFloatingPopulationTransition(String code) { |
| 78 | + List<Population> populations = populationRepository.findFloatingPopulationTransition(code); |
| 79 | + List<PopulationData> populationDataList = new ArrayList<>(); |
| 80 | + |
| 81 | + long[] quarterArr = new long[]{20241L, 20234L, 20233L, 20232L, 20231L}; |
| 82 | + for(long quarter : quarterArr){ |
| 83 | + |
| 84 | + List<Population> listOfCity = populations.stream().filter |
| 85 | + (p -> p.getTown().getQuarter().equals(quarter)).toList(); |
| 86 | + |
| 87 | + Population population = listOfCity.stream().filter(p -> p.getTown().getCode().equals(code)).findFirst().get(); |
| 88 | + long populationOfTown = population.getTotalPopulation(); |
| 89 | + |
| 90 | + int rankAtCity = listOfCity.indexOf(population) + 1; // 20241분기 시 내 등수 |
| 91 | + long populationAvgOfCity = (long) listOfCity.stream().mapToLong(Population::getTotalPopulation).average().getAsDouble(); |
| 92 | + |
| 93 | + |
| 94 | + List<Population> listOfDistrict = listOfCity.stream().filter |
| 95 | + (p -> p.getTown().getName().split(" ")[0].equals(population.getTown().getName().split(" ")[0])).toList(); |
| 96 | + |
| 97 | + int rankAtDistrict = listOfDistrict.indexOf(population) + 1; // 20241분기 구 내 등수 |
| 98 | + long populationAvgOfDistrict = (long) listOfDistrict.stream().mapToLong(Population::getTotalPopulation).average().getAsDouble(); |
| 99 | + |
| 100 | + populationDataList.add(new PopulationData(quarter, populationOfTown, rankAtCity, populationAvgOfCity, rankAtDistrict, populationAvgOfDistrict)); |
| 101 | + } |
| 102 | + |
| 103 | + return PopulationTransitionResponse.from(populationDataList); |
| 104 | + |
| 105 | + |
| 106 | + } |
77 | 107 | }
|
0 commit comments