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 ec82f2aaa6f758dc76302faf3fe9dff8dce1389f..8f9b0ab13871031f6a33740716db31d59e3ef662 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; @@ -11,6 +14,7 @@ import cn.sh.stc.sict.cloud.upms.dto.CurrentUser; import cn.sh.stc.sict.theme.hpgp.vo.IntelligentAnswerVO; import com.alibaba.fastjson.JSON; 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; @@ -22,6 +26,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -46,94 +51,108 @@ 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 qa(String question) { +// public R qaV2(String question) { // CurrentUser current = SecurityUtils.getCurrentUser(); -// String from = StrUtil.isNotBlank(current.getOpenId()) ? current.getOpenId() : current.getId().toString(); +// List> qaHistory = current.getQaHistory(); +// 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(currentQa); +// +// jsonObject.put("history", qaHistory); +// String req = JSON.toJSONString(jsonObject); // -// String xml = "\n" + -// " \n" + -// " \n" + -// " " + DateUtil.now() + "\n" + -// " \n" + -// " \n" + -// " " + IdWorker.getId() + "\n" + -// ""; // // 162 为黄浦高血压专病导医机器人 // // 51 黄浦高血压全科导诊机器人 -// String body = HttpRequest.post(" http://www.365jqr.com/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("全科医疗科"); -// } -// } +// 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(); // } -// return new R<>(answerVO); +// +// body = body.replaceAll(QA_RESULT_FLAG, ""); +// body = body.replaceAll("<[.[^>]]*>", ""); +// currentQa.set(1, body); +// current.setQaHistory(qaHistory); +// SecurityUtils.updateCurrent(current); +// +// IntelligentAnswerVO answerVO = new IntelligentAnswerVO(); +// answerVO.setAnswer(body); +// return new R(answerVO); // } - - @SysLog - @ApiOperation("智能问答") - @PostMapping - public R qaV2(String question) { - CurrentUser current = SecurityUtils.getCurrentUser(); - List> qaHistory = current.getQaHistory(); - 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(currentQa); - - jsonObject.put("history", qaHistory); - 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(); - } - - body = body.replaceAll(QA_RESULT_FLAG, ""); - body = body.replaceAll("<[.[^>]]*>", ""); - currentQa.set(1, body); - current.setQaHistory(qaHistory); - SecurityUtils.updateCurrent(current); - - IntelligentAnswerVO answerVO = new IntelligentAnswerVO(); - answerVO.setAnswer(body); - return new R(answerVO); - } } diff --git a/smart-health-modules/theme-schema/src/main/resources/mapper/hphy/HpStatisticsMapper.xml b/smart-health-modules/theme-schema/src/main/resources/mapper/hphy/HpStatisticsMapper.xml index 7fccc9a29c386bff8f8233168af504272cc0e4f9..7815aad7bc7585cdcb8840f28f7f419586db8583 100644 --- a/smart-health-modules/theme-schema/src/main/resources/mapper/hphy/HpStatisticsMapper.xml +++ b/smart-health-modules/theme-schema/src/main/resources/mapper/hphy/HpStatisticsMapper.xml @@ -72,14 +72,19 @@ \ No newline at end of file