Commit b4d5d1f0 authored by 邢磊's avatar 邢磊

*)修改部分数据从行数据获取,减少后端请求

parent 998ca368
...@@ -62,29 +62,25 @@ public class DPSubServiceImpl { ...@@ -62,29 +62,25 @@ public class DPSubServiceImpl {
JSONArray tabs = result.getJSONArray("tabs"); JSONArray tabs = result.getJSONArray("tabs");
JSONObject content = result.getJSONObject("content"); JSONObject content = result.getJSONObject("content");
tabs.stream().forEach(x -> { tabs.stream().forEach(x -> {
this.buildContent(content, (JSONObject) x); this.buildContent(content, (JSONObject) x, param);
}); });
return result; return result;
} }
public void buildContent(JSONObject content, JSONObject tab) { public void buildContent(JSONObject content, JSONObject tab, Map<String, Object> param) {
Long formSeq = tab.getLong("formSeq"); Long formSeq = tab.getLong("formSeq");
Object resultConvert = JsonValueUtils.getValueByKey(tab, "dataConfig", "dataConfig.resultConvert"); Object resultConvert = JsonValueUtils.getValueByKey(tab, "dataConfig", "dataConfig.resultConvert");
Object api = JsonValueUtils.getValueByKey(tab, "dataConfig", "dataConfig.api"); Object api = JsonValueUtils.getValueByKey(tab, "dataConfig", "dataConfig.api");
Object columnWidth = JsonValueUtils.getValueByKey(tab, "dataConfig", "dataConfig.columnWidth"); Object columnWidth = JsonValueUtils.getValueByKey(tab, "dataConfig", "dataConfig.columnWidth");
tab.put("param", param);
JSONObject map = content.getJSONObject(tab.getString("key")); JSONObject map = content.getJSONObject(tab.getString("key"));
JSONObject apiResult = new JSONObject(); Object apiResult = null;
JSONArray apiArrayResult = new JSONArray();
if (!ValidationUtil.isEmpty(api)) { if (!ValidationUtil.isEmpty(api)) {
ResponseModel responseModel = this.getApiResult((JSONObject) api, !ValidationUtil.isEmpty(resultConvert) ? resultConvert.toString() : null); ResponseModel responseModel = this.getApiResult((JSONObject) api, !ValidationUtil.isEmpty(resultConvert) ? resultConvert.toString() : null);
if (!ValidationUtil.isEmpty(responseModel.getResult())) { if (!ValidationUtil.isEmpty(responseModel.getResult())) {
if (responseModel.getResult() instanceof JSONObject){ apiResult = responseModel.getResult();
apiResult = JSONObject.parseObject(responseModel.getResult().toString());
} else {
apiArrayResult = JSONArray.parseArray(responseModel.getResult().toString());
}
} }
} }
...@@ -111,9 +107,9 @@ public class DPSubServiceImpl { ...@@ -111,9 +107,9 @@ public class DPSubServiceImpl {
List<Object> mergedArray = mergedList(yObj.getJSONArray("children")); List<Object> mergedArray = mergedList(yObj.getJSONArray("children"));
// 第一组去除标题 // 第一组去除标题
if (i == 0 || ValidationUtil.isEmpty(map.get("datas"))) { if (i == 0 || ValidationUtil.isEmpty(map.get("datas"))) {
this.buildContentData(map, mergedArray, apiResult, matinfo); this.buildContentData(tab, map, mergedArray, apiResult, matinfo);
} else { } else {
this.buildSubContentData(map, i, yObj, mergedArray, apiResult, matinfo); this.buildSubContentData(tab, map, i, yObj, mergedArray, apiResult, matinfo);
} }
} else if ("subForm".equals(yObj.get("componentKey"))) { // 子表单 } else if ("subForm".equals(yObj.get("componentKey"))) { // 子表单
this.buildSubFormData(map, i, yObj, apiResult); this.buildSubFormData(map, i, yObj, apiResult);
...@@ -136,18 +132,18 @@ public class DPSubServiceImpl { ...@@ -136,18 +132,18 @@ public class DPSubServiceImpl {
} }
} }
if (!ValidationUtil.isEmpty(matinfo.getJSONArray("datas"))){ if (!ValidationUtil.isEmpty(matinfo.getJSONArray("datas"))) {
matinfo.put("columns", map.get("columns")); matinfo.put("columns", map.get("columns"));
map.getJSONArray("subs").add(matinfo); map.getJSONArray("subs").add(matinfo);
} }
} else { } else {
if (ValidationUtil.isEmpty(map)) { if (ValidationUtil.isEmpty(map)) {
content.put(tab.getString("key"), apiArrayResult); content.put(tab.getString("key"), apiResult);
} }
} }
} }
private JSONArray processShowHideRules(JSONArray children, Object showHideRules, JSONObject apiResult) { private JSONArray processShowHideRules(JSONArray children, Object showHideRules, Object apiResult) {
if (!ValidationUtil.isEmpty(showHideRules)) { if (!ValidationUtil.isEmpty(showHideRules)) {
((JSONArray) showHideRules).stream().forEach(x -> { ((JSONArray) showHideRules).stream().forEach(x -> {
JSONObject xObj = (JSONObject) x; JSONObject xObj = (JSONObject) x;
...@@ -291,13 +287,14 @@ public class DPSubServiceImpl { ...@@ -291,13 +287,14 @@ public class DPSubServiceImpl {
return mergedArray; return mergedArray;
} }
public JSONObject buildContentData(JSONObject map, List<Object> mergedArray, JSONObject apiResult, JSONObject matinfo) { public JSONObject buildContentData(JSONObject tab, JSONObject map, List<Object> mergedArray, Object apiResult, JSONObject matinfo) {
JSONObject result = JSONObject.parseObject(apiResult.toString());
JSONArray datas = new JSONArray(); JSONArray datas = new JSONArray();
// 处理二维码 // 处理二维码
mergedArray.stream().filter(x -> "QRCode".equals(JsonValueUtils.getValueByKey(x, "componentKey", null))).findFirst().ifPresent(x -> { mergedArray.stream().filter(x -> "QRCode".equals(JsonValueUtils.getValueByKey(x, "componentKey", null))).findFirst().ifPresent(x -> {
JSONObject qrcode = map.getJSONObject("qrcode"); JSONObject qrcode = map.getJSONObject("qrcode");
String problemTime = apiResult.getString("problemTime"); String problemTime = result.getString("problemTime");
String problemStatus = apiResult.getString("problemStatus"); String problemStatus = result.getString("problemStatus");
String color = null; String color = null;
if (!ValidationUtil.isEmpty(problemTime)) { if (!ValidationUtil.isEmpty(problemTime)) {
try { try {
...@@ -312,7 +309,7 @@ public class DPSubServiceImpl { ...@@ -312,7 +309,7 @@ public class DPSubServiceImpl {
} else if ("异常".equals(problemStatus)) { } else if ("异常".equals(problemStatus)) {
color = "red"; color = "red";
} }
qrcode.put("value", !ValidationUtil.isEmpty(apiResult.get("useCode")) ? apiResult.get("useCode") : apiResult.get("USE_ORG_CODE")); qrcode.put("value", !ValidationUtil.isEmpty(result.get("useCode")) ? result.get("useCode") : result.get("USE_ORG_CODE"));
qrcode.put("status", problemStatus); qrcode.put("status", problemStatus);
qrcode.put("color", color); qrcode.put("color", color);
}); });
...@@ -322,14 +319,14 @@ public class DPSubServiceImpl { ...@@ -322,14 +319,14 @@ public class DPSubServiceImpl {
mergedArray.stream().forEach(x -> { mergedArray.stream().forEach(x -> {
Object fieldKey = JsonValueUtils.getValueByKey(x, "visualParams", "visualParams.fieldKey"); Object fieldKey = JsonValueUtils.getValueByKey(x, "visualParams", "visualParams.fieldKey");
if (!ValidationUtil.isEmpty(fieldKey)) { if (!ValidationUtil.isEmpty(fieldKey)) {
this.processWidgets(datas, x, fieldKey.toString(), apiResult, matinfo); this.processWidgets(tab, datas, x, fieldKey.toString(), result, matinfo);
} }
}); });
map.put("datas", datas); map.put("datas", datas);
return map; return map;
} }
public JSONObject buildSubContentData(JSONObject map, int i, JSONObject yObj, List<Object> mergedArray, JSONObject apiResult, JSONObject matinfo) { public JSONObject buildSubContentData(JSONObject tab, JSONObject map, int i, JSONObject yObj, List<Object> mergedArray, Object apiResult, JSONObject matinfo) {
JSONArray subs = map.getJSONArray("subs"); JSONArray subs = map.getJSONArray("subs");
JSONArray children = yObj.getJSONArray("children"); JSONArray children = yObj.getJSONArray("children");
List<Object> columnsArray = children.stream().filter(x -> { List<Object> columnsArray = children.stream().filter(x -> {
...@@ -347,7 +344,7 @@ public class DPSubServiceImpl { ...@@ -347,7 +344,7 @@ public class DPSubServiceImpl {
mergedArray.stream().forEach(x -> { mergedArray.stream().forEach(x -> {
Object fieldKey = JsonValueUtils.getValueByKey(x, "visualParams", "visualParams.fieldKey"); Object fieldKey = JsonValueUtils.getValueByKey(x, "visualParams", "visualParams.fieldKey");
if (!ValidationUtil.isEmpty(fieldKey)) { if (!ValidationUtil.isEmpty(fieldKey)) {
this.processWidgets(datas, x, fieldKey.toString(), apiResult, matinfo); this.processWidgets(tab, datas, x, fieldKey.toString(), JSONObject.parseObject(apiResult.toString()), matinfo);
subObj.put("datas", datas); subObj.put("datas", datas);
} }
}); });
...@@ -364,7 +361,7 @@ public class DPSubServiceImpl { ...@@ -364,7 +361,7 @@ public class DPSubServiceImpl {
* @param apiResult * @param apiResult
* @return * @return
*/ */
public JSONArray processWidgets(JSONArray datas, Object x, String fieldKey, JSONObject apiResult, JSONObject matinfo) { public JSONArray processWidgets(JSONObject tab, JSONArray datas, Object x, String fieldKey, JSONObject apiResult, JSONObject matinfo) {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
JSONObject xObj = (JSONObject) x; JSONObject xObj = (JSONObject) x;
...@@ -372,6 +369,15 @@ public class DPSubServiceImpl { ...@@ -372,6 +369,15 @@ public class DPSubServiceImpl {
jsonObject.put("label", visualParams.getString("label")); jsonObject.put("label", visualParams.getString("label"));
Object value = apiResult.get(fieldKey); Object value = apiResult.get(fieldKey);
Object paramFieldKeys = JsonValueUtils.getValueByKey(tab, "dataConfig", "dataConfig.paramFieldKeys");
JSONObject param = tab.getJSONObject("param");
jsonObject.put("type", "text");
jsonObject.put("value", value);
if (!ValidationUtil.isEmpty(paramFieldKeys)){
if (((JSONArray) paramFieldKeys).contains(fieldKey)){
jsonObject.put("value", param.getString(fieldKey));
}
} else {
if ("upload".equals(xObj.getString("componentKey"))) { if ("upload".equals(xObj.getString("componentKey"))) {
jsonObject.put("type", "img"); jsonObject.put("type", "img");
if (!ValidationUtil.isEmpty(value)) { if (!ValidationUtil.isEmpty(value)) {
...@@ -383,55 +389,45 @@ public class DPSubServiceImpl { ...@@ -383,55 +389,45 @@ public class DPSubServiceImpl {
JSONObject attachmentUploadDatasObj = new JSONObject(); JSONObject attachmentUploadDatasObj = new JSONObject();
attachmentUploadDatasObj.put("value", value); attachmentUploadDatasObj.put("value", value);
String accept = JsonValueUtils.getValueByKey(xObj, "visualParams", "visualParams.accept").toString(); String accept = JsonValueUtils.getValueByKey(xObj, "visualParams", "visualParams.accept").toString();
if (accept.contains("doc") || accept.contains("docx") || accept.contains("pdf") || accept.contains("xls") || accept.contains("xlsx")){ if (accept.contains("doc") || accept.contains("docx") || accept.contains("pdf") || accept.contains("xls") || accept.contains("xlsx")) {
attachmentUploadDatasObj.put("label", "附件"); attachmentUploadDatasObj.put("label", "附件");
attachmentUploadDatasObj.put("type", "file"); attachmentUploadDatasObj.put("type", "file");
} else if(accept.contains("png") || accept.contains("img")){ } else if (accept.contains("png") || accept.contains("img")) {
attachmentUploadDatasObj.put("label", "证照"); attachmentUploadDatasObj.put("label", "证照");
attachmentUploadDatasObj.put("type", "img"); attachmentUploadDatasObj.put("type", "img");
} else if(accept.contains("mp4") || accept.contains("flv")){ } else if (accept.contains("mp4") || accept.contains("flv")) {
attachmentUploadDatasObj.put("label", "视频"); attachmentUploadDatasObj.put("label", "视频");
attachmentUploadDatasObj.put("type", "video"); attachmentUploadDatasObj.put("type", "video");
} }
attachmentUploadDatas.add(attachmentUploadDatasObj); attachmentUploadDatas.add(attachmentUploadDatasObj);
} }
} else if ("lnglatSelect".equals(xObj.getString("componentKey"))) { } else if ("lnglatSelect".equals(xObj.getString("componentKey"))) {
jsonObject.put("type", "text");
if (!ValidationUtil.isEmpty(value) && value instanceof JSONObject) { if (!ValidationUtil.isEmpty(value) && value instanceof JSONObject) {
JSONObject lnglatSelect = (JSONObject) value; JSONObject lnglatSelect = (JSONObject) value;
jsonObject.put("value", String.format("[%s,%s]", lnglatSelect.getString("latitude"), lnglatSelect.getString("longitude"))); jsonObject.put("value", (!ValidationUtil.isEmpty(lnglatSelect.getString("latitude")) && !ValidationUtil.isEmpty(lnglatSelect.getString("longitude")))
} else { ? String.format("[%s,%s]", lnglatSelect.getString("latitude"), lnglatSelect.getString("longitude")) : lnglatSelect.getString("address"));
jsonObject.put("value", value);
} }
} else if ("checkbox".equals(xObj.getString("componentKey"))) { } else if ("checkbox".equals(xObj.getString("componentKey"))) {
jsonObject.put("type", "text");
ResponseModel checkboxResult = this.getApiResult(visualParams.getJSONObject("api"), null); ResponseModel checkboxResult = this.getApiResult(visualParams.getJSONObject("api"), null);
if (!ValidationUtil.isEmpty(checkboxResult) && checkboxResult.getStatus() == 200 && !ValidationUtil.isEmpty(value)) { if (!ValidationUtil.isEmpty(checkboxResult) && checkboxResult.getStatus() == 200 && !ValidationUtil.isEmpty(value)) {
List<Object> collect = ((JSONArray) checkboxResult.getResult()).stream().filter(y -> ((JSONArray) value).contains(JsonValueUtils.getValueByKey(y, "valueKey", "valueKey"))).collect(Collectors.toList()); List<Object> collect = ((JSONArray) checkboxResult.getResult()).stream().filter(y -> ((JSONArray) value).contains(JsonValueUtils.getValueByKey(y, "valueKey", "valueKey"))).collect(Collectors.toList());
String nameKey = collect.stream().map(item -> ((JSONObject) item).getString("nameKey")).collect(Collectors.joining("、")); String nameKey = collect.stream().map(item -> ((JSONObject) item).getString("nameKey")).collect(Collectors.joining("、"));
jsonObject.put("value", nameKey); jsonObject.put("value", nameKey);
} else {
jsonObject.put("value", value);
} }
} else if ("select".equals(xObj.getString("componentKey"))) { } else if ("select".equals(xObj.getString("componentKey"))) {
jsonObject.put("type", "text");
ResponseModel selectResult = this.getApiResult(visualParams.getJSONObject("api"), null); ResponseModel selectResult = this.getApiResult(visualParams.getJSONObject("api"), null);
if (!ValidationUtil.isEmpty(selectResult) && selectResult.getStatus() == 200 && !ValidationUtil.isEmpty(value)) { if (!ValidationUtil.isEmpty(selectResult) && selectResult.getStatus() == 200 && !ValidationUtil.isEmpty(value)) {
((JSONArray) selectResult.getResult()).stream().filter(y -> value.equals(JsonValueUtils.getValueByKey(y, "valueKey", "valueKey"))).findFirst().ifPresent(z -> { ((JSONArray) selectResult.getResult()).stream().filter(y -> value.equals(JsonValueUtils.getValueByKey(y, "valueKey", "valueKey"))).findFirst().ifPresent(z -> {
jsonObject.put("value", ((JSONObject) z).getString("nameKey")); jsonObject.put("value", ((JSONObject) z).getString("nameKey"));
}); });
} else {
jsonObject.put("value", value);
} }
} else { }
jsonObject.put("type", "text");
jsonObject.put("value", value);
} }
datas.add(jsonObject); datas.add(jsonObject);
return datas; return datas;
} }
public JSONObject buildSubFormData(JSONObject map, int i, JSONObject yObj, JSONObject apiResult) { public JSONObject buildSubFormData(JSONObject map, int i, JSONObject yObj, Object apiResult) {
JSONArray subs = map.getJSONArray("subs"); JSONArray subs = map.getJSONArray("subs");
JSONArray children = yObj.getJSONArray("children"); JSONArray children = yObj.getJSONArray("children");
...@@ -458,7 +454,8 @@ public class DPSubServiceImpl { ...@@ -458,7 +454,8 @@ public class DPSubServiceImpl {
subObj.put("rowKey", "key"); subObj.put("rowKey", "key");
subObj.put("showPage", false); subObj.put("showPage", false);
subObj.put("columns", columns); subObj.put("columns", columns);
subObj.put("dataList", apiResult.get(JsonValueUtils.getValueByKey(yObj, "visualParams", "visualParams.fieldKey"))); JSONObject result = JSONObject.parseObject(apiResult.toString());
subObj.put("dataList", result.get(JsonValueUtils.getValueByKey(yObj, "visualParams", "visualParams.fieldKey")));
subs.add(subObj); subs.add(subObj);
return map; return map;
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
"ruleData": { "ruleData": {
"responseSuccess": "data.result.equipInfo" "responseSuccess": "data.result.equipInfo"
} }
} },
"paramFieldKeys": ["EQU_LIST","EQU_CATEGORY","EQU_DEFINE"]
} }
}, },
{ {
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
"ruleData": { "ruleData": {
"responseSuccess": "data.result.equipInfo" "responseSuccess": "data.result.equipInfo"
} }
} },
"paramFieldKeys": ["EQU_LIST","EQU_CATEGORY","EQU_DEFINE"]
} }
}, },
{ {
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
"ruleData": { "ruleData": {
"responseSuccess": "data.result.equipInfo" "responseSuccess": "data.result.equipInfo"
} }
} },
"paramFieldKeys": ["EQU_LIST","EQU_CATEGORY","EQU_DEFINE"]
} }
}, },
{ {
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
"ruleData": { "ruleData": {
"responseSuccess": "data.result.equipInfo" "responseSuccess": "data.result.equipInfo"
} }
} },
"paramFieldKeys": ["EQU_LIST","EQU_CATEGORY","EQU_DEFINE"]
} }
}, },
{ {
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
"ruleData": { "ruleData": {
"responseSuccess": "data.result.equipInfo" "responseSuccess": "data.result.equipInfo"
} }
} },
"paramFieldKeys": ["EQU_LIST","EQU_CATEGORY","EQU_DEFINE"]
} }
}, },
{ {
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
"ruleData": { "ruleData": {
"responseSuccess": "data.result.equipInfo" "responseSuccess": "data.result.equipInfo"
} }
} },
"paramFieldKeys": ["EQU_LIST","EQU_CATEGORY","EQU_DEFINE"]
} }
}, },
{ {
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
"ruleData": { "ruleData": {
"responseSuccess": "data.result.equipInfo" "responseSuccess": "data.result.equipInfo"
} }
} },
"paramFieldKeys": ["EQU_LIST","EQU_CATEGORY","EQU_DEFINE"]
} }
}, },
{ {
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
"ruleData": { "ruleData": {
"responseSuccess": "data.result.equipInfo" "responseSuccess": "data.result.equipInfo"
} }
} },
"paramFieldKeys": ["EQU_LIST","EQU_CATEGORY","EQU_DEFINE"]
} }
}, },
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment