-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from PlanIt-Project/BE
Be
- Loading branch information
Showing
34 changed files
with
1,229 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/com/sideProject/PlanIT/common/scheduler/MemberShipScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.sideProject.PlanIT.common.scheduler; | ||
|
||
import com.sideProject.PlanIT.domain.product.entity.enums.ProductType; | ||
import com.sideProject.PlanIT.domain.program.entity.Program; | ||
import com.sideProject.PlanIT.domain.program.repository.ProgramRepository; | ||
import com.sideProject.PlanIT.domain.user.service.EmailService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class MemberShipScheduler { | ||
private final ProgramRepository programRepository; | ||
private final EmailService emailService; | ||
|
||
@Scheduled(cron = "0 0 0 * * ?") | ||
public void memberShipEndTimeEvent() { | ||
log.info("이메일 전송"); | ||
LocalDate nowDate = LocalDate.now(); | ||
|
||
LocalDate afterOneWeek = nowDate.plusWeeks(1); | ||
LocalDate afterOneMonth = nowDate.plusMonths(1); | ||
|
||
sendMailToOneWeekLeft(afterOneWeek); | ||
sendMailToOneMonthLeft(afterOneMonth); | ||
} | ||
|
||
private void sendMailToOneWeekLeft(LocalDate afterOneWeek) { | ||
List<Program> oneWeekLefts = programRepository.findMembershipProgramsByEndAtAndProductType(afterOneWeek, ProductType.MEMBERSHIP); | ||
|
||
oneWeekLefts.forEach(program -> { | ||
emailService.memberShipEmail(program.getMember().getEmail(), "일주일"); | ||
}); | ||
} | ||
|
||
private void sendMailToOneMonthLeft(LocalDate afterOneMonth) { | ||
List<Program> oneWeekLefts = programRepository.findMembershipProgramsByEndAtAndProductType(afterOneMonth, ProductType.MEMBERSHIP); | ||
|
||
oneWeekLefts.forEach(program -> { | ||
emailService.memberShipEmail(program.getMember().getEmail(), "한 달"); | ||
}); | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,4 @@ public enum ProgramSearchStatus { | |
ALL, | ||
VALID, | ||
INVALID | ||
|
||
} |
12 changes: 11 additions & 1 deletion
12
src/main/java/com/sideProject/PlanIT/domain/program/entity/enums/ProgramStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
package com.sideProject.PlanIT.domain.program.entity.enums; | ||
|
||
import java.util.List; | ||
|
||
public enum ProgramStatus { | ||
NOT_STARTED, | ||
IN_PROGRESS, | ||
SUSPEND, | ||
REFUND, | ||
EXPIRED | ||
EXPIRED; | ||
|
||
public static List<ProgramStatus> forValid() { | ||
return List.of(IN_PROGRESS); | ||
} | ||
|
||
public static List<ProgramStatus> forUnValid() { | ||
return List.of(NOT_STARTED,SUSPEND,REFUND,EXPIRED); | ||
} | ||
} |
12 changes: 9 additions & 3 deletions
12
src/main/java/com/sideProject/PlanIT/domain/program/repository/ProgramRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,29 @@ | ||
package com.sideProject.PlanIT.domain.program.repository; | ||
|
||
import com.sideProject.PlanIT.domain.program.entity.enums.ProgramStatus; | ||
import com.sideProject.PlanIT.domain.product.entity.enums.ProductType; | ||
import com.sideProject.PlanIT.domain.program.entity.Program; | ||
import com.sideProject.PlanIT.domain.program.entity.enums.ProgramStatus; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Repository | ||
public interface ProgramRepository extends JpaRepository<Program, Long> { | ||
@Query("SELECT o FROM Program o WHERE o.registration.id = :registrationId") | ||
Program findSingleProgramByRegistrationId(@Param("registrationId") Long registrationId); | ||
//status가 IN_PROGRESS인 모든 프로그램 조회 | ||
Page<Program> findByMemberId(Long memberId, Pageable pageable); | ||
Page<Program> findByEmployeeId(Long employeeId, Pageable pageable); | ||
Page<Program> findByMemberIdAndStatus(Long memberId, ProgramStatus status, Pageable pageable); | ||
Page<Program> findByMemberIdAndStatusIn(Long memberId, List<ProgramStatus> status, Pageable pageable); | ||
Page<Program> findByEmployeeIdAndStatus(Long employeeId,ProgramStatus status, Pageable pageable); | ||
Page<Program> findByStatus(ProgramStatus status, Pageable pageable); | ||
Page<Program> findByStatusIn(List<ProgramStatus> status, Pageable pageable); | ||
|
||
@Query("SELECT p FROM Program p JOIN p.product pr WHERE p.endAt = ?1 AND pr.type = ?2") | ||
List<Program> findMembershipProgramsByEndAtAndProductType(LocalDate endAt, ProductType productType); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.