Skip to content

Commit

Permalink
#23 [Update] 업장 필터링 null case 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
JSoi committed Jul 30, 2022
1 parent 6583114 commit 45c5550
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public static BooleanBuilder getBooleanBuilder(String category, List<String> 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);
// 남서, 북동으로 받아오기
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/mpnp/baechelin/store/domain/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.Getter;

import java.util.Arrays;

@Getter
public enum Category {
KOREAN("한식"), WESTERN("양식"), JAPANESE("일식"), ASIAN("아시아음식"), CHINESE("중식"),
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ public Page<Store> findBetweenOnePointOrder(BigDecimal latStart,
String category,
List<String> 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<Store> storeList =
queryFactory
.selectFrom(store)
Expand All @@ -61,7 +63,20 @@ public Page<Store> findBetweenOnePointOrder(BigDecimal latStart,
return new PageImpl<>(storeList, pageable, fetchCount);
}

private OrderSpecifier<?> orderDistance(BigDecimal nowLat, BigDecimal nowLng){
private Page<Store> findBetweenOnePointOrderNullCase(BooleanBuilder builder,
Pageable pageable) {
List<Store> 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();
}

Expand All @@ -77,7 +92,7 @@ public Page<Store> 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();
Expand All @@ -96,7 +111,7 @@ public Page<Store> findStoreOrderByBookmark(BigDecimal lat,
List<Store> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public StorePagedResponseDto getStoreInRange(BigDecimal latStart, BigDecimal lat
*/
public StorePagedResponseDto getStoreInOnePointRange(BigDecimal lat, BigDecimal lng, String category, List<String> 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);
}

Expand Down Expand Up @@ -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());
}
}
}
Expand Down

0 comments on commit 45c5550

Please sign in to comment.