@@ -76,7 +76,7 @@ public Object intercept(Object obj, Method method, Object[] args, MethodProxy pr
7676 }
7777
7878 if (fields .isEmpty ()){
79- this .readFields ();
79+ this .readFields (fields , target , propertyDescriptors );
8080 }
8181 Object result = method .invoke (target , args );
8282 this .compareAndUpdateField ();
@@ -88,14 +88,28 @@ public Object intercept(Object obj, Method method, Object[] args, MethodProxy pr
8888 * @throws InvocationTargetException InvocationTargetException
8989 * @throws IllegalAccessException InvocationTargetException
9090 */
91- private void readFields () throws InvocationTargetException , IllegalAccessException {
91+ private void readFields (Map < String , Object > fields , Object target , PropertyDescriptor [] propertyDescriptors ) throws InvocationTargetException , IllegalAccessException {
9292 for (PropertyDescriptor propertyDescriptor : propertyDescriptors ) {
9393 String name = propertyDescriptor .getName ();
9494 Object value = propertyDescriptor .getReadMethod ().invoke (target );
95- fields .put (name , value );
95+ if (isPrimitive (value )) {
96+ fields .put (name , value );
97+ }else {
98+ Map <String ,Object > childFields = new HashMap <>();
99+ this .readFields (childFields ,value ,BeanUtils .getPropertyDescriptors (value .getClass ()));
100+ fields .put (name , childFields );
101+ }
96102 }
97103 }
98104
105+
106+ private boolean isPrimitive (Object obj ) {
107+ return obj instanceof String || obj instanceof Integer || obj instanceof Long
108+ || obj instanceof Double || obj instanceof Float || obj instanceof Boolean
109+ || obj instanceof Short || obj instanceof Byte || obj instanceof Character
110+ || obj instanceof Enum || obj instanceof Class ;
111+ }
112+
99113 /**
100114 * 对比字段
101115 * @throws InvocationTargetException InvocationTargetException
@@ -106,10 +120,27 @@ private void compareAndUpdateField() throws InvocationTargetException, IllegalAc
106120 String name = propertyDescriptor .getName ();
107121 Object newValue = propertyDescriptor .getReadMethod ().invoke (target );
108122 Object oldValue = fields .get (name );
109- if (!newValue .equals (oldValue )) {
110- pushEvent (name , oldValue , newValue );
123+ if (isPrimitive (newValue )) {
124+ if (!newValue .equals (oldValue )) {
125+ pushEvent (name , oldValue , newValue );
126+ }
127+ fields .put (name , newValue );
128+ }else {
129+ Map <String ,Object > newFields = new HashMap <>();
130+ this .readFields (newFields ,newValue ,BeanUtils .getPropertyDescriptors (newValue .getClass ()));
131+
132+ Map <String ,Object > oldFields = (Map <String ,Object >)oldValue ;
133+ for (String key :oldFields .keySet ()){
134+ Object oldChildValue = oldFields .get (key );
135+ Object newChildValue = newFields .get (key );
136+ if (!oldChildValue .equals (newChildValue )){
137+ String namePrefix = name + "." ;
138+ pushEvent (namePrefix +key , oldChildValue , newChildValue );
139+ }
140+ }
141+ fields .put (name , newFields );
111142 }
112- fields . put ( name , newValue );
143+
113144 }
114145 }
115146
0 commit comments