From eb6e5e8f4ea304be3503616111750ccf2ca26b96 Mon Sep 17 00:00:00 2001 From: Jeong ki hyuk <39195377+ROMANIAPEOPLE@users.noreply.github.com> Date: Mon, 31 May 2021 22:00:59 +0900 Subject: [PATCH] =?UTF-8?q?[#131]=20feat=20:=20=EC=9B=94=EB=B3=84=20?= =?UTF-8?q?=EA=B1=B0=EB=9E=98=EB=9F=89=20=EC=A1=B0=ED=9A=8C=20(#132)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. ADMIN 권한을 가진 사용자가 연도별 검색을 통해 1월~12월 거래량을 확인할 수 있다. issue number : #131 --- .../controller/TradeApiController.java | 9 ++++++ .../shoeauction/controller/dto/TradeDto.java | 18 ++++++++++- .../domain/trade/SearchTradeRepository.java | 9 +++++- .../trade/SearchTradeRepositoryImpl.java | 30 +++++++++++++++++++ .../shoeauction/service/TradeService.java | 8 +++++ 5 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/flab/shoeauction/controller/TradeApiController.java b/src/main/java/com/flab/shoeauction/controller/TradeApiController.java index 9ba610f..dfce17c 100644 --- a/src/main/java/com/flab/shoeauction/controller/TradeApiController.java +++ b/src/main/java/com/flab/shoeauction/controller/TradeApiController.java @@ -5,13 +5,16 @@ import com.flab.shoeauction.controller.dto.TradeDto; import com.flab.shoeauction.controller.dto.TradeDto.ChangeRequest; import com.flab.shoeauction.controller.dto.TradeDto.ImmediateTradeRequest; +import com.flab.shoeauction.controller.dto.TradeDto.MonthlyTradingVolumesResponse; import com.flab.shoeauction.controller.dto.TradeDto.ReasonRequest; import com.flab.shoeauction.controller.dto.TradeDto.TrackingNumberRequest; import com.flab.shoeauction.controller.dto.TradeDto.TradeInfoResponse; +import com.flab.shoeauction.controller.dto.TradeDto.TradeMonthSearchCondition; import com.flab.shoeauction.controller.dto.TradeDto.TradeResource; import com.flab.shoeauction.controller.dto.TradeDto.TradeSearchCondition; import com.flab.shoeauction.domain.users.common.UserLevel; import com.flab.shoeauction.service.TradeService; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -127,4 +130,10 @@ public Page getTradeInfos(TradeSearchCondition tradeSearchCon Pageable pageable) { return tradeService.getTradeInfos(tradeSearchCondition, pageable); } + + @LoginCheck(authority =UserLevel.ADMIN) + @GetMapping("/month-volumes") + public List getMonthVolumes(TradeMonthSearchCondition tradeMonthSearchCondition) { + return tradeService.getMonthlyTradingVolumes(tradeMonthSearchCondition); + } } \ No newline at end of file diff --git a/src/main/java/com/flab/shoeauction/controller/dto/TradeDto.java b/src/main/java/com/flab/shoeauction/controller/dto/TradeDto.java index 18a5911..e52f6ff 100644 --- a/src/main/java/com/flab/shoeauction/controller/dto/TradeDto.java +++ b/src/main/java/com/flab/shoeauction/controller/dto/TradeDto.java @@ -176,6 +176,7 @@ public boolean isSearchByBuyer() { @Getter @NoArgsConstructor public static class TradeInfoResponse { + private Long id; private TradeStatus status; @@ -189,6 +190,7 @@ public TradeInfoResponse(Long id, TradeStatus status) { @Getter @NoArgsConstructor public static class TradeCompleteInfo { + private double productSize; private Long price; private LocalDateTime completeTime; @@ -200,4 +202,18 @@ public TradeCompleteInfo(double productSize, Long price, LocalDateTime completeT this.completeTime = completeTime; } } -} \ No newline at end of file + + @Getter + @NoArgsConstructor + public static class TradeMonthSearchCondition { + private String year; + } + + @Getter + @NoArgsConstructor + public static class MonthlyTradingVolumesResponse { + private String date; + private Long count; + } +} + diff --git a/src/main/java/com/flab/shoeauction/domain/trade/SearchTradeRepository.java b/src/main/java/com/flab/shoeauction/domain/trade/SearchTradeRepository.java index 6762d89..0cf99c7 100644 --- a/src/main/java/com/flab/shoeauction/domain/trade/SearchTradeRepository.java +++ b/src/main/java/com/flab/shoeauction/domain/trade/SearchTradeRepository.java @@ -1,8 +1,11 @@ package com.flab.shoeauction.domain.trade; +import com.flab.shoeauction.controller.dto.TradeDto.MonthlyTradingVolumesResponse; import com.flab.shoeauction.controller.dto.TradeDto.TradeInfoResponse; +import com.flab.shoeauction.controller.dto.TradeDto.TradeMonthSearchCondition; import com.flab.shoeauction.controller.dto.TradeDto.TradeSearchCondition; import com.flab.shoeauction.domain.users.user.User; +import java.util.List; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -10,5 +13,9 @@ public interface SearchTradeRepository { boolean existsProgressingByUser(User user); - Page searchByTradeStatusAndTradeId(TradeSearchCondition searchCondition, Pageable pageable); + Page searchByTradeStatusAndTradeId(TradeSearchCondition searchCondition, + Pageable pageable); + + List searchTradeVolumeByMonth( + TradeMonthSearchCondition tradeMonthSearchCondition); } diff --git a/src/main/java/com/flab/shoeauction/domain/trade/SearchTradeRepositoryImpl.java b/src/main/java/com/flab/shoeauction/domain/trade/SearchTradeRepositoryImpl.java index 6a3be2a..a177f93 100644 --- a/src/main/java/com/flab/shoeauction/domain/trade/SearchTradeRepositoryImpl.java +++ b/src/main/java/com/flab/shoeauction/domain/trade/SearchTradeRepositoryImpl.java @@ -2,12 +2,17 @@ import static com.flab.shoeauction.domain.trade.QTrade.trade; +import com.flab.shoeauction.controller.dto.TradeDto.MonthlyTradingVolumesResponse; import com.flab.shoeauction.controller.dto.TradeDto.TradeInfoResponse; +import com.flab.shoeauction.controller.dto.TradeDto.TradeMonthSearchCondition; import com.flab.shoeauction.controller.dto.TradeDto.TradeSearchCondition; import com.flab.shoeauction.domain.users.user.User; import com.querydsl.core.QueryResults; +import com.querydsl.core.types.ConstantImpl; import com.querydsl.core.types.Projections; import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.core.types.dsl.Expressions; +import com.querydsl.core.types.dsl.StringTemplate; import com.querydsl.jpa.impl.JPAQueryFactory; import java.util.List; import lombok.RequiredArgsConstructor; @@ -54,7 +59,32 @@ public Page searchByTradeStatusAndTradeId(TradeSearchConditio } return searchByTradeId(searchRequest.getTradeId(), pageable); + } + + @Override + public List searchTradeVolumeByMonth( + TradeMonthSearchCondition tradeMonthSearchCondition) { + + StringTemplate dateFormat = Expressions.stringTemplate( + "DATE_FORMAT({0}, {1})", trade.modifiedDate, ConstantImpl.create("%Y-%m")); + + List results = jpaQueryFactory + .select(Projections.fields(MonthlyTradingVolumesResponse.class, + trade.id.count().as("count"), + dateFormat.as("date") + )).from(trade) + .where(statusEqAndDateContains(tradeMonthSearchCondition, dateFormat)) + .groupBy(dateFormat) + .fetch(); + + return results; + } + private BooleanExpression statusEqAndDateContains( + TradeMonthSearchCondition tradeMonthSearchCondition, + StringTemplate dateFormat) { + return trade.status.eq(TradeStatus.TRADE_COMPLETE).and(dateFormat.contains( + tradeMonthSearchCondition.getYear())); } private Page searchByTradeId(Long tradeId, Pageable pageable) { diff --git a/src/main/java/com/flab/shoeauction/service/TradeService.java b/src/main/java/com/flab/shoeauction/service/TradeService.java index 96b37a2..13815e5 100644 --- a/src/main/java/com/flab/shoeauction/service/TradeService.java +++ b/src/main/java/com/flab/shoeauction/service/TradeService.java @@ -7,8 +7,10 @@ import com.flab.shoeauction.controller.dto.ProductDto.ProductInfoByTrade; import com.flab.shoeauction.controller.dto.TradeDto.ChangeRequest; import com.flab.shoeauction.controller.dto.TradeDto.ImmediateTradeRequest; +import com.flab.shoeauction.controller.dto.TradeDto.MonthlyTradingVolumesResponse; import com.flab.shoeauction.controller.dto.TradeDto.SaveRequest; import com.flab.shoeauction.controller.dto.TradeDto.TradeInfoResponse; +import com.flab.shoeauction.controller.dto.TradeDto.TradeMonthSearchCondition; import com.flab.shoeauction.controller.dto.TradeDto.TradeResource; import com.flab.shoeauction.controller.dto.TradeDto.TradeSearchCondition; import com.flab.shoeauction.controller.dto.UserDto.TradeUserInfo; @@ -23,6 +25,7 @@ import com.flab.shoeauction.exception.user.NotAuthorizedException; import com.flab.shoeauction.exception.user.UserNotFoundException; import com.flab.shoeauction.service.message.MessageService; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.cache.annotation.CacheEvict; import org.springframework.data.domain.Page; @@ -218,4 +221,9 @@ public void confirmPurchase(Long tradeId, String email) { pointService.salesPointReceive(trade.getSeller(), trade.getPrice()); } + + public List getMonthlyTradingVolumes( + TradeMonthSearchCondition tradeMonthSearchCondition) { + return tradeRepository.searchTradeVolumeByMonth(tradeMonthSearchCondition); + } } \ No newline at end of file