diff --git a/src/main/java/com/ai/da/common/config/MyTaskScheduler.java b/src/main/java/com/ai/da/common/config/MyTaskScheduler.java index 0bbc7e05..0dbc41fd 100644 --- a/src/main/java/com/ai/da/common/config/MyTaskScheduler.java +++ b/src/main/java/com/ai/da/common/config/MyTaskScheduler.java @@ -203,7 +203,8 @@ public class MyTaskScheduler { } } } -// @Scheduled(cron = "0 0 9 * * ?") + + @Scheduled(cron = "0 0 9 * * ?") public void sendTrialOrderExcelToManagements() { // 获取前一天日期 LocalDate yesterday = LocalDate.now().minusDays(1); diff --git a/src/main/java/com/ai/da/common/constant/AffiliateConstants.java b/src/main/java/com/ai/da/common/constant/AffiliateConstants.java new file mode 100644 index 00000000..3d1b926d --- /dev/null +++ b/src/main/java/com/ai/da/common/constant/AffiliateConstants.java @@ -0,0 +1,9 @@ +package com.ai.da.common.constant; + +public class AffiliateConstants { + public static final String STATUS_ACTIVE = "Active"; + public static final String STATUS_INACTIVE = "Inactive"; + public static final String STATUS_DELETE = "Delete"; + public static final Integer DELETED = 1; + public static final Integer NOT_DELETED = 0; +} diff --git a/src/main/java/com/ai/da/common/task/AccountTask.java b/src/main/java/com/ai/da/common/task/AccountTask.java index 8b29cd88..542837ce 100644 --- a/src/main/java/com/ai/da/common/task/AccountTask.java +++ b/src/main/java/com/ai/da/common/task/AccountTask.java @@ -38,7 +38,7 @@ public class AccountTask { } // 每天凌晨0点执行一次 -// @Scheduled(cron = "0 0 0 * * ?") + @Scheduled(cron = "0 0 0 * * ?") public void cancelActivityBenefits() { // 1、查询当前所有参与了活动且过期的用户 List accountList = accountService.getExpiredUserBySystemUser(4); diff --git a/src/main/java/com/ai/da/common/task/GenerateTask.java b/src/main/java/com/ai/da/common/task/GenerateTask.java index 38c12507..88551175 100644 --- a/src/main/java/com/ai/da/common/task/GenerateTask.java +++ b/src/main/java/com/ai/da/common/task/GenerateTask.java @@ -100,9 +100,9 @@ public class GenerateTask { // 万相 -> pose transformation 补偿 当前任务执行完后,5分钟再执行一次(不会出现任务重叠的情况) @Scheduled(fixedDelay = 5 * 60 * 1000) public void wxCompensationMechanism(){ - log.info("=====万相补偿获取结果开始====="); List apiGenerates = apiGenerateService.getPendingTaskByStatus("wx"); if (apiGenerates != null && !apiGenerates.isEmpty()){ + log.info("=====万相补偿获取结果开始====="); for (APIGenerate apiGenerate : apiGenerates){ String taskId = apiGenerate.getTaskId(); PoseTransformation poseTransformation = poseTransformationMapper.selectOne(new QueryWrapper().eq("unique_id", taskId)); diff --git a/src/main/java/com/ai/da/common/task/PaymentTask.java b/src/main/java/com/ai/da/common/task/PaymentTask.java index f1cf4d96..0ead7b54 100644 --- a/src/main/java/com/ai/da/common/task/PaymentTask.java +++ b/src/main/java/com/ai/da/common/task/PaymentTask.java @@ -104,12 +104,12 @@ public class PaymentTask { } // 定时同步(每分钟一次) -// @Scheduled(fixedRate = 60000) + @Scheduled(fixedRate = 60000) public void syncLinkViewCountToDB(){ affiliateService.syncLinkViewCountToDB(); } - // @Scheduled(cron = "0 0 8 28-31 * ?") +// @Scheduled(cron = "0 0 8 28-31 * ?") public void commissionSummaryReminder(){ // 每个月末的最后一天的早上八点执行 LocalDate today = LocalDate.now(); @@ -120,7 +120,7 @@ public class PaymentTask { } } -// @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes + @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes public void calcCouponsCommission(){ log.info("优惠券佣金计算定时器"); affiliateService.calcCouponsCommission(); diff --git a/src/main/java/com/ai/da/common/task/SubscriptionReminderTask.java b/src/main/java/com/ai/da/common/task/SubscriptionReminderTask.java index a29838d6..7266f30d 100644 --- a/src/main/java/com/ai/da/common/task/SubscriptionReminderTask.java +++ b/src/main/java/com/ai/da/common/task/SubscriptionReminderTask.java @@ -7,6 +7,7 @@ import com.ai.da.mapper.primary.entity.Account; import com.ai.da.mapper.primary.entity.SubscriptionInfo; import com.ai.da.service.StripeService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import io.netty.util.internal.StringUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -45,6 +46,11 @@ public class SubscriptionReminderTask { log.warn("未知的订阅类型: {}", subscriptionInfo.getType()); continue; } + String emailType = subscriptionInfo.getStatus().equals("active") ? "reminder_subscriber" : subscriptionInfo.getStatus().equals("canceled") ? "reminder_expire" : null; + if (StringUtil.isNullOrEmpty(emailType)) { + log.warn("未知订阅状态:{}", subscriptionInfo.getStatus()); + continue; + } boolean success = stripeService.sendEmail(subscriptionInfo.getSubscriptionId(), "reminder_subscriber", null); if (success) { @@ -78,7 +84,7 @@ public class SubscriptionReminderTask { QueryWrapper qw = new QueryWrapper<>(); qw.ge("current_period_end", startTimestamp); qw.lt("current_period_end", endTimestamp); - qw.eq("status", "active"); +// qw.eq("status", "active"); qw.eq("subscription_type", subscriptionType); return subscriptionInfoMapper.selectList(qw); diff --git a/src/main/java/com/ai/da/common/utils/SendEmailUtil.java b/src/main/java/com/ai/da/common/utils/SendEmailUtil.java index fd49e25c..c155b463 100644 --- a/src/main/java/com/ai/da/common/utils/SendEmailUtil.java +++ b/src/main/java/com/ai/da/common/utils/SendEmailUtil.java @@ -840,6 +840,18 @@ public class SendEmailUtil { templateUser.setTemplateID(156074L); } break; + case "reminder_expire": + if (language.equals("ENGLISH")) { + user.setSubject("[Code-Create] AiDA account is about to expire"); + templateUser.setTemplateID(156749L); + } else if (language.equals("CHINESE")){ + user.setSubject("[Code-Create] 您的AiDA账号即将到期"); + templateUser.setTemplateID(156750L); + } else { + user.setSubject("[Code-Create] 您的AiDA帳號即將到期"); + templateUser.setTemplateID(156751L); + } + break; case "reminder_trial": if (language.equals("ENGLISH")) { user.setSubject("[Code-Create] AiDA — Free Trial Ending"); diff --git a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java index 219cea74..1374b1c5 100644 --- a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java @@ -313,8 +313,8 @@ public class AccountServiceImpl extends ServiceImpl impl setEduAdminToExpire(account); } else { toVisitor(account); - return; - // throw new BusinessException("user.expired"); +// return; + throw new BusinessException("account.expired", ResultEnum.PROMPT.getCode()); } } } @@ -2499,8 +2499,15 @@ public class AccountServiceImpl extends ServiceImpl impl if (Objects.nonNull(subAccount) && personAccRole.contains(subAccount.getSystemUser())) { log.info("将用户{} 加入组织{}", addSubAccountDTO.getUserEmail(), adminAcc.getOrganizationName()); subAccount.setUserName(addSubAccountDTO.getUserName()); - if (!StringUtil.isNullOrEmpty(addSubAccountDTO.getUserPassword())) + if (!StringUtil.isNullOrEmpty(addSubAccountDTO.getUserPassword())){ subAccount.setUserPassword(addSubAccountDTO.getUserPassword()); + } + + // 判断当前账号的有效期是否与管理员同步 + if (subAccount.getValidEndTime() < adminAcc.getValidEndTime()){ + subAccount.setValidEndTime(adminAcc.getValidEndTime()); + } + subAccount.setSystemUser(subUserRole); subAccount.setOrganizationName(adminAcc.getOrganizationName()); subAccount.setParentId(adminAcc.getId()); diff --git a/src/main/java/com/ai/da/service/impl/AffiliateServiceImpl.java b/src/main/java/com/ai/da/service/impl/AffiliateServiceImpl.java index b189e11e..8b7879e9 100644 --- a/src/main/java/com/ai/da/service/impl/AffiliateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/AffiliateServiceImpl.java @@ -1,6 +1,7 @@ package com.ai.da.service.impl; import com.ai.da.common.config.exception.BusinessException; +import com.ai.da.common.constant.AffiliateConstants; import com.ai.da.common.constant.CommonConstant; import com.ai.da.common.context.UserContext; import com.ai.da.common.response.PageBaseResponse; @@ -202,29 +203,70 @@ public class AffiliateServiceImpl extends ServiceImpl 激活 | Inactive -> 关闭 | Delete -> 删除 - if (!StringUtil.isNullOrEmpty(operationType)) { - if (operationType.equals("Delete")) { - baseMapper.deleteById(id); - return; - } else if (operationType.equals("Active") || operationType.equals("Inactive")) { - affiliate.setStatus(operationType); - } else { - throw new BusinessException("unknown.operationType"); - } + Affiliate affiliate = baseMapper.selectById(id); + if (affiliate == null) { + log.warn("未知affiliate id: {}", id); // 使用warn级别更合适 + throw new BusinessException("unknown.affiliate"); + } + + // 构建更新条件 + UpdateWrapper updateWrapper = buildUpdateWrapper(affiliate, commission, operationType); + baseMapper.update(null, updateWrapper); + } + + private UpdateWrapper buildUpdateWrapper(Affiliate affiliate, Float commission, String operationType) { + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.lambda() + .eq(Affiliate::getId, affiliate.getId()) + .set(Affiliate::getUpdateTime, LocalDateTime.now()); + + // 处理佣金更新 + handleCommissionUpdate(affiliate, commission, updateWrapper); + + // 处理操作类型 + if (!StringUtil.isNullOrEmpty(operationType)) { + handleOperationType(affiliate, operationType, updateWrapper); + } + + return updateWrapper; + } + + private void handleCommissionUpdate(Affiliate affiliate, Float commission, + UpdateWrapper updateWrapper) { + if (commission != null && !Objects.equals(affiliate.getCommissionPercent(), commission)) { + updateWrapper.lambda().set(Affiliate::getCommissionPercent, commission); + } + } + + private void handleOperationType(Affiliate affiliate, String operationType, + UpdateWrapper updateWrapper) { + switch (operationType) { + case AffiliateConstants.STATUS_DELETE: + updateWrapper.lambda() + .set(Affiliate::getStatus, AffiliateConstants.STATUS_DELETE) + .set(Affiliate::getIsDeleted, AffiliateConstants.DELETED); + break; + + case AffiliateConstants.STATUS_ACTIVE: + case AffiliateConstants.STATUS_INACTIVE: + updateWrapper.lambda().set(Affiliate::getStatus, operationType); + // 激活时生成链接 + if (AffiliateConstants.STATUS_ACTIVE.equals(operationType) && + StringUtil.isNullOrEmpty(affiliate.getLink())) { + updateWrapper.lambda().set(Affiliate::getLink, + CommonConstant.AFFILIATE_LINK + affiliate.getId()); + } + break; + + default: + throw new BusinessException("unknown.operationType"); } - affiliate.setUpdateTime(LocalDateTime.now()); - baseMapper.updateById(affiliate); } // 定时计算佣金 diff --git a/src/main/java/com/ai/da/service/impl/DesignItemServiceImpl.java b/src/main/java/com/ai/da/service/impl/DesignItemServiceImpl.java index 1a4a1413..e5c1f520 100644 --- a/src/main/java/com/ai/da/service/impl/DesignItemServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/DesignItemServiceImpl.java @@ -427,13 +427,7 @@ public class DesignItemServiceImpl extends ServiceImpl AND f.id = #{affiliateId} + AND f.is_deleted = 0 @@ -83,6 +84,7 @@ AND f.id = #{affiliateId} + AND f.is_deleted = 0