|
@@ -177,8 +177,8 @@ public class PropertyUpdateInterceptor implements Interceptor {
|
|
|
}
|
|
|
|
|
|
// 设置创建人字段值
|
|
|
- boolean includeCreator = !this.isContains(insert.getColumns(), Expressions.CREATOR_COLUMN);
|
|
|
- if (includeCreator) {
|
|
|
+ boolean containCreator = this.isContains(insert.getColumns(), Expressions.CREATOR_COLUMN);
|
|
|
+ if (!containCreator) {
|
|
|
insert.addColumns(Expressions.CREATOR_COLUMN);
|
|
|
Expression operator = this.operator();
|
|
|
ItemsList items = insert.getItemsList();
|
|
@@ -190,8 +190,8 @@ public class PropertyUpdateInterceptor implements Interceptor {
|
|
|
}
|
|
|
|
|
|
// 设置创建时间字段值
|
|
|
- boolean includeCreateTime = !this.isContains(insert.getColumns(), Expressions.CREATE_TIME_COLUMN);
|
|
|
- if (includeCreateTime) {
|
|
|
+ boolean containCreateTime = this.isContains(insert.getColumns(), Expressions.CREATE_TIME_COLUMN);
|
|
|
+ if (!containCreateTime) {
|
|
|
insert.addColumns(Expressions.CREATE_TIME_COLUMN);
|
|
|
Expression datetime = this.datetime();
|
|
|
ItemsList items = insert.getItemsList();
|
|
@@ -201,7 +201,7 @@ public class PropertyUpdateInterceptor implements Interceptor {
|
|
|
((ExpressionList) items).getExpressions().add(datetime);
|
|
|
}
|
|
|
}
|
|
|
- return includeCreator || includeCreateTime;
|
|
|
+ return !(containCreator && containCreateTime);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -217,8 +217,8 @@ public class PropertyUpdateInterceptor implements Interceptor {
|
|
|
}
|
|
|
|
|
|
// 设置更新人字段值
|
|
|
- boolean includeUpdater = !this.isContains(insert.getColumns(), Expressions.UPDATER_COLUMN);
|
|
|
- if (includeUpdater) {
|
|
|
+ boolean containUpdater = this.isContains(insert.getColumns(), Expressions.UPDATER_COLUMN);
|
|
|
+ if (!containUpdater) {
|
|
|
insert.addColumns(Expressions.UPDATER_COLUMN);
|
|
|
Expression operator = this.operator();
|
|
|
ItemsList items = insert.getItemsList();
|
|
@@ -230,8 +230,8 @@ public class PropertyUpdateInterceptor implements Interceptor {
|
|
|
}
|
|
|
|
|
|
// 设置更新时间字段值
|
|
|
- boolean includeUpdateTime = !this.isContains(insert.getColumns(), Expressions.UPDATE_TIME_COLUMN);
|
|
|
- if (includeUpdateTime) {
|
|
|
+ boolean containUpdateTime = this.isContains(insert.getColumns(), Expressions.UPDATE_TIME_COLUMN);
|
|
|
+ if (!containUpdateTime) {
|
|
|
insert.addColumns(Expressions.UPDATE_TIME_COLUMN);
|
|
|
Expression datetime = this.datetime();
|
|
|
ItemsList items = insert.getItemsList();
|
|
@@ -241,7 +241,7 @@ public class PropertyUpdateInterceptor implements Interceptor {
|
|
|
((ExpressionList) items).getExpressions().add(datetime);
|
|
|
}
|
|
|
}
|
|
|
- return includeUpdater || includeUpdateTime;
|
|
|
+ return !(containUpdater && containUpdateTime);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -258,21 +258,19 @@ public class PropertyUpdateInterceptor implements Interceptor {
|
|
|
|
|
|
// 设置更新人字段值
|
|
|
Table table = update.getTable();
|
|
|
- Expression operator = this.operator();
|
|
|
- boolean includeUpdater = operator != Expressions.NULL_VALUE
|
|
|
- && !this.isContains(table, update.getColumns(), Expressions.UPDATER_COLUMN);
|
|
|
- if (includeUpdater) {
|
|
|
+ boolean containUpdater = this.isContains(table, update.getColumns(), Expressions.UPDATER_COLUMN);
|
|
|
+ if (!containUpdater) {
|
|
|
if (StringUtils.isEmpty(table.getAlias())) {
|
|
|
update.addColumns(Expressions.UPDATER_COLUMN);
|
|
|
} else {
|
|
|
update.addColumns(new Column(table, Expressions.UPDATER_COLUMN.getColumnName()));
|
|
|
}
|
|
|
- update.addExpressions(operator);
|
|
|
+ update.addExpressions(this.operator());
|
|
|
}
|
|
|
|
|
|
// 设置更新时间字段值
|
|
|
- boolean includeUpdateTime = !this.isContains(table, update.getColumns(), Expressions.UPDATE_TIME_COLUMN);
|
|
|
- if (includeUpdateTime) {
|
|
|
+ boolean containUpdateTime = this.isContains(table, update.getColumns(), Expressions.UPDATE_TIME_COLUMN);
|
|
|
+ if (!containUpdateTime) {
|
|
|
if (StringUtils.isEmpty(table.getAlias())) {
|
|
|
update.addColumns(Expressions.UPDATE_TIME_COLUMN);
|
|
|
} else {
|
|
@@ -280,7 +278,7 @@ public class PropertyUpdateInterceptor implements Interceptor {
|
|
|
}
|
|
|
update.addExpressions(this.datetime());
|
|
|
}
|
|
|
- return includeUpdater || includeUpdateTime;
|
|
|
+ return !(containUpdater && containUpdateTime);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -434,22 +432,37 @@ public class PropertyUpdateInterceptor implements Interceptor {
|
|
|
if (entity instanceof Creatable || entity instanceof Updatable || entity instanceof Deletable) {
|
|
|
Date now = new Date();
|
|
|
Long operator = SessionContextHolder.getId();
|
|
|
- if (entity instanceof Updatable) {
|
|
|
- if (operator != null) {
|
|
|
- ((Updatable<?>) entity).setUpdater(operator);
|
|
|
- }
|
|
|
- ((Updatable<?>) entity).setUpdateTime(now);
|
|
|
- }
|
|
|
if (operation == SqlCommandType.INSERT) {
|
|
|
if (entity instanceof Creatable) {
|
|
|
- if (operator != null) {
|
|
|
- ((Creatable<?>) entity).setCreator(operator);
|
|
|
+ Creatable<?> creatable = (Creatable<?>) entity;
|
|
|
+ if (creatable.getCreator() == null) {
|
|
|
+ creatable.setCreator(operator);
|
|
|
+ }
|
|
|
+ if (creatable.getCreateTime() == null) {
|
|
|
+ creatable.setCreateTime(now);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (entity instanceof Updatable) {
|
|
|
+ Updatable<?> updatable = (Updatable<?>) entity;
|
|
|
+ if (updatable.getUpdater() == null) {
|
|
|
+ updatable.setUpdater(operator);
|
|
|
+ }
|
|
|
+ if (updatable.getUpdateTime() == null) {
|
|
|
+ updatable.setUpdateTime(now);
|
|
|
}
|
|
|
- ((Creatable<?>) entity).setCreateTime(now);
|
|
|
}
|
|
|
if (entity instanceof Deletable) {
|
|
|
- ((Deletable<?>) entity).setDeleted(false);
|
|
|
+ Deletable<?> deletable = (Deletable<?>) entity;
|
|
|
+ if (deletable.getDeleted() == null) {
|
|
|
+ deletable.setDeleted(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (operation == SqlCommandType.UPDATE && entity instanceof Updatable) {
|
|
|
+ Updatable<?> updatable = (Updatable<?>) entity;
|
|
|
+ if (operator != null) {
|
|
|
+ updatable.setUpdater(operator);
|
|
|
}
|
|
|
+ updatable.setUpdateTime(now);
|
|
|
}
|
|
|
}
|
|
|
|