Skip to content

Commit 24cfb66

Browse files
authored
fix: Fix schema (#248)
1 parent 553f6af commit 24cfb66

File tree

1 file changed

+18
-10
lines changed
  • base/src/main/java/com/tinyengine/it/common/utils

1 file changed

+18
-10
lines changed

base/src/main/java/com/tinyengine/it/common/utils/Schema.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212

1313
package com.tinyengine.it.common.utils;
1414

15+
import cn.hutool.core.exceptions.UtilException;
16+
import cn.hutool.core.util.ReflectUtil;
1517
import com.tinyengine.it.model.dto.SchemaConfig;
1618

1719
import lombok.extern.slf4j.Slf4j;
1820

19-
import java.lang.reflect.InvocationTargetException;
21+
import java.lang.reflect.Method;
2022
import java.text.ParseException;
2123
import java.text.SimpleDateFormat;
2224
import java.util.Date;
@@ -148,12 +150,15 @@ protected Map<String, Object> formatFields(Map<String, Object> data, Map<String,
148150
String key = entry.getKey();
149151
String funcName = entry.getValue();
150152
try {
151-
// 使用反射调用相应的格式化方法
152-
java.lang.reflect.Method method = this.getClass().getMethod(funcName, Object.class);
153-
Object value = data.get(key);
154-
formattedData.put(key, method.invoke(this, value));
155-
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
156-
log.error(e.getMessage());
153+
Method method = ReflectUtil.getMethod(Schema.class, funcName, Object.class);
154+
if (method == null) {
155+
log.error("not found {} funcName from schema", funcName);
156+
continue;
157+
}
158+
159+
formattedData.put(key, ReflectUtil.invoke(this, method, data.get(key)));
160+
} catch (SecurityException | UtilException err) {
161+
log.error(err.getMessage());
157162
}
158163
}
159164
return formattedData;
@@ -248,11 +253,14 @@ public String toRootElement(Object isBody) {
248253
* @return the string
249254
*/
250255
// group名称转换
251-
public String toGroupName(String group) {
256+
public String toGroupName(Object group) {
257+
if (group == null) {
258+
return "";
259+
}
252260
// 调整一下group命名
253-
if (GROUPS.contains(group)) {
261+
if (GROUPS.contains(group.toString())) {
254262
return group + "Pages";
255263
}
256-
return group;
264+
return group.toString();
257265
}
258266
}

0 commit comments

Comments
 (0)