10
10
import org .springframework .stereotype .Service ;
11
11
import org .springframework .transaction .annotation .Transactional ;
12
12
13
- import java .util .ArrayList ;
14
- import java .util .Comparator ;
15
- import java .util .List ;
13
+ import java .util .*;
16
14
17
15
@ Service
18
16
@ RequiredArgsConstructor
@@ -78,6 +76,9 @@ public PopulationTransitionResponse getFloatingPopulationTransition(String code)
78
76
List <Population > populations = populationRepository .findFloatingPopulationTransition (code );
79
77
List <PopulationData > populationDataList = new ArrayList <>();
80
78
79
+ int districtCount = 0 ;
80
+
81
+ Map <Long , Long > map = new HashMap <>();
81
82
long [] quarterArr = new long []{20231L , 20232L , 20233L , 20234L ,20241L };
82
83
for (long quarter : quarterArr ){
83
84
@@ -87,20 +88,26 @@ public PopulationTransitionResponse getFloatingPopulationTransition(String code)
87
88
Population population = listOfCity .stream ().filter (p -> p .getTown ().getCode ().equals (code )).findFirst ().get ();
88
89
long populationOfTown = population .getTotalPopulation ();
89
90
91
+ map .put (quarter , population .getTotalPopulation ()); // 분기 별 매출 저장
92
+
90
93
int rankAtCity = listOfCity .indexOf (population ) + 1 ; // 20241분기 시 내 등수
91
94
long populationAvgOfCity = (long ) listOfCity .stream ().mapToLong (Population ::getTotalPopulation ).average ().getAsDouble ();
92
95
93
96
94
97
List <Population > listOfDistrict = listOfCity .stream ().filter
95
98
(p -> p .getTown ().getName ().split (" " )[0 ].equals (population .getTown ().getName ().split (" " )[0 ])).toList ();
96
99
100
+ districtCount = listOfDistrict .size ();
101
+
97
102
int rankAtDistrict = listOfDistrict .indexOf (population ) + 1 ; // 20241분기 구 내 등수
98
103
long populationAvgOfDistrict = (long ) listOfDistrict .stream ().mapToLong (Population ::getTotalPopulation ).average ().getAsDouble ();
99
104
100
105
populationDataList .add (new PopulationData (population .getTown ().getName ().split (" " )[1 ] ,quarter , populationOfTown , rankAtCity , populationAvgOfCity , rankAtDistrict , populationAvgOfDistrict ));
101
106
}
107
+ long differenceFromPreviousQuarter = map .get (20241L ) - map .get (20234L );
108
+ long differenceFromPreviousYear = map .get (20241L ) - map .get (20231L );
102
109
103
- return PopulationTransitionResponse .from (populationDataList );
110
+ return PopulationTransitionResponse .from (populationDataList , districtCount , differenceFromPreviousQuarter , differenceFromPreviousYear );
104
111
105
112
106
113
}
0 commit comments