TASK:订阅到期通知或续订通知(暂时关闭邮件发送)
This commit is contained in:
@@ -10,8 +10,11 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -19,6 +22,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class SubscriptionReminderTask {
|
||||
|
||||
@@ -32,10 +36,11 @@ public class SubscriptionReminderTask {
|
||||
private static final Map<String, Integer> REMINDER_DAYS_CONFIG = new HashMap<>();
|
||||
|
||||
static {
|
||||
REMINDER_DAYS_CONFIG.put("monthly", 7);
|
||||
REMINDER_DAYS_CONFIG.put("yearly", 14);
|
||||
REMINDER_DAYS_CONFIG.put("month", 7);
|
||||
REMINDER_DAYS_CONFIG.put("year", 14);
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0 9 * * ?")
|
||||
public void subscriptionReminder() {
|
||||
// 获取所有需要通知的订阅
|
||||
List<SubscriptionInfo> subscriptionInfos = getDueSubscriptions();
|
||||
@@ -52,7 +57,7 @@ public class SubscriptionReminderTask {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean success = stripeService.sendEmail(subscriptionInfo.getSubscriptionId(), "reminder_subscriber", null);
|
||||
boolean success = stripeService.sendEmail(subscriptionInfo.getSubscriptionId(), emailType, subscriptionInfo.getOrderNo());
|
||||
if (success) {
|
||||
log.info("提前{}天向用户 {} 发送续订通知邮件,订阅类型: {}",
|
||||
daysBefore, subscriptionInfo.getAccountId(), subscriptionInfo.getType());
|
||||
@@ -78,26 +83,30 @@ public class SubscriptionReminderTask {
|
||||
LocalDateTime startOfDay = targetDate.toLocalDate().atStartOfDay();
|
||||
LocalDateTime endOfDay = targetDate.toLocalDate().atTime(23, 59, 59);
|
||||
|
||||
long startTimestamp = startOfDay.toEpochSecond(ZoneOffset.UTC);
|
||||
long endTimestamp = endOfDay.toEpochSecond(ZoneOffset.UTC);
|
||||
// 使用系统默认时区
|
||||
ZoneId zoneId = ZoneId.systemDefault();
|
||||
long startTimestamp = startOfDay.atZone(zoneId).toEpochSecond();
|
||||
long endTimestamp = endOfDay.atZone(zoneId).toEpochSecond();
|
||||
|
||||
QueryWrapper<SubscriptionInfo> qw = new QueryWrapper<>();
|
||||
qw.ge("current_period_end", startTimestamp);
|
||||
qw.lt("current_period_end", endTimestamp);
|
||||
qw.lambda().ge(SubscriptionInfo::getCurrentPeriodEnd, startTimestamp);
|
||||
qw.lambda().lt(SubscriptionInfo::getCurrentPeriodEnd, endTimestamp);
|
||||
// qw.eq("status", "active");
|
||||
qw.eq("subscription_type", subscriptionType);
|
||||
qw.lambda().eq(SubscriptionInfo::getType, subscriptionType);
|
||||
|
||||
return subscriptionInfoMapper.selectList(qw);
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0 9 * * ?")
|
||||
public void trialReminder() {
|
||||
// 今天的 00:00:00 和 23:59:59
|
||||
LocalDateTime startOfDay = LocalDateTime.now().toLocalDate().atStartOfDay();
|
||||
LocalDateTime endOfDay = LocalDateTime.now().toLocalDate().atTime(23, 59, 59);
|
||||
|
||||
// 转为时间戳
|
||||
long startTimestamp = startOfDay.toEpochSecond(ZoneOffset.UTC);
|
||||
long endTimestamp = endOfDay.toEpochSecond(ZoneOffset.UTC);
|
||||
// 使用系统默认时区
|
||||
ZoneId zoneId = ZoneId.systemDefault();
|
||||
long startTimestamp = startOfDay.atZone(zoneId).toEpochSecond() * 1000;
|
||||
long endTimestamp = endOfDay.atZone(zoneId).toEpochSecond() * 1000;
|
||||
|
||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().gt(Account::getValidEndTime, startTimestamp)
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 邮件发送类
|
||||
@@ -832,7 +833,7 @@ public class SendEmailUtil {
|
||||
if (language.equals("ENGLISH")) {
|
||||
user.setSubject("[Code-Create] AiDA Subscription Renewal Reminder");
|
||||
templateUser.setTemplateID(156072L);
|
||||
} else if (language.equals("CHINESE")){
|
||||
} else if (language.equals("CHINESE_SIMPLIFIED")){
|
||||
user.setSubject("[Code-Create] AiDA续订提醒");
|
||||
templateUser.setTemplateID(156073L);
|
||||
} else {
|
||||
@@ -844,7 +845,7 @@ public class SendEmailUtil {
|
||||
if (language.equals("ENGLISH")) {
|
||||
user.setSubject("[Code-Create] AiDA account is about to expire");
|
||||
templateUser.setTemplateID(156749L);
|
||||
} else if (language.equals("CHINESE")){
|
||||
} else if (language.equals("CHINESE_SIMPLIFIED")){
|
||||
user.setSubject("[Code-Create] 您的AiDA账号即将到期");
|
||||
templateUser.setTemplateID(156750L);
|
||||
} else {
|
||||
@@ -856,7 +857,7 @@ public class SendEmailUtil {
|
||||
if (language.equals("ENGLISH")) {
|
||||
user.setSubject("[Code-Create] AiDA — Free Trial Ending");
|
||||
templateUser.setTemplateID(156075L);
|
||||
} else if (language.equals("CHINESE")){
|
||||
} else if (language.equals("CHINESE_SIMPLIFIED")){
|
||||
user.setSubject("[Code-Create] AiDA — 免费试用结束提醒");
|
||||
templateUser.setTemplateID(156076L);
|
||||
} else {
|
||||
@@ -874,14 +875,16 @@ public class SendEmailUtil {
|
||||
templateUser.setTemplateData(JSON.toJSONString(subscriptionEmailParamsDTO));
|
||||
user.setTemplate(templateUser);
|
||||
|
||||
subscriptionEmailParamsDTO.setEndDate("When cancelled");
|
||||
if (Objects.nonNull(subscriptionEmailParamsDTO)) {
|
||||
subscriptionEmailParamsDTO.setEndDate("When cancelled");
|
||||
}
|
||||
templateMerchant.setTemplateData(JSON.toJSONString(subscriptionEmailParamsDTO));
|
||||
merchant.setTemplate(templateMerchant);
|
||||
|
||||
if (!type.equals("cancel") && !type.equals("fail_new")) {
|
||||
// 返回的resp是一个SendEmailResponse的实例,与请求对象对应
|
||||
SendEmailResponse respUser = client.SendEmail(user);
|
||||
log.info("邮件主题:{},发送结果toUser###{}", user.getSubject(), SendEmailResponse.toJsonString(respUser));
|
||||
// SendEmailResponse respUser = client.SendEmail(user);
|
||||
log.info("邮件主题:{},发送结果toUser###{}, email:{}", user.getSubject(), /*SendEmailResponse.toJsonString(respUser)*/null, receiverAddress);
|
||||
}
|
||||
if (!type.startsWith("reminder")) {
|
||||
SendEmailResponse respMerchant = client.SendEmail(merchant);
|
||||
|
||||
Reference in New Issue
Block a user