Skip to content

Commit

Permalink
성별 비율 api 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
gkfktkrh153 committed Aug 14, 2024
1 parent 2471a18 commit b7a1ba2
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -66,4 +63,20 @@ public ApiResponse<SalesTransitionByIndustryResponse> getSalesTransitionByIndust
SalesTransitionByIndustryResponse salesTransitionResponseByIndustry = salesService.getSalesTransitionByIndustry(townCode, industryName);
return success(salesTransitionResponseByIndustry);
}

@Operation(summary = "행정동의 업종 별 성 별 매출 비율")
@GetMapping("/towns/industry/sales/gender-rate")
public ApiResponse<SalesRateByGenderAndIndustryResponse> 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<SalesRateByAgeAndIndustryResponse> getSalesRateByAgeAndIndustry(@RequestParam(value = "code") String townCode, @RequestParam(value = "industryName") String industryName){
SalesRateByAgeAndIndustryResponse salesRateByAgeAndIndustry = salesService.getSalesRateByAgeAndIndustry(townCode, industryName);
return success(
salesRateByAgeAndIndustry
);
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.dduckddak.domain.data.sales.dto;

public interface SalesRateByGenderAndIndustryResponse {
String getTownName();
String getIndustryName();
Double getMenPercentage();
Double getWomenPercentage();
Long getSalesOfIndustry();
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit b7a1ba2

Please sign in to comment.