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 e586468..fba9f93 100644 --- a/src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java +++ b/src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java @@ -29,6 +29,8 @@ import static com.mpnp.baechelin.common.QueryDslSearch.getSearchBooleanBuilder; import static com.mpnp.baechelin.common.QuerydslLocation.locTwoPointAndConditions; import static com.mpnp.baechelin.store.domain.QStore.store; +import static com.querydsl.core.types.dsl.Expressions.constant; +import static com.querydsl.core.types.dsl.MathExpressions.*; @Repository @Transactional @@ -57,14 +59,11 @@ public Page findBetweenTwoPointOrder(BigDecimal latStart, List tupleList = queryFactory .select(store, -// ((store.latitude.subtract(nowLat)).abs().add(store.longitude.subtract(nowLng)).abs()).as(diff), - MathExpressions.acos(MathExpressions.cos(MathExpressions.radians(Expressions.constant(nowLat)))).multiply(6371) - .multiply(MathExpressions.cos(MathExpressions.radians(store.latitude))) - .multiply(MathExpressions.cos(MathExpressions.radians(store.longitude) - .subtract(MathExpressions.radians(Expressions.constant(nowLng))))) - .add(MathExpressions.sin(MathExpressions.radians(Expressions.constant(nowLat))) - .multiply(MathExpressions.sin(MathExpressions.radians(store.latitude)))).doubleValue().as(path) - ) + acos(sin(radians(Expressions.constant(nowLat))) + .multiply(sin(radians(store.latitude))) + .add(cos(radians(Expressions.constant(nowLat))).multiply(cos(radians(store.latitude))) + .multiply(cos(radians(Expressions.constant(nowLng)).subtract(radians(store.longitude)))))).multiply(6371).as(path) + ) .from(store) .where(builder) .orderBy(path.desc()) @@ -97,13 +96,10 @@ public Page findBetweenOnePointOrder(BigDecimal latStart, List tupleList = queryFactory .select(store, -// ((store.latitude.subtract(nowLat)).abs().add(store.longitude.subtract(nowLng)).abs()).as(diff), - MathExpressions.acos(MathExpressions.cos(MathExpressions.radians(Expressions.constant(lat)))).multiply(6371) - .multiply(MathExpressions.cos(MathExpressions.radians(store.latitude))) - .multiply(MathExpressions.cos(MathExpressions.radians(store.longitude) - .subtract(MathExpressions.radians(Expressions.constant(lng))))) - .add(MathExpressions.sin(MathExpressions.radians(Expressions.constant(lat))) - .multiply(MathExpressions.sin(MathExpressions.radians(store.latitude)))).doubleValue().as(path) + acos(sin(radians(Expressions.constant(lat))) + .multiply(sin(radians(store.latitude))) + .add(cos(radians(Expressions.constant(lat))).multiply(cos(radians(store.latitude))) + .multiply(cos(radians(Expressions.constant(lng)).subtract(radians(store.longitude)))))).multiply(6371).as(path) ) .from(store) .where(builder) 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 aa37d6c..de1ebd8 100644 --- a/src/main/java/com/mpnp/baechelin/store/service/StoreService.java +++ b/src/main/java/com/mpnp/baechelin/store/service/StoreService.java @@ -78,7 +78,7 @@ public StorePagedResponseDto getStoreInOnePointRange(BigDecimal latStart, BigDec * @return 위도, 경도, 카테고리, 배리어 프리, 페이징을 만족하는 배리어 프리 업장 리턴 */ public StorePagedResponseDto getStoreInOnePointRange(BigDecimal lat, BigDecimal lng, String category, List facility, Pageable pageable, String socialId) { - BigDecimal[] range = QuerydslLocation.getRange(lat, lng, 3); + BigDecimal[] range = QuerydslLocation.getRange(lat, lng, 2); if (range == null) return getStoreInOnePointRange(null, null, null, null,lat,lng, category, facility, pageable, socialId); return getStoreInOnePointRange(range[0], range[1], range[2], range[3],lat,lng, category, facility, pageable, socialId);