|
@@ -71,10 +71,11 @@ public class PropertyUpdateInterceptor implements Interceptor {
|
|
|
* 数据更新
|
|
|
*
|
|
|
* @param invocation 方法调用信息
|
|
|
+ * @param operation 数据更新类型
|
|
|
* @return 更新结果
|
|
|
* @throws Throwable 操作异常
|
|
|
*/
|
|
|
- private Object modify(Invocation invocation) throws Throwable {
|
|
|
+ private Object modify(Invocation invocation, SqlCommandType operation) throws Throwable {
|
|
|
// 获取更新目标对象实例
|
|
|
Object object = invocation.getArgs()[1];
|
|
|
if (object instanceof MapperMethod.ParamMap) {
|
|
@@ -93,11 +94,11 @@ public class PropertyUpdateInterceptor implements Interceptor {
|
|
|
if (object instanceof Collection) {
|
|
|
((Collection<?>) object).forEach(entity -> {
|
|
|
if (entity instanceof Entity) {
|
|
|
- this.modify((Entity<?>) entity);
|
|
|
+ this.modify((Entity<?>) entity, operation);
|
|
|
}
|
|
|
});
|
|
|
} else if (object instanceof Entity) {
|
|
|
- this.modify((Entity<?>) object);
|
|
|
+ this.modify((Entity<?>) object, operation);
|
|
|
}
|
|
|
return invocation.proceed();
|
|
|
}
|
|
@@ -105,13 +106,16 @@ public class PropertyUpdateInterceptor implements Interceptor {
|
|
|
/**
|
|
|
* 实体信息更新
|
|
|
*
|
|
|
- * @param entity 实体对象实例
|
|
|
- * @param <T> 实体类型
|
|
|
+ * @param entity 实体对象实例
|
|
|
+ * @param operation 数据更新类型
|
|
|
+ * @param <T> 实体类型
|
|
|
*/
|
|
|
@SuppressWarnings("unchecked")
|
|
|
- private <T extends Entity<?>> void modify(T entity) {
|
|
|
- // 初始化默认属性值
|
|
|
- DatabaseContextHolder.initializeEntityDefaultValue(entity);
|
|
|
+ private <T extends Entity<?>> void modify(T entity, SqlCommandType operation) {
|
|
|
+ // 初始化实体新增默认属性值
|
|
|
+ if (operation == SqlCommandType.INSERT) {
|
|
|
+ DatabaseContextHolder.initializeEntityDefaultValue(entity);
|
|
|
+ }
|
|
|
|
|
|
// 设置加密属性值
|
|
|
Class<T> clazz = (Class<T>) entity.getClass();
|
|
@@ -165,7 +169,7 @@ public class PropertyUpdateInterceptor implements Interceptor {
|
|
|
if (operation == SqlCommandType.SELECT) {
|
|
|
return this.select(invocation);
|
|
|
} else if (operation == SqlCommandType.INSERT || operation == SqlCommandType.UPDATE) {
|
|
|
- return this.modify(invocation);
|
|
|
+ return this.modify(invocation, operation);
|
|
|
}
|
|
|
return invocation.proceed();
|
|
|
}
|