统一AI返回值

master
gongzhenkun 2 years ago
parent afd096a0b4
commit c77d89ddef

@ -141,7 +141,7 @@ public class MpController extends BaseController {
tPatient.setName(appPatientHospitalDoctor.getName());
tPatient.setPhone(appPatientHospitalDoctor.getPhone());
List<TPatient> tPatients = patientService.selectTPatientList(tPatient);
if (tPatients.isEmpty()) {
if (CollectionUtils.isEmpty(tPatients)) {
ajaxResult.put("status", null);
}
// 查询该患者当天是否有预约记录

@ -141,6 +141,16 @@ public class RuoYiConfig
return getProfile() + "/appInfo";
}
/**
* jsontemplate
*
* @return {@code String}
*/
public static String getJSONTemplatePath()
{
return getProfile() + "/template";
}
/**
*
*/

@ -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<String, JSONObject> jsonKeyMap = new HashMap<>();
private static Map<String, String> newJsonKeyMap = new HashMap<String, String>(){{
put("sx_vein_color", "sx_vein_color2");
put("sz_color", "sz_color2");
put("st_color", "st_color2");
}};
/**
* AIkey
*/
@ -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();
}
/**
* jsonk vmap
*
* @param obj obj
*/
private void readJsonToMap(Object obj) {
if (obj instanceof JSONObject) {
for (Map.Entry<String, Object> 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<String, Object> 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<TRecordResp> queryRecordListByPHDids(TPatientHospitalDoctor tPatientHospitalDoctor)
{
return tRecordMapper.queryRecordListByPHDids(tPatientHospitalDoctor);
List<TRecordResp> 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

Loading…
Cancel
Save