TASK:向全体用户发送邮件
This commit is contained in:
@@ -3672,30 +3672,63 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
|
|
||||||
/* @Override
|
/* @Override
|
||||||
public void send618PromotionEmailTemp() {
|
public void send618PromotionEmailTemp() {
|
||||||
QueryWrapper<TrialOrder> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("is_deleted", 0);
|
|
||||||
|
|
||||||
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);
|
List<Account> accounts = baseMapper.selectList(queryWrapper);
|
||||||
System.out.println(trialOrders);
|
|
||||||
int total = trialOrders.size();
|
// 按邮箱去重,保留每个邮箱的第一条记录
|
||||||
log.info("试用用户总量:{}", total);
|
Map<String, Account> emailToAccountMap = new LinkedHashMap<>();
|
||||||
int current = 1;
|
for (Account account : accounts) {
|
||||||
for (TrialOrder trialOrder : trialOrders) {
|
String email = account.getUserEmail();
|
||||||
log.info("邮件发送进度 {}/{}", current, total);
|
if (!StringUtil.isNullOrEmpty(email)) {
|
||||||
try {
|
email = email.trim().toLowerCase();
|
||||||
if (!StringUtil.isNullOrEmpty(trialOrder.getCountry()) && trialOrder.getCountry().equals("China")) {
|
// 保留第一次出现的记录
|
||||||
SendEmailUtil.send618PromotionEmailTemp(trialOrder.getEmail(), "CHINESE_SIMPLIFIED");
|
emailToAccountMap.putIfAbsent(email, account);
|
||||||
} else {
|
|
||||||
// 英文
|
|
||||||
SendEmailUtil.send618PromotionEmailTemp(trialOrder.getEmail(), "ENGLISH");
|
|
||||||
}
|
|
||||||
}catch (Exception e) {
|
|
||||||
log.info(e.getMessage());
|
|
||||||
}
|
}
|
||||||
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
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user