租赁管理模块
模块导读
租赁管理不只有到期任务。参考项目笔记,后台先管理看房预约,再管理租约:预约侧包括条件分页与状态更新;租约侧包括保存或更新、条件分页、详情、删除和状态更新,最后由定时任务处理到期状态。本文原先重点记录的定时任务代码保留在下方。
阅读租约相关接口时,建议同时关注房间、公寓、租期和支付方式之间的关系。笔记中的租约详情会在查询租约后,再组装对应的公寓、房间、支付方式与租期信息,避免列表字段和详情字段混淆。
状态更新也要区分人工操作与到期任务:笔记里的通用状态更新接口是教学写法,实际业务不能让请求任意跳转状态;下方定时任务只筛选到期且处于指定状态的租约,再批量更新为已过期。
租约过期修改状态功能
定时任务
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 许可协议。转载请注明来源 𝐺ℎ𝑎𝑜 の 𝐵𝑙𝑜𝑔!
评论
