TASK: 订阅或试用用户账号到期邮件通知

This commit is contained in:
2025-11-14 18:08:40 +08:00
parent 18f5528d59
commit f239c8c02b
8 changed files with 222 additions and 15 deletions

View File

@@ -37,11 +37,13 @@ public interface StripeService {
boolean sendEmail(String subscriptionId, String type, String orderNo);
String getLanguage(String language, String country, String type);
/*void updateSubscription(String subscriptionId);
void resume(String subscriptionId);*/
void subscriptionReminder();
// void subscriptionReminder();
void checkSubscriptionExpiration();

View File

@@ -634,7 +634,7 @@ public class EmailServiceImpl implements EmailService {
userTemplate = RENEWAL_USER_CN;
}
break;
case "reminder":
/*case "reminder":
if (language.equals("ENGLISH")) {
userSubject = "[Code-Create] AiDA Subscription Renewal Reminder";
userTemplate = RENEWAL_REMINDER_USER_EN;
@@ -642,6 +642,30 @@ public class EmailServiceImpl implements EmailService {
userSubject = "[Code-Create] AiDA续订提醒";
userTemplate = RENEWAL_REMINDER_USER_CN;
}
break;*/
case "reminder_subscriber":
if (language.equals("ENGLISH")) {
userSubject = "[Code-Create] AiDA Subscription Renewal Reminder";
userTemplate = String.valueOf(156072L);
} else if (language.equals("CHINESE")){
userSubject = "[Code-Create] AiDA续订提醒";
userTemplate = String.valueOf(156073L);
} else {
userSubject = "[Code-Create] AiDA續訂提醒";
userTemplate = String.valueOf(156074L);
}
break;
case "reminder_trial":
if (language.equals("ENGLISH")) {
userSubject = "[Code-Create] AiDA — Free Trial Ending";
userTemplate = String.valueOf(156075L);
} else if (language.equals("CHINESE")){
userSubject = "[Code-Create] AiDA — 免费试用结束提醒";
userTemplate = String.valueOf(156076L);
} else {
userSubject = "[Code-Create] AiDA — 免費試用結束提醒";
userTemplate = String.valueOf(156077L);
}
break;
default:
log.error("unknown subscription email type");
@@ -654,7 +678,7 @@ public class EmailServiceImpl implements EmailService {
sendEmail(Collections.singletonList(receiverAddress), jsonObject, userTemplate, userSubject, null, null);
}
// 排除不向商家发送邮件的情况
if (!type.equals("reminder")) {
if (!type.startsWith("reminder")) {
sendEmail(merchantReceiver, jsonObject, merchantTemplate, merchantSubject, null, null);
}
return true;

View File

@@ -2472,6 +2472,9 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
}
public ToProductImageResultVO poseTransform(PoseTransformDTO poseTransformDTO) {
// 参数判断
handleMotionParams(poseTransformDTO);
Long accountId = UserContext.getUserHolder().getId();
Long projectId = poseTransformDTO.getProjectId();
String productImage = poseTransformDTO.getProductImage();
@@ -2557,6 +2560,23 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
throw new BusinessException("pose.transformation.error", ResultEnum.ERROR.getCode());
}
private void handleMotionParams(PoseTransformDTO poseTransformDTO) {
if (Objects.isNull(poseTransformDTO.getMode()) || poseTransformDTO.getMode() == 0) {
throw new BusinessException("Mode cannot be empty");
}
MotionModeEnum motionModeEnum = MotionModeEnum.of(poseTransformDTO.getMode());
if (Objects.isNull(motionModeEnum)) {
throw new BusinessException("unknown.mode");
}
if (poseTransformDTO.getMode() == 1 && Objects.isNull(poseTransformDTO.getPoseId())) {
throw new BusinessException("Please choose a pose");
}
if (poseTransformDTO.getMode() == 3 && StringUtil.isNullOrEmpty(poseTransformDTO.getLastFrameProductImage())) {
throw new BusinessException("Last frame cannot be empty");
}
}
private CollectionSort addPoseTransferLike(PoseTransformDTO poseTransformDTO, Long poseTransformationId) {
if (Objects.nonNull(poseTransformDTO.getParentId())
&& !poseTransformDTO.getParentId().equals(0L)) {

View File

@@ -16,6 +16,7 @@ import com.ai.da.model.dto.CreateCouponDTO;
import com.ai.da.model.dto.ProductPurchaseDTO;
import com.ai.da.model.dto.QueryCouponsPageDTO;
import com.ai.da.model.dto.SubscriptionEmailParamsDTO;
import com.ai.da.model.enums.Language;
import com.ai.da.model.vo.CheckCouponsVO;
import com.ai.da.service.*;
import com.alibaba.fastjson.JSON;
@@ -1072,7 +1073,7 @@ public class StripeServiceImpl implements StripeService {
String key = RedisUtil.SUBSCRIPTION_SENT_EMAIL_TYPE + subscriptionInfo.getId();
// 先判断当前订单 这个类型的邮件是否已发送过
Boolean elementExistsInSet = redisUtil.isElementExistsInSet(key, type);
if (!type.equals("reminder") && !type.equals("cancel") && paymentInfo.getNotified() == 1 && elementExistsInSet){
if (!type.startsWith("reminder") && !type.equals("cancel") && paymentInfo.getNotified() == 1 && elementExistsInSet){
// 已经邮件通知过,直接返回
log.info("不发送邮件原因【type为{}order_no为{},已经进行邮件通知】", type, orderNo);
return true;
@@ -1080,7 +1081,7 @@ public class StripeServiceImpl implements StripeService {
com.ai.da.mapper.primary.entity.Account account = accountMapper.selectById(subscriptionInfo.getAccountId());
String userName = account.getUserName();
String language = account.getLanguage();
String language = getLanguage(account.getLanguage(), account.getCountry(), type);
OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(subscriptionInfo.getOrderNo());
SubscriptionEmailParamsDTO emailParamsDTO = new SubscriptionEmailParamsDTO();
@@ -1101,7 +1102,7 @@ public class StripeServiceImpl implements StripeService {
if (!b) return false;
// 邮件通知成功后,更新标志
if (!type.equals("reminder") && !type.equals("cancel")){
if (!type.startsWith("reminder") && !type.equals("cancel")){
PaymentInfo payment = new PaymentInfo();
payment.setId(paymentInfo.getId());
payment.setNotified(1);
@@ -1114,6 +1115,20 @@ public class StripeServiceImpl implements StripeService {
return true;
}
public String getLanguage(String language, String country, String type) {
if (StringUtil.isNullOrEmpty(language)){
return Language.ENGLISH.name();
} else {
if (!StringUtil.isNullOrEmpty(type) && type.startsWith("reminder")
&& language.equals(Language.CHINESE_SIMPLIFIED.name())
&& !StringUtil.isNullOrEmpty(country)
&& (country.equals("Hong Kong, China") || country.equals("Taiwan, China"))) {
return "zh-Hant";
}
return language;
}
}
public boolean sendEmail(String orderNo){
SubscriptionEmailParamsDTO emailParamsDTO = new SubscriptionEmailParamsDTO();
OrderInfo orderInfo = orderInfoService.getOrderByOrderNo(orderNo);
@@ -1257,9 +1272,10 @@ public class StripeServiceImpl implements StripeService {
emailParamsDTO.setNextPayDate(DateUtil.changeTimeStampFormat(subscriptionInfo.getCurrentPeriodEnd(), "seconds", CommonConstant.TIME_FORMAT_MMM_dd_yyyy));
}
emailParamsDTO.setRenewalTime(DateUtil.changeTimeStampFormat(subscriptionInfo.getCurrentPeriodEnd(), "seconds", CommonConstant.TIME_FORMAT_MMM_dd_yyyy));
emailParamsDTO.setDays(subscriptionInfo.getType().equals("month") ? "7" : subscriptionInfo.getType().equals("year") ? "14" : "N/A");
}
public void subscriptionReminder(){
/*public void subscriptionReminder(){
// 提前7天的 00:00:00 和 23:59:59
LocalDateTime startOfDay = LocalDateTime.now().plusDays(7).toLocalDate().atStartOfDay();
LocalDateTime endOfDay = LocalDateTime.now().plusDays(7).toLocalDate().atTime(23, 59, 59);
@@ -1278,7 +1294,7 @@ public class StripeServiceImpl implements StripeService {
boolean b = sendEmail(subscriptionInfo.getSubscriptionId(), "reminder", null);
if (b) log.info("提前7天向用户 {} 发送续订通知邮件", subscriptionInfo.getAccountId());
}
}
}*/
public void checkSubscriptionExpiration(){
long epochSecond = Instant.now().getEpochSecond();