|
12 | 12 |
|
13 | 13 | package com.tinyengine.it.common.utils; |
14 | 14 |
|
| 15 | +import cn.hutool.core.exceptions.UtilException; |
| 16 | +import cn.hutool.core.util.ReflectUtil; |
15 | 17 | import com.tinyengine.it.model.dto.SchemaConfig; |
16 | 18 |
|
17 | 19 | import lombok.extern.slf4j.Slf4j; |
18 | 20 |
|
19 | | -import java.lang.reflect.InvocationTargetException; |
| 21 | +import java.lang.reflect.Method; |
20 | 22 | import java.text.ParseException; |
21 | 23 | import java.text.SimpleDateFormat; |
22 | 24 | import java.util.Date; |
@@ -148,12 +150,15 @@ protected Map<String, Object> formatFields(Map<String, Object> data, Map<String, |
148 | 150 | String key = entry.getKey(); |
149 | 151 | String funcName = entry.getValue(); |
150 | 152 | 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()); |
157 | 162 | } |
158 | 163 | } |
159 | 164 | return formattedData; |
@@ -248,11 +253,14 @@ public String toRootElement(Object isBody) { |
248 | 253 | * @return the string |
249 | 254 | */ |
250 | 255 | // group名称转换 |
251 | | - public String toGroupName(String group) { |
| 256 | + public String toGroupName(Object group) { |
| 257 | + if (group == null) { |
| 258 | + return ""; |
| 259 | + } |
252 | 260 | // 调整一下group命名 |
253 | | - if (GROUPS.contains(group)) { |
| 261 | + if (GROUPS.contains(group.toString())) { |
254 | 262 | return group + "Pages"; |
255 | 263 | } |
256 | | - return group; |
| 264 | + return group.toString(); |
257 | 265 | } |
258 | 266 | } |
0 commit comments