mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-23 11:09:29 +08:00
开启异步任务
This commit is contained in:
@@ -3,7 +3,9 @@ package xyz.playedu.api;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
@EnableAsync
|
||||
@SpringBootApplication
|
||||
public class PlayeduApiApplication {
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
import xyz.playedu.api.constant.BackendLogConstant;
|
||||
import xyz.playedu.api.domain.AdminLog;
|
||||
@@ -13,6 +14,8 @@ import xyz.playedu.api.service.AdminLogService;
|
||||
import xyz.playedu.api.service.AdminUserService;
|
||||
import xyz.playedu.api.util.IpUtil;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AdminUserLoginListener {
|
||||
@@ -38,15 +41,17 @@ public class AdminUserLoginListener {
|
||||
|
||||
@Order(10)
|
||||
@EventListener
|
||||
@Async
|
||||
public void log(AdminUserLoginEvent event) {
|
||||
String area = IpUtil.getRealAddressByIP(event.getIp());
|
||||
|
||||
AdminLog adminLog = new AdminLog();
|
||||
adminLog.setAdminId(event.getAdminId());
|
||||
adminLog.setModule(BackendLogConstant.MODULE_LOGIN);
|
||||
adminLog.setOpt(BackendLogConstant.OPT_LOGIN);
|
||||
adminLog.setIp(event.getIp());
|
||||
adminLog.setIpArea(area);
|
||||
adminLog.setCreatedAt(event.getLoginAt());
|
||||
adminLog.setCreatedAt(new Date());
|
||||
|
||||
adminLogService.save(adminLog);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user