diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/config/EncodeResponseAdvice.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/config/EncodeResponseAdvice.java index 8d13da7077d481166100697397b1520e19c9cb4b..0535bafc025fc880cbb1efe4358a4f84f200141b 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/config/EncodeResponseAdvice.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/config/EncodeResponseAdvice.java @@ -27,6 +27,7 @@ public class EncodeResponseAdvice implements ResponseBodyAdvice { @Override public boolean supports(MethodParameter methodParameter, Class aClass) { // 方法上有SecurityParameter注解的进行加密 根据需求可以在判断SecurityParameter注解中的outEncode是否为true + // 这里返回true对所有接口返回结果加密,可能影响swagger显示 return true; } diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/controller/mobile/HpGpIntelligentQAController.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/controller/mobile/HpGpIntelligentQAController.java index 57cc5f759a503a719693e2c2ac93a4f998f93bce..ffe3a941b91b7c1debf3d6ff44e6e6af95cd725a 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/controller/mobile/HpGpIntelligentQAController.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/controller/mobile/HpGpIntelligentQAController.java @@ -1,7 +1,10 @@ package cn.sh.stc.sict.theme.hpgp.controller.mobile; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.core.util.XmlUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import cn.sh.stc.sict.cloud.common.core.util.R; @@ -12,6 +15,7 @@ import cn.sh.stc.sict.theme.hpgp.vo.IntelligentAnswerVO; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.google.api.client.util.Lists; import com.google.common.collect.Sets; import io.swagger.annotations.Api; @@ -24,10 +28,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.reactive.function.client.WebClient; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; -import java.util.Set; +import java.util.*; import java.util.concurrent.Executor; import java.util.concurrent.Executors; @@ -47,12 +48,8 @@ public class HpGpIntelligentQAController { @Value("${hpgp-guide.qa-history-limit:3}") private Integer qaHistoryLimit; - private WebClient webClient; private final static String QA_RESULT_FLAG = "Helper: "; - private static final String ERROR_MSG = "使用的人太多啦!等下再用吧!"; - private static final Random RANDOM = new Random(); - private static final Executor EXECUTOR = Executors.newFixedThreadPool(10); // 报告查询、医疗知识问答、医疗分诊、预约挂号 private static final Set QA_TYPE= Sets.newHashSet("报告查询","预约挂号"); @@ -62,139 +59,139 @@ public class HpGpIntelligentQAController { private final static Set DPQ_DEPARTMENT = Sets.newHashSet("皮肤性病科", "中医科", "儿保科", "全科医疗科"); private final static Set XDM_DEPARTMENT = Sets.newHashSet("全科", "全科名医", "中医", "针伤科", "齿科"); -// @SysLog -// @ApiOperation("智能问答") -// @PostMapping -// public R qa(String question) { -// CurrentUser current = SecurityUtils.getCurrentUser(); -// String from = StrUtil.isNotBlank(current.getOpenId()) ? current.getOpenId() : current.getId().toString(); -// -// String xml = "\n" + -// " \n" + -// " \n" + -// " " + DateUtil.now() + "\n" + -// " \n" + -// " \n" + -// " " + IdWorker.getId() + "\n" + -// ""; -// // 162 为黄浦高血压专病导医机器人 -// // 51 黄浦高血压全科导诊机器人 -// String body = HttpRequest.post("http://30.30.5.74:9988/qa/jqrsvr.ashx?Command=talk_51") -// .body(xml) -// .execute() -// .body(); -// log.error("孙总接口请求 xml = {}", xml); -// log.error("孙总接口返回 body = {}", body); -// IntelligentAnswerVO answerVO = new IntelligentAnswerVO(); -// Map result = XmlUtil.xmlToMap(body); -// if (result.containsKey(CONTENT)) { -// answerVO.setAnswer(MapUtil.getStr(result, CONTENT)); -// -// // 打浦桥单独处理 -// if (StrUtil.isNotBlank(current.getHospitalCode()) -// && "42502942300".equals(current.getHospitalCode())) { -// if (StrUtil.isNotBlank(answerVO.getDeptName()) -// && !DPQ_DEPARTMENT.contains(answerVO.getDeptName())) { -// String oldDeptName = answerVO.getDeptName(); -// answerVO.setAnswer(answerVO.getAnswer().replace(oldDeptName, "全科医疗科")); -// answerVO.setDeptName("全科医疗科"); -// } -// } -// -// // 小东门单独处理 -// if (StrUtil.isNotBlank(current.getHospitalCode()) -// && "42507025800".equals(current.getHospitalCode())) { -// if (StrUtil.isNotBlank(answerVO.getDeptName()) -// && !XDM_DEPARTMENT.contains(answerVO.getDeptName())) { -// String oldDeptName = answerVO.getDeptName(); -// answerVO.setAnswer(answerVO.getAnswer().replace(oldDeptName, "全科")); -// answerVO.setDeptName("全科"); -// } -// } -// -// } -// return new R<>(answerVO); -// } - @SysLog @ApiOperation("智能问答") @PostMapping - public R qaV2(String question) { - if (StrUtil.isNotBlank(question) && question.contains("上周的血检报告出了")) { - IntelligentAnswerVO answerVO = new IntelligentAnswerVO(); - answerVO.setAnswer("https://www.sh-sict.com/healthExam"); - return new R(answerVO); - } + public R qa(String question) { CurrentUser current = SecurityUtils.getCurrentUser(); - List qaHistory = JSON.parseArray(current.getQaHistory(), String.class); - String from = current.getId().toString(); - - JSONObject jsonObject = new JSONObject(); - jsonObject.put("username", from); - if (CollUtil.isEmpty(qaHistory)) { - qaHistory = Lists.newArrayListWithCapacity(1); - } - - if (qaHistory.size() > qaHistoryLimit) { - qaHistory = qaHistory.subList(0, qaHistoryLimit - 1); - } - - List currentQa = Lists.newArrayList(); - currentQa.add(question); - currentQa.add(null); - qaHistory.add(JSON.toJSONString(currentQa)); - - List> reqList = new ArrayList<>(); - for (Object item : qaHistory) { - if (item instanceof String) { - List itemList = JSONArray.parseArray((String) item, String.class); - reqList.add(itemList); - } - } - jsonObject.put("history", reqList); - String req = JSON.toJSONString(jsonObject); + String from = StrUtil.isNotBlank(current.getOpenId()) ? current.getOpenId() : current.getId().toString(); + String xml = "\n" + + " \n" + + " \n" + + " " + DateUtil.now() + "\n" + + " \n" + + " \n" + + " " + IdWorker.getId() + "\n" + + ""; // 162 为黄浦高血压专病导医机器人 // 51 黄浦高血压全科导诊机器人 - HttpResponse response = HttpRequest.post(qaUrl) - .body(req, "application/json") - .execute(); - String body = response.body(); - log.error("接口请求 req = {}", req); - log.error("接口返回 body = {}", body); - if (response.getStatus() != 200 || StrUtil.isBlank(body)) { - return new R(); - } + String body = HttpRequest.post("http://30.30.5.74:9988/qa/jqrsvr.ashx?Command=talk_51") + .body(xml) + .execute() + .body(); + log.error("孙总接口请求 xml = {}", xml); + log.error("孙总接口返回 body = {}", body); + IntelligentAnswerVO answerVO = new IntelligentAnswerVO(); + Map result = XmlUtil.xmlToMap(body); + if (result.containsKey(CONTENT)) { + answerVO.setAnswer(MapUtil.getStr(result, CONTENT)); - JSONObject bodyJson = JSON.parseObject(body); - String chat = bodyJson.getString("Chat"); - JSONArray departmentArray = bodyJson.getJSONArray("Department"); - String medicalType = bodyJson.getString("Medical_type"); - if(StrUtil.isNotBlank(medicalType) && QA_TYPE.contains(medicalType)){ - IntelligentAnswerVO answerVO = new IntelligentAnswerVO(); - answerVO.setAnswer("https://www.sh-sict.com/healthExam"); - return new R(answerVO); - } - if (StrUtil.isBlank(chat)) { - return new R(); - } + // 打浦桥单独处理 + if (StrUtil.isNotBlank(current.getHospitalCode()) + && "42502942300".equals(current.getHospitalCode())) { + if (StrUtil.isNotBlank(answerVO.getDeptName()) + && !DPQ_DEPARTMENT.contains(answerVO.getDeptName())) { + String oldDeptName = answerVO.getDeptName(); + answerVO.setAnswer(answerVO.getAnswer().replace(oldDeptName, "全科医疗科")); + answerVO.setDeptName("全科医疗科"); + } + } - chat = chat.replaceAll(QA_RESULT_FLAG, ""); - if (chat.startsWith("\"") && chat.endsWith("\"")) { - chat = chat.substring(1, chat.length() - 1); - } - currentQa.set(1, chat); - current.setQaHistory(JSON.toJSONString(qaHistory)); - SecurityUtils.updateCurrent(current); + // 小东门单独处理 + if (StrUtil.isNotBlank(current.getHospitalCode()) + && "42507025800".equals(current.getHospitalCode())) { + if (StrUtil.isNotBlank(answerVO.getDeptName()) + && !XDM_DEPARTMENT.contains(answerVO.getDeptName())) { + String oldDeptName = answerVO.getDeptName(); + answerVO.setAnswer(answerVO.getAnswer().replace(oldDeptName, "全科")); + answerVO.setDeptName("全科"); + } + } - IntelligentAnswerVO answerVO = new IntelligentAnswerVO(); - answerVO.setAnswer(chat); - if (CollUtil.isNotEmpty(departmentArray)) { - answerVO.setDeptName(departmentArray.getString(0)); } - return new R(answerVO); + return new R<>(answerVO); } +// @SysLog +// @ApiOperation("智能问答") +// @PostMapping +// public R qaV2(String question) { +// if (StrUtil.isNotBlank(question) && question.contains("上周的血检报告出了")) { +// IntelligentAnswerVO answerVO = new IntelligentAnswerVO(); +// answerVO.setAnswer("https://www.sh-sict.com/healthExam"); +// return new R(answerVO); +// } +// CurrentUser current = SecurityUtils.getCurrentUser(); +// List qaHistory = JSON.parseArray(current.getQaHistory(), String.class); +// String from = current.getId().toString(); +// +// JSONObject jsonObject = new JSONObject(); +// jsonObject.put("username", from); +// if (CollUtil.isEmpty(qaHistory)) { +// qaHistory = Lists.newArrayListWithCapacity(1); +// } +// +// if (qaHistory.size() > qaHistoryLimit) { +// qaHistory = qaHistory.subList(0, qaHistoryLimit - 1); +// } +// +// List currentQa = Lists.newArrayList(); +// currentQa.add(question); +// currentQa.add(null); +// qaHistory.add(JSON.toJSONString(currentQa)); +// +// List> reqList = new ArrayList<>(); +// for (Object item : qaHistory) { +// if (item instanceof String) { +// List itemList = JSONArray.parseArray((String) item, String.class); +// reqList.add(itemList); +// } +// } +// jsonObject.put("history", reqList); +// String req = JSON.toJSONString(jsonObject); +// +// // 162 为黄浦高血压专病导医机器人 +// // 51 黄浦高血压全科导诊机器人 +// HttpResponse response = HttpRequest.post(qaUrl) +// .body(req, "application/json") +// .execute(); +// String body = response.body(); +// log.error("接口请求 req = {}", req); +// log.error("接口返回 body = {}", body); +// if (response.getStatus() != 200 || StrUtil.isBlank(body)) { +// return new R(); +// } +// +// JSONObject bodyJson = JSON.parseObject(body); +// String chat = bodyJson.getString("Chat"); +// JSONArray departmentArray = bodyJson.getJSONArray("Department"); +// String medicalType = bodyJson.getString("Medical_type"); +// if(StrUtil.isNotBlank(medicalType) && QA_TYPE.contains(medicalType)){ +// IntelligentAnswerVO answerVO = new IntelligentAnswerVO(); +// answerVO.setAnswer("https://www.sh-sict.com/healthExam"); +// return new R(answerVO); +// } +// if (StrUtil.isBlank(chat)) { +// return new R(); +// } +// +// chat = chat.replaceAll(QA_RESULT_FLAG, ""); +// if (chat.startsWith("\"") && chat.endsWith("\"")) { +// chat = chat.substring(1, chat.length() - 1); +// } +// currentQa.set(1, chat); +// current.setQaHistory(JSON.toJSONString(qaHistory)); +// SecurityUtils.updateCurrent(current); +// +// IntelligentAnswerVO answerVO = new IntelligentAnswerVO(); +// answerVO.setAnswer(chat); +// if (CollUtil.isNotEmpty(departmentArray)) { +// answerVO.setDeptName(departmentArray.getString(0)); +// } +// return new R(answerVO); +// } + /** * post方式,可以解决特殊符号,过长的文本等问题 *