From 0543087b0e4423a6d04c06ced4f048a8f5a6d4b6 Mon Sep 17 00:00:00 2001 From: gongzhenkun <1658878546@qq.com> Date: Mon, 22 Aug 2022 17:26:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=82=A3=E8=80=85=E5=8E=86=E5=8F=B2=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=9B=BE=E8=A1=A8=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/resp/RecordHistoryDataResp.java | 14 +++- .../service/impl/TRecordServiceImpl.java | 66 +++++++++++-------- 2 files changed, 51 insertions(+), 29 deletions(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/resp/RecordHistoryDataResp.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/resp/RecordHistoryDataResp.java index 0241d7a..524bd5d 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/resp/RecordHistoryDataResp.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/resp/RecordHistoryDataResp.java @@ -1,8 +1,6 @@ package com.ruoyi.system.domain.resp; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; public class RecordHistoryDataResp { @@ -11,10 +9,20 @@ public class RecordHistoryDataResp private List shexiaList; private List dateList; + private HashMap> historyDataMap; + public RecordHistoryDataResp() { } + public HashMap> getHistoryDataMap() { + return historyDataMap; + } + + public void setHistoryDataMap(HashMap> historyDataMap) { + this.historyDataMap = historyDataMap; + } + public List getShezhiList() { return shezhiList; diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TRecordServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TRecordServiceImpl.java index d99fee4..c9bf904 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TRecordServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TRecordServiceImpl.java @@ -1,9 +1,7 @@ package com.ruoyi.system.service.impl; -import com.alibaba.fastjson.JSONException; import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.core.domain.AjaxResult; -import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.system.domain.TPatientHospitalDoctor; @@ -147,9 +145,13 @@ public class TRecordServiceImpl implements ITRecordService } List records = tRecords.stream().sorted(Comparator.comparing(TRecord::getCreateTime)).collect(Collectors.toList()); List jsonKeyList = new ArrayList(){{ - add("shemian-img_sz"); + add("img_sz"); + add("img_sz_yudian"); + add("img_sz_yuban"); + add("img_sz_liewen"); add("img_st"); add("img_sx"); + add("img_sx_vein"); }}; RecordHistoryDataResp recordHistoryDataRespMap = getDataList(records,jsonKeyList); return AjaxResult.success(recordHistoryDataRespMap); @@ -171,35 +173,47 @@ public class TRecordServiceImpl implements ITRecordService return jsonObject; }).filter(Objects::nonNull).collect(Collectors.toList()); if (!CollectionUtils.isEmpty(result)){ - List shezhiList = new LinkedList<>(); - List shetaiList = new LinkedList<>(); - List shexiaList = new LinkedList<>(); - String[] keys0 = jsonKeyList.get(0).split("-"); - String key1 = jsonKeyList.get(1); - String key2 = jsonKeyList.get(2); + HashMap> map = new HashMap<>(); result.forEach(jsonObject -> { - Integer value1 ; - Integer value2 ; - Integer value3 ; - try - { - value1 = jsonObject.getJSONObject("data").getJSONObject("shezhi").getJSONObject(keys0[0]).getJSONObject(keys0[1]).getInteger("anomaly"); - value2 = jsonObject.getJSONObject("data").getJSONObject("shetai").getJSONObject(key1).getInteger("anomaly"); - value3 = jsonObject.getJSONObject("data").getJSONObject("shexia").getJSONObject(key2).getInteger("anomaly"); - }catch (Exception e){ - throw new ServiceException("JSON格式错误"); - } - shezhiList.add(value1); - shetaiList.add(value2); - shexiaList.add(value3); + getJsonData(jsonObject.getJSONObject("data"), "data", map, jsonKeyList); }); - recordHistoryDataResp.setShezhiList(shezhiList); - recordHistoryDataResp.setShetaiList(shetaiList); - recordHistoryDataResp.setShexiaList(shexiaList); + recordHistoryDataResp.setHistoryDataMap(map); } return recordHistoryDataResp; } + /** + * 得到json关键字 + * + * @param obj obj + * @param listName 列表名称 + * @param historyDataMap 历史数据 + * @param removeKeyList 删除键列表 + */ + private static void getJsonData(Object obj, String listName, HashMap> historyDataMap, List removeKeyList) { + // aiResult结果集中只包括JSONObject,不包括JSONArray + if (obj instanceof JSONObject) { + for (Map.Entry entry : ((JSONObject) obj).entrySet()) { + if (!(entry.getValue() instanceof String)) { + getJsonData(entry.getValue(), entry.getKey(), historyDataMap, removeKeyList); + } else { + // 去除 + if (removeKeyList.contains(listName)) { + continue; + } + ArrayList list; + if (null == historyDataMap.get(listName)) { + list = new ArrayList<>(); + } else { + list = historyDataMap.get(listName); + } + list.add((String) entry.getValue()); + historyDataMap.put(listName, list); + } + } + } + } + /** * 查询医生诊断次数 *