diff --git a/kernel-d-scanner/scanner-api/src/main/java/cn/stylefeng/roses/kernel/scanner/api/factory/ClassMetaFactory.java b/kernel-d-scanner/scanner-api/src/main/java/cn/stylefeng/roses/kernel/scanner/api/factory/ClassMetaFactory.java index c95f747ef..8495912f3 100644 --- a/kernel-d-scanner/scanner-api/src/main/java/cn/stylefeng/roses/kernel/scanner/api/factory/ClassMetaFactory.java +++ b/kernel-d-scanner/scanner-api/src/main/java/cn/stylefeng/roses/kernel/scanner/api/factory/ClassMetaFactory.java @@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j; import java.lang.reflect.Field; import java.lang.reflect.Type; import java.util.LinkedHashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -41,7 +42,7 @@ public class ClassMetaFactory { // 1. 如果是基础类型,直接渲染结果 if (FieldTypeEnum.BASIC.equals(classParseResult.getFieldTypeEnum())) { - return MetadataCreateFactory.createBaseClassMetadata((Class) type, uuid); + return MetadataCreateFactory.createBaseClassMetadata((Class) type, classParseResult.getFieldTypeEnum(), uuid); } // 2. 如果是数组类型,则先创建一个数组类型的元数据,再获取数组具体的类型,再继续解析数组的类型 @@ -60,7 +61,7 @@ public class ClassMetaFactory { Class clazz = (Class) type; // 创建对象的基础信息 - FieldMetadata currentClassMetaData = MetadataCreateFactory.createBaseClassMetadata((Class) type, uuid); + FieldMetadata currentClassMetaData = MetadataCreateFactory.createBaseClassMetadata((Class) type, classParseResult.getFieldTypeEnum(), uuid); // 如果被初始化过,则不继续进行解析 if (MetadataContext.ensureFieldClassHaveParse(uuid, clazz)) { @@ -107,12 +108,12 @@ public class ClassMetaFactory { // 6. Map的类型 else if (FieldTypeEnum.MAP.equals(classParseResult.getFieldTypeEnum())) { - return MetadataCreateFactory.createBaseClassMetadata(Map.class, uuid); + return MetadataCreateFactory.createBaseClassMetadata(Map.class, FieldTypeEnum.MAP, uuid); } // 7. 其他情况,返回最基本的数据 else { - return MetadataCreateFactory.createBaseClassMetadata(String.class, uuid); + return MetadataCreateFactory.createBaseClassMetadata(String.class, FieldTypeEnum.BASIC, uuid); } } @@ -124,7 +125,7 @@ public class ClassMetaFactory { */ private static FieldMetadata createArrayMetaDateResult(String uuid, ClassParseResult classParseResult) { // 先创建一个数组类型的元数据 - FieldMetadata arrayItemMetadata = MetadataCreateFactory.createArrayItemMetadata(uuid); + FieldMetadata arrayItemMetadata = MetadataCreateFactory.createBaseClassMetadata(List.class, FieldTypeEnum.COLLECTION, uuid); // 获取数组元素的类型 Type genericType = classParseResult.getGenericType(); diff --git a/kernel-d-scanner/scanner-api/src/main/java/cn/stylefeng/roses/kernel/scanner/api/factory/MetadataCreateFactory.java b/kernel-d-scanner/scanner-api/src/main/java/cn/stylefeng/roses/kernel/scanner/api/factory/MetadataCreateFactory.java index 5ece69525..7746a46ff 100644 --- a/kernel-d-scanner/scanner-api/src/main/java/cn/stylefeng/roses/kernel/scanner/api/factory/MetadataCreateFactory.java +++ b/kernel-d-scanner/scanner-api/src/main/java/cn/stylefeng/roses/kernel/scanner/api/factory/MetadataCreateFactory.java @@ -28,7 +28,7 @@ public class MetadataCreateFactory { * @author fengshuonan * @since 2024/8/7 9:48 */ - public static FieldMetadata createBaseClassMetadata(Class clazz, String uuid) { + public static FieldMetadata createBaseClassMetadata(Class clazz, FieldTypeEnum fieldTypeEnum, String uuid) { FieldMetadata fieldMetadataItem = new FieldMetadata(); // 设置唯一id @@ -50,50 +50,7 @@ public class MetadataCreateFactory { } // 设置字段类型,基本类型 - fieldMetadataItem.setFieldType(FieldTypeEnum.BASIC.getCode()); - - // 设置当前context构造的参数类型 - ParamTypeEnum paramTypeMetadata = MetadataContext.getParamTypeMetadata(uuid); - if (paramTypeMetadata != null) { - fieldMetadataItem.setRequestParamType(paramTypeMetadata.getCode()); - } - - // 设置字段 - return fieldMetadataItem; - } - - /** - * 创建一个数组类型的元数据 - * - * @author fengshuonan - * @since 2024/8/7 9:53 - */ - public static FieldMetadata createArrayItemMetadata(String uuid) { - FieldMetadata fieldMetadataItem = new FieldMetadata(); - - // 设置唯一id - fieldMetadataItem.setMetadataId(IdUtil.fastSimpleUUID()); - - // 设置字段中文含义 - fieldMetadataItem.setChineseName("数组元素"); - - // 设置字段类类型 - fieldMetadataItem.setFieldClassType("String"); - - // 设置类的全路径 - fieldMetadataItem.setFieldClassPath("java.lang.String"); - - // 设置字段名称 - fieldMetadataItem.setFieldName("arrayItem"); - - // 根据uuid获取参数的名称 - String paramName = MetadataContext.getParamName(uuid); - if (StrUtil.isNotBlank(paramName)) { - fieldMetadataItem.setFieldName(paramName); - } - - // 设置数组类型 - fieldMetadataItem.setFieldType(FieldTypeEnum.ARRAY.getCode()); + fieldMetadataItem.setFieldType(fieldTypeEnum.getCode()); // 设置当前context构造的参数类型 ParamTypeEnum paramTypeMetadata = MetadataContext.getParamTypeMetadata(uuid);