diff --git a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/mapping/defaults/DefaultUpdate.java b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/mapping/defaults/DefaultUpdate.java index 74c0beef..d322c984 100644 --- a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/mapping/defaults/DefaultUpdate.java +++ b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/mapping/defaults/DefaultUpdate.java @@ -77,33 +77,38 @@ public T toQueryParam(Supplier template) { protected UpdateResultOperator doExecute() { return EventResultOperator.create( - () -> { - if (null != instance) { - applyColumns(instance); + () -> { + if (null != instance) { + applyColumns(instance); + } + for (Map.Entry entry : tempInstance.entrySet()) { + if (entry.getValue() != null) { + operator.set(entry.getKey(), entry.getValue()); } - return operator - .where(dsl -> terms.forEach(dsl::accept)) - .execute(); - }, - UpdateResultOperator.class, - table, - MappingEventTypes.update_before, - MappingEventTypes.update_after, - contextKeyValues.toArray(new ContextKeyValue[0]) + } + return operator + .where(dsl -> terms.forEach(dsl::accept)) + .execute(); + }, + UpdateResultOperator.class, + table, + MappingEventTypes.update_before, + MappingEventTypes.update_after, + contextKeyValues.toArray(new ContextKeyValue[0]) ); } private void applyColumns(E instance) { mapping - .getColumnPropertyMapping() - .entrySet() - .stream() - .filter(e -> includes.isEmpty() || includes.contains(e.getKey()) || includes.contains(e.getValue())) - .filter(e -> !excludes.contains(e.getKey()) && !excludes.contains(e.getValue())) - .forEach(e -> GlobalConfig - .getPropertyOperator() - .getProperty(instance, e.getValue()) - .ifPresent(val -> this.set(e.getKey(), val))); + .getColumnPropertyMapping() + .entrySet() + .stream() + .filter(e -> includes.isEmpty() || includes.contains(e.getKey()) || includes.contains(e.getValue())) + .filter(e -> !excludes.contains(e.getKey()) && !excludes.contains(e.getValue())) + .forEach(e -> GlobalConfig + .getPropertyOperator() + .getProperty(instance, e.getValue()) + .ifPresent(val -> this.set(e.getKey(), val))); } @Override @@ -214,7 +219,7 @@ public ME accept(Param param) { if (param instanceof UpdateParam) { includes.addAll(param.getIncludes()); excludes.addAll(param.getExcludes()); - set((E)((UpdateParam) param).getData()); + set((E) ((UpdateParam) param).getData()); } return DSLUpdate.super.accept(param); } diff --git a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/dml/update/BuildParameterUpdateOperator.java b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/dml/update/BuildParameterUpdateOperator.java index c67046ed..e215afdb 100644 --- a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/dml/update/BuildParameterUpdateOperator.java +++ b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/dml/update/BuildParameterUpdateOperator.java @@ -19,8 +19,7 @@ public UpdateOperator set(String column, Object value) { UpdateColumn updateColumn = new UpdateColumn(); updateColumn.setColumn(column); updateColumn.setValue(value); - parameter.getColumns().add(updateColumn); - return this; + return set(updateColumn); } @Override @@ -30,6 +29,7 @@ public UpdateOperator set(Object entity) { @Override public UpdateOperator set(UpdateColumn column) { + parameter.getColumns().remove(column); parameter.getColumns().add(column); return this; } diff --git a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/dml/update/UpdateColumn.java b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/dml/update/UpdateColumn.java index 30f5a278..0e08f372 100644 --- a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/dml/update/UpdateColumn.java +++ b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/dml/update/UpdateColumn.java @@ -1,11 +1,13 @@ package org.hswebframework.ezorm.rdb.operator.dml.update; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; import org.hswebframework.ezorm.rdb.operator.dml.FunctionColumn; @Getter @Setter +@EqualsAndHashCode(callSuper = true,exclude = "value") public class UpdateColumn extends FunctionColumn { private Object value;