package com.lf.server.aspect; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.reflect.MethodSignature; import org.springframework.stereotype.Component; import java.lang.reflect.Method; /** * 日志切面类 * @author WWW */ @Aspect @Component public class LogAspect { @Pointcut("") public void logPointCut() { } @Around("logPointCut()") public Object around(ProceedingJoinPoint point) throws Throwable { long beginTime = System.currentTimeMillis(); // 执行方法 Object result = point.proceed(); // 执行时长(毫秒) long time = System.currentTimeMillis() - beginTime; // System.out.println("time:"+time) // 保存日志 saveLogAction(point, time); return result; } private void saveLogAction(ProceedingJoinPoint joinPoint, long time) { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); /*LogAction logAction = new LogAction(); com.landtool.lanbase.common.annotation.LogAction log = method.getAnnotation(com.landtool.lanbase.common.annotation.LogAction.class); if(log != null){ // 注解上的描述 String[] list = log.value().split(","); logAction.setLargemodel(list[0]); //大模块 logAction.setSmallmodel(list[1]);//小模块 logAction.setRemark(list[2]); //备注 logAction.setActiontype(list[3]);//操作类型 //logAction.setRemark(log.value()); //logAction.setActiontype(log.value()); } //获取request HttpServletRequest request = HttpContextUtils.getHttpServletRequest(); String url=request.getServletPath(); logAction.setRequesturl(url); //设置IP地址 logAction.setRequestip(IPUtils.getIpAddr(request)); //用户名 Long userid = ((OrgUser) SecurityUtils.getSubject().getPrincipal()).getUserid(); logAction.setUserid(userid); logAction.setAppid(loginConfig.getAppId()); //logAction.setLargemodel(loginConfig.getAppFullName()); //保存系统日志 logActionService.save(logAction);*/ } }