diff --git a/lib/EmergencyService/zdxtEmergencyKnowledgeService/src/main/java/com/zdxt/knowledge/service/impl/SceneQuestionServiceImpl.java b/lib/EmergencyService/zdxtEmergencyKnowledgeService/src/main/java/com/zdxt/knowledge/service/impl/SceneQuestionServiceImpl.java index fdacc3e8..17ee6d25 100644 --- a/lib/EmergencyService/zdxtEmergencyKnowledgeService/src/main/java/com/zdxt/knowledge/service/impl/SceneQuestionServiceImpl.java +++ b/lib/EmergencyService/zdxtEmergencyKnowledgeService/src/main/java/com/zdxt/knowledge/service/impl/SceneQuestionServiceImpl.java @@ -1,10 +1,10 @@ package com.zdxt.knowledge.service.impl; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.lang.Pair; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONException; import com.alibaba.fastjson.JSONObject; import com.zdxt.auth.dto.RoleBean; import com.zdxt.auth.dto.UserBean; @@ -218,7 +218,7 @@ public class SceneQuestionServiceImpl implements ISceneQuestionService { JSONObject json = JSON.parseObject(sceneRole.getContent()); JSONObject dataJson = json.getJSONObject("drawflow").getJSONObject("Home").getJSONObject("data"); Map root = new HashMap<>(); - Map> answerList = new HashMap<>(); + Map>> answerList = new HashMap<>(); List> paramsList = new ArrayList<>(); // 因不是正常顺序, 并且会出下断层 因此取最大key值做循环底数 @@ -231,7 +231,9 @@ public class SceneQuestionServiceImpl implements ISceneQuestionService { // for (int i = 1; i <= dataJson.size(); i++) { for (int i = 1; i <= maxNum; i++) { JSONObject data = dataJson.getJSONObject(i + ""); - if (null == data) { continue; } + if (null == data) { + continue; + } Map params = new HashMap<>(); params.put("questionId", data.get("name")); params.put("nodeId", data.get("id")); @@ -263,10 +265,11 @@ public class SceneQuestionServiceImpl implements ISceneQuestionService { } JSONArray option = dataTmp.getJSONArray("option"); if (Objects.nonNull(option) && option.size() != 0) { - Map map = new HashMap<>(); + Map> map = new HashMap<>(); for (int j = 0; j < option.size(); j++) { JSONObject ot = option.getJSONObject(j); - map.put(ot.getString("identify"), ot.getString("content")); + Pair pair = new Pair<>(ot.getString("content"), ot.getString("analysis")); + map.put(ot.getString("identify"), pair); answerList.put(data.getString("id"), map); } } @@ -307,11 +310,13 @@ public class SceneQuestionServiceImpl implements ISceneQuestionService { .filter(item -> Objects.nonNull(item.get("ints"))) .filter(item -> Objects.nonNull(item.get("channel"))) .peek(item -> { - Map stringStringMap = answerList.get((String) item.get("ints")); + Map> stringStringMap = answerList.get((String) item.get("ints")); if (Objects.nonNull(stringStringMap) && !stringStringMap.isEmpty()) { String channel = (String) item.get("channel"); - String newChannel = stringStringMap.get(channel); + String newChannel = stringStringMap.get(channel).getKey(); + String newAnalysis = stringStringMap.get(channel).getValue(); item.put("channel", StringUtils.isEmpty(newChannel) ? channel : channel + ":" + newChannel); + item.put("analysis", StringUtils.isNotEmpty(newChannel) && StringUtils.isNotEmpty(newAnalysis) ? channel + ":" + newChannel + ":" + newAnalysis : ""); } }) .collect(Collectors.toList()); @@ -343,12 +348,12 @@ public class SceneQuestionServiceImpl implements ISceneQuestionService { return getChildList(params, p).size() > 0 ? true : false; } - private int getMax(List arr){ + private int getMax(List arr) { //假设数组第一位是最大值 int max = arr.get(0); - for (int index = 0 ; index < arr.size() ; index ++) { + for (int index = 0; index < arr.size(); index++) { // 数组的每一个元素和假设的第一个最大值做比较 - if(arr.get(index) > max) { + if (arr.get(index) > max) { // 把得到的真正的最大值赋给Max max = arr.get(index); }