diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/MpController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/MpController.java index 2f0af35..a5b66bf 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/MpController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/MpController.java @@ -141,7 +141,7 @@ public class MpController extends BaseController { tPatient.setName(appPatientHospitalDoctor.getName()); tPatient.setPhone(appPatientHospitalDoctor.getPhone()); List tPatients = patientService.selectTPatientList(tPatient); - if (tPatients.isEmpty()) { + if (CollectionUtils.isEmpty(tPatients)) { ajaxResult.put("status", null); } // 查询该患者当天是否有预约记录 diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/config/RuoYiConfig.java b/ruoyi-common/src/main/java/com/ruoyi/common/config/RuoYiConfig.java index 853a9d7..52c9db0 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/config/RuoYiConfig.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/config/RuoYiConfig.java @@ -141,6 +141,16 @@ public class RuoYiConfig return getProfile() + "/appInfo"; } + /** + * 得到jsontemplate路径 + * + * @return {@code String} + */ + public static String getJSONTemplatePath() + { + return getProfile() + "/template"; + } + /** * 获取应用信息路径 */ 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 2679b6c..e11751a 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,7 +1,9 @@ package com.ruoyi.system.service.impl; import com.alibaba.fastjson.JSONObject; +import com.ruoyi.common.config.RuoYiConfig; 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; @@ -18,6 +20,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.io.IOException; import java.util.*; import java.util.stream.Collectors; @@ -32,6 +35,14 @@ public class TRecordServiceImpl implements ITRecordService { private static final Logger logger = LoggerFactory.getLogger(TRecordServiceImpl.class); + private static Map jsonKeyMap = new HashMap<>(); + + private static Map newJsonKeyMap = new HashMap(){{ + put("sx_vein_color", "sx_vein_color2"); + put("sz_color", "sz_color2"); + put("st_color", "st_color2"); + }}; + /** * AI返回结果中可能为空值的key */ @@ -157,13 +168,122 @@ public class TRecordServiceImpl implements ITRecordService @Override public TRecordResp selectById(Long id) { - return tRecordMapper.selectById(id); + TRecordResp tRecordResp = tRecordMapper.selectById(id); + String aiResult = tRecordResp.getAiResult(); + String aiResult2 = tRecordResp.getAiResult(); + String updateResult = tRecordResp.getUpdateResult(); + String updateResult2 = tRecordResp.getUpdateResult(); + if (!aiResult.contains("sz_color2")) { + try { + tRecordResp.setAiResult(dealJsonString(aiResult)); + tRecordResp.setAiResult2(dealJsonString(aiResult2)); + tRecordResp.setUpdateResult(dealJsonString(updateResult)); + tRecordResp.setUpdateResult2(dealJsonString(updateResult2)); + } catch (IOException e) { + throw new ServiceException("loading json template failed.."); + } + } + return tRecordResp; + } + + /** + * 处理json字符串 + * + * @param jsonString json字符串 + * @return {@code String} + * @throws IOException ioexception + */ + private String dealJsonString(String jsonString) throws IOException { + if (null == jsonString || "".equals(jsonString)) { + return ""; + } + // 将老数据结构对应的数据读出来 + JSONObject jsonObject = JSONObject.parseObject(jsonString); + readJsonToMap(jsonObject.getJSONObject("data")); + // 加载新数据结构模板 + String localPath = RuoYiConfig.getJSONTemplatePath(); + String jsonStr = com.ruoyi.common.utils.file.FileUtils.readJsonFile(localPath +"/" + "Result.json"); + JSONObject newJsonObj = JSONObject.parseObject(jsonStr); + // 构建数据 + newJsonObj.put("data", buildJson(newJsonObj.getJSONObject("data"))); + return newJsonObj.toJSONString(); + } + + /** + * 读取json,将对应的k v存入map + * + * @param obj obj + */ + private void readJsonToMap(Object obj) { + if (obj instanceof JSONObject) { + for (Map.Entry entry : ((JSONObject) obj).entrySet()) { + if ((entry.getValue() instanceof JSONObject)) { + // 子对象中包含v, qu.. + if (null != ((JSONObject) entry.getValue()).get("anomaly")) { + // json to map + jsonKeyMap.put(entry.getKey(), (JSONObject) entry.getValue()); + continue; + } + // 递归调用 + readJsonToMap(entry.getValue()); + } + } + } + } + + /** + * 构建新结构的json + * + * @param obj obj + * @return {@code JSONObject} + */ + private JSONObject buildJson(Object obj) { + JSONObject jsonResult = null; + if (obj instanceof JSONObject) { + jsonResult = (JSONObject) obj; + for (Map.Entry entry : ((JSONObject) obj).entrySet()) { + if ((entry.getValue() instanceof JSONObject)) { + // 子对象中包含v, qu.. + if (null != ((JSONObject) entry.getValue()).get("anomaly")) { + // build json + String key = entry.getKey(); + String newKey = newJsonKeyMap.get(key); + if (null == newKey) { + newKey = key; + } + JSONObject jsonValByKey = jsonKeyMap.get(newKey); + if (null != jsonValByKey) { + jsonResult.put(key, jsonValByKey); + } + continue; + } + // 递归调用 + JSONObject jsonChild = buildJson(entry.getValue()); + jsonResult.put(entry.getKey(), jsonChild); + } + } + } + return jsonResult; } @Override public List queryRecordListByPHDids(TPatientHospitalDoctor tPatientHospitalDoctor) { - return tRecordMapper.queryRecordListByPHDids(tPatientHospitalDoctor); + List tRecordResps = tRecordMapper.queryRecordListByPHDids(tPatientHospitalDoctor); + TRecordResp tRecordResp1 = tRecordResps.get(0); + if (null != tRecordResp1 && !tRecordResp1.getAiResult().contains("sz_color2")) { + tRecordResps = tRecordResps.stream().peek(tRecordResp -> { + try { + tRecordResp.setAiResult(dealJsonString(tRecordResp.getAiResult())); + tRecordResp.setAiResult2(dealJsonString(tRecordResp.getAiResult2())); + tRecordResp.setUpdateResult(dealJsonString(tRecordResp.getUpdateResult())); + tRecordResp.setUpdateResult2(dealJsonString(tRecordResp.getUpdateResult2())); + } catch (IOException e) { + throw new ServiceException("加载json模板失败。"); + } + }).collect(Collectors.toList()); + } + return tRecordResps; } @Override