Skip to content

Commit

Permalink
행정동 별 매출 추이 api변경(구 수, 전분기 and 전년도 대비 증감)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkfktkrh153 committed Aug 14, 2024
1 parent 2ba6484 commit d6ac6a0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public PopulationTransitionResponse getFloatingPopulationTransition(String code)
Population population = listOfCity.stream().filter(p -> p.getTown().getCode().equals(code)).findFirst().get();
long populationOfTown = population.getTotalPopulation();

map.put(quarter, population.getTotalPopulation()); // 분기 별 매출 저장
map.put(quarter, population.getTotalPopulation()); // 분기 별 유동인구수 저장

int rankAtCity = listOfCity.indexOf(population) + 1; // 20241분기 시 내 등수
long populationAvgOfCity = (long) listOfCity.stream().mapToLong(Population::getTotalPopulation).average().getAsDouble();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import java.util.List;

public record SalesTransitionByIndustryResponse(
List<SalesData> salesList
List<SalesData> salesList,
int districtCount,
long differenceFromPreviousQuarter,
long differenceFromPreviousYear
) {
public record SalesData(
String townName,
Expand All @@ -18,8 +21,8 @@ public record SalesData(
) {
}

public static SalesTransitionByIndustryResponse from(List<SalesData> sales) {
return new SalesTransitionByIndustryResponse(sales);
public static SalesTransitionByIndustryResponse from(List<SalesData> sales, int districtCount, long differenceFromPreviousQuarter, long differenceFromPreviousYear) {
return new SalesTransitionByIndustryResponse(sales, districtCount, differenceFromPreviousQuarter, differenceFromPreviousYear);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import java.util.List;

public record SalesTransitionResponse(
List<SalesData> salesList
List<SalesData> salesList,
int districtCount,
long differenceFromPreviousQuarter,
long differenceFromPreviousYear
) {
public record SalesData(
String townName,
Expand All @@ -17,8 +20,8 @@ public record SalesData(
) {
}

public static SalesTransitionResponse from(List<SalesData> sales) {
return new SalesTransitionResponse(sales);
public static SalesTransitionResponse from(List<SalesData> sales, int districtCount, long differenceFromPreviousQuarter, long differenceFromPreviousYear) {
return new SalesTransitionResponse(sales, districtCount, differenceFromPreviousQuarter, differenceFromPreviousYear);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -41,7 +43,8 @@ public SalesTransitionResponse getSalesTransition(String code) {


List<SalesTransitionResponse.SalesData> salesDataList = new ArrayList<>();

int districtCount = 0;
Map<Long , Long> map = new HashMap<>();
long[] quarterArr = new long[]{20231L, 20232L, 20233L, 20234L ,20241L };
for(long quarter : quarterArr){

Expand All @@ -50,21 +53,25 @@ public SalesTransitionResponse getSalesTransition(String code) {

SalesForTransitionData sales = listOfCity.stream().filter(s -> s.getTownCode().equals(code)).findFirst().get();
Long salesAtTown = sales.getSalesAtTown();
map.put(quarter, sales.getSalesAtTown()); // 분기 별 매출 저장


int rankAtCity = listOfCity.indexOf(sales) + 1; // 20241분기 시 내 등수
long salesAvgOfCity = (long) listOfCity.stream().mapToLong(s -> s.getSalesAtTown()).average().getAsDouble();


List<SalesForTransitionData> listOfDistrict = listOfCity.stream().filter
(s -> s.getTownName().split(" ")[0].equals(sales.getTownName().split(" ")[0])).toList();

districtCount = listOfDistrict.size();

int rankAtDistrict = listOfDistrict.indexOf(sales) + 1; // 20241분기 구 내 등수
long populationAvgOfDistrict = (long) listOfDistrict.stream().mapToLong(s -> s.getSalesAtTown()).average().getAsDouble();

salesDataList.add(new SalesTransitionResponse.SalesData(sales.getTownName().split(" ")[1] ,quarter, sales.getSalesAtTown(), rankAtCity, salesAvgOfCity, rankAtDistrict, populationAvgOfDistrict));
}

return SalesTransitionResponse.from(salesDataList);
long differenceFromPreviousQuarter = map.get(20241L) - map.get(20234L);
long differenceFromPreviousYear = map.get(20241L) - map.get(20231L);
return SalesTransitionResponse.from(salesDataList, districtCount, differenceFromPreviousQuarter, differenceFromPreviousYear);
}

public SalesTransitionByIndustryResponse getSalesTransitionByIndustry(String townCode, String industryName) {
Expand All @@ -73,6 +80,9 @@ public SalesTransitionByIndustryResponse getSalesTransitionByIndustry(String tow

List<SalesTransitionByIndustryResponse.SalesData> salesDataList = new ArrayList<>();

int districtCount = 0;

Map<Long , Long> map = new HashMap<>();
long[] quarterArr = new long[]{20231L, 20232L, 20233L, 20234L ,20241L };
for(long quarter : quarterArr){

Expand All @@ -82,20 +92,25 @@ public SalesTransitionByIndustryResponse getSalesTransitionByIndustry(String tow
SalesForTransitionData sales = listOfCity.stream().filter(s -> s.getTownCode().equals(townCode)).findFirst().get();
Long salesAtTown = sales.getSalesAtTown();

map.put(quarter, sales.getSalesAtTown()); // 분기 별 매출 저장

int rankAtCity = listOfCity.indexOf(sales) + 1; // 20241분기 시 내 등수
long salesAvgOfCity = (long) listOfCity.stream().mapToLong(s -> s.getSalesAtTown()).average().getAsDouble();


List<SalesForTransitionData> listOfDistrict = listOfCity.stream().filter
(s -> s.getTownName().split(" ")[0].equals(sales.getTownName().split(" ")[0])).toList();

districtCount = listOfDistrict.size();

int rankAtDistrict = listOfDistrict.indexOf(sales) + 1; // 20241분기 구 내 등수
long populationAvgOfDistrict = (long) listOfDistrict.stream().mapToLong(s -> s.getSalesAtTown()).average().getAsDouble();

salesDataList.add(new SalesTransitionByIndustryResponse.SalesData(sales.getTownName().split(" ")[1], industryName, quarter, sales.getSalesAtTown(), rankAtCity, salesAvgOfCity, rankAtDistrict, populationAvgOfDistrict));
}

return SalesTransitionByIndustryResponse.from(salesDataList);
long differenceFromPreviousQuarter = map.get(20241L) - map.get(20234L);
long differenceFromPreviousYear = map.get(20241L) - map.get(20231L);
return SalesTransitionByIndustryResponse.from(salesDataList, districtCount, differenceFromPreviousQuarter, differenceFromPreviousYear);
}

public SalesRateByGenderAndIndustryResponse getSalesRateByGenderAndIndustry(String townCode, String industryName) {
Expand Down

0 comments on commit d6ac6a0

Please sign in to comment.