23
23
import org .springframework .stereotype .Service ;
24
24
import org .springframework .transaction .annotation .Transactional ;
25
25
26
+ import java .time .LocalDate ;
26
27
import java .time .ZoneId ;
27
28
import java .time .ZonedDateTime ;
28
29
import java .util .List ;
30
+ import java .util .stream .Stream ;
29
31
30
32
@ Service
31
33
@ RequiredArgsConstructor
@@ -71,6 +73,36 @@ public GetReportMemoryListDto getMemory(Long memberId){
71
73
return createReportMemoryListDto (reportMemories );
72
74
}
73
75
76
+ public GetReportMemoryListDto createReportMemoryListDto (List <ReportMemory > reportMemories ) {
77
+ ZoneId koreaZoneId = ZoneId .of ("Asia/Seoul" );
78
+ LocalDate startDate = ZonedDateTime .now (koreaZoneId ).toLocalDate ().minusDays (13 );
79
+
80
+ // 주어진 기간 내의 모든 날짜 리스트 생성
81
+ List <LocalDate > allDates = Stream .iterate (startDate , date -> date .plusDays (1 ))
82
+ .limit (14 )
83
+ .toList ();
84
+
85
+ List <GetReportMemoryDto > getReportMemoryDtos = allDates .stream ()
86
+ .map (date -> {
87
+ // 해당 날짜의 ReportMemory 객체를 찾음 (한국 시간대 기준으로 LocalDate 비교)
88
+ ReportMemory memory = reportMemories .stream ()
89
+ .filter (m -> m .getCreatedDate ().withZoneSameInstant (koreaZoneId ).toLocalDate ().equals (date ))
90
+ .findFirst ()
91
+ .orElse (null );
92
+
93
+ // ReportMemory 객체가 존재하면 해당 객체를 기반으로 DTO 생성, 없으면 임시 DTO 생성
94
+ return GetReportMemoryDto .builder ()
95
+ .id (memory != null ? memory .getId () : 0 ) // 존재하지 않으면 ID는 0
96
+ .createdDate (memory != null ? memory .getCreatedDate ().toString () : date .atStartOfDay (koreaZoneId ).toString ()) // 존재하지 않으면 해당 날짜의 00:00 KST 사용
97
+ .memory (memory != null ? memory .getMemory () : "\uD83C \uDE1A " ) // 임시 메모리 데이터
98
+ .build ();
99
+ })
100
+ .toList ();
101
+
102
+ return new GetReportMemoryListDto (getReportMemoryDtos );
103
+ }
104
+
105
+ /*
74
106
public GetReportMemoryListDto createReportMemoryListDto(List<ReportMemory> reportMemories) {
75
107
//ReportMemoryListResponseDto에 매핑
76
108
List<GetReportMemoryDto> getReportMemoryDtos = reportMemories.stream()
@@ -83,6 +115,7 @@ public GetReportMemoryListDto createReportMemoryListDto(List<ReportMemory> repor
83
115
84
116
return new GetReportMemoryListDto(getReportMemoryDtos);
85
117
}
118
+ */
86
119
87
120
public String postNewAiMemory (Long memberId , ZonedDateTime today ){
88
121
String persona = getPersona (memberId );
@@ -229,6 +262,8 @@ public PostFastApiAiRecommendActivityDto postNewAiRecommend(Long memberId, Zoned
229
262
}
230
263
231
264
public String parseAiRecommend (String text ){
265
+ // AI에서 이 접두사를 붙여서 반환하는 경우가 많이 발생함
266
+ text = text .replace ("AI Recommendation: " , "" );
232
267
return text .replace ("\" " , "" );
233
268
}
234
269
0 commit comments