-
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
1 parent
2d8acad
commit 53362d9
Showing
18 changed files
with
281 additions
and
6 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
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
40 changes: 40 additions & 0 deletions
40
src/main/java/io/walkers/planes/fundhelper/schedule/DailyTaskProcessorSchedule.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,40 @@ | ||
package io.walkers.planes.fundhelper.schedule; | ||
|
||
import io.walkers.planes.fundhelper.dao.WebsiteNoticeDao; | ||
import io.walkers.planes.fundhelper.entity.model.WebsiteNoticeModel; | ||
import io.walkers.planes.fundhelper.service.task.impl.DefaultDelayTaskHandler; | ||
import io.walkers.planes.fundhelper.service.task.impl.DefaultDirectTaskHandler; | ||
import io.walkers.planes.fundhelper.service.task.processor.TaskProcessor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.Resource; | ||
import java.util.List; | ||
|
||
/** | ||
* 定时任务:激活任务(每日执行) | ||
* | ||
* @author planeswalker23 | ||
*/ | ||
@Slf4j | ||
@Component | ||
public class DailyTaskProcessorSchedule { | ||
|
||
@Resource | ||
private DefaultDirectTaskHandler defaultDirectTaskHandler; | ||
@Resource | ||
private DefaultDelayTaskHandler defaultDelayTaskHandler; | ||
@Resource | ||
private WebsiteNoticeDao websiteNoticeDao; | ||
|
||
/** | ||
* 触发待激活任务 | ||
* 触发时机:每天00:00 | ||
*/ | ||
@Scheduled(cron = "1 * * * * ?") | ||
public void dailyActiveTask() { | ||
List<WebsiteNoticeModel> data = websiteNoticeDao.selectActivatedWebsiteNotices(); | ||
TaskProcessor.process(data, defaultDirectTaskHandler, defaultDelayTaskHandler); | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
src/main/java/io/walkers/planes/fundhelper/service/task/ActivateCondition.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,24 @@ | ||
package io.walkers.planes.fundhelper.service.task; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* 满足激活条件的接口 | ||
* | ||
* @author planeswalker23 | ||
*/ | ||
public interface ActivateCondition { | ||
|
||
/** | ||
* 是否满足条件 | ||
* | ||
* @return Boolean | ||
*/ | ||
Boolean match(); | ||
|
||
/** | ||
* 获取激活时间 | ||
* @return Date | ||
*/ | ||
Date activeDate(); | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/io/walkers/planes/fundhelper/service/task/ModelAggregation.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,42 @@ | ||
package io.walkers.planes.fundhelper.service.task; | ||
|
||
import io.walkers.planes.fundhelper.util.TimeUtil; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* 需要具备秒级触发能力的模型需要实现该接口 | ||
* | ||
* @author planeswalker23 | ||
*/ | ||
public interface ModelAggregation extends ActivateCondition { | ||
|
||
/** | ||
* 获取激活时间 | ||
* | ||
* @return Date | ||
*/ | ||
@Override | ||
Date activeDate(); | ||
|
||
/** | ||
* 是否满足条件 | ||
* | ||
* @return Boolean | ||
*/ | ||
@Override | ||
default Boolean match() { | ||
Date startOfDay = TimeUtil.startOfDay(this.activeDate()); | ||
// 应已激活(今天第一秒大于激活时间) | ||
return startOfDay.after(this.activeDate()); | ||
} | ||
|
||
/** | ||
* 执行任务 | ||
* | ||
* @param taskHandler 任务执行器 | ||
*/ | ||
default void handle(TaskHandler taskHandler) { | ||
taskHandler.handle(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/io/walkers/planes/fundhelper/service/task/TaskHandler.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,16 @@ | ||
package io.walkers.planes.fundhelper.service.task; | ||
|
||
/** | ||
* 任务执行器接口 | ||
* | ||
* @author planeswalker23 | ||
*/ | ||
public interface TaskHandler { | ||
|
||
/** | ||
* 执行任务 | ||
* | ||
* @return Boolean | ||
*/ | ||
Boolean handle(); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/io/walkers/planes/fundhelper/service/task/impl/DefaultDelayTaskHandler.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,20 @@ | ||
package io.walkers.planes.fundhelper.service.task.impl; | ||
|
||
import io.walkers.planes.fundhelper.service.task.TaskHandler; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* 默认延迟任务执行器 | ||
* | ||
* @author planeswalker23 | ||
*/ | ||
@Slf4j | ||
@Component | ||
public class DefaultDelayTaskHandler implements TaskHandler { | ||
@Override | ||
public Boolean handle() { | ||
log.info("延迟任务执行器开始执行"); | ||
return null; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/io/walkers/planes/fundhelper/service/task/impl/DefaultDirectTaskHandler.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,20 @@ | ||
package io.walkers.planes.fundhelper.service.task.impl; | ||
|
||
import io.walkers.planes.fundhelper.service.task.TaskHandler; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* 默认直接任务执行器 | ||
* | ||
* @author planeswalker23 | ||
*/ | ||
@Slf4j | ||
@Component | ||
public class DefaultDirectTaskHandler implements TaskHandler { | ||
@Override | ||
public Boolean handle() { | ||
log.info("直接任务执行器开始执行"); | ||
return null; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/io/walkers/planes/fundhelper/service/task/processor/TaskProcessor.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,32 @@ | ||
package io.walkers.planes.fundhelper.service.task.processor; | ||
|
||
import io.walkers.planes.fundhelper.entity.model.WebsiteNoticeModel; | ||
import io.walkers.planes.fundhelper.service.task.TaskHandler; | ||
import org.springframework.util.CollectionUtils; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* 默认任务模板处理器 | ||
* | ||
* @author planeswalker23 | ||
*/ | ||
public class TaskProcessor { | ||
|
||
/** | ||
* 执行处理方法 | ||
* | ||
* @return Boolean | ||
*/ | ||
public static void process(List<WebsiteNoticeModel> data, TaskHandler directTaskHandler, TaskHandler delayTaskHandler) { | ||
if (CollectionUtils.isEmpty(data)) { | ||
return; | ||
} | ||
data.forEach(model -> { | ||
// 应已激活的数据:直接任务执行器 | ||
// 即将激活的数据:插入 Redis 过期键,监听过期事件 | ||
TaskHandler taskHandler = model.match() ? directTaskHandler : delayTaskHandler; | ||
model.handle(taskHandler); | ||
}); | ||
} | ||
} |
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.