|
@@ -247,6 +247,18 @@ public class Binlog implements Serializable {
|
|
|
* @return 实体模型实例
|
|
|
*/
|
|
|
public <T> T modification(@NonNull Class<T> model) {
|
|
|
+ return this.modification(model, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取更新信息
|
|
|
+ *
|
|
|
+ * @param model 实体模型
|
|
|
+ * @param limit 限制模型
|
|
|
+ * @param <T> 数据类型
|
|
|
+ * @return 实体模型实例
|
|
|
+ */
|
|
|
+ public <T> T modification(@NonNull Class<T> model, Class<?> limit) {
|
|
|
if (ObjectUtils.isEmpty(this.after)) {
|
|
|
return null;
|
|
|
}
|
|
@@ -256,7 +268,11 @@ public class Binlog implements Serializable {
|
|
|
return null;
|
|
|
}
|
|
|
T instance = null;
|
|
|
+ Map<String, Field> limits = ObjectUtils.ifNull(limit, ObjectUtils::getAllFields);
|
|
|
for (Map.Entry<String, Field> entry : fields.entrySet()) {
|
|
|
+ if (ObjectUtils.notEmpty(limits) && !limits.containsKey(entry.getKey())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
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));
|
|
@@ -277,6 +293,17 @@ public class Binlog implements Serializable {
|
|
|
* @return 实体对象属性名/值映射表
|
|
|
*/
|
|
|
public Map<String, Object> different(@NonNull Class<?> model) {
|
|
|
+ return this.different(model, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取差异属性值
|
|
|
+ *
|
|
|
+ * @param model 实体模型
|
|
|
+ * @param limit 限制模型
|
|
|
+ * @return 实体对象属性名/值映射表
|
|
|
+ */
|
|
|
+ public Map<String, Object> different(@NonNull Class<?> model, Class<?> limit) {
|
|
|
if (ObjectUtils.isEmpty(this.after)) {
|
|
|
return Collections.emptyMap();
|
|
|
}
|
|
@@ -286,7 +313,11 @@ public class Binlog implements Serializable {
|
|
|
return Collections.emptyMap();
|
|
|
}
|
|
|
Map<String, Object> different = Maps.newHashMap();
|
|
|
+ Map<String, Field> limits = ObjectUtils.ifNull(limit, ObjectUtils::getAllFields);
|
|
|
for (Map.Entry<String, Field> entry : fields.entrySet()) {
|
|
|
+ if (ObjectUtils.notEmpty(limits) && !limits.containsKey(entry.getKey())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
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));
|