Commit b4d5d1f0 authored by 邢磊's avatar 邢磊

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

parent 998ca368
......@@ -62,29 +62,25 @@ public class DPSubServiceImpl {
JSONArray tabs = result.getJSONArray("tabs");
JSONObject content = result.getJSONObject("content");
tabs.stream().forEach(x -> {
this.buildContent(content, (JSONObject) x);
this.buildContent(content, (JSONObject) x, param);
});
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");
Object resultConvert = JsonValueUtils.getValueByKey(tab, "dataConfig", "dataConfig.resultConvert");
Object api = JsonValueUtils.getValueByKey(tab, "dataConfig", "dataConfig.api");
Object columnWidth = JsonValueUtils.getValueByKey(tab, "dataConfig", "dataConfig.columnWidth");
tab.put("param", param);
JSONObject map = content.getJSONObject(tab.getString("key"));
JSONObject apiResult = new JSONObject();
JSONArray apiArrayResult = new JSONArray();
Object apiResult = null;
if (!ValidationUtil.isEmpty(api)) {
ResponseModel responseModel = this.getApiResult((JSONObject) api, !ValidationUtil.isEmpty(resultConvert) ? resultConvert.toString() : null);
if (!ValidationUtil.isEmpty(responseModel.getResult())) {
if (responseModel.getResult() instanceof JSONObject){
apiResult = JSONObject.parseObject(responseModel.getResult().toString());
} else {
apiArrayResult = JSONArray.parseArray(responseModel.getResult().toString());
}
apiResult = responseModel.getResult();
}
}
......@@ -111,9 +107,9 @@ public class DPSubServiceImpl {
List<Object> mergedArray = mergedList(yObj.getJSONArray("children"));
// 第一组去除标题
if (i == 0 || ValidationUtil.isEmpty(map.get("datas"))) {
this.buildContentData(map, mergedArray, apiResult, matinfo);
this.buildContentData(tab, map, mergedArray, apiResult, matinfo);
} 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"))) { // 子表单
this.buildSubFormData(map, i, yObj, apiResult);
......@@ -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"));
map.getJSONArray("subs").add(matinfo);
}
} else {
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)) {
((JSONArray) showHideRules).stream().forEach(x -> {
JSONObject xObj = (JSONObject) x;
......@@ -291,13 +287,14 @@ public class DPSubServiceImpl {
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();
// 处理二维码
mergedArray.stream().filter(x -> "QRCode".equals(JsonValueUtils.getValueByKey(x, "componentKey", null))).findFirst().ifPresent(x -> {
JSONObject qrcode = map.getJSONObject("qrcode");
String problemTime = apiResult.getString("problemTime");
String problemStatus = apiResult.getString("problemStatus");
String problemTime = result.getString("problemTime");
String problemStatus = result.getString("problemStatus");
String color = null;
if (!ValidationUtil.isEmpty(problemTime)) {
try {
......@@ -312,7 +309,7 @@ public class DPSubServiceImpl {
} else if ("异常".equals(problemStatus)) {
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("color", color);
});
......@@ -322,14 +319,14 @@ public class DPSubServiceImpl {
mergedArray.stream().forEach(x -> {
Object fieldKey = JsonValueUtils.getValueByKey(x, "visualParams", "visualParams.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);
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 children = yObj.getJSONArray("children");
List<Object> columnsArray = children.stream().filter(x -> {
......@@ -347,7 +344,7 @@ public class DPSubServiceImpl {
mergedArray.stream().forEach(x -> {
Object fieldKey = JsonValueUtils.getValueByKey(x, "visualParams", "visualParams.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);
}
});
......@@ -364,7 +361,7 @@ public class DPSubServiceImpl {
* @param apiResult
* @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 xObj = (JSONObject) x;
......@@ -372,6 +369,15 @@ public class DPSubServiceImpl {
jsonObject.put("label", visualParams.getString("label"));
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"))) {
jsonObject.put("type", "img");
if (!ValidationUtil.isEmpty(value)) {
......@@ -383,55 +389,45 @@ public class DPSubServiceImpl {
JSONObject attachmentUploadDatasObj = new JSONObject();
attachmentUploadDatasObj.put("value", value);
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("type", "file");
} else if(accept.contains("png") || accept.contains("img")){
} else if (accept.contains("png") || accept.contains("img")) {
attachmentUploadDatasObj.put("label", "证照");
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("type", "video");
}
attachmentUploadDatas.add(attachmentUploadDatasObj);
}
} else if ("lnglatSelect".equals(xObj.getString("componentKey"))) {
jsonObject.put("type", "text");
if (!ValidationUtil.isEmpty(value) && value instanceof JSONObject) {
JSONObject lnglatSelect = (JSONObject) value;
jsonObject.put("value", String.format("[%s,%s]", lnglatSelect.getString("latitude"), lnglatSelect.getString("longitude")));
} else {
jsonObject.put("value", value);
jsonObject.put("value", (!ValidationUtil.isEmpty(lnglatSelect.getString("latitude")) && !ValidationUtil.isEmpty(lnglatSelect.getString("longitude")))
? String.format("[%s,%s]", lnglatSelect.getString("latitude"), lnglatSelect.getString("longitude")) : lnglatSelect.getString("address"));
}
} else if ("checkbox".equals(xObj.getString("componentKey"))) {
jsonObject.put("type", "text");
ResponseModel checkboxResult = this.getApiResult(visualParams.getJSONObject("api"), null);
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());
String nameKey = collect.stream().map(item -> ((JSONObject) item).getString("nameKey")).collect(Collectors.joining("、"));
jsonObject.put("value", nameKey);
} else {
jsonObject.put("value", value);
}
} else if ("select".equals(xObj.getString("componentKey"))) {
jsonObject.put("type", "text");
ResponseModel selectResult = this.getApiResult(visualParams.getJSONObject("api"), null);
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 -> {
jsonObject.put("value", ((JSONObject) z).getString("nameKey"));
});
} else {
jsonObject.put("value", value);
}
} else {
jsonObject.put("type", "text");
jsonObject.put("value", value);
}
}
datas.add(jsonObject);
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 children = yObj.getJSONArray("children");
......@@ -458,7 +454,8 @@ public class DPSubServiceImpl {
subObj.put("rowKey", "key");
subObj.put("showPage", false);
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);
return map;
......
......@@ -16,7 +16,8 @@
"ruleData": {
"responseSuccess": "data.result.equipInfo"
}
}
},
"paramFieldKeys": ["EQU_LIST","EQU_CATEGORY","EQU_DEFINE"]
}
},
{
......
......@@ -16,7 +16,8 @@
"ruleData": {
"responseSuccess": "data.result.equipInfo"
}
}
},
"paramFieldKeys": ["EQU_LIST","EQU_CATEGORY","EQU_DEFINE"]
}
},
{
......
......@@ -16,7 +16,8 @@
"ruleData": {
"responseSuccess": "data.result.equipInfo"
}
}
},
"paramFieldKeys": ["EQU_LIST","EQU_CATEGORY","EQU_DEFINE"]
}
},
{
......
......@@ -16,7 +16,8 @@
"ruleData": {
"responseSuccess": "data.result.equipInfo"
}
}
},
"paramFieldKeys": ["EQU_LIST","EQU_CATEGORY","EQU_DEFINE"]
}
},
{
......
......@@ -16,7 +16,8 @@
"ruleData": {
"responseSuccess": "data.result.equipInfo"
}
}
},
"paramFieldKeys": ["EQU_LIST","EQU_CATEGORY","EQU_DEFINE"]
}
},
{
......
......@@ -16,7 +16,8 @@
"ruleData": {
"responseSuccess": "data.result.equipInfo"
}
}
},
"paramFieldKeys": ["EQU_LIST","EQU_CATEGORY","EQU_DEFINE"]
}
},
{
......
......@@ -16,7 +16,8 @@
"ruleData": {
"responseSuccess": "data.result.equipInfo"
}
}
},
"paramFieldKeys": ["EQU_LIST","EQU_CATEGORY","EQU_DEFINE"]
}
},
{
......
......@@ -16,7 +16,8 @@
"ruleData": {
"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