diff --git a/src/main/java/com/mpnp/baechelin/common/QuerydslLocation.java b/src/main/java/com/mpnp/baechelin/common/QuerydslLocation.java index 721ea7a..f04062c 100644 --- a/src/main/java/com/mpnp/baechelin/common/QuerydslLocation.java +++ b/src/main/java/com/mpnp/baechelin/common/QuerydslLocation.java @@ -68,6 +68,7 @@ public static BooleanBuilder getBooleanBuilder(String category, List fac public static BigDecimal[] getRange(BigDecimal lat, BigDecimal lng, int km) { // km->lat,lng로 변환하기 + if (lat == null || lng == null) return null; final BigDecimal latitude = BigDecimal.valueOf(km / 110.569); // 반경 final BigDecimal longitude = BigDecimal.valueOf(km / 111.322); // 남서, 북동으로 받아오기 diff --git a/src/main/java/com/mpnp/baechelin/store/domain/Category.java b/src/main/java/com/mpnp/baechelin/store/domain/Category.java index 2327fb0..ee4fe71 100644 --- a/src/main/java/com/mpnp/baechelin/store/domain/Category.java +++ b/src/main/java/com/mpnp/baechelin/store/domain/Category.java @@ -3,6 +3,7 @@ import lombok.Getter; import java.util.Arrays; + @Getter public enum Category { KOREAN("한식"), WESTERN("양식"), JAPANESE("일식"), ASIAN("아시아음식"), CHINESE("중식"), @@ -11,12 +12,12 @@ public enum Category { ETC("기타"); private final String desc; - public static Category giveCategory(String input){ + public static Category giveCategory(String input) { return Arrays.stream(Category.values()) .filter(cate -> cate.desc.equals(input)).findAny().orElse(Category.ETC); } - public static String giveCategoryDesc(String key){ + public static String giveCategoryDesc(String key) { return Arrays.stream(Category.values()) .filter(cate -> cate.toString().equals(key)).findAny().orElse(Category.ETC).getDesc(); } 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 1c6875d..25a1622 100644 --- a/src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java +++ b/src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java @@ -46,9 +46,11 @@ public Page findBetweenOnePointOrder(BigDecimal latStart, String category, List facility, Pageable pageable) { + BooleanBuilder builder = QuerydslLocation.locAndConditions(latStart, latEnd, lngStart, lngEnd, category, facility); + if (latStart == null || lngStart == null || lngEnd == null || latEnd == null) + return findBetweenOnePointOrderNullCase(builder, pageable); 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); - BooleanBuilder builder = QuerydslLocation.locAndConditions(latStart, latEnd, lngStart, lngEnd, category, facility); List storeList = queryFactory .selectFrom(store) @@ -61,7 +63,20 @@ public Page findBetweenOnePointOrder(BigDecimal latStart, return new PageImpl<>(storeList, pageable, fetchCount); } - private OrderSpecifier orderDistance(BigDecimal nowLat, BigDecimal nowLng){ + private Page findBetweenOnePointOrderNullCase(BooleanBuilder builder, + Pageable pageable) { + List storeList = + queryFactory + .selectFrom(store) + .where(builder) + .limit(pageable.getPageSize()) + .offset(pageable.getOffset()) + .fetch(); + int fetchCount = queryFactory.selectFrom(store).where(builder).fetch().size(); + return new PageImpl<>(storeList, pageable, fetchCount); + } + + private OrderSpecifier orderDistance(BigDecimal nowLat, BigDecimal nowLng) { return QStore.store.latitude.subtract(nowLat).abs().add(QStore.store.longitude.subtract(nowLng)).abs().asc(); } @@ -77,7 +92,7 @@ public Page findStoreOrderByPoint(BigDecimal lat, .selectFrom(store) .where(builder) .orderBy(store.pointAvg.desc()) - .orderBy(orderDistance(lat,lng)) + .orderBy(orderDistance(lat, lng)) .limit(pageable.getPageSize()) .offset(pageable.getOffset()) .fetch(); @@ -96,7 +111,7 @@ public Page findStoreOrderByBookmark(BigDecimal lat, List storeList = queryFactory.selectFrom(store) .where(builder) .orderBy(store.bookMarkCount.desc()) - .orderBy(orderDistance(lat,lng)) + .orderBy(orderDistance(lat, lng)) .limit(pageable.getPageSize()) .offset(pageable.getOffset()) .fetch(); diff --git a/src/main/java/com/mpnp/baechelin/store/service/StoreService.java b/src/main/java/com/mpnp/baechelin/store/service/StoreService.java index 0586abc..439f449 100644 --- a/src/main/java/com/mpnp/baechelin/store/service/StoreService.java +++ b/src/main/java/com/mpnp/baechelin/store/service/StoreService.java @@ -77,6 +77,7 @@ public StorePagedResponseDto getStoreInRange(BigDecimal latStart, BigDecimal lat */ public StorePagedResponseDto getStoreInOnePointRange(BigDecimal lat, BigDecimal lng, String category, List facility, Pageable pageable, String socialId) { BigDecimal[] range = QuerydslLocation.getRange(lat, lng, 10); + if (range == null) return getStoreInRange(null, null, null, null, category, facility, pageable, socialId); return getStoreInRange(range[0], range[1], range[2], range[3], category, facility, pageable, socialId); } @@ -263,7 +264,7 @@ public void updateSchedule() { } if (!store.getBookmarkList().isEmpty()) { int bookmarkCnt = storeRepository.getBookmarkCnt(store.getId()); - storeRepository.updateBookmarkCnt(bookmarkCnt,store.getId()); + storeRepository.updateBookmarkCnt(bookmarkCnt, store.getId()); } } }