From 66b0d55966b5868c2426249d9091beb8cffeee02 Mon Sep 17 00:00:00 2001 From: lhpqaq <657407891@qq.com> Date: Fri, 20 Sep 2024 12:06:50 +0800 Subject: [PATCH] add checkBaseField --- .../bigtop/manager/dao/sql/SQLBuilder.java | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/bigtop-manager-dao/src/main/java/org/apache/bigtop/manager/dao/sql/SQLBuilder.java b/bigtop-manager-dao/src/main/java/org/apache/bigtop/manager/dao/sql/SQLBuilder.java index 3170060e..4321f223 100644 --- a/bigtop-manager-dao/src/main/java/org/apache/bigtop/manager/dao/sql/SQLBuilder.java +++ b/bigtop-manager-dao/src/main/java/org/apache/bigtop/manager/dao/sql/SQLBuilder.java @@ -20,7 +20,11 @@ package org.apache.bigtop.manager.dao.sql; import org.apache.bigtop.manager.common.utils.ClassUtils; +import org.apache.bigtop.manager.dao.annotations.CreateBy; +import org.apache.bigtop.manager.dao.annotations.CreateTime; import org.apache.bigtop.manager.dao.annotations.QueryCondition; +import org.apache.bigtop.manager.dao.annotations.UpdateBy; +import org.apache.bigtop.manager.dao.annotations.UpdateTime; import org.apache.bigtop.manager.dao.enums.DBType; import org.apache.ibatis.jdbc.SQL; @@ -297,7 +301,10 @@ public static String updateList( if (ps == null || ps.getReadMethod() == null) { continue; } - + Field field = ReflectionUtils.findField(entityClass, entry.getKey()); + if (field == null || checkBaseField(field)) { + continue; + } Object value = ReflectionUtils.invokeMethod(ps.getReadMethod(), entity); PropertyDescriptor pkPs = BeanUtils.getPropertyDescriptor(entityClass, tableMetaData.getPkProperty()); @@ -316,12 +323,9 @@ public static String updateList( .append(escapeSingleQuote(value.toString())) .append("' "); } else if (!partial) { - Field field = ReflectionUtils.findField(entityClass, entry.getKey()); - if (field != null) { - Column column = field.getAnnotation(Column.class); - if (column != null && !column.nullable() && value == null) { - continue; - } + Column column = field.getAnnotation(Column.class); + if (column != null && !column.nullable() && value == null) { + continue; } caseClause .append("WHEN ") @@ -368,7 +372,10 @@ public static String updateList( primaryKey = keywordsFormat(entry.getValue(), DBType.POSTGRESQL); continue; } - + Field field = ReflectionUtils.findField(entityClass, entry.getKey()); + if (field == null || checkBaseField(field)) { + continue; + } StringBuilder caseClause = new StringBuilder(); caseClause .append(keywordsFormat(entry.getValue(), DBType.POSTGRESQL)) @@ -397,12 +404,9 @@ public static String updateList( .append(escapeSingleQuote(value.toString())) .append("' "); } else if (!partial) { - Field field = ReflectionUtils.findField(entityClass, entry.getKey()); - if (field != null) { - Column column = field.getAnnotation(Column.class); - if (column != null && !column.nullable() && value == null) { - continue; - } + Column column = field.getAnnotation(Column.class); + if (column != null && !column.nullable() && value == null) { + continue; } caseClause .append("WHEN ") @@ -637,6 +641,13 @@ private static String escapeSingleQuote(String input) { return null; } + private static boolean checkBaseField(Field field) { + return field.isAnnotationPresent(CreateBy.class) + || field.isAnnotationPresent(CreateTime.class) + || field.isAnnotationPresent(UpdateBy.class) + || field.isAnnotationPresent(UpdateTime.class); + } + private static SQL mysqlCondition(Condition condition, TableMetaData tableMetaData) throws IllegalAccessException {