-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
src/main/java/io/oeid/mogakgo/core/configuration/SchedulerConfig.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,10 @@ | ||
package io.oeid.mogakgo.core.configuration; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
|
||
@EnableScheduling | ||
@Configuration | ||
public class SchedulerConfig { | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/io/oeid/mogakgo/scheduler/FinishedProjectScheduler.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,51 @@ | ||
package io.oeid.mogakgo.scheduler; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.core.io.ResourceLoader; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class FinishedProjectScheduler { | ||
|
||
private final JdbcTemplate jdbcTemplate; | ||
private final ResourceLoader resourceLoader; | ||
|
||
private final List<String> sqlFilePaths; | ||
|
||
public FinishedProjectScheduler( | ||
JdbcTemplate jdbcTemplate, ResourceLoader resourceLoader, | ||
@Value("${path.sql.finished-matched-project}") String finishedMatchedProjectSqlPath, | ||
@Value("${path.sql.finished-pending-project}") String finishedPendingProjectSqlPath, | ||
@Value("${path.sql.finished-project-request}") String finishedProjectRequestSqlPath | ||
) { | ||
this.jdbcTemplate = jdbcTemplate; | ||
this.resourceLoader = resourceLoader; | ||
this.sqlFilePaths = List.of(finishedMatchedProjectSqlPath, finishedPendingProjectSqlPath, | ||
finishedProjectRequestSqlPath); | ||
} | ||
|
||
@Scheduled(cron = "0 0 0 * * ?") // 매일 자정에 실행 | ||
public void executeSqlFile() throws IOException { | ||
for (String sqlFilePath : sqlFilePaths) { | ||
String sql = loadSqlFromFile(sqlFilePath); | ||
jdbcTemplate.execute(sql); | ||
} | ||
} | ||
|
||
private String loadSqlFromFile(String path) throws IOException { | ||
try (BufferedReader reader = new BufferedReader( | ||
new InputStreamReader(resourceLoader.getResource(path).getInputStream(), | ||
StandardCharsets.UTF_8))) { | ||
return reader.lines().collect(Collectors.joining("\n")); | ||
} | ||
} | ||
|
||
} |
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,4 @@ | ||
UPDATE project_tb | ||
SET project_status = 'FINISHED' | ||
WHERE DATE(created_at) != CURDATE() | ||
AND project_status = 'MATCHED'; |
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,4 @@ | ||
UPDATE project_tb | ||
SET project_status = 'CANCELED' | ||
WHERE DATE(created_at) != CURDATE() | ||
AND project_status = 'PENDING'; |
5 changes: 5 additions & 0 deletions
5
src/main/resources/sql/rejected_project_request_about_finished_project.sql
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,5 @@ | ||
UPDATE project_join_request_tb pjr | ||
JOIN project_tb p ON pjr.project_id = p.id | ||
SET pjr.join_request_status = 'REJECTED' | ||
WHERE p.project_status in ('FINISHED', 'CANCELED') | ||
AND pjr.join_request_status = 'PENDING'; |