From b7a1ba219c988ab68f5b2a0f18dab34b45e6a1ac Mon Sep 17 00:00:00 2001 From: gkfktkrh153 Date: Wed, 14 Aug 2024 13:50:58 +0900 Subject: [PATCH] =?UTF-8?q?=EC=84=B1=EB=B3=84=20=EB=B9=84=EC=9C=A8=20api?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sales/controller/SalesController.java | 21 ++++++-- .../SalesRateByAgeAndIndustryResponse.java | 14 ++++++ .../SalesRateByGenderAndIndustryResponse.java | 9 ++++ .../sales/repository/SalesRepository.java | 50 +++++++++++++++++++ .../data/sales/service/SalesService.java | 10 ++++ 5 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/dduckddak/domain/data/sales/dto/SalesRateByAgeAndIndustryResponse.java create mode 100644 src/main/java/com/dduckddak/domain/data/sales/dto/SalesRateByGenderAndIndustryResponse.java diff --git a/src/main/java/com/dduckddak/domain/data/sales/controller/SalesController.java b/src/main/java/com/dduckddak/domain/data/sales/controller/SalesController.java index 8facebf..1dce04a 100644 --- a/src/main/java/com/dduckddak/domain/data/sales/controller/SalesController.java +++ b/src/main/java/com/dduckddak/domain/data/sales/controller/SalesController.java @@ -1,10 +1,7 @@ package com.dduckddak.domain.data.sales.controller; import com.dduckddak.domain.data.population.dto.TimelyDto; -import com.dduckddak.domain.data.sales.dto.SalesTop10OfIndustryResponse; -import com.dduckddak.domain.data.sales.dto.SalesTop10Response; -import com.dduckddak.domain.data.sales.dto.SalesTransitionByIndustryResponse; -import com.dduckddak.domain.data.sales.dto.SalesTransitionResponse; +import com.dduckddak.domain.data.sales.dto.*; import com.dduckddak.domain.data.sales.service.SalesService; import com.dduckddak.domain.town.dto.SalesResponse; import com.dduckddak.global.ApiResponse; @@ -66,4 +63,20 @@ public ApiResponse getSalesTransitionByIndust SalesTransitionByIndustryResponse salesTransitionResponseByIndustry = salesService.getSalesTransitionByIndustry(townCode, industryName); return success(salesTransitionResponseByIndustry); } + + @Operation(summary = "행정동의 업종 별 성 별 매출 비율") + @GetMapping("/towns/industry/sales/gender-rate") + public ApiResponse getSalesRateByGenderAndIndustry(@RequestParam(value = "code") String townCode, @RequestParam(value = "industryName") String industryName){ + SalesRateByGenderAndIndustryResponse salesRateByGenderAndIndustry = salesService.getSalesRateByGenderAndIndustry(townCode, industryName); + return success(salesRateByGenderAndIndustry); + } + + @Operation(summary = "행정동의 업종 별 나이 별 매출 비율") + @GetMapping("/towns/industry/sales/age-rate") + public ApiResponse getSalesRateByAgeAndIndustry(@RequestParam(value = "code") String townCode, @RequestParam(value = "industryName") String industryName){ + SalesRateByAgeAndIndustryResponse salesRateByAgeAndIndustry = salesService.getSalesRateByAgeAndIndustry(townCode, industryName); + return success( + salesRateByAgeAndIndustry + ); + } } diff --git a/src/main/java/com/dduckddak/domain/data/sales/dto/SalesRateByAgeAndIndustryResponse.java b/src/main/java/com/dduckddak/domain/data/sales/dto/SalesRateByAgeAndIndustryResponse.java new file mode 100644 index 0000000..7a83e14 --- /dev/null +++ b/src/main/java/com/dduckddak/domain/data/sales/dto/SalesRateByAgeAndIndustryResponse.java @@ -0,0 +1,14 @@ +package com.dduckddak.domain.data.sales.dto; + +public interface SalesRateByAgeAndIndustryResponse { + String getTownName(); + String getIndustryName(); + Double getAge10sSales(); + Double getAge20sSales(); + Double getAge30sSales(); + Double getAge40sSales(); + Double getAge50sSales(); + Double getAge60sAndMoreSales(); + Double getWomenPercentage(); + Long getTotalSales(); +} diff --git a/src/main/java/com/dduckddak/domain/data/sales/dto/SalesRateByGenderAndIndustryResponse.java b/src/main/java/com/dduckddak/domain/data/sales/dto/SalesRateByGenderAndIndustryResponse.java new file mode 100644 index 0000000..d21dbfd --- /dev/null +++ b/src/main/java/com/dduckddak/domain/data/sales/dto/SalesRateByGenderAndIndustryResponse.java @@ -0,0 +1,9 @@ +package com.dduckddak.domain.data.sales.dto; + +public interface SalesRateByGenderAndIndustryResponse { + String getTownName(); + String getIndustryName(); + Double getMenPercentage(); + Double getWomenPercentage(); + Long getSalesOfIndustry(); +} diff --git a/src/main/java/com/dduckddak/domain/data/sales/repository/SalesRepository.java b/src/main/java/com/dduckddak/domain/data/sales/repository/SalesRepository.java index 09f82f8..9db0302 100644 --- a/src/main/java/com/dduckddak/domain/data/sales/repository/SalesRepository.java +++ b/src/main/java/com/dduckddak/domain/data/sales/repository/SalesRepository.java @@ -1,5 +1,7 @@ package com.dduckddak.domain.data.sales.repository; +import com.dduckddak.domain.data.sales.dto.SalesRateByAgeAndIndustryResponse; +import com.dduckddak.domain.data.sales.dto.SalesRateByGenderAndIndustryResponse; import com.dduckddak.domain.data.sales.model.Sales; import com.dduckddak.domain.town.dto.SalesVO; import com.dduckddak.domain.town.model.TownIndustry; @@ -35,4 +37,52 @@ SalesVO getSalesCompare(@Param("code") String code, + + + @Query(value = + "SELECT \n" + + "\tt.name AS townName, \n" + + " i.name as industryName,\n" + + " ROUND(s.men_sales / (s.men_sales + s.women_sales) * 100, 1) AS menPercentage,\n" + + " ROUND(s.women_sales / (s.men_sales + s.women_sales) * 100, 1) AS womenPercentage,\n" + + " s.men_sales + s.women_sales as salesOfIndustry\n" + + "FROM \n" + + "\ttown_industry ti\n" + + "INNER JOIN \n" + + "\ttown t ON ti.town_id = t.id\n" + + "INNER JOIN \n" + + "\tindustry i ON ti.industry_id = i.id\n" + + "INNER JOIN \n" + + "\tsales s ON ti.id = s.town_industry_id\n" + + "WHERE \n" + + "\tt.quarter in (20241) AND t.code = :townCode AND i.name = :industryName", + nativeQuery = true) + SalesRateByGenderAndIndustryResponse findSalesRateByGenderAndIndustry(@Param("townCode") String townCode, @Param("industryName") String industryName); + + + @Query(value = + "SELECT \n" + + "\tt.name AS townName, \n" + + " i.name as industryName,\n" + + " age10s_sales + age20s_sales + age30s_sales + age40s_sales + age50s_sales + age60s_and_more_sales AS totalSales,\n" + + "\tROUND(age10s_sales / (age10s_sales + age20s_sales + age30s_sales + age40s_sales + age50s_sales + age60s_and_more_sales) * 100, 1) AS age10sSales,\n" + + "\tROUND(age20s_sales / (age10s_sales + age20s_sales + age30s_sales + age40s_sales + age50s_sales + age60s_and_more_sales) * 100, 1) AS age20sSales,\n" + + "\tROUND(age30s_sales / (age10s_sales + age20s_sales + age30s_sales + age40s_sales + age50s_sales + age60s_and_more_sales) * 100, 1) AS age30sSales,\n" + + "\tROUND(age40s_sales / (age10s_sales + age20s_sales + age30s_sales + age40s_sales + age50s_sales + age60s_and_more_sales) * 100, 1) AS age40sSales,\n" + + "\tROUND(age50s_sales / (age10s_sales + age20s_sales + age30s_sales + age40s_sales + age50s_sales + age60s_and_more_sales) * 100, 1) AS age50sSales,\n" + + "\tROUND(age60s_and_more_sales / (age10s_sales + age20s_sales + age30s_sales + age40s_sales + age50s_sales + age60s_and_more_sales) * 100, 1) AS age60sAndMoreSales,\n" + + " ROUND(s.men_sales / (s.men_sales + s.women_sales) * 100, 1) AS menPercentage,\n" + + " ROUND(s.women_sales / (s.men_sales + s.women_sales) * 100, 1) AS womenPercentage\n" + + "FROM \n" + + "\ttown_industry ti\n" + + "INNER JOIN \n" + + "\ttown t ON ti.town_id = t.id\n" + + "INNER JOIN \n" + + "\tindustry i ON ti.industry_id = i.id\n" + + "INNER JOIN \n" + + "\tsales s ON ti.id = s.town_industry_id\n" + + "WHERE \n" + + "\tt.quarter in (20241) AND t.code = :townCode AND i.name = :industryName ", + nativeQuery = true) + SalesRateByAgeAndIndustryResponse findSalesRateByAgeAndIndustry(@Param("townCode") String townCode, @Param("industryName") String industryName); } diff --git a/src/main/java/com/dduckddak/domain/data/sales/service/SalesService.java b/src/main/java/com/dduckddak/domain/data/sales/service/SalesService.java index a00006d..de81488 100644 --- a/src/main/java/com/dduckddak/domain/data/sales/service/SalesService.java +++ b/src/main/java/com/dduckddak/domain/data/sales/service/SalesService.java @@ -97,4 +97,14 @@ public SalesTransitionByIndustryResponse getSalesTransitionByIndustry(String tow return SalesTransitionByIndustryResponse.from(salesDataList); } + + public SalesRateByGenderAndIndustryResponse getSalesRateByGenderAndIndustry(String townCode, String industryName) { + SalesRateByGenderAndIndustryResponse salesRateByGenderAndIndustry = salesRepository.findSalesRateByGenderAndIndustry(townCode, industryName); + return salesRateByGenderAndIndustry; + } + + public SalesRateByAgeAndIndustryResponse getSalesRateByAgeAndIndustry(String townCode, String industryName) { + SalesRateByAgeAndIndustryResponse salesRateByAgeAndIndustryResponse = salesRepository.findSalesRateByAgeAndIndustry(townCode, industryName); + return salesRateByAgeAndIndustryResponse; + } }