mirror of
https://github.com/dataease/dataease.git
synced 2026-05-23 22:08:34 +08:00
fix: 数据源某条记录不包含某个字段时,置空
This commit is contained in:
@@ -446,23 +446,34 @@ public class ApiUtils {
|
||||
return response;
|
||||
}
|
||||
|
||||
private static void previewNum(List<Map<String, Object>> field) {
|
||||
for (Map<String, Object> stringObjectMap : field) {
|
||||
private static void previewNum(List<Map<String, Object>> fields, String response) {
|
||||
int previewNum = 100;
|
||||
for (Map<String, Object> field : fields) {
|
||||
JSONArray newArray = new JSONArray();
|
||||
if (stringObjectMap.get("value") != null) {
|
||||
try {
|
||||
TypeReference<JSONArray> listTypeReference = new TypeReference<JSONArray>() {
|
||||
};
|
||||
JSONArray array = objectMapper.readValue(stringObjectMap.get("value").toString(), listTypeReference);
|
||||
if (array.size() > 100) {
|
||||
for (int i = 0; i < Math.min(100, array.size()); i++) {
|
||||
newArray.add(array.get(i));
|
||||
if (field.get("value") != null) {
|
||||
Object object = JsonPath.using(jsonPathConf).parse(response).read(field.get("jsonPath").toString());
|
||||
int i = 0;
|
||||
if (object instanceof List) {
|
||||
for (Object o : (List<String>) object) {
|
||||
if (Objects.isNull(o)) {
|
||||
newArray.add("");
|
||||
} else {
|
||||
newArray.add(o.toString());
|
||||
}
|
||||
i++;
|
||||
if (i >= previewNum) {
|
||||
break;
|
||||
}
|
||||
stringObjectMap.put("value", newArray);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
} else {
|
||||
if (object != null) {
|
||||
newArray.add(object.toString());
|
||||
}
|
||||
}
|
||||
field.put("value", newArray);
|
||||
} else {
|
||||
List<Map<String, Object>> childrenFields = (List<Map<String, Object>>) field.get("children");
|
||||
previewNum(childrenFields, response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -505,7 +516,7 @@ public class ApiUtils {
|
||||
rootPath = "$";
|
||||
handleStr(apiDefinition, response, fields, rootPath);
|
||||
}
|
||||
previewNum(fields);
|
||||
previewNum(fields, response);
|
||||
apiDefinition.setJsonFields(fields);
|
||||
return apiDefinition;
|
||||
} else {
|
||||
@@ -552,7 +563,6 @@ public class ApiUtils {
|
||||
};
|
||||
array = objectMapper.readValue(field.get("value").toString(), listTypeReference);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
DEException.throwException(e);
|
||||
}
|
||||
array.add(Optional.ofNullable(data.get(field.get("originName"))).orElse("").toString().replaceAll("\n", " ").replaceAll("\r", " "));
|
||||
|
||||
Reference in New Issue
Block a user