Skip to content

Commit

Permalink
[FEATURE] 학사일정 알림 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
wnehgus101 committed Oct 8, 2024
1 parent 9ade078 commit 682d542
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package depth.mvp.thinkerbell.domain.user.service;

import depth.mvp.thinkerbell.domain.common.service.CategoryService;
import depth.mvp.thinkerbell.domain.notice.entity.AcademicSchedule;
import depth.mvp.thinkerbell.domain.notice.entity.AllNoticesView;
import depth.mvp.thinkerbell.domain.notice.entity.CrawlingNum;
import depth.mvp.thinkerbell.domain.notice.repository.AcademicScheduleRepository;
import depth.mvp.thinkerbell.domain.notice.repository.AllNoticeViewRepository;
import depth.mvp.thinkerbell.domain.notice.repository.CrawlingNumRepository;
import depth.mvp.thinkerbell.domain.notice.service.ScheduleParser;
import depth.mvp.thinkerbell.domain.user.dto.AlarmDto;
import depth.mvp.thinkerbell.domain.user.entity.Alarm;
import depth.mvp.thinkerbell.domain.user.entity.Bookmark;
Expand All @@ -25,6 +28,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.webjars.NotFoundException;

import java.time.LocalDate;
import java.util.*;

@Service
Expand All @@ -36,6 +40,7 @@ public class AlarmService {
private EntityManager entityManager;

private final AllNoticeViewRepository allNoticeViewRepository;
private final AcademicScheduleRepository academicScheduleRepository;
private final KeywordRepository keywordRepository;
private final CrawlingNumRepository crawlingNumRepository;
private final AlarmRepository alarmRepository;
Expand Down Expand Up @@ -97,6 +102,31 @@ public void updateNoticeAndMatchKeyword(){
}
}

//매일 오전 8시에 학사일정 알림 전송
@Scheduled(cron = "0 0 8 * * ?", zone = "Asia/Seoul")
public void sendAlarmForBookmarkSchedule(){
List<User> userList = userRepository.findAll();
LocalDate currentDate = LocalDate.now();

for (User user : userList) {
List<Bookmark> bookmarkList = bookmarkRepository.findByUserAndCategoryOrderByCreatedAtDesc(user, "AcademicSchedule");;

if (bookmarkList != null) {
for (Bookmark bookmark : bookmarkList) {
AcademicSchedule academicSchedule = academicScheduleRepository.findOneById(bookmark.getNoticeID());

if (academicSchedule != null) {
if (currentDate.isEqual(ScheduleParser.parseDate(academicSchedule.getSchedule())[0])){
fcmService.sendScheduleMessage(user, academicSchedule.getTitle());
}
}
}
}
}
}



public synchronized void updateCrawlingNum(CrawlingNum crawlingNum, Long newMaxID) {
Optional<CrawlingNum> existingCrawlingNumOpt = crawlingNumRepository.findByNoticeType(crawlingNum.getNoticeType());
if (existingCrawlingNumOpt.isPresent()) {
Expand Down

0 comments on commit 682d542

Please sign in to comment.