forked from github/dataease
fix(数据源): api 数据源校验问题
This commit is contained in:
parent
a2fe087ca1
commit
a8e816588a
@ -181,28 +181,28 @@ public class ApiProvider extends Provider {
|
|||||||
if (StringUtils.isEmpty(response)) {
|
if (StringUtils.isEmpty(response)) {
|
||||||
throw new Exception("该请求返回数据为空");
|
throw new Exception("该请求返回数据为空");
|
||||||
}
|
}
|
||||||
List<JSONObject> jsonFields = new ArrayList<>();
|
List<JSONObject> fields = new ArrayList<>();
|
||||||
String rootPath;
|
String rootPath;
|
||||||
if (response.startsWith("[")) {
|
if (response.startsWith("[")) {
|
||||||
rootPath = "$[*]";
|
rootPath = "$[*]";
|
||||||
JSONArray jsonArray = JSONObject.parseArray(response);
|
JSONArray jsonArray = JSONObject.parseArray(response);
|
||||||
for (Object o : jsonArray) {
|
for (Object o : jsonArray) {
|
||||||
handleStr(apiDefinition, o.toString(), jsonFields, rootPath);
|
handleStr(apiDefinition, o.toString(), fields, rootPath);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rootPath = "$";
|
rootPath = "$";
|
||||||
handleStr(apiDefinition, response, jsonFields, rootPath);
|
handleStr(apiDefinition, response, fields, rootPath);
|
||||||
}
|
}
|
||||||
apiDefinition.setJsonFields(jsonFields);
|
apiDefinition.setJsonFields(fields);
|
||||||
return apiDefinition;
|
return apiDefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static private void handleStr(ApiDefinition apiDefinition, String jsonStr, List<JSONObject> objects, String rootPath) {
|
static private void handleStr(ApiDefinition apiDefinition, String jsonStr, List<JSONObject> fields, String rootPath) {
|
||||||
if (jsonStr.startsWith("[")) {
|
if (jsonStr.startsWith("[")) {
|
||||||
JSONArray jsonArray = JSONObject.parseArray(jsonStr);
|
JSONArray jsonArray = JSONObject.parseArray(jsonStr);
|
||||||
for (Object o : jsonArray) {
|
for (Object o : jsonArray) {
|
||||||
handleStr(apiDefinition, o.toString(), objects, rootPath);
|
handleStr(apiDefinition, o.toString(), fields, rootPath);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
JSONObject jsonObject = JSONObject.parseObject(jsonStr);
|
JSONObject jsonObject = JSONObject.parseObject(jsonStr);
|
||||||
@ -213,12 +213,12 @@ public class ApiProvider extends Provider {
|
|||||||
JSONObject o = new JSONObject();
|
JSONObject o = new JSONObject();
|
||||||
JSONArray jsonArray = JSONObject.parseArray(jsonObject.getString(s));
|
JSONArray jsonArray = JSONObject.parseArray(jsonObject.getString(s));
|
||||||
try {
|
try {
|
||||||
List<JSONObject> children = new ArrayList<>();
|
List<JSONObject> childrenField = new ArrayList<>();
|
||||||
for (Object object: jsonArray) {
|
for (Object object: jsonArray) {
|
||||||
JSONObject.parseObject(object.toString());
|
JSONObject.parseObject(object.toString());
|
||||||
handleStr(apiDefinition, object.toString(), children, rootPath + "." + s + "[*]");
|
handleStr(apiDefinition, object.toString(), childrenField, rootPath + "." + s + "[*]");
|
||||||
}
|
}
|
||||||
o.put("children", children);
|
o.put("children", childrenField);
|
||||||
o.put("childrenDataType", "LIST");
|
o.put("childrenDataType", "LIST");
|
||||||
|
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
@ -228,8 +228,8 @@ public class ApiProvider extends Provider {
|
|||||||
}
|
}
|
||||||
o.put("jsonPath", rootPath + "." + s);
|
o.put("jsonPath", rootPath + "." + s);
|
||||||
setProperty(apiDefinition, o, s);
|
setProperty(apiDefinition, o, s);
|
||||||
if (!hasItem(apiDefinition, objects, o)) {
|
if (!hasItem(apiDefinition, fields, o)) {
|
||||||
objects.add(o);
|
fields.add(o);
|
||||||
}
|
}
|
||||||
} else if (StringUtils.isNotEmpty(value) && value.startsWith("{")) {
|
} else if (StringUtils.isNotEmpty(value) && value.startsWith("{")) {
|
||||||
List<JSONObject> children = new ArrayList<>();
|
List<JSONObject> children = new ArrayList<>();
|
||||||
@ -239,8 +239,8 @@ public class ApiProvider extends Provider {
|
|||||||
o.put("childrenDataType", "OBJECT");
|
o.put("childrenDataType", "OBJECT");
|
||||||
o.put("jsonPath", rootPath + "." + s);
|
o.put("jsonPath", rootPath + "." + s);
|
||||||
setProperty(apiDefinition, o, s);
|
setProperty(apiDefinition, o, s);
|
||||||
if (!hasItem(apiDefinition, objects, o)) {
|
if (!hasItem(apiDefinition, fields, o)) {
|
||||||
objects.add(o);
|
fields.add(o);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
JSONObject o = new JSONObject();
|
JSONObject o = new JSONObject();
|
||||||
@ -249,8 +249,8 @@ public class ApiProvider extends Provider {
|
|||||||
JSONArray array = new JSONArray();
|
JSONArray array = new JSONArray();
|
||||||
array.add(StringUtils.isNotEmpty(jsonObject.getString(s)) ? jsonObject.getString(s) : "");
|
array.add(StringUtils.isNotEmpty(jsonObject.getString(s)) ? jsonObject.getString(s) : "");
|
||||||
o.put("value", array);
|
o.put("value", array);
|
||||||
if (!hasItem(apiDefinition, objects, o)) {
|
if (!hasItem(apiDefinition, fields, o)) {
|
||||||
objects.add(o);
|
fields.add(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,12 +278,13 @@ public class ApiProvider extends Provider {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static private boolean hasItem(ApiDefinition apiDefinition, List<JSONObject> objects, JSONObject item) {
|
static private boolean hasItem(ApiDefinition apiDefinition, List<JSONObject> fields, JSONObject item) {
|
||||||
boolean has = false;
|
boolean has = false;
|
||||||
for (JSONObject object : objects) {
|
for (JSONObject field : fields) {
|
||||||
if (object.getString("jsonPath").equals(item.getString("jsonPath"))) {
|
if (field.getString("jsonPath").equals(item.getString("jsonPath"))) {
|
||||||
has = true;
|
has = true;
|
||||||
mergeValue(object, apiDefinition, item);
|
mergeField(field, item);
|
||||||
|
mergeValue(field, apiDefinition, item);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -292,6 +293,30 @@ public class ApiProvider extends Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void mergeField(JSONObject field, JSONObject item){
|
||||||
|
if(item.getJSONArray("children") != null ){
|
||||||
|
JSONArray itemChildren = item.getJSONArray("children");
|
||||||
|
JSONArray fieldChildren = field.getJSONArray("children");
|
||||||
|
if(fieldChildren == null){
|
||||||
|
fieldChildren = new JSONArray();
|
||||||
|
}
|
||||||
|
for (Object itemChild : itemChildren) {
|
||||||
|
boolean hasKey = false;
|
||||||
|
JSONObject itemChildObject = JSONObject.parseObject(itemChild.toString());
|
||||||
|
for (Object fieldChild : fieldChildren) {
|
||||||
|
JSONObject fieldChildObject = JSONObject.parseObject(fieldChild.toString());
|
||||||
|
if(itemChildObject.getString("jsonPath").equals(fieldChildObject.getString("jsonPath"))){
|
||||||
|
mergeField(fieldChildObject, itemChildObject);
|
||||||
|
hasKey = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!hasKey){
|
||||||
|
fieldChildren.add(itemChild);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void mergeValue(JSONObject object, ApiDefinition apiDefinition, JSONObject item) {
|
static void mergeValue(JSONObject object, ApiDefinition apiDefinition, JSONObject item) {
|
||||||
|
|
||||||
JSONArray array = object.getJSONArray("value");
|
JSONArray array = object.getJSONArray("value");
|
||||||
@ -346,7 +371,9 @@ public class ApiProvider extends Provider {
|
|||||||
if (object instanceof List) {
|
if (object instanceof List) {
|
||||||
datas = (List<String>) object;
|
datas = (List<String>) object;
|
||||||
} else {
|
} else {
|
||||||
datas.add((String) object);
|
if (object != null) {
|
||||||
|
datas.add(object.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
maxLenth = maxLenth > datas.size() ? maxLenth : datas.size();
|
maxLenth = maxLenth > datas.size() ? maxLenth : datas.size();
|
||||||
columnDataList.add(datas);
|
columnDataList.add(datas);
|
||||||
|
@ -478,7 +478,7 @@ export default {
|
|||||||
method(form).then(res => {
|
method(form).then(res => {
|
||||||
this.$success(i18n.t('commons.save_success'))
|
this.$success(i18n.t('commons.save_success'))
|
||||||
this.refreshType(form)
|
this.refreshType(form)
|
||||||
this.backToList()
|
// this.backToList()
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getSchema() {
|
getSchema() {
|
||||||
|
@ -267,6 +267,11 @@ export default {
|
|||||||
for (let index = 0; index < this.tData.length; index++) {
|
for (let index = 0; index < this.tData.length; index++) {
|
||||||
if (typeData[0].id === this.tData[index].id) {
|
if (typeData[0].id === this.tData[index].id) {
|
||||||
this.tData[index].children = typeData[0].children
|
this.tData[index].children = typeData[0].children
|
||||||
|
for (let i = 0; i < this.tData[index].children.length; i++) {
|
||||||
|
if(this.tData[index].children[i].id === datasource.id){
|
||||||
|
this.showInfo({data: this.tData[index].children[i]})
|
||||||
|
}
|
||||||
|
}
|
||||||
find = true
|
find = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user