开启异步任务

This commit is contained in:
none
2023-02-17 16:00:54 +08:00
parent b44ced67a0
commit dbbfdb00ce
3 changed files with 19 additions and 1 deletions

View File

@@ -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 {

View File

@@ -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);
}