|
@@ -59,9 +59,6 @@ public class AccountServiceImpl implements IAccountService {
|
|
|
|
|
|
String email = bindingVo.getEmail();
|
|
String email = bindingVo.getEmail();
|
|
|
|
|
|
- // ProgressVo progressVo = RedisCache.get(RedisConstant.PROGRESS_KEY + email);
|
|
|
|
- // Assert.isNull(progressVo, "邮箱正在同步中,请勿重复操作");
|
|
|
|
-
|
|
|
|
EmailInfo emailInfo = emailInfoService.getOne(Wrappers.<EmailInfo>lambdaQuery().eq(EmailInfo::getEmail, email));
|
|
EmailInfo emailInfo = emailInfoService.getOne(Wrappers.<EmailInfo>lambdaQuery().eq(EmailInfo::getEmail, email));
|
|
// 如果存在,直接返回邮箱信息
|
|
// 如果存在,直接返回邮箱信息
|
|
if (emailInfo != null) {
|
|
if (emailInfo != null) {
|
|
@@ -77,9 +74,9 @@ public class AccountServiceImpl implements IAccountService {
|
|
// 添加邮箱文件夹
|
|
// 添加邮箱文件夹
|
|
List<EmailMailbox> emailMailboxList = this.saveEmailMailbox(mailboxList, emailInfo.getId(), email);
|
|
List<EmailMailbox> emailMailboxList = this.saveEmailMailbox(mailboxList, emailInfo.getId(), email);
|
|
// redis添加同步进度
|
|
// redis添加同步进度
|
|
- this.synchronizationProgressInitialization(email, mailboxList);
|
|
|
|
|
|
+ this.synchronizationProgressInitialization(email, bindingVo.getPages(), mailboxList);
|
|
// 异步遍历文件夹下的所有邮件
|
|
// 异步遍历文件夹下的所有邮件
|
|
- this.asyncReadEmail(email, emailMailboxList);
|
|
|
|
|
|
+ this.asyncReadEmail(email, bindingVo.getPages(), emailMailboxList);
|
|
|
|
|
|
return emailInfo;
|
|
return emailInfo;
|
|
}
|
|
}
|
|
@@ -141,7 +138,7 @@ public class AccountServiceImpl implements IAccountService {
|
|
emailMailbox.setIsShow(true);
|
|
emailMailbox.setIsShow(true);
|
|
emailMailbox.setInitialize(false);
|
|
emailMailbox.setInitialize(false);
|
|
return emailMailbox;
|
|
return emailMailbox;
|
|
- }).collect(Collectors.toList());
|
|
|
|
|
|
+ }).distinct().collect(Collectors.toList());
|
|
|
|
|
|
emailMailboxService.saveBatch(mailboxList);
|
|
emailMailboxService.saveBatch(mailboxList);
|
|
|
|
|
|
@@ -151,7 +148,7 @@ public class AccountServiceImpl implements IAccountService {
|
|
/**
|
|
/**
|
|
* 同步邮件进度初始化
|
|
* 同步邮件进度初始化
|
|
*/
|
|
*/
|
|
- private void synchronizationProgressInitialization(String email, List<EmailMailboxVo.MailboxesDTO> mailboxList) {
|
|
|
|
|
|
+ private void synchronizationProgressInitialization(String email, int pages, List<EmailMailboxVo.MailboxesDTO> mailboxList) {
|
|
|
|
|
|
ProgressVo progressVo = new ProgressVo();
|
|
ProgressVo progressVo = new ProgressVo();
|
|
|
|
|
|
@@ -161,6 +158,7 @@ public class AccountServiceImpl implements IAccountService {
|
|
int totalMessageCount = 0;
|
|
int totalMessageCount = 0;
|
|
|
|
|
|
for (ProgressVo.Details detail : detailsList) {
|
|
for (ProgressVo.Details detail : detailsList) {
|
|
|
|
+ detail.setMessages(detail.getMessages() > pages * 10 ? pages * 10 : detail.getMessages());
|
|
detail.setCompleteMessageCount(0);
|
|
detail.setCompleteMessageCount(0);
|
|
detail.setPercentage(0);
|
|
detail.setPercentage(0);
|
|
totalMessageCount += detail.getMessages();
|
|
totalMessageCount += detail.getMessages();
|
|
@@ -178,7 +176,7 @@ public class AccountServiceImpl implements IAccountService {
|
|
/**
|
|
/**
|
|
* 异步读取文件
|
|
* 异步读取文件
|
|
*/
|
|
*/
|
|
- private void asyncReadEmail(String email, List<EmailMailbox> emailMailboxList) {
|
|
|
|
|
|
+ private void asyncReadEmail(String email, int pages, List<EmailMailbox> emailMailboxList) {
|
|
executor.execute(() -> {
|
|
executor.execute(() -> {
|
|
ThreadUtil.sleep(3000);
|
|
ThreadUtil.sleep(3000);
|
|
|
|
|
|
@@ -188,8 +186,7 @@ public class AccountServiceImpl implements IAccountService {
|
|
// 遍历每个邮箱
|
|
// 遍历每个邮箱
|
|
for (EmailMailbox emailMailbox : emailMailboxList) {
|
|
for (EmailMailbox emailMailbox : emailMailboxList) {
|
|
int page = 0;
|
|
int page = 0;
|
|
- int pages;
|
|
|
|
- do {
|
|
|
|
|
|
+ while (page < pages) {
|
|
MessageVo result = EmailEngineUtil.getMessageList(email, emailMailbox.getPath(), page);
|
|
MessageVo result = EmailEngineUtil.getMessageList(email, emailMailbox.getPath(), page);
|
|
List<MessageVo.MessagesDTO> messagesDTOList = result.getMessages();
|
|
List<MessageVo.MessagesDTO> messagesDTOList = result.getMessages();
|
|
if (messagesDTOList.size() > 0) {
|
|
if (messagesDTOList.size() > 0) {
|
|
@@ -201,14 +198,12 @@ public class AccountServiceImpl implements IAccountService {
|
|
lastMessageIdList.add(emailMessage.getMessageId());
|
|
lastMessageIdList.add(emailMessage.getMessageId());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- pages = result.getPages();
|
|
|
|
page++;
|
|
page++;
|
|
- } while (page < pages);
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 批量保存邮件信息
|
|
* 批量保存邮件信息
|
|
*/
|
|
*/
|