|
@@ -0,0 +1,42 @@
|
|
|
+package com.fjhx.mail.listener;
|
|
|
+
|
|
|
+import com.fjhx.mail.util.MailHttpUtil;
|
|
|
+import com.ruoyi.framework.config.ThreadPoolConfig;
|
|
|
+import com.ruoyi.framework.event.LoginEvent;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.context.event.EventListener;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class LoginEventListeners {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @Qualifier(ThreadPoolConfig.threadPoolTaskExecutor)
|
|
|
+ private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
+
|
|
|
+ @Async
|
|
|
+ @EventListener
|
|
|
+ public void loginEvent(LoginEvent loginEvent) {
|
|
|
+ threadPoolTaskExecutor.execute(() -> {
|
|
|
+ Long userId = (Long) loginEvent.getSource();
|
|
|
+
|
|
|
+ int num = 0;
|
|
|
+ while (num < 3) {
|
|
|
+ try {
|
|
|
+ MailHttpUtil.userLogin(userId);
|
|
|
+ num = 3;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("同步邮件服务用户登录失败", e);
|
|
|
+ num++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+}
|