开启异步任务

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

View File

@ -23,6 +23,17 @@ spring:
max-active: 100 # 连接池最大连接数(使用负数表示没有限制,默认8)
max-idle: 20 # 连接池中的最大空闲连接(默认8)
min-idle: 5 # 连接池中的最小空闲连接(默认0)
# 线程池配置
task:
execution:
pool:
max-size: 16 #最大线程数量
core-size: 8 #初始化线程数量
queue-capacity: 1000 #队列最大长度
keep-alive: 60s #线程终止前允许保存的最大时间
shutdown:
await-termination: true
thread-name-prefix: "playedu-default-thread"
mybatis:
mapper-locations: classpath:mapper/*.xml