Skip to content

Commit

Permalink
Merge pull request #29 from mouzt/feature/opt_before
Browse files Browse the repository at this point in the history
Feature/opt before
  • Loading branch information
mouzt authored Sep 16, 2021
2 parents cde5f24 + be2b0ad commit 91b0bd6
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bizlog-sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>bizlog-sdk</artifactId>
<version>1.0.7</version>
<version>1.0.8</version>
<parent>
<groupId>io.github.mouzt</groupId>
<artifactId>mzt-biz-log</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

String operator() default "";

String operatorId() default "";

String prefix();

String bizNo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private LogRecordOps parseLogRecordAnnotation(AnnotatedElement ae, LogRecordAnno
.failLogTemplate(recordAnnotation.fail())
.bizKey(recordAnnotation.prefix().concat("_").concat(recordAnnotation.bizNo()))
.bizNo(recordAnnotation.bizNo())
.operatorId(recordAnnotation.operatorId())
.operatorId(recordAnnotation.operator())
.category(StringUtils.isEmpty(recordAnnotation.category()) ? recordAnnotation.prefix() : recordAnnotation.category())
.detail(recordAnnotation.detail())
.condition(recordAnnotation.condition())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public class LogRecordExpressionEvaluator extends CachedExpressionEvaluator {
private final Map<AnnotatedElementKey, Method> targetMethodCache = new ConcurrentHashMap<>(64);

public String parseExpression(String conditionExpression, AnnotatedElementKey methodKey, EvaluationContext evalContext) {
return getExpression(this.expressionCache, methodKey, conditionExpression).getValue(evalContext, String.class);
Object value = getExpression(this.expressionCache, methodKey, conditionExpression).getValue(evalContext, Object.class);
return value == null ? "" : value.toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ public Map<String, String> processBeforeExecuteFunctionTemplate(Collection<Strin
Matcher matcher = pattern.matcher(expressionTemplate);
while (matcher.find()) {
String expression = matcher.group(2);
if (expression.contains("#_ret") || expression.contains("#_errorMsg")) {
continue;
}
AnnotatedElementKey annotatedElementKey = new AnnotatedElementKey(method, targetClass);
String value = expressionEvaluator.parseExpression(expression, annotatedElementKey, evaluationContext);
String functionName = matcher.group(1);
if (functionService.beforeFunction(functionName)) {
String value = expressionEvaluator.parseExpression(expression, annotatedElementKey, evaluationContext);
String functionReturnValue = getFunctionReturnValue(null, value, functionName);
functionNameAndReturnValueMap.put(functionName, functionReturnValue);
}
Expand Down
2 changes: 1 addition & 1 deletion bizlog-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<dependency>
<groupId>io.github.mouzt</groupId>
<artifactId>bizlog-sdk</artifactId>
<version>1.0.7</version>
<version>1.0.8</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
| 1.0.1 |发版 |
| 1.0.4 |支持 Context 添加变量|
| 1.0.5 |支持 condition;修复https://github.com/mouzt/mzt-biz-log/issues/18|
| 1.0.7 |自定义函数支持 在业务的方法运行前执行|
| 1.0.8 |自定义函数支持 在业务的方法运行前执行|

## 使用方式

Expand All @@ -23,7 +23,7 @@
<dependency>
<groupId>io.github.mouzt</groupId>
<artifactId>bizlog-sdk</artifactId>
<version>1.0.7</version>
<version>1.0.8</version>
</dependency>
```
#### SpringBoot入口打开开关,添加 @EnableLogRecord 注解
Expand Down Expand Up @@ -381,13 +381,13 @@ public class UserParseFunction implements IParseFunction {

#### 变量相关

> LogRecordAnnotation 可以使用的变量出了参数也可以使用返回值#_ret变量,以及异常的错误信息#_errorMsg,也可以通过SpEL的 T 方式调用静态方法噢
> LogRecordAnnotation 可以使用的变量出了参数也可以使用返回值 #_ret 变量,以及异常的错误信息 #_errorMsg,也可以通过 SpEL 的 T 方式调用静态方法噢
#### Change Log & TODO

| 名称 |状态 |
|----|----|
| 支持自定义函数在业务方法运行之前解析 https://github.com/mouzt/mzt-biz-log/issues/17 |1.0.7 |
| 支持自定义函数在业务方法运行之前解析 https://github.com/mouzt/mzt-biz-log/issues/17 |1.0.8 |
| 支持condition; 修复 https://github.com/mouzt/mzt-biz-log/issues/18 |1.0.5 |
| 支持Context添加变量|1.0.4 已经支持 |
|支持对象的diff|TODO|
Expand Down

0 comments on commit 91b0bd6

Please sign in to comment.