微调
This commit is contained in:
@@ -2,7 +2,6 @@ package com.njcn.gather.system.log.aop;
|
|||||||
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
|
||||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.db.mybatisplus.constant.UserConstant;
|
import com.njcn.db.mybatisplus.constant.UserConstant;
|
||||||
@@ -13,7 +12,6 @@ import com.njcn.gather.system.log.pojo.po.SysLogAudit;
|
|||||||
import com.njcn.gather.system.log.service.ISysLogAuditService;
|
import com.njcn.gather.system.log.service.ISysLogAuditService;
|
||||||
import com.njcn.gather.user.user.pojo.po.SysUser;
|
import com.njcn.gather.user.user.pojo.po.SysUser;
|
||||||
import com.njcn.gather.user.user.service.ISysUserService;
|
import com.njcn.gather.user.user.service.ISysUserService;
|
||||||
import com.njcn.web.utils.HttpServletUtil;
|
|
||||||
import com.njcn.web.utils.RequestUtil;
|
import com.njcn.web.utils.RequestUtil;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -26,11 +24,14 @@ import org.springframework.context.ApplicationListener;
|
|||||||
import org.springframework.context.event.ContextRefreshedEvent;
|
import org.springframework.context.event.ContextRefreshedEvent;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.concurrent.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
import java.util.concurrent.LinkedBlockingDeque;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author caozehui
|
* @author caozehui
|
||||||
@@ -104,25 +105,25 @@ public class LogAdvice implements ApplicationListener<ContextRefreshedEvent> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
|
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
|
||||||
ExecutorService pool = new ThreadPoolExecutor(1, 1,
|
new Thread(new Runnable() {
|
||||||
0L, TimeUnit.SECONDS,
|
|
||||||
new LinkedBlockingQueue<>(),
|
|
||||||
new ThreadFactoryBuilder().setNameFormat("Save-Logs-%d").setDaemon(true).build());
|
|
||||||
pool.submit(new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
SysLogAudit log = logQueue.poll(5, TimeUnit.MILLISECONDS);
|
List<SysLogAudit> logList = new ArrayList<>();
|
||||||
if (log != null) {
|
SysLogAudit log;
|
||||||
|
while ((log = logQueue.poll(5, TimeUnit.MILLISECONDS)) != null) {
|
||||||
log.setSort(sysLogAuditService.getMaxSort() + 1);
|
log.setSort(sysLogAuditService.getMaxSort() + 1);
|
||||||
sysLogAuditService.save(log);
|
logList.add(log);
|
||||||
|
}
|
||||||
|
if (!logList.isEmpty()) {
|
||||||
|
sysLogAuditService.saveBatch(logList); // 假设有一个批量保存的方法
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new BusinessException(LogResponseEnum.LOG_RECORD_FAILED);
|
throw new BusinessException(LogResponseEnum.LOG_RECORD_FAILED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}).start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user