|
19 | 19 | package datart.server.service.impl; |
20 | 20 |
|
21 | 21 | import com.alibaba.fastjson.JSON; |
| 22 | +import com.alibaba.fastjson.JSONArray; |
22 | 23 | import com.alibaba.fastjson.JSONObject; |
23 | 24 | import com.fasterxml.jackson.databind.DeserializationFeature; |
24 | 25 | import com.fasterxml.jackson.databind.ObjectMapper; |
@@ -412,9 +413,33 @@ private Map<String, Column> parseSchema(String model) { |
412 | 413 | } |
413 | 414 |
|
414 | 415 | JSONObject jsonObject = JSON.parseObject(model); |
415 | | - for (String key : jsonObject.keySet()) { |
416 | | - ValueType type = ValueType.valueOf(jsonObject.getJSONObject(key).getString("type")); |
417 | | - schema.put(key, new Column(key, type)); |
| 416 | + try { |
| 417 | + if (jsonObject.containsKey("hierarchy")) { |
| 418 | + jsonObject = jsonObject.getJSONObject("hierarchy"); |
| 419 | + for (String key : jsonObject.keySet()) { |
| 420 | + JSONObject item = jsonObject.getJSONObject(key); |
| 421 | + if (item.containsKey("children")) { |
| 422 | + JSONArray children = item.getJSONArray("children"); |
| 423 | + if (children != null && children.size() > 0) { |
| 424 | + for (int i = 0; i < children.size(); i++) { |
| 425 | + JSONObject child = children.getJSONObject(i); |
| 426 | + schema.put(child.getString("name"), new Column(child.getString("name"), ValueType.valueOf(child.getString("type")))); |
| 427 | + } |
| 428 | + } |
| 429 | + } else { |
| 430 | + schema.put(key, new Column(item.getString("name"), ValueType.valueOf(item.getString("type")))); |
| 431 | + } |
| 432 | + } |
| 433 | + } else { |
| 434 | + // 兼容1.0.0-beta.1以前的版本 |
| 435 | + jsonObject = jsonObject.getJSONObject("columns"); |
| 436 | + for (String key : jsonObject.keySet()) { |
| 437 | + ValueType type = ValueType.valueOf(jsonObject.getJSONObject(key).getString("type")); |
| 438 | + schema.put(key, new Column(key, type)); |
| 439 | + } |
| 440 | + } |
| 441 | + } catch (Exception e) { |
| 442 | + log.error("view model parse error", e); |
418 | 443 | } |
419 | 444 | return schema; |
420 | 445 | } |
|
0 commit comments