|
@@ -1,61 +0,0 @@
|
|
|
-package org.thyy.emrquery.utils;
|
|
|
-
|
|
|
-import org.thyy.emrquery.entity.timeLimitConfig.CreateEditingRestrictions;
|
|
|
-
|
|
|
-import java.lang.reflect.Field;
|
|
|
-import java.util.Date;
|
|
|
-
|
|
|
-public class JavaToTypeScriptConverter {
|
|
|
-
|
|
|
- public static String convertType(Class<?> type) {
|
|
|
- if (type == Integer.class) {
|
|
|
- return "number | null";
|
|
|
- }
|
|
|
- if (type == Date.class) {
|
|
|
- return "date";
|
|
|
- }
|
|
|
- if (type == int.class) {
|
|
|
- return "number";
|
|
|
- } else if (type == String.class) {
|
|
|
- return "string";
|
|
|
- } else if (type == Boolean.class || type == boolean.class) {
|
|
|
- return "boolean";
|
|
|
- } else if (type == Double.class || type == double.class || type == Float.class || type == float.class) {
|
|
|
- return "number";
|
|
|
- } else if (type == Long.class || type == long.class) {
|
|
|
- return "bigint";
|
|
|
- } else {
|
|
|
- return type.getSimpleName();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static String generateTypeScriptDefinition(Class<?> clazz) {
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- sb.append("interface ").append(clazz.getSimpleName()).append(" {\n");
|
|
|
- Field[] fields = clazz.getDeclaredFields();
|
|
|
- for (Field field : fields) {
|
|
|
- sb.append(" /**\n");
|
|
|
- sb.append(" * ").append(field.getName()).append("\n");
|
|
|
- sb.append(" */\n");
|
|
|
-
|
|
|
- // 处理嵌套类型
|
|
|
- if (field.getType().isArray()) {
|
|
|
- Class<?> componentType = field.getType().getComponentType();
|
|
|
- sb.append(" ").append(field.getName()).append(": ").append(convertType(componentType)).append("[];\n");
|
|
|
- } else if (field.getType().isPrimitive() || field.getType().getPackage().getName().startsWith("java")) {
|
|
|
- sb.append(" ").append(field.getName()).append(": ").append(convertType(field.getType())).append(";\n");
|
|
|
- } else {
|
|
|
- sb.append(" ").append(field.getName()).append(": ").append(convertType(field.getType())).append(";\n");
|
|
|
- sb.append(generateTypeScriptDefinition(field.getType())); // 递归处理嵌套类型
|
|
|
- }
|
|
|
- }
|
|
|
- sb.append("}\n");
|
|
|
- return sb.toString();
|
|
|
- }
|
|
|
-
|
|
|
- public static void main(String[] args) {
|
|
|
- Class<?> clazz = CreateEditingRestrictions.class;
|
|
|
- String definition = generateTypeScriptDefinition(clazz);
|
|
|
- System.out.println(definition);
|
|
|
- }
|
|
|
-}
|