历史数据特殊字段取值问题

master
gongzhenkun 2 years ago
parent 393cf8ee2d
commit 624b6e3897

@ -40,7 +40,28 @@ public class TRecordServiceImpl implements ITRecordService
add("sz_avg_purple"); add("sz_avg_purple");
add("sz_avg_red"); add("sz_avg_red");
add("sx_vein_avg_purple"); add("sx_vein_avg_purple");
}};; }};
/**
* vbase64key
*/
private static final List<String> ignoreKeys = new ArrayList<String>(){{
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");
}};
/**
* key
*/
private static final List<String> getQuantificationKeys = new ArrayList<String>(){{
add("sx_vein_width");
add("sx_vein_length");
}};
@Autowired @Autowired
private TRecordMapper tRecordMapper; private TRecordMapper tRecordMapper;
@ -155,20 +176,11 @@ public class TRecordServiceImpl implements ITRecordService
return AjaxResult.success(); return AjaxResult.success();
} }
List<TRecord> records = tRecords.stream().sorted(Comparator.comparing(TRecord::getCreateTime)).collect(Collectors.toList()); List<TRecord> records = tRecords.stream().sorted(Comparator.comparing(TRecord::getCreateTime)).collect(Collectors.toList());
List<String> jsonKeyList = new ArrayList<String>(){{ RecordHistoryDataResp recordHistoryDataRespMap = getDataList(records);
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); return AjaxResult.success(recordHistoryDataRespMap);
} }
private RecordHistoryDataResp getDataList(List<TRecord> records, List<String> jsonKeyList) private RecordHistoryDataResp getDataList(List<TRecord> records)
{ {
RecordHistoryDataResp recordHistoryDataResp = new RecordHistoryDataResp(); RecordHistoryDataResp recordHistoryDataResp = new RecordHistoryDataResp();
// 构造时间轴坐标值 // 构造时间轴坐标值
@ -193,7 +205,7 @@ public class TRecordServiceImpl implements ITRecordService
if (!CollectionUtils.isEmpty(result)){ if (!CollectionUtils.isEmpty(result)){
HashMap<String, ArrayList<Object>> map = new HashMap<>(); HashMap<String, ArrayList<Object>> map = new HashMap<>();
result.forEach(jsonObject -> { result.forEach(jsonObject -> {
getJsonData(jsonObject.getJSONObject("data"), "data", map, jsonKeyList); getJsonData(jsonObject.getJSONObject("data"), "data", map, ignoreKeys);
}); });
recordHistoryDataResp.setHistoryDataMap(map); recordHistoryDataResp.setHistoryDataMap(map);
} }
@ -206,9 +218,9 @@ public class TRecordServiceImpl implements ITRecordService
* @param obj obj * @param obj obj
* @param listName * @param listName
* @param historyDataMap * @param historyDataMap
* @param removeKeyList * @param ignoreKeyList
*/ */
private void getJsonData(Object obj, String listName, HashMap<String, ArrayList<Object>> historyDataMap, List<String> removeKeyList) { private void getJsonData(Object obj, String listName, HashMap<String, ArrayList<Object>> historyDataMap, List<String> ignoreKeyList) {
// aiResult结果集中只包括JSONObject,不包括JSONArray // aiResult结果集中只包括JSONObject,不包括JSONArray
if (obj instanceof JSONObject) { if (obj instanceof JSONObject) {
// "sx_vein_avg_purple": {} // "sx_vein_avg_purple": {}
@ -219,23 +231,27 @@ public class TRecordServiceImpl implements ITRecordService
doSetHistoryData(historyDataMap, listName, "0"); doSetHistoryData(historyDataMap, listName, "0");
} }
for (Map.Entry<String, Object> entry : ((JSONObject) obj).entrySet()) { for (Map.Entry<String, Object> entry : ((JSONObject) obj).entrySet()) {
if ((entry.getValue() instanceof JSONObject)) {
getJsonData(entry.getValue(), entry.getKey(), historyDataMap, removeKeyList);
} else {
// 忽略带图片字段 // 忽略带图片字段
if (removeKeyList.contains(listName)) { if (ignoreKeyList.contains(listName)) {
continue; continue;
} }
if ((entry.getValue() instanceof JSONObject)) {
// 递归调用
getJsonData(entry.getValue(), entry.getKey(), historyDataMap, ignoreKeyList);
} else {
// sx_vein_length和sx_vein_width使用quantification量化字段
if (getQuantificationKeys.contains(listName) && "quantification".equals(entry.getKey())) {
doSetHistoryData(historyDataMap, listName, entry.getValue());
}
//sz_avg_purple: { "anomaly": 0, "v": "正常" } //sz_avg_purple: { "anomaly": 0, "v": "正常" }
// anomaly属于预留字段暂时无用; 各个任务中的字段v是任务实际值 // anomaly属于预留字段暂时无用; 各个任务中的字段v是任务实际值
if (!"v".equals(entry.getKey())) { if (!getQuantificationKeys.contains(listName) && "v".equals(entry.getKey())) {
continue;
}
doSetHistoryData(historyDataMap, listName, entry.getValue()); doSetHistoryData(historyDataMap, listName, entry.getValue());
} }
} }
} }
} }
}
/** /**
* *

Loading…
Cancel
Save