From e36b1fb663ee578f30375f488050891afd6c503d Mon Sep 17 00:00:00 2001 From: muzhantong Date: Wed, 19 Oct 2022 10:59:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4guava=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bizlog-sdk/pom.xml | 10 +++++----- .../com/mzt/logapi/context/LogRecordContext.java | 6 ++---- .../service/impl/DefaultLogRecordServiceImpl.java | 6 +++--- .../starter/annotation/EnableLogRecord.java | 2 ++ .../diff/DefaultDiffItemsToLogContentService.java | 7 +++---- .../starter/support/aop/LogRecordInterceptor.java | 15 ++++++--------- .../support/parse/LogRecordValueParser.java | 3 +-- readme.md | 1 + 8 files changed, 23 insertions(+), 27 deletions(-) diff --git a/bizlog-sdk/pom.xml b/bizlog-sdk/pom.xml index 96473ff..177a56c 100644 --- a/bizlog-sdk/pom.xml +++ b/bizlog-sdk/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 bizlog-sdk - 3.0.2-SNAPSHOT + 3.0.2 io.github.mouzt mzt-biz-log @@ -31,13 +31,13 @@ lombok 1.18.12 + - com.google.guava - guava - 30.0-jre + com.google.code.findbugs + annotations + 3.0.1 - org.hibernate.validator hibernate-validator diff --git a/bizlog-sdk/src/main/java/com/mzt/logapi/context/LogRecordContext.java b/bizlog-sdk/src/main/java/com/mzt/logapi/context/LogRecordContext.java index de1165b..418c9d1 100644 --- a/bizlog-sdk/src/main/java/com/mzt/logapi/context/LogRecordContext.java +++ b/bizlog-sdk/src/main/java/com/mzt/logapi/context/LogRecordContext.java @@ -1,7 +1,5 @@ package com.mzt.logapi.context; -import com.google.common.collect.Maps; - import java.util.ArrayDeque; import java.util.Deque; import java.util.HashMap; @@ -28,7 +26,7 @@ public static void putVariable(String name, Object value) { } Deque> mapStack = VARIABLE_MAP_STACK.get(); if (mapStack.isEmpty()) { - VARIABLE_MAP_STACK.get().push(Maps.newHashMap()); + VARIABLE_MAP_STACK.get().push(new HashMap<>()); } VARIABLE_MAP_STACK.get().element().put(name, value); } @@ -73,7 +71,7 @@ public static void putEmptySpan() { Deque> stack = new ArrayDeque<>(); VARIABLE_MAP_STACK.set(stack); } - VARIABLE_MAP_STACK.get().push(Maps.newHashMap()); + VARIABLE_MAP_STACK.get().push(new HashMap<>()); if (GLOBAL_VARIABLE_MAP.get() == null) { GLOBAL_VARIABLE_MAP.set(new HashMap<>()); diff --git a/bizlog-sdk/src/main/java/com/mzt/logapi/service/impl/DefaultLogRecordServiceImpl.java b/bizlog-sdk/src/main/java/com/mzt/logapi/service/impl/DefaultLogRecordServiceImpl.java index 11c57b3..3282c60 100644 --- a/bizlog-sdk/src/main/java/com/mzt/logapi/service/impl/DefaultLogRecordServiceImpl.java +++ b/bizlog-sdk/src/main/java/com/mzt/logapi/service/impl/DefaultLogRecordServiceImpl.java @@ -1,10 +1,10 @@ package com.mzt.logapi.service.impl; -import com.google.common.collect.Lists; import com.mzt.logapi.beans.LogRecord; import com.mzt.logapi.service.ILogRecordService; import lombok.extern.slf4j.Slf4j; +import java.util.ArrayList; import java.util.List; /** @@ -27,12 +27,12 @@ public void record(LogRecord logRecord) { @Override public List queryLog(String bizNo, String type) { - return Lists.newArrayList(); + return new ArrayList<>(); } @Override public List queryLogByBizNo(String bizNo, String type, String subType) { - return Lists.newArrayList(); + return new ArrayList<>(); } diff --git a/bizlog-sdk/src/main/java/com/mzt/logapi/starter/annotation/EnableLogRecord.java b/bizlog-sdk/src/main/java/com/mzt/logapi/starter/annotation/EnableLogRecord.java index b4d7b10..26c1e1a 100644 --- a/bizlog-sdk/src/main/java/com/mzt/logapi/starter/annotation/EnableLogRecord.java +++ b/bizlog-sdk/src/main/java/com/mzt/logapi/starter/annotation/EnableLogRecord.java @@ -49,6 +49,8 @@ * Indicate the ordering of the execution of the transaction advisor * when multiple advices are applied at a specific joinpoint. *

The default is {@link Ordered#LOWEST_PRECEDENCE}. + * + * @return 事务 advisor 的优先级 */ int order() default Ordered.LOWEST_PRECEDENCE; } diff --git a/bizlog-sdk/src/main/java/com/mzt/logapi/starter/diff/DefaultDiffItemsToLogContentService.java b/bizlog-sdk/src/main/java/com/mzt/logapi/starter/diff/DefaultDiffItemsToLogContentService.java index e74b978..809294e 100644 --- a/bizlog-sdk/src/main/java/com/mzt/logapi/starter/diff/DefaultDiffItemsToLogContentService.java +++ b/bizlog-sdk/src/main/java/com/mzt/logapi/starter/diff/DefaultDiffItemsToLogContentService.java @@ -1,10 +1,9 @@ package com.mzt.logapi.starter.diff; -import com.google.common.collect.Lists; import com.mzt.logapi.service.IFunctionService; -import com.mzt.logapi.starter.annotation.DiffLogField; -import com.mzt.logapi.starter.annotation.DiffLogAllFields; import com.mzt.logapi.starter.annotation.DIffLogIgnore; +import com.mzt.logapi.starter.annotation.DiffLogAllFields; +import com.mzt.logapi.starter.annotation.DiffLogField; import com.mzt.logapi.starter.configuration.LogRecordProperties; import de.danielbechler.diff.node.DiffNode; import de.danielbechler.diff.selector.ElementSelector; @@ -167,7 +166,7 @@ private Collection getListValue(DiffNode node, Object object) { if (fieldSourceValue != null && fieldSourceValue.getClass().isArray()) { return new ArrayList<>(Arrays.asList((Object[]) fieldSourceValue)); } - return fieldSourceValue == null ? Lists.newArrayList() : (Collection) fieldSourceValue; + return fieldSourceValue == null ? new ArrayList<>() : (Collection) fieldSourceValue; } private Collection listSubtract(Collection minuend, Collection subTractor) { diff --git a/bizlog-sdk/src/main/java/com/mzt/logapi/starter/support/aop/LogRecordInterceptor.java b/bizlog-sdk/src/main/java/com/mzt/logapi/starter/support/aop/LogRecordInterceptor.java index 30995f5..ac781da 100644 --- a/bizlog-sdk/src/main/java/com/mzt/logapi/starter/support/aop/LogRecordInterceptor.java +++ b/bizlog-sdk/src/main/java/com/mzt/logapi/starter/support/aop/LogRecordInterceptor.java @@ -1,8 +1,5 @@ package com.mzt.logapi.starter.support.aop; -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import com.mzt.logapi.beans.CodeVariableType; import com.mzt.logapi.beans.LogRecord; import com.mzt.logapi.beans.LogRecordOps; @@ -15,9 +12,6 @@ import com.mzt.logapi.service.impl.DiffParseFunction; import com.mzt.logapi.starter.support.parse.LogFunctionParser; import com.mzt.logapi.starter.support.parse.LogRecordValueParser; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; @@ -210,19 +204,22 @@ private void saveLog(Method method, boolean flag, LogRecordOps operation, String .createTime(new Date()) .build(); - Preconditions.checkNotNull(bizLogService, "bizLogService not init!!"); bizLogService.record(logRecord); } private Map getCodeVariable(Method method) { - Map map = Maps.newHashMap(); + Map map = new HashMap<>(); map.put(CodeVariableType.ClassName, method.getDeclaringClass()); map.put(CodeVariableType.MethodName, method.getName()); return map; } private List getSpElTemplates(LogRecordOps operation, String... actions) { - List spElTemplates = Lists.newArrayList(operation.getType(), operation.getBizNo(), operation.getSubType(), operation.getExtra()); + List spElTemplates = new ArrayList<>(); + spElTemplates.add(operation.getType()); + spElTemplates.add(operation.getBizNo()); + spElTemplates.add(operation.getSubType()); + spElTemplates.add(operation.getExtra()); spElTemplates.addAll(Arrays.asList(actions)); return spElTemplates; } diff --git a/bizlog-sdk/src/main/java/com/mzt/logapi/starter/support/parse/LogRecordValueParser.java b/bizlog-sdk/src/main/java/com/mzt/logapi/starter/support/parse/LogRecordValueParser.java index 24069c8..79d7e73 100644 --- a/bizlog-sdk/src/main/java/com/mzt/logapi/starter/support/parse/LogRecordValueParser.java +++ b/bizlog-sdk/src/main/java/com/mzt/logapi/starter/support/parse/LogRecordValueParser.java @@ -1,6 +1,5 @@ package com.mzt.logapi.starter.support.parse; -import com.google.common.base.Strings; import com.mzt.logapi.beans.MethodExecuteResult; import com.mzt.logapi.service.impl.DiffParseFunction; import org.springframework.beans.BeansException; @@ -74,7 +73,7 @@ public Map processTemplate(Collection templates, MethodE Object value = expressionEvaluator.parseExpression(expression, annotatedElementKey, evaluationContext); expression = logFunctionParser.getFunctionReturnValue(beforeFunctionNameAndReturnMap, value, expression, functionName); } - matcher.appendReplacement(parsedStr, Matcher.quoteReplacement(Strings.nullToEmpty(expression))); + matcher.appendReplacement(parsedStr, Matcher.quoteReplacement(expression == null ? "" : expression)); } matcher.appendTail(parsedStr); expressionValues.put(expressionTemplate, parsedStr.toString()); diff --git a/readme.md b/readme.md index 7daa8b1..b812fa1 100644 --- a/readme.md +++ b/readme.md @@ -22,6 +22,7 @@ * 修复 DIffLogIgnore注解在集合类型上失效问题 * 支持跨方法的全局变量 * 支持日志记录异常与业务逻辑一起回滚的逻辑,默认日志记录不影响业务逻辑 +* 移除了 guava 依赖 | 版本 | 状态 | |-------|-------------------------------------------------------------------------------------------------------------------------------------------------|