From d6201c37c34681b11d6eeb5d3fa2008991d9f370 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期五, 12 四月 2024 15:26:21 +0800 Subject: [PATCH] # --- zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/common/aspect/OperationLogAspect.java | 66 ++++++++++++++++++-------------- 1 files changed, 37 insertions(+), 29 deletions(-) diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/common/aspect/OperationLogAspect.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/common/aspect/OperationLogAspect.java index 8af863f..2097f99 100644 --- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/common/aspect/OperationLogAspect.java +++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/common/aspect/OperationLogAspect.java @@ -4,10 +4,10 @@ import com.zy.asrs.common.utils.IpTools; import com.zy.asrs.framework.common.Cools; import com.zy.asrs.wcs.common.annotation.OperationLog; -import com.zy.asrs.wcs.sys.entity.OperationRecord; -import com.zy.asrs.wcs.sys.entity.User; -import com.zy.asrs.wcs.sys.service.OperationRecordService; -import com.zy.asrs.wcs.utils.Utils; +import com.zy.asrs.wcs.system.entity.OperationRecord; +import com.zy.asrs.wcs.system.entity.User; +import com.zy.asrs.wcs.system.service.OperationRecordService; +import com.zy.asrs.wcs.utils.CommonUtils; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.*; import org.aspectj.lang.reflect.MethodSignature; @@ -23,6 +23,7 @@ import javax.servlet.http.HttpServletResponse; import java.lang.reflect.Method; import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -66,8 +67,23 @@ * 淇濆瓨鎿嶄綔璁板綍 */ private void saveLog(JoinPoint joinPoint, Object result, Exception e) { + // 璁板綍妯″潡鍚嶃�佹搷浣滃姛鑳姐�佽姹傛柟娉曘�佽姹傚弬鏁般�佽繑鍥炵粨鏋� + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + Method method = signature.getMethod(); + if (null == method) { + return; + } + OperationLog ol = method.getAnnotation(OperationLog.class); + if (null == ol) { + return; + } + String desc = getDescription(method, ol); + if (Cools.isEmpty(desc)) { + return; + } OperationRecord record = new OperationRecord(); Long endTime = startTime.get(); + record.setCreateTime(new Date()); // 璁板綍鎿嶄綔鑰楁椂 if (endTime != null) { record.setSpendTime((int) (System.currentTimeMillis() - endTime)); @@ -77,7 +93,7 @@ User user = getLoginUser(); if (user != null) { record.setUserId(user.getId()); - record.setHostId(user.getHostId()); +// record.setHostId(user.getHostId()); } // 璁板綍璇锋眰鍦板潃銆佽姹傛柟寮忋�乮p ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); @@ -89,33 +105,25 @@ // 璁板綍寮傚父淇℃伅 if (e != null) { record.setResult(0); - record.setErr(Utils.sub(e.toString(), MAX_LENGTH)); + record.setErr(CommonUtils.sub(e.toString(), MAX_LENGTH)); } else { record.setResult(1); } - // 璁板綍妯″潡鍚嶃�佹搷浣滃姛鑳姐�佽姹傛柟娉曘�佽姹傚弬鏁般�佽繑鍥炵粨鏋� - MethodSignature signature = (MethodSignature) joinPoint.getSignature(); - Method method = signature.getMethod(); - if (method != null) { - OperationLog ol = method.getAnnotation(OperationLog.class); - if (ol != null) { - // 璁板綍鎿嶄綔鍔熻兘 - record.setNamespace(getDescription(method, ol)); - // 璁板綍澶囨敞 - if (!Cools.isEmpty(ol.comments())) { - record.setMemo(ol.comments()); - } - // 璁板綍璇锋眰鍙傛暟 - if (ol.param() && request != null) { - record.setRequest(Utils.sub(getParams(joinPoint, request), MAX_LENGTH)); - } - // 璁板綍璇锋眰缁撴灉 - if (ol.result() && result != null) { - record.setResponse(Utils.sub(JSON.toJSONString(result), MAX_LENGTH)); - } - } + // 璁板綍鎿嶄綔鍔熻兘 + record.setNamespace(desc); + // 璁板綍澶囨敞 + if (!Cools.isEmpty(ol.comments())) { + record.setMemo(ol.comments()); } - operationRecordService.save(record); + // 璁板綍璇锋眰鍙傛暟 + if (ol.param() && request != null) { + record.setRequest(CommonUtils.sub(getParams(joinPoint, request), MAX_LENGTH)); + } + // 璁板綍璇锋眰缁撴灉 + if (ol.result() && result != null) { + record.setResponse(CommonUtils.sub(JSON.toJSONString(result), MAX_LENGTH)); + } + operationRecordService.saveAsync(record); } /** @@ -146,7 +154,7 @@ Map<String, String[]> map = Collections.unmodifiableMap(request.getParameterMap()); for (Map.Entry<String, String[]> entry : map.entrySet()) { - paramsMap.put(entry.getKey(), Utils.join(entry.getValue(), ",")); + paramsMap.put(entry.getKey(), CommonUtils.join(entry.getValue(), ",")); } if (paramsMap.keySet().size() > 0) { -- Gitblit v1.9.1