opts: 嵌套json

feihu.wang
This commit is contained in:
feihu.wang
2022-05-11 20:56:09 +08:00
parent 5a5e0de414
commit c086a46d76
2 changed files with 22 additions and 8 deletions

View File

@@ -83,13 +83,11 @@ public class ActivationApiController {
if (StringUtils.isNotEmpty(pt.getType()) && pt.getType().equals("JSON")) {
//load http request data
JsonNode json = preItem.getConfigJson();
List<DataColumnInfo> children = new ArrayList<>();
extractMetaColumn(ds, preItem, json.toString(), children);
extractMetaColumn(ds, preItem, json.toString());
} else if (StringUtils.isNotEmpty(pt.getType())) {
ds.addChildren(preItem.getLabel(), preItem.getDestField(), pt.getType());
} else {
List<DataColumnInfo> children = new ArrayList<>();
extractMetaColumn(ds, preItem, pt.getMeta(), children);
extractMetaColumn(ds, preItem, pt.getMeta());
}
}
list.add(ds);
@@ -163,14 +161,23 @@ public class ActivationApiController {
return activationService.updateOrder(activationId,ruleOrder);
}
private void extractMetaColumn(DataColumnInfo ds, PreItemVO preItem, String jsonStr, List<DataColumnInfo> children) {
JSONArray array = JSONArray.parseArray(jsonStr);
private void extractMetaColumn(DataColumnInfo ds, PreItemVO preItem, String jsonStr) {
JSONArray jsonArray = JSONArray.parseArray(jsonStr);
List<DataColumnInfo> children = getColumnInfos(jsonArray);
ds.addChildren(preItem.getLabel(), preItem.getDestField(), children);
}
private static List<DataColumnInfo> getColumnInfos(JSONArray array) {
if(array == null){
return null;
}
List<DataColumnInfo> children = new ArrayList<>();
for (int i = 0; i < array.size(); i++) {
JSONObject obj = array.getJSONObject(i);
children.add(new DataColumnInfo(obj.getString("title"), obj.getString("column"), obj
.getString("type")));
.getString("type"), getColumnInfos((JSONArray)obj.get("children"))));
}
ds.addChildren(preItem.getLabel(), preItem.getDestField(), children);
return children;
}
@PostMapping("/disable/{activationId}")

View File

@@ -37,6 +37,13 @@ public class DataColumnInfo {
this.children = children;
}
public DataColumnInfo(String label, String value, String type, List<DataColumnInfo> children) {
this.label = label;
this.value = value;
this.type = type;
this.children = children;
}
public String getLabel() {
return label;
}