Skip to content

Commit b7a1ba2

Browse files
committed
성별 비율 api 구현
1 parent 2471a18 commit b7a1ba2

File tree

5 files changed

+100
-4
lines changed

5 files changed

+100
-4
lines changed

src/main/java/com/dduckddak/domain/data/sales/controller/SalesController.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package com.dduckddak.domain.data.sales.controller;
22

33
import com.dduckddak.domain.data.population.dto.TimelyDto;
4-
import com.dduckddak.domain.data.sales.dto.SalesTop10OfIndustryResponse;
5-
import com.dduckddak.domain.data.sales.dto.SalesTop10Response;
6-
import com.dduckddak.domain.data.sales.dto.SalesTransitionByIndustryResponse;
7-
import com.dduckddak.domain.data.sales.dto.SalesTransitionResponse;
4+
import com.dduckddak.domain.data.sales.dto.*;
85
import com.dduckddak.domain.data.sales.service.SalesService;
96
import com.dduckddak.domain.town.dto.SalesResponse;
107
import com.dduckddak.global.ApiResponse;
@@ -66,4 +63,20 @@ public ApiResponse<SalesTransitionByIndustryResponse> getSalesTransitionByIndust
6663
SalesTransitionByIndustryResponse salesTransitionResponseByIndustry = salesService.getSalesTransitionByIndustry(townCode, industryName);
6764
return success(salesTransitionResponseByIndustry);
6865
}
66+
67+
@Operation(summary = "행정동의 업종 별 성 별 매출 비율")
68+
@GetMapping("/towns/industry/sales/gender-rate")
69+
public ApiResponse<SalesRateByGenderAndIndustryResponse> getSalesRateByGenderAndIndustry(@RequestParam(value = "code") String townCode, @RequestParam(value = "industryName") String industryName){
70+
SalesRateByGenderAndIndustryResponse salesRateByGenderAndIndustry = salesService.getSalesRateByGenderAndIndustry(townCode, industryName);
71+
return success(salesRateByGenderAndIndustry);
72+
}
73+
74+
@Operation(summary = "행정동의 업종 별 나이 별 매출 비율")
75+
@GetMapping("/towns/industry/sales/age-rate")
76+
public ApiResponse<SalesRateByAgeAndIndustryResponse> getSalesRateByAgeAndIndustry(@RequestParam(value = "code") String townCode, @RequestParam(value = "industryName") String industryName){
77+
SalesRateByAgeAndIndustryResponse salesRateByAgeAndIndustry = salesService.getSalesRateByAgeAndIndustry(townCode, industryName);
78+
return success(
79+
salesRateByAgeAndIndustry
80+
);
81+
}
6982
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.dduckddak.domain.data.sales.dto;
2+
3+
public interface SalesRateByAgeAndIndustryResponse {
4+
String getTownName();
5+
String getIndustryName();
6+
Double getAge10sSales();
7+
Double getAge20sSales();
8+
Double getAge30sSales();
9+
Double getAge40sSales();
10+
Double getAge50sSales();
11+
Double getAge60sAndMoreSales();
12+
Double getWomenPercentage();
13+
Long getTotalSales();
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.dduckddak.domain.data.sales.dto;
2+
3+
public interface SalesRateByGenderAndIndustryResponse {
4+
String getTownName();
5+
String getIndustryName();
6+
Double getMenPercentage();
7+
Double getWomenPercentage();
8+
Long getSalesOfIndustry();
9+
}

src/main/java/com/dduckddak/domain/data/sales/repository/SalesRepository.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.dduckddak.domain.data.sales.repository;
22

3+
import com.dduckddak.domain.data.sales.dto.SalesRateByAgeAndIndustryResponse;
4+
import com.dduckddak.domain.data.sales.dto.SalesRateByGenderAndIndustryResponse;
35
import com.dduckddak.domain.data.sales.model.Sales;
46
import com.dduckddak.domain.town.dto.SalesVO;
57
import com.dduckddak.domain.town.model.TownIndustry;
@@ -35,4 +37,52 @@ SalesVO getSalesCompare(@Param("code") String code,
3537

3638

3739

40+
41+
42+
@Query(value =
43+
"SELECT \n" +
44+
"\tt.name AS townName, \n" +
45+
" i.name as industryName,\n" +
46+
" ROUND(s.men_sales / (s.men_sales + s.women_sales) * 100, 1) AS menPercentage,\n" +
47+
" ROUND(s.women_sales / (s.men_sales + s.women_sales) * 100, 1) AS womenPercentage,\n" +
48+
" s.men_sales + s.women_sales as salesOfIndustry\n" +
49+
"FROM \n" +
50+
"\ttown_industry ti\n" +
51+
"INNER JOIN \n" +
52+
"\ttown t ON ti.town_id = t.id\n" +
53+
"INNER JOIN \n" +
54+
"\tindustry i ON ti.industry_id = i.id\n" +
55+
"INNER JOIN \n" +
56+
"\tsales s ON ti.id = s.town_industry_id\n" +
57+
"WHERE \n" +
58+
"\tt.quarter in (20241) AND t.code = :townCode AND i.name = :industryName",
59+
nativeQuery = true)
60+
SalesRateByGenderAndIndustryResponse findSalesRateByGenderAndIndustry(@Param("townCode") String townCode, @Param("industryName") String industryName);
61+
62+
63+
@Query(value =
64+
"SELECT \n" +
65+
"\tt.name AS townName, \n" +
66+
" i.name as industryName,\n" +
67+
" age10s_sales + age20s_sales + age30s_sales + age40s_sales + age50s_sales + age60s_and_more_sales AS totalSales,\n" +
68+
"\tROUND(age10s_sales / (age10s_sales + age20s_sales + age30s_sales + age40s_sales + age50s_sales + age60s_and_more_sales) * 100, 1) AS age10sSales,\n" +
69+
"\tROUND(age20s_sales / (age10s_sales + age20s_sales + age30s_sales + age40s_sales + age50s_sales + age60s_and_more_sales) * 100, 1) AS age20sSales,\n" +
70+
"\tROUND(age30s_sales / (age10s_sales + age20s_sales + age30s_sales + age40s_sales + age50s_sales + age60s_and_more_sales) * 100, 1) AS age30sSales,\n" +
71+
"\tROUND(age40s_sales / (age10s_sales + age20s_sales + age30s_sales + age40s_sales + age50s_sales + age60s_and_more_sales) * 100, 1) AS age40sSales,\n" +
72+
"\tROUND(age50s_sales / (age10s_sales + age20s_sales + age30s_sales + age40s_sales + age50s_sales + age60s_and_more_sales) * 100, 1) AS age50sSales,\n" +
73+
"\tROUND(age60s_and_more_sales / (age10s_sales + age20s_sales + age30s_sales + age40s_sales + age50s_sales + age60s_and_more_sales) * 100, 1) AS age60sAndMoreSales,\n" +
74+
" ROUND(s.men_sales / (s.men_sales + s.women_sales) * 100, 1) AS menPercentage,\n" +
75+
" ROUND(s.women_sales / (s.men_sales + s.women_sales) * 100, 1) AS womenPercentage\n" +
76+
"FROM \n" +
77+
"\ttown_industry ti\n" +
78+
"INNER JOIN \n" +
79+
"\ttown t ON ti.town_id = t.id\n" +
80+
"INNER JOIN \n" +
81+
"\tindustry i ON ti.industry_id = i.id\n" +
82+
"INNER JOIN \n" +
83+
"\tsales s ON ti.id = s.town_industry_id\n" +
84+
"WHERE \n" +
85+
"\tt.quarter in (20241) AND t.code = :townCode AND i.name = :industryName ",
86+
nativeQuery = true)
87+
SalesRateByAgeAndIndustryResponse findSalesRateByAgeAndIndustry(@Param("townCode") String townCode, @Param("industryName") String industryName);
3888
}

src/main/java/com/dduckddak/domain/data/sales/service/SalesService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,14 @@ public SalesTransitionByIndustryResponse getSalesTransitionByIndustry(String tow
9797

9898
return SalesTransitionByIndustryResponse.from(salesDataList);
9999
}
100+
101+
public SalesRateByGenderAndIndustryResponse getSalesRateByGenderAndIndustry(String townCode, String industryName) {
102+
SalesRateByGenderAndIndustryResponse salesRateByGenderAndIndustry = salesRepository.findSalesRateByGenderAndIndustry(townCode, industryName);
103+
return salesRateByGenderAndIndustry;
104+
}
105+
106+
public SalesRateByAgeAndIndustryResponse getSalesRateByAgeAndIndustry(String townCode, String industryName) {
107+
SalesRateByAgeAndIndustryResponse salesRateByAgeAndIndustryResponse = salesRepository.findSalesRateByAgeAndIndustry(townCode, industryName);
108+
return salesRateByAgeAndIndustryResponse;
109+
}
100110
}

0 commit comments

Comments
 (0)