From 1ab15737507bb6dfc34a8139096386d6f3c45ef6 Mon Sep 17 00:00:00 2001 From: yanyan Date: Wed, 28 Feb 2024 17:35:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=98=E5=82=A8=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/SceneQuestionServiceImpl.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) 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); }