首页>代码>基于Springboot+Mybatis+ SpringMvc+springsecrity+Redis完整网站后台管理系统>/boot-security-master/src/main/java/com/boot/security/server/advice/LogAdvice.java
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;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import com.boot.security.server.annotation.LogAnnotation;
import com.boot.security.server.model.SysLogs;
import com.boot.security.server.service.SysLogService;
import io.swagger.annotations.ApiOperation;
/**
* 统一日志处理
*
* @author wpw
*
* 2017年8月19日
*/
@Aspect
@Component
public class LogAdvice {
@Autowired
private SysLogService logService;
@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;
LogAnnotation logAnnotation = methodSignature.getMethod().getDeclaredAnnotation(LogAnnotation.class);
module = logAnnotation.module();
if (StringUtils.isEmpty(module)) {
ApiOperation apiOperation = methodSignature.getMethod().getDeclaredAnnotation(ApiOperation.class);
if (apiOperation != null) {
module = apiOperation.value();
}
}
if (StringUtils.isEmpty(module)) {
throw new RuntimeException("没有指定日志module");
}
sysLogs.setModule(module);
try {
Object object = joinPoint.proceed();
sysLogs.setFlag(true);
return object;
} catch (Exception e) {
sysLogs.setFlag(false);
sysLogs.setRemark(e.getMessage());
throw e;
} finally {
if (sysLogs.getUser() != null) {
logService.save(sysLogs);
}
}
}
}
最近下载更多
15719908287 LV10
2024年11月1日
CB6548 LV1
2024年8月23日
llllllK LV5
2024年5月13日
微信网友_6765346083115008 LV1
2023年12月5日
wuying8208 LV15
2023年11月28日
WHY-small LV15
2023年8月29日
yqyqyqyqy LV4
2023年7月23日
debris LV1
2023年5月18日
hihhhh LV6
2023年4月2日
adongliu666 LV4
2023年3月28日

最近浏览