From fee67ca8a0760315047a52fc4101a8f4f80b7a7f Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期一, 11 十一月 2024 15:02:54 +0800 Subject: [PATCH] 1 --- src/main/java/com/moon/server/aspect/LogAspect.java | 35 ++++++++++++++--------------------- 1 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/moon/server/aspect/LogAspect.java b/src/main/java/com/moon/server/aspect/LogAspect.java index 6eff335..5d5393e 100644 --- a/src/main/java/com/moon/server/aspect/LogAspect.java +++ b/src/main/java/com/moon/server/aspect/LogAspect.java @@ -1,8 +1,10 @@ package com.moon.server.aspect; import com.moon.server.annotation.SysLog; +import com.moon.server.entity.all.StaticData; import com.moon.server.entity.sys.OperateEntity; import com.moon.server.entity.sys.UserEntity; +import com.moon.server.helper.AsyncHelper; import com.moon.server.helper.WebHelper; import com.moon.server.service.sys.OperateService; import com.moon.server.service.sys.TokenService; @@ -19,13 +21,11 @@ import javax.servlet.http.HttpServletRequest; import java.lang.reflect.Method; +import java.util.TimerTask; -/** - * 鏃ュ織鍒囬潰绫� - * @author WWW - */ @Aspect @Component +@SuppressWarnings("ALL") public class LogAspect { @Autowired private TokenService tokenService; @@ -47,8 +47,6 @@ private final static String COUNT = "count"; - private final static String SPLIT = "\\\\"; - private static final Log log = LogFactory.getLog(LogAspect.class); @Pointcut("@annotation(com.moon.server.annotation.SysLog)") @@ -57,27 +55,21 @@ } /** - * 鐜粫閫氱煡 @Around锛屼篃鍙互浣跨敤 @Before (鍓嶇疆閫氱煡) 鎴� @After (鍚庣疆閫氱煡) + * @Around,@Before,@After */ @Around("logPointCut()") public Object around(ProceedingJoinPoint point) throws Throwable { long beginTime = System.currentTimeMillis(); - // 鎵ц鏂规硶 Object result = point.proceed(); - // 鎵ц鏃堕暱(姣) long time = System.currentTimeMillis() - beginTime; - // 淇濆瓨鏃ュ織 saveLog(point, time); return result; } - /** - * 淇濆瓨鏃ュ織 - */ private void saveLog(ProceedingJoinPoint joinPoint, long time) { try { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); @@ -92,19 +84,16 @@ oe.setUrl(url); oe.setExec(time); - // 璁剧疆妯″潡 Api api = clazz.getAnnotation(Api.class); if (api != null) { - String[] strs = api.tags()[0].split(SPLIT); + String[] strs = api.tags()[0].split(StaticData.BACKSLASH); oe.setModular1(strs[0]); oe.setModular2(strs[1]); } - // 璁剧疆绫诲悕\鏂规硶鍚嶃�佺被鍒� oe.setClazz(clazz.getName() + "." + method.getName()); oe.setType(getType(method.getName())); - // 璁剧疆澶囨敞 SysLog sysLog = method.getAnnotation(SysLog.class); if (sysLog != null) { oe.setBak(sysLog.value()); @@ -115,15 +104,19 @@ oe.setUserid(ue.getId()); } - operateService.insertOperate(oe); + // operateService.insertOperate(oe) + AsyncHelper helper = new AsyncHelper(); + helper.execute(new TimerTask() { + @Override + public void run() { + operateService.insertOperate(oe); + } + }); } catch (Exception ex) { log.error(ex.getMessage(), ex); } } - /** - * 鑾峰彇鎿嶄綔绫诲瀷 - */ private static int getType(String methodName) { if (methodName.contains(SELECT)) { return 1; -- Gitblit v1.9.3