保存日志改为异步

master
zhangw 2018-05-12 22:29:14 +08:00
parent 36b1a4956e
commit 846aeba6b2
2 changed files with 18 additions and 8 deletions

View File

@ -1,5 +1,6 @@
package com.boot.security.server.advice;
import com.boot.security.server.utils.UserUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
@ -16,7 +17,7 @@ import io.swagger.annotations.ApiOperation;
/**
*
*
*
* @author
*
* 2017819
@ -31,6 +32,7 @@ public class LogAdvice {
@Around(value = "@annotation(com.boot.security.server.annotation.LogAnnotation)")
public Object logSave(ProceedingJoinPoint joinPoint) throws Throwable {
SysLogs sysLogs = new SysLogs();
sysLogs.setUser(UserUtil.getLoginUser()); // 设置当前登录用户
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
String module = null;
@ -50,17 +52,18 @@ public class LogAdvice {
try {
Object object = joinPoint.proceed();
sysLogs.setFlag(true);
logService.save(sysLogs);
return object;
} catch (Exception e) {
sysLogs.setFlag(false);
sysLogs.setRemark(e.getMessage());
logService.save(sysLogs);
throw e;
}
} finally {
if (sysLogs.getUser() != null) {
logService.save(sysLogs);
}
}
}
}

View File

@ -24,14 +24,21 @@ public class SysLogServiceImpl implements SysLogService {
@Autowired
private SysLogsDao sysLogsDao;
/**
* 2018.05.12,
*
* @param sysLogs
* @see com.boot.security.server.advice.LogAdvice
*/
@Async
@Override
public void save(SysLogs sysLogs) {
SysUser user = UserUtil.getLoginUser();
if (user == null || user.getId() == null) {
// SysUser user = UserUtil.getLoginUser();
if (sysLogs == null || sysLogs.getUser() == null || sysLogs.getUser().getId() == null) {
return;
}
sysLogs.setUser(user);
// sysLogs.setUser(user);
sysLogsDao.save(sysLogs);
}