-
Notifications
You must be signed in to change notification settings - Fork 2
[Feat] 위치기반 리마인드 알림 시 해당 일기와 해당 일기 기준 반경 500m 내의 일기들에 한달(30일) 쿨타임 부여 #245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |||||
| import TtattaBackend.ttatta.security.EnvelopeCryptoService; | ||||||
| import TtattaBackend.ttatta.web.dto.DiaryRequestDTO; | ||||||
| import TtattaBackend.ttatta.web.dto.DiaryResponseDTO; | ||||||
| import jakarta.transaction.Transactional; | ||||||
| import lombok.RequiredArgsConstructor; | ||||||
| import lombok.extern.slf4j.Slf4j; | ||||||
| import org.locationtech.jts.geom.Coordinate; | ||||||
|
|
@@ -52,6 +53,7 @@ public class DiaryQueryServiceImpl implements DiaryQueryService{ | |||||
| private static final int SEARCH_RANGE = 100; // 검색 범위 설정 (100m) | ||||||
| private final GeometryFactory geometryFactory; | ||||||
| private final EnvelopeCryptoService envelopeCryptoService; | ||||||
| private static final int MEMORY_DIARY_COOL_TIME_AREA_RANGE = 500; // 검색 범위 설정 (100m) | ||||||
|
|
||||||
| @Override | ||||||
| public DiaryResponseDTO.FootprintDiaryListDTO getFootprintDiaryList(Long diaryCategoryId, DiaryRequestDTO.ViewOnMapDTO request){ | ||||||
|
|
@@ -269,6 +271,7 @@ public List<LocalDateTime> getDiaryDateList() { | |||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| @Transactional | ||||||
| public void findRemindDiary(DiaryRequestDTO.RemindDTO request) { | ||||||
| Long userId = SecurityUtil.getCurrentUserId(); | ||||||
| Users user = userRepository.findById(userId).orElseThrow( | ||||||
|
|
@@ -310,6 +313,8 @@ public void findRemindDiary(DiaryRequestDTO.RemindDTO request) { | |||||
| )); | ||||||
| System.out.println("nearestDiaries real Candidates: " + nearestDiary.get().getId()); | ||||||
|
|
||||||
| // 반환한 일기(nearestDiary) 주변 500m반경 내의 일기들의 위치기반 추억 알림 쿨타임을 한달(30일)로 설정 | ||||||
| setMemoryDiaryAlarmCoolTime(userId, nearestDiary.get(), 30); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
|
|
||||||
| // 시간 계산 | ||||||
| long days = ChronoUnit.DAYS.between(nearestDiary.get().getDate().toLocalDate(), LocalDate.now()); | ||||||
|
|
@@ -331,6 +336,37 @@ public void findRemindDiary(DiaryRequestDTO.RemindDTO request) { | |||||
| alarmCommandService.sendMemoryDiaryAlarm(user, timeMessage, nearestDiary.get().getId()); | ||||||
| } | ||||||
|
|
||||||
| private void setMemoryDiaryAlarmCoolTime(Long userId, Diaries currentDiary, int coolTime) { | ||||||
| // 1. 일기 주변 500m 반경 내 일기들 조회 | ||||||
| Decoded decoded = tryDecode(currentDiary, userId); | ||||||
| Double currentLatitude = decoded.lat(); | ||||||
| Double currentLongitude = decoded.lng(); | ||||||
| List<Pt> square = buildSquare(currentLatitude, currentLongitude, 600.0); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 500m 반경 내의 일기를 찾기 위해 600m 변의 정사각형을 사용하는 것은 부정확합니다. 이 정사각형은 중심에서 모서리까지의 거리가 약 424m( 500m 반경을 완전히 포함하려면 정사각형의 한 변의 길이는 최소 1000m(
Suggested change
|
||||||
| String wkt = toPolygonWKT(square); | ||||||
| List<Diaries> nearDiariesCandidates = diaryRepository.findNearDiariesCandidates(wkt, userId); | ||||||
| // 서버 로그에서 확인하기 위함 | ||||||
| for (Diaries diary : nearDiariesCandidates) { | ||||||
| System.out.println("nearDiariesCandidates id: " + diary.getId()); | ||||||
| } | ||||||
|
Comment on lines
+348
to
+350
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
|
|
||||||
| if (nearDiariesCandidates.isEmpty()) { // 검색 범위 내에 일기가 없는 경우 | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| // 검색 범위(정사각형) 내 복호화를 진행하고, 실제로 일기 위도 경도에서 100m 원 안에 있는 일기 중 가장 최신 일기 반환 | ||||||
| // 영 이상하면 getDate -> getCreatedAt으로 수정 (마지막줄) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| List<Diaries> nearestDiary = nearDiariesCandidates | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| .parallelStream() | ||||||
| .map(d -> tryDecode(d, userId)) // Decoded(diaries, lat, lng, ok) | ||||||
| .filter(Decoded::ok) | ||||||
| .filter(dd -> haversineMeters(currentLatitude, currentLongitude, dd.lat(), dd.lng()) <= MEMORY_DIARY_COOL_TIME_AREA_RANGE) | ||||||
| .map(Decoded::diary) | ||||||
| .toList(); | ||||||
|
|
||||||
| // 2. 각 엔티티 값 수정 -> 트랜잭션 커밋 때 DB에 UPDATE됨(Managed라면) | ||||||
| nearestDiary.forEach(d -> d.updateMemoryDiaryAlarmCoolTime(coolTime)); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public List<String> getPresignedForPost(String imageType) { | ||||||
| Long userId = SecurityUtil.getCurrentUserId(); | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
상수 값이 500인데 주석에는
(100m)로 잘못 기재되어 있습니다. 코드의 의도를 명확히 하고 혼동을 피하기 위해 주석을 실제 값과 일치시켜 주세요.