TASK:向全体用户发送邮件
This commit is contained in:
@@ -3672,30 +3672,63 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
|
||||
/* @Override
|
||||
public void send618PromotionEmailTemp() {
|
||||
QueryWrapper<TrialOrder> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("is_deleted", 0);
|
||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
List<TrialOrder> trialOrders = trialOrderMapper.selectList(queryWrapper);
|
||||
queryWrapper.lambda()
|
||||
.isNotNull(Account::getUserEmail)
|
||||
// .in(Account::getUserEmail, "xupei3360@163.com", "kimwong@code-create.com.hk", "kaicpang.pang@connect.polyu.hk", "chelseayu@code-create.com.hk")
|
||||
.apply("LENGTH(TRIM(user_email)) > 0");
|
||||
|
||||
// List<Account> accountList = accountMapper.selectList(queryWrapper);
|
||||
System.out.println(trialOrders);
|
||||
int total = trialOrders.size();
|
||||
log.info("试用用户总量:{}", total);
|
||||
int current = 1;
|
||||
for (TrialOrder trialOrder : trialOrders) {
|
||||
log.info("邮件发送进度 {}/{}", current, total);
|
||||
try {
|
||||
if (!StringUtil.isNullOrEmpty(trialOrder.getCountry()) && trialOrder.getCountry().equals("China")) {
|
||||
SendEmailUtil.send618PromotionEmailTemp(trialOrder.getEmail(), "CHINESE_SIMPLIFIED");
|
||||
} else {
|
||||
// 英文
|
||||
SendEmailUtil.send618PromotionEmailTemp(trialOrder.getEmail(), "ENGLISH");
|
||||
}
|
||||
}catch (Exception e) {
|
||||
log.info(e.getMessage());
|
||||
List<Account> accounts = baseMapper.selectList(queryWrapper);
|
||||
|
||||
// 按邮箱去重,保留每个邮箱的第一条记录
|
||||
Map<String, Account> emailToAccountMap = new LinkedHashMap<>();
|
||||
for (Account account : accounts) {
|
||||
String email = account.getUserEmail();
|
||||
if (!StringUtil.isNullOrEmpty(email)) {
|
||||
email = email.trim().toLowerCase();
|
||||
// 保留第一次出现的记录
|
||||
emailToAccountMap.putIfAbsent(email, account);
|
||||
}
|
||||
current ++;
|
||||
}
|
||||
|
||||
List<String> uniqueEmails = new ArrayList<>(emailToAccountMap.keySet());
|
||||
int total = uniqueEmails.size();
|
||||
log.info("AiDA用户去重后邮件发送总量:{}", total);
|
||||
|
||||
// 控制发送速率:每发送20封后等待1秒,控制QPS在20以内
|
||||
int batchSize = 20;
|
||||
long sleepMillis = 1000;
|
||||
int successCount = 0;
|
||||
int failCount = 0;
|
||||
|
||||
for (int i = 0; i < uniqueEmails.size(); i++) {
|
||||
String email = uniqueEmails.get(i);
|
||||
log.info("邮件发送进度 {}/{}", i + 1, total);
|
||||
|
||||
try {
|
||||
// 统一发送英文版本
|
||||
// log.info("邮件地址 {}", email);
|
||||
SendEmailUtil.send618PromotionEmailTemp(email, "ENGLISH");
|
||||
successCount++;
|
||||
} catch (Exception e) {
|
||||
failCount++;
|
||||
log.error("邮件发送失败,收件人:{},错误信息:{}", email, e.getMessage());
|
||||
}
|
||||
|
||||
// 控制发送速率,每发送 batchSize 封后等待
|
||||
if ((i + 1) % batchSize == 0 && (i + 1) < uniqueEmails.size()) {
|
||||
try {
|
||||
Thread.sleep(sleepMillis);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
log.warn("邮件发送被中断");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.info("邮件发送完成,成功:{},失败:{}", successCount, failCount);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user