From a0ef5f28fbf1df7667f4a31e23fbfae7273fe10f Mon Sep 17 00:00:00 2001 From: JSoi Date: Wed, 20 Jul 2022 23:52:30 +0900 Subject: [PATCH] =?UTF-8?q?#23=20[Fix]=20=ED=8F=89=EC=A0=90=EC=88=9C=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EA=B0=80=EA=B9=8C=EC=9A=B4=20=EA=B1=B0?= =?UTF-8?q?=EB=A6=AC=EC=88=9C=EC=9C=BC=EB=A1=9C=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../review/dto/ReviewMainResponseDto.java | 2 + .../repository/StoreQueryRepository.java | 48 +++++-------------- 2 files changed, 13 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/mpnp/baechelin/review/dto/ReviewMainResponseDto.java b/src/main/java/com/mpnp/baechelin/review/dto/ReviewMainResponseDto.java index a60747b..cc7bef3 100644 --- a/src/main/java/com/mpnp/baechelin/review/dto/ReviewMainResponseDto.java +++ b/src/main/java/com/mpnp/baechelin/review/dto/ReviewMainResponseDto.java @@ -23,6 +23,7 @@ public class ReviewMainResponseDto { private String storeName; private String userName; private String content; //리뷰 코멘트 + private String address; private double point; //별점 private List reviewImageUrlList; //리뷰 이미지 사진 private List tagList; @@ -31,6 +32,7 @@ public ReviewMainResponseDto(Review review, Store store, User user) { this.storeId = store.getId(); this.userId = user.getId(); this.storeName = store.getName(); + this.address = store.getAddress(); this.userName = user.getEmail(); this.content = review.getContent(); this.point = review.getPoint(); diff --git a/src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java b/src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java index bb30b66..a5088b5 100644 --- a/src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java +++ b/src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java @@ -15,6 +15,7 @@ import javax.transaction.Transactional; import java.math.BigDecimal; import java.math.RoundingMode; +import java.util.Collections; import java.util.List; import static com.mpnp.baechelin.common.QuerydslLocation.locTwoPointAndConditions; @@ -42,20 +43,6 @@ public Page findBetweenLngLat(BigDecimal latStart, Pageable pageable) { BooleanBuilder builder = QuerydslLocation.locAndConditions(latStart, latEnd, lngStart, lngEnd, category, facility); - -// BigDecimal nowLat = (latStart.add(latEnd)).divide(new BigDecimal("2"), 22, RoundingMode.HALF_UP); -// BigDecimal nowLng = (lngStart.add(lngEnd)).divide(new BigDecimal("2"), 22, RoundingMode.HALF_UP); -// List storeResultList = queryFactory.selectFrom(store) -// .where(builder) -// .fetch(); -// // 가까운순으로 정렬하기 -// storeResultList.sort((thisStore, newStore) -> { -// BigDecimal thisDiff = nowLat.subtract(thisStore.getLatitude()).abs().add(nowLng.subtract(thisStore.getLongitude()).abs()); -// BigDecimal newDiff = nowLat.subtract(newStore.getLatitude()).abs().add(nowLng.subtract(newStore.getLongitude()).abs()); -// return thisDiff.compareTo(newDiff); -// }); -// getStorePaged(storeResultList, pageable); - List storeList = queryFactory.selectFrom(store) .where(builder) .limit(pageable.getPageSize()) @@ -65,16 +52,20 @@ public Page findBetweenLngLat(BigDecimal latStart, if (latEnd != null && latStart != null && lngStart != null && lngEnd != null) { BigDecimal nowLat = (latStart.add(latEnd)).divide(new BigDecimal("2"), 22, RoundingMode.HALF_UP); BigDecimal nowLng = (lngStart.add(lngEnd)).divide(new BigDecimal("2"), 22, RoundingMode.HALF_UP); - storeList.sort((thisStore, newStore) -> { - BigDecimal thisDiff = nowLat.subtract(thisStore.getLatitude()).abs().add(nowLng.subtract(thisStore.getLongitude()).abs()); - BigDecimal newDiff = nowLat.subtract(newStore.getLatitude()).abs().add(nowLng.subtract(newStore.getLongitude()).abs()); - return thisDiff.compareTo(newDiff); - }); + storeSortByDistance(storeList, nowLat, nowLng); } int fetchCount = queryFactory.selectFrom(store).where(builder).fetch().size(); return new PageImpl<>(storeList, pageable, fetchCount); } + private void storeSortByDistance(List storeList, BigDecimal nowLat, BigDecimal nowLng) { + storeList.sort((thisStore, newStore) -> { + BigDecimal thisDiff = nowLat.subtract(thisStore.getLatitude()).abs().add(nowLng.subtract(thisStore.getLongitude()).abs()); + BigDecimal newDiff = nowLat.subtract(newStore.getLatitude()).abs().add(nowLng.subtract(newStore.getLongitude()).abs()); + return thisDiff.compareTo(newDiff); + }); + } + //TODO 별점순 - 쿼리 결과로 산출된 리스트의 평균 구하기, 정렬, 페이징 // public List findStoreOrderByPoint(BigDecimal lat, public Page findStoreOrderByPoint(BigDecimal lat, @@ -84,24 +75,6 @@ public Page findStoreOrderByPoint(BigDecimal lat, Pageable pageable) { BooleanBuilder builder = locTwoPointAndConditions(lat, lng, category, facility); -// 직접 DTO를 조작 -// List resultList = queryFactory.selectFrom(store) -// .where(builder) -// .fetch(); - -// List resultAvgList = resultList.stream() -// .map(store -> { -// long count = user == null ? 0L : user.getBookmarkList().stream() -// .filter(b -> b.getUserId() == user && b.getStoreId() == store).count(); -// double avg = Double.parseDouble(String.format(String.valueOf(store.getReviewList().stream() -// .collect(Collectors.averagingDouble(Review::getPoint))), "0.1f")); -// StoreCardResponseDto storeCardResponseDto = new StoreCardResponseDto(store, count > 0); -// storeCardResponseDto.setPointAvg(avg); -// return storeCardResponseDto; -// }).sorted().collect(Collectors.toList()); -// -// return getStoreCardPaged(resultAvgList, pageable); - // 업데이트시 쿼리 List updateResultList = queryFactory.selectFrom(store) .where(builder) @@ -109,6 +82,7 @@ public Page findStoreOrderByPoint(BigDecimal lat, .offset(pageable.getOffset()) .orderBy(store.pointAvg.desc()) .fetch(); + storeSortByDistance(updateResultList, lat, lng); int fetchCount = queryFactory.selectFrom(store).where(builder).fetch().size(); return new PageImpl<>(updateResultList, pageable, fetchCount); }