Skip to content

Commit

Permalink
#18 [Refactor] 리팩토링, 거리순 정렬 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
JSoi committed Aug 2, 2022
1 parent fa4f62f commit a81dfef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ public StorePagedResponseDto(Page<Store> resultStoreList, List<StoreCardResponse
this.totalCount = resultStoreList.getTotalElements();
this.page = resultStoreList.getNumber();
this.leftElement = totalCount - (long) page * resultStoreList.getSize() - resultStoreList.getNumberOfElements();
this.leftElement = this.leftElement < 0 ? 0 : this.leftElement;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,7 @@ public Page<Store> findBetweenTwoPointOrder(BigDecimal latStart,
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);
NumberPath<Double> path = Expressions.numberPath(Double.class, "realdist");
List<Tuple> tupleList =
queryFactory
.select(store,
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())
.limit(pageable.getPageSize())
.offset(pageable.getOffset())
.fetch();
List<Store> storeList = tupleList.stream().map(tuple -> tuple.get(store)).collect(Collectors.toList());
int fetchCount = queryFactory.selectFrom(store).where(builder).fetch().size();
return new PageImpl<>(storeList, pageable, fetchCount);
return getNearStores(nowLat, nowLng, pageable, builder, path);
}


Expand All @@ -88,11 +72,11 @@ public Page<Store> findBetweenOnePointOrder(BigDecimal latStart,
BooleanBuilder builder = QuerydslLocation.locAndConditions(latStart, latEnd, lngStart, lngEnd, category, facility);
if (latStart == null || lngStart == null || lngEnd == null || latEnd == null)
return findBetweenOnePointOrderNullCase(builder, pageable);
BigDecimal latH = new BigDecimal("110.852");
BigDecimal lngH = new BigDecimal("78.847");
NumberPath<Double> path = Expressions.numberPath(Double.class, "realdist");
return getNearStores(lat, lng, pageable, builder, path);
}

NumberPath<BigDecimal> diff = Expressions.numberPath(BigDecimal.class, "diff");
private Page<Store> getNearStores(BigDecimal lat, BigDecimal lng, Pageable pageable, BooleanBuilder builder, NumberPath<Double> path) {
List<Tuple> tupleList =
queryFactory
.select(store,
Expand All @@ -103,7 +87,6 @@ public Page<Store> findBetweenOnePointOrder(BigDecimal latStart,
)
.from(store)
.where(builder)
// .orderBy(diff.asc())
.orderBy(path.asc())
.limit(pageable.getPageSize())
.offset(pageable.getOffset())
Expand Down

0 comments on commit a81dfef

Please sign in to comment.