租赁管理模块
a
租约过期修改状态功能
定时任务
SpringBoot定时任务
在SpringBoot启动类上增加
@EnableScheduling注解1
2
3
4
5
6
7
8
public class AdminWebApplication {
public static void main(String[] args) {
SpringApplication.run(AdminWebApplication.class, args);
}
}编写定时逻辑
在web-admin模块下创建
com.atguigu.lease.web.admin.schedule.ScheduledTasks类,内容如下1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class ScheduledTasks {
private LeaseAgreementService leaseAgreementService;
public void checkLeaseStatus() {
LambdaUpdateWrapper<LeaseAgreement> updateWrapper = new LambdaUpdateWrapper<>();
Date now = new Date();
updateWrapper.le(LeaseAgreement::getLeaseEndDate, now);
updateWrapper.in(LeaseAgreement::getStatus, LeaseStatus.SIGNED, LeaseStatus.WITHDRAWING);
updateWrapper.set(LeaseAgreement::getStatus, LeaseStatus.EXPIRED);
leaseAgreementService.update(updateWrapper);
}
}
知识点:
SpringBoot中的cron表达式语法如下
1 | ┌───────────── second (0-59) |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 𝐺ℎ𝑎𝑜 の 𝐵𝑙𝑜𝑔!
评论
