Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
*/
package com.yfive.gbjs.domain.chat.service;

import com.yfive.gbjs.domain.chat.dto.request.ChatRequest;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.document.Document;
import org.springframework.ai.vectorstore.SearchRequest;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.stereotype.Service;

import com.yfive.gbjs.domain.chat.dto.request.ChatRequest;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Service
@RequiredArgsConstructor
@Slf4j
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package com.yfive.gbjs.domain.guide.scheduler;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.yfive.gbjs.domain.guide.service.GuideService;
Expand All @@ -25,7 +24,7 @@ public class AudioDataScheduler {
private final GuideService guideService;

/** 매일 새벽 2시에 경북 지역 오디오 데이터를 동기화합니다. */
@Scheduled(cron = "0 0 2 * * ?")
// @Scheduled(cron = "0 0 2 * * ?")
public void syncAudioData() {

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,35 @@ public interface UserSealRepository extends JpaRepository<UserSeal, Long> {
Map<Long, Long> countSealsByUserIds(@Param("userIds") List<Long> userIds);

long countByUserAndSealIn(User user, List<Seal> seals);

/**
* 가장 인기 있는 띠부씰 관광지 ID 목록을 조회합니다. (전체 기간)
*
* @param pageable 페이지 정보 (상위 N개를 가져오기 위해 사용)
* @return 인기 띠부씰 관광지 ID 목록
*/
@Query(
"SELECT us.seal.sealSpot.id FROM UserSeal us WHERE us.seal.sealSpot.id IS NOT NULL GROUP BY us.seal.sealSpot.id ORDER BY COUNT(us.seal.sealSpot.id) DESC")
List<Long> findPopularSealSpotIds(org.springframework.data.domain.Pageable pageable);

/**
* 지정된 날짜 이후 가장 인기 있는 띠부씰 관광지 ID 목록을 조회합니다.
*
* @param pageable 페이지 정보 (상위 N개를 가져오기 위해 사용)
* @param startDate 시작 날짜
* @return 인기 띠부씰 관광지 ID 목록
*/
@Query(
"SELECT us.seal.sealSpot.id FROM UserSeal us WHERE us.collectedAt >= :startDate AND us.seal.sealSpot.id IS NOT NULL GROUP BY us.seal.sealSpot.id ORDER BY COUNT(us.seal.sealSpot.id) DESC")
List<Long> findPopularSealSpotIdsByDate(
org.springframework.data.domain.Pageable pageable,
@Param("startDate") java.time.LocalDateTime startDate);

/**
* 지정된 날짜 이후 수집된 띠부씰의 총 개수를 조회합니다.
*
* @param startDate 시작 날짜
* @return 띠부씰 수집 개수
*/
long countByCollectedAtAfter(java.time.LocalDateTime startDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package com.yfive.gbjs.domain.seal.service;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -496,7 +495,21 @@ public void deleteCollectedSeal(Long sealId) {
/** 인기 띠부실 관광지 조회 */
@Override
public List<PopularSealSpotResponse> getPopularSealSpots() {
List<Long> popularSealSpotIds = Arrays.asList(1L, 2L, 3L, 4L);
// 상위 4개 조회
org.springframework.data.domain.Pageable pageable =
org.springframework.data.domain.PageRequest.of(0, 4);

// 최근 한 달 기준
LocalDateTime startDate = LocalDateTime.now().minusMonths(1);

List<Long> popularSealSpotIds;

// 최근 한 달간 수집된 씰이 2개 이하이면 누적 데이터, 그렇지 않으면 최신 데이터 사용
if (userSealRepository.countByCollectedAtAfter(startDate) <= 2) {
popularSealSpotIds = userSealRepository.findPopularSealSpotIds(pageable);
} else {
popularSealSpotIds = userSealRepository.findPopularSealSpotIdsByDate(pageable, startDate);
}

List<SealSpot> popularSealSpots = sealSpotRepository.findAllById(popularSealSpotIds);

Expand Down
Loading