TASK:续订通知;
This commit is contained in:
53
src/main/java/com/ai/da/common/config/MyTaskScheduler.java
Normal file
53
src/main/java/com/ai/da/common/config/MyTaskScheduler.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package com.ai.da.common.config;
|
||||
|
||||
import com.ai.da.common.utils.SendEmailUtil;
|
||||
import com.ai.da.mapper.AccountMapper;
|
||||
import com.ai.da.mapper.entity.Account;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class MyTaskScheduler {
|
||||
|
||||
@Resource
|
||||
private AccountMapper accountMapper;
|
||||
|
||||
// 定时任务,每周一零点执行一次
|
||||
@Scheduled(cron = "0 0 0 ? * MON")
|
||||
// @Scheduled(cron = "0 0/1 * * * ?")
|
||||
public void checkExpiry() {
|
||||
// 检测正式用户是否快要过期
|
||||
QueryWrapper<Account> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(Account::getIsTrial, 0);
|
||||
// qw.lambda().eq(Account::getId, 88);
|
||||
List<Account> accountList = accountMapper.selectList(qw);
|
||||
for (Account account : accountList) {
|
||||
// 用户到期时间戳
|
||||
Long timestamp = account.getValidEndTime(); // 替换为你的时间戳
|
||||
|
||||
// 获取当前时间戳
|
||||
Long currentTimestamp = System.currentTimeMillis();
|
||||
|
||||
// 计算时间差(毫秒)
|
||||
long timeDifference = currentTimestamp - timestamp;
|
||||
|
||||
if (timeDifference < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 判断是否在30天以内(30天的毫秒数)
|
||||
long thirtyDaysInMillis = 30L * 24 * 60 * 60 * 1000;
|
||||
boolean within30Days = timeDifference <= thirtyDaysInMillis;
|
||||
|
||||
if (within30Days) {
|
||||
// 发邮件
|
||||
SendEmailUtil.sendWillBeExpiredEmail(account, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user