|
@@ -6,14 +6,12 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
|
|
import com.baomidou.mybatisplus.annotation.TableField;
|
|
|
import com.baomidou.mybatisplus.annotation.TableName;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.baomidou.mybatisplus.extension.service.IService;
|
|
|
import org.springframework.beans.BeansException;
|
|
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
-import java.lang.reflect.ParameterizedType;
|
|
|
-import java.lang.reflect.Type;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
@@ -26,57 +24,36 @@ public class RemoveParam implements BeanPostProcessor {
|
|
|
@Override
|
|
|
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
|
|
|
|
|
- if (bean instanceof ServiceImpl) {
|
|
|
- Class<?> beanClass = bean.getClass();
|
|
|
- try {
|
|
|
- // spring代理对象类名转换成普通对象类名
|
|
|
- String name = beanClass.getName().split("\\$")[0];
|
|
|
- Class<?> aClass = Class.forName(name);
|
|
|
- Type genericSuperclass = aClass.getGenericSuperclass();
|
|
|
- if (genericSuperclass instanceof ParameterizedType) {
|
|
|
- ParameterizedType parameterizedType = (ParameterizedType) genericSuperclass;
|
|
|
- Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
|
|
|
- Type actualTypeArgument = actualTypeArguments[1];
|
|
|
+ if (bean instanceof IService) {
|
|
|
+ Class<?> entityClass = ((IService<?>) bean).getEntityClass();
|
|
|
|
|
|
- Class<?> entityClass = Class.forName(actualTypeArgument.getTypeName());
|
|
|
-
|
|
|
- String tableName;
|
|
|
- TableName annotation = entityClass.getAnnotation(TableName.class);
|
|
|
- if (annotation != null && annotation.value() != null) {
|
|
|
- tableName = annotation.value();
|
|
|
- } else {
|
|
|
- tableName = StrUtil.toUnderlineCase(entityClass.getSimpleName());
|
|
|
- }
|
|
|
-
|
|
|
- Field[] fields = ReflectUtil.getFields(entityClass);
|
|
|
-
|
|
|
- // 字段
|
|
|
- for (Field field : fields) {
|
|
|
- TableField tableField = field.getAnnotation(TableField.class);
|
|
|
- if (tableField == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ TableName annotation = entityClass.getAnnotation(TableName.class);
|
|
|
+ String tableName;
|
|
|
+ if (annotation != null && StrUtil.isNotBlank(annotation.value())) {
|
|
|
+ tableName = annotation.value();
|
|
|
+ } else {
|
|
|
+ tableName = StrUtil.toUnderlineCase(entityClass.getSimpleName());
|
|
|
+ }
|
|
|
|
|
|
- FieldFill fill = tableField.fill();
|
|
|
- if (ObjectUtil.notEqual(fill, FieldFill.INSERT_UPDATE)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ Field[] fields = ReflectUtil.getFields(entityClass);
|
|
|
+ for (Field field : fields) {
|
|
|
|
|
|
- if (ObjectUtil.equals(tableField.value(), "update_time") || field.getName().equals("updateTime")) {
|
|
|
- RemoveParam.updateTimeMap.put(tableName, true);
|
|
|
- continue;
|
|
|
- }
|
|
|
+ TableField tableField = field.getAnnotation(TableField.class);
|
|
|
+ if (tableField == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- if (ObjectUtil.equals(tableField.value(), "update_user") || field.getName().equals("updateUser")) {
|
|
|
- RemoveParam.updateUserMap.put(tableName, true);
|
|
|
- }
|
|
|
- }
|
|
|
+ FieldFill fill = tableField.fill();
|
|
|
+ if (ObjectUtil.notEqual(fill, FieldFill.INSERT_UPDATE) && ObjectUtil.notEqual(fill, FieldFill.UPDATE)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- RemoveParam.updateTimeMap.putIfAbsent(tableName, false);
|
|
|
- RemoveParam.updateUserMap.putIfAbsent(tableName, false);
|
|
|
+ if ("update_time".equals(tableField.value()) || "updateTime".equals(field.getName())) {
|
|
|
+ RemoveParam.updateTimeMap.put(tableName, true);
|
|
|
+ } else if ("update_user".equals(tableField.value()) || "updateUser".equals(field.getName())) {
|
|
|
+ RemoveParam.updateUserMap.put(tableName, true);
|
|
|
}
|
|
|
- } catch (ClassNotFoundException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|