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 095ac70..ecdfdd0 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 @@ -32,6 +32,16 @@ public class TRecordServiceImpl implements ITRecordService { private static final Logger logger = LoggerFactory.getLogger(TRecordServiceImpl.class); + /** + * AI返回结果中可能为空值的key + */ + private static final List nullValKeys = new ArrayList(){{ + add("st_avg_yellow"); + add("sz_avg_purple"); + add("sz_avg_red"); + add("sx_vein_avg_purple"); + }};; + @Autowired private TRecordMapper tRecordMapper; @@ -160,8 +170,8 @@ public class TRecordServiceImpl implements ITRecordService private RecordHistoryDataResp getDataList(List records, List jsonKeyList) { - RecordHistoryDataResp recordHistoryDataResp = new RecordHistoryDataResp(); + // 构造时间轴坐标值 List dateList = records.stream().map(TRecord -> { if (null != TRecord.getUploadTime()) { return TRecord.getUploadTime(); @@ -170,6 +180,7 @@ public class TRecordServiceImpl implements ITRecordService } }).collect(Collectors.toList()); recordHistoryDataResp.setDateList(dateList); + // 构造纵坐标值 List result = records.stream().map(tRecord -> { JSONObject jsonObject = new JSONObject(); if(StringUtils.isEmpty(tRecord.getUpdateResult())){ @@ -197,14 +208,21 @@ public class TRecordServiceImpl implements ITRecordService * @param historyDataMap 历史数据 * @param removeKeyList 删除键列表 */ - private static void getJsonData(Object obj, String listName, HashMap> historyDataMap, List removeKeyList) { + private void getJsonData(Object obj, String listName, HashMap> historyDataMap, List removeKeyList) { // aiResult结果集中只包括JSONObject,不包括JSONArray if (obj instanceof JSONObject) { + // "sx_vein_avg_purple": {} + // "sx_vein_avg_purple": {"anomaly": 0} + // 这两种情况应该添加默认值 + if (nullValKeys.contains(listName) && null == ((JSONObject) obj).get("v")) { + // 加默认值 + doSetHistoryData(historyDataMap, listName, "0"); + } for (Map.Entry entry : ((JSONObject) obj).entrySet()) { if ((entry.getValue() instanceof JSONObject)) { getJsonData(entry.getValue(), entry.getKey(), historyDataMap, removeKeyList); } else { - // 去除带图片字段 + // 忽略带图片字段 if (removeKeyList.contains(listName)) { continue; } @@ -213,19 +231,30 @@ public class TRecordServiceImpl implements ITRecordService if (!"v".equals(entry.getKey())) { continue; } - ArrayList list; - if (null == historyDataMap.get(listName)) { - list = new ArrayList<>(); - } else { - list = historyDataMap.get(listName); - } - list.add(entry.getValue()); - historyDataMap.put(listName, list); + doSetHistoryData(historyDataMap, listName, entry.getValue()); } } } } + /** + * 做历史数据 + * + * @param historyDataMap 历史数据map + * @param listName 列表名称 + * @param val 值 + */ + private void doSetHistoryData(HashMap> historyDataMap, String listName, Object val) { + ArrayList list; + if (null == historyDataMap.get(listName)) { + list = new ArrayList<>(); + } else { + list = historyDataMap.get(listName); + } + list.add(val); + historyDataMap.put(listName, list); + } + /** * 查询医生诊断次数 *