diff --git a/apollo-audit/apollo-audit-impl/src/main/java/com/ctrip/framework/apollo/audit/aop/ApolloAuditSpanAspect.java b/apollo-audit/apollo-audit-impl/src/main/java/com/ctrip/framework/apollo/audit/aop/ApolloAuditSpanAspect.java index 535a07dfda6..04ecc223bfe 100644 --- a/apollo-audit/apollo-audit-impl/src/main/java/com/ctrip/framework/apollo/audit/aop/ApolloAuditSpanAspect.java +++ b/apollo-audit/apollo-audit-impl/src/main/java/com/ctrip/framework/apollo/audit/aop/ApolloAuditSpanAspect.java @@ -24,7 +24,7 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.Arrays; -import java.util.Objects; +import java.util.Collection; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; @@ -72,8 +72,17 @@ public Object around(ProceedingJoinPoint pjp, ApolloAuditLog auditLog) throws Th } } if (entityName != null && fieldName != null) { - String matchedValue = String.valueOf(arg); - api.appendDataInfluence("AnyMatched", entityName, fieldName, matchedValue); + // if arg is a collection + if (arg instanceof Collection) { + for (Object o : ((Collection) arg).toArray()) { + String matchedValue = String.valueOf(o); + api.appendDataInfluence(entityName, "AnyMatched", fieldName, matchedValue); + } + } + else { + String matchedValue = String.valueOf(arg); + api.appendDataInfluence(entityName, "AnyMatched", fieldName, matchedValue); + } } } } diff --git a/apollo-audit/apollo-audit-impl/src/main/java/com/ctrip/framework/apollo/audit/component/ApolloAuditLogApiJpaImpl.java b/apollo-audit/apollo-audit-impl/src/main/java/com/ctrip/framework/apollo/audit/component/ApolloAuditLogApiJpaImpl.java index d7c1baab2a4..742fe593222 100644 --- a/apollo-audit/apollo-audit-impl/src/main/java/com/ctrip/framework/apollo/audit/component/ApolloAuditLogApiJpaImpl.java +++ b/apollo-audit/apollo-audit-impl/src/main/java/com/ctrip/framework/apollo/audit/component/ApolloAuditLogApiJpaImpl.java @@ -78,6 +78,9 @@ public void appendDataInfluence(String entityName, String entityId, String field OpType type = traceContext.tracer().getActiveSpan().getOpType(); ApolloAuditLogDataInfluence.Builder builder = ApolloAuditLogDataInfluence.builder().spanId(spanId) .entityName(entityName).entityId(entityId).fieldName(fieldName); + if (type == null) { + return; + } switch (type) { case CREATE: case UPDATE: @@ -106,7 +109,7 @@ public void appendDataInfluences(List entities, Class beanDefinition) f.setAccessible(true); String val = String.valueOf(f.get(e)); String fieldName = f.getAnnotation(ApolloAuditLogDataInfluenceTableField.class).fieldName(); - appendDataInfluence(tableId, tableName, fieldName, val); + appendDataInfluence(tableName, tableId, fieldName, val); } } catch (IllegalAccessException ex) { throw new IllegalArgumentException("failed append data influence, " diff --git a/apollo-audit/apollo-audit-impl/src/test/java/com/ctrip/framework/apollo/audit/component/ApolloAuditLogApiJpaImplTest.java b/apollo-audit/apollo-audit-impl/src/test/java/com/ctrip/framework/apollo/audit/component/ApolloAuditLogApiJpaImplTest.java index f1ddd8e8f30..728b9689712 100644 --- a/apollo-audit/apollo-audit-impl/src/test/java/com/ctrip/framework/apollo/audit/component/ApolloAuditLogApiJpaImplTest.java +++ b/apollo-audit/apollo-audit-impl/src/test/java/com/ctrip/framework/apollo/audit/component/ApolloAuditLogApiJpaImplTest.java @@ -185,7 +185,7 @@ public void testAppendDataInfluences() { api.appendDataInfluences(entities, MockDataInfluenceEntity.class); Mockito.verify(api, Mockito.times(entityNum)) - .appendDataInfluence(Mockito.anyString(), Mockito.eq("MockTableName"), Mockito.eq("MarkedAttribute"), + .appendDataInfluence(Mockito.eq("MockTableName"), Mockito.any(), Mockito.eq("MarkedAttribute"), Mockito.any()); } diff --git a/apollo-portal/src/main/resources/static/audit_log_trace_detail.html b/apollo-portal/src/main/resources/static/audit_log_trace_detail.html index f66bc60b213..2fd446b479f 100644 --- a/apollo-portal/src/main/resources/static/audit_log_trace_detail.html +++ b/apollo-portal/src/main/resources/static/audit_log_trace_detail.html @@ -99,31 +99,35 @@

- {{'ApolloAuditLog.DataInfluence.EntityName' | translate}}: {{dataInfluenceEntity[0].name}} + {{'ApolloAuditLog.DataInfluence.EntityName' | translate}}: {{dataInfluenceEntity[1].name}}
-
- {{'ApolloAuditLog.DataInfluence.EntityId' | translate}}: {{dataInfluenceEntity[0].id}} +
+ {{'ApolloAuditLog.DataInfluence.EntityId' | translate}}: {{dataInfluenceEntity[1].id}}
-
+
{{'ApolloAuditLog.DataInfluence.AnyMatchedEntityId' | translate}}

-
+
{{'ApolloAuditLog.DataInfluence.Fields' | translate}}:
-
+
{{'ApolloAuditLog.DataInfluence.MatchedFields' | translate}}:
-
+ ng-show="dataInfluenceEntity[1].id != 'AnyMatched' && dataInfluence.fieldNewValue"> {{dataInfluence.fieldName}} ==> {{dataInfluence.fieldNewValue}}
+ ng-show="dataInfluenceEntity[1].id != 'AnyMatched' && !dataInfluence.fieldNewValue"> + {{dataInfluence.fieldName}} : {{dataInfluence.fieldOldValue}} ==> (deleted) +
+
{{dataInfluence.fieldName}} <== {{showingDetail.logDTO.opType == 'DELETE' ? dataInfluence.fieldOldValue : dataInfluence.fieldNewValue}}
@@ -158,7 +162,7 @@

- {{ di.fieldNewValue }} + {{ di.fieldNewValue ? di.fieldNewValue : '(deleted)' }} {{ di.happenedTime | date: 'yyyy-MM-dd HH:mm:ss' }} diff --git a/apollo-portal/src/main/resources/static/scripts/controller/AuditLogTraceDetailController.js b/apollo-portal/src/main/resources/static/scripts/controller/AuditLogTraceDetailController.js index 43b56f196a1..b2887964bce 100644 --- a/apollo-portal/src/main/resources/static/scripts/controller/AuditLogTraceDetailController.js +++ b/apollo-portal/src/main/resources/static/scripts/controller/AuditLogTraceDetailController.js @@ -136,10 +136,16 @@ function auditLogTraceDetailController($scope, $location, $window, $translate, t name: dto.influenceEntityName, id: dto.influenceEntityId }; - if (!entityMap.has(key)) { - entityMap.set(key, []); + var keyString = JSON.stringify(key); + var value = { + name: dto.influenceEntityName, + id: dto.influenceEntityId, + dtoList: [] + }; + if (!entityMap.has(keyString)) { + entityMap.set(keyString, value); } - entityMap.get(key).push(dto); + entityMap.get(keyString).dtoList.push(dto); }); $scope.dataInfluenceEntities = Array.from(entityMap); }