|
@@ -89,18 +89,6 @@ public class Binlog implements Serializable {
|
|
|
return entity;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 转换字段值
|
|
|
- *
|
|
|
- * @param model 数据模型
|
|
|
- * @param property 模型属性
|
|
|
- * @param object 字段原始值
|
|
|
- * @return 转换后字段值
|
|
|
- */
|
|
|
- public static Object convert(@NonNull Class<?> model, @NonNull String property, Object object) {
|
|
|
- return object == null ? null : convert(ObjectUtils.getClassField(model, property), object);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 更新实体属性值
|
|
|
*
|
|
@@ -114,14 +102,13 @@ public class Binlog implements Serializable {
|
|
|
|
|
|
Class<?> model = entity.getClass();
|
|
|
Map<String, Field> fields = ObjectUtils.getClassFields(model);
|
|
|
- if (ObjectUtils.isEmpty(fields)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- for (Map.Entry<String, Field> entry : fields.entrySet()) {
|
|
|
- String column = StringUtils.hump2underscore(entry.getKey());
|
|
|
- Object value = mapping.get(column);
|
|
|
- value = convert(entry.getValue(), value);
|
|
|
- ObjectUtils.setObjectValue(entity, entry.getValue(), value);
|
|
|
+ if (ObjectUtils.notEmpty(fields)) {
|
|
|
+ for (Map.Entry<String, Field> entry : fields.entrySet()) {
|
|
|
+ String column = StringUtils.hump2underscore(entry.getKey());
|
|
|
+ Object value = mapping.get(column);
|
|
|
+ value = convert(entry.getValue(), value);
|
|
|
+ ObjectUtils.setObjectValue(entity, entry.getValue(), value);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -164,15 +151,14 @@ public class Binlog implements Serializable {
|
|
|
}
|
|
|
|
|
|
Map<String, Field> fields = ObjectUtils.getClassFields(model);
|
|
|
- if (ObjectUtils.isEmpty(fields)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- for (Map.Entry<String, Field> entry : fields.entrySet()) {
|
|
|
- String column = StringUtils.hump2underscore(entry.getKey());
|
|
|
- Object a = ObjectUtils.ifNull(this.after, map -> map.get(column));
|
|
|
- Object b = ObjectUtils.ifNull(this.before, map -> map.get(column));
|
|
|
- if (!ObjectUtils.equals(a, b)) {
|
|
|
- return true;
|
|
|
+ if (ObjectUtils.notEmpty(fields)) {
|
|
|
+ for (Map.Entry<String, Field> entry : fields.entrySet()) {
|
|
|
+ String column = StringUtils.hump2underscore(entry.getKey());
|
|
|
+ Object a = ObjectUtils.ifNull(this.after, map -> map.get(column));
|
|
|
+ Object b = ObjectUtils.ifNull(this.before, map -> map.get(column));
|
|
|
+ if (!ObjectUtils.equals(a, b)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
@@ -268,9 +254,10 @@ public class Binlog implements Serializable {
|
|
|
return null;
|
|
|
}
|
|
|
T instance = null;
|
|
|
- Map<String, Field> limits = ObjectUtils.ifNull(limit, ObjectUtils::getClassFields);
|
|
|
+ boolean identical = limit == model;
|
|
|
+ Map<String, Field> limits = identical ? fields : ObjectUtils.ifNull(limit, ObjectUtils::getClassFields);
|
|
|
for (Map.Entry<String, Field> entry : fields.entrySet()) {
|
|
|
- if (ObjectUtils.notEmpty(limits) && !limits.containsKey(entry.getKey())) {
|
|
|
+ if (!identical && ObjectUtils.notEmpty(limits) && !limits.containsKey(entry.getKey())) {
|
|
|
continue;
|
|
|
}
|
|
|
String column = StringUtils.hump2underscore(entry.getKey());
|
|
@@ -312,10 +299,11 @@ public class Binlog implements Serializable {
|
|
|
if (ObjectUtils.isEmpty(fields)) {
|
|
|
return Collections.emptyMap();
|
|
|
}
|
|
|
+ boolean identical = limit == model;
|
|
|
Map<String, Object> different = Maps.newHashMap();
|
|
|
- Map<String, Field> limits = ObjectUtils.ifNull(limit, ObjectUtils::getClassFields);
|
|
|
+ Map<String, Field> limits = identical ? fields : ObjectUtils.ifNull(limit, ObjectUtils::getClassFields);
|
|
|
for (Map.Entry<String, Field> entry : fields.entrySet()) {
|
|
|
- if (ObjectUtils.notEmpty(limits) && !limits.containsKey(entry.getKey())) {
|
|
|
+ if (!identical && ObjectUtils.notEmpty(limits) && !limits.containsKey(entry.getKey())) {
|
|
|
continue;
|
|
|
}
|
|
|
String column = StringUtils.hump2underscore(entry.getKey());
|
|
@@ -325,7 +313,7 @@ public class Binlog implements Serializable {
|
|
|
different.put(entry.getKey(), convert(entry.getValue(), a));
|
|
|
}
|
|
|
}
|
|
|
- return different;
|
|
|
+ return different.isEmpty() ? Collections.emptyMap() : different;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -356,6 +344,6 @@ public class Binlog implements Serializable {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return different;
|
|
|
+ return different.isEmpty() ? Collections.emptyMap() : different;
|
|
|
}
|
|
|
}
|