在项目的开发中需要这样的一种业务,需要对客户设置到点提醒
我们可以使用定时任务的方式去实现
时间设置每隔一分钟查询一次
由于时间可能不是确定的某一天,而是一段的时间内需要执行的业务,就像我们平时的闹钟一样提醒,所以时间节点使用Time存储,只含有时分秒的时间结构
@Scheduled(cron="0 * * * * ?")
//每分钟查询一次
public void execute() {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date=new Date();
formatter.format(new Date());
log.info("当前的时间是{}",date);
Time time = new Time(date.getTime());
//转为Java.sql.Time
if(time.toString().equals(sqldate/*数据库获取的时间*/)){
Users users = userMapper.selectById(userId);
log.info("发送邮件{}",users.getEmail());
mailUtil.sendMessage("学习打卡提醒","提醒:您今天的学习打卡任务还没有完成。", users.getEmail());
log.info("提醒中....");
}
}