|
|
@ -76,6 +76,7 @@ public class AskServiceImpl implements AskService {
|
|
|
|
// 这里设置的模板,对于action的动作全部是用ancillary_ | tool_进行标记,详情看生成rasa的yml的代码:RasaServiceImpl.generateDomain
|
|
|
|
// 这里设置的模板,对于action的动作全部是用ancillary_ | tool_进行标记,详情看生成rasa的yml的代码:RasaServiceImpl.generateDomain
|
|
|
|
// ancillary_ | tool_
|
|
|
|
// ancillary_ | tool_
|
|
|
|
if (rasaResult.startsWith("ancillary_") || rasaResult.startsWith("tool_")) {
|
|
|
|
if (rasaResult.startsWith("ancillary_") || rasaResult.startsWith("tool_")) {
|
|
|
|
|
|
|
|
log.info("呼出语句:{}", rasaResult);
|
|
|
|
List<String> actionList = StrUtil.split(rasaResult, '_');
|
|
|
|
List<String> actionList = StrUtil.split(rasaResult, '_');
|
|
|
|
if (actionList.size() > 1) {
|
|
|
|
if (actionList.size() > 1) {
|
|
|
|
ActionDTO actionDTO = new ActionDTO();
|
|
|
|
ActionDTO actionDTO = new ActionDTO();
|
|
|
@ -90,39 +91,70 @@ public class AskServiceImpl implements AskService {
|
|
|
|
String roomId = HumanUtil.queryRoomId(talkReqVO.getRoomKey(), talkReqVO.getRoomToken());
|
|
|
|
String roomId = HumanUtil.queryRoomId(talkReqVO.getRoomKey(), talkReqVO.getRoomToken());
|
|
|
|
AskTemplateQuestionLibrary library = askTemplateQuestionLibraryService.getById(rasaResult);
|
|
|
|
AskTemplateQuestionLibrary library = askTemplateQuestionLibraryService.getById(rasaResult);
|
|
|
|
if (ObjectUtil.isEmpty(library)) {
|
|
|
|
if (ObjectUtil.isEmpty(library)) {
|
|
|
|
|
|
|
|
log.info("{}:未从问题库中找到,回答未识别语句", rasaResult);
|
|
|
|
HumanUtil.textDriven("您好,我没有听懂您说什么", roomId);
|
|
|
|
HumanUtil.textDriven("您好,我没有听懂您说什么", roomId);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// 首先看看default里面是不是存在,如果存在,就从default里面去找
|
|
|
|
|
|
|
|
if (CollUtil.isNotEmpty(library.getDefaultAnswer())) {
|
|
|
|
|
|
|
|
String resText = library.getDefaultAnswer().get(RandomUtil.randomInt(0, library.getDefaultAnswer().size()));
|
|
|
|
|
|
|
|
HumanUtil.textDriven(resText, roomId);
|
|
|
|
|
|
|
|
// 保存记录
|
|
|
|
|
|
|
|
DiagnosisQaRecord record = new DiagnosisQaRecord();
|
|
|
|
|
|
|
|
record.setProcessId(talkReqVO.getProcessId());
|
|
|
|
|
|
|
|
record.setAnswerType("default");
|
|
|
|
|
|
|
|
// 注意,这里如果有默认回答,回答的结果是默认结果ID
|
|
|
|
|
|
|
|
record.setAnswerId(library.getId());
|
|
|
|
|
|
|
|
record.setQuestion(talkReqVO.getText());
|
|
|
|
|
|
|
|
record.setAnswer(resText);
|
|
|
|
|
|
|
|
record.setCreateUserId(UserUtil.getUser().getId());
|
|
|
|
|
|
|
|
record.insert();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
AskPatientAnswer askPatientAnswer = askPatientAnswerService.lambdaQuery().eq(AskPatientAnswer::getPatientId, process.getPatientId())
|
|
|
|
AskPatientAnswer askPatientAnswer = askPatientAnswerService.lambdaQuery().eq(AskPatientAnswer::getPatientId, process.getPatientId())
|
|
|
|
.eq(AskPatientAnswer::getLibraryQuestionId, library.getId()).last("limit 1").one();
|
|
|
|
.eq(AskPatientAnswer::getLibraryQuestionId, library.getId()).last("limit 1").one();
|
|
|
|
if (ObjectUtil.isEmpty(askPatientAnswer) || CollUtil.isEmpty(askPatientAnswer.getAnswer())) {
|
|
|
|
// 如果没有找到回答,去默认回答里面看看有没有
|
|
|
|
HumanUtil.textDriven("您好,我没有听懂您说什么", roomId);
|
|
|
|
if (ObjectUtil.isEmpty(askPatientAnswer)) {
|
|
|
|
|
|
|
|
log.info("{}:病历配置的回答为空,尝试回答默认答案", rasaResult);
|
|
|
|
|
|
|
|
// 首先看看default里面是不是存在,如果存在,就从default里面去找
|
|
|
|
|
|
|
|
if (CollUtil.isNotEmpty(library.getDefaultAnswer())) {
|
|
|
|
|
|
|
|
String resText = library.getDefaultAnswer().get(RandomUtil.randomInt(0, library.getDefaultAnswer().size()));
|
|
|
|
|
|
|
|
HumanUtil.textDriven(resText, roomId);
|
|
|
|
|
|
|
|
// 保存记录
|
|
|
|
|
|
|
|
DiagnosisQaRecord record = new DiagnosisQaRecord();
|
|
|
|
|
|
|
|
record.setProcessId(talkReqVO.getProcessId());
|
|
|
|
|
|
|
|
record.setAnswerType("default");
|
|
|
|
|
|
|
|
// 注意,这里如果有默认回答,回答的结果是默认结果ID
|
|
|
|
|
|
|
|
record.setAnswerId(library.getId());
|
|
|
|
|
|
|
|
record.setQuestion(talkReqVO.getText());
|
|
|
|
|
|
|
|
record.setAnswer(resText);
|
|
|
|
|
|
|
|
record.setCreateUserId(UserUtil.getUser().getId());
|
|
|
|
|
|
|
|
record.insert();
|
|
|
|
|
|
|
|
log.info("{}:找到了默认答案:{}", rasaResult, talkReqVO.getText());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
log.info("{}:没有从默认答案中找到找到默认内容,回复未识别语句", rasaResult);
|
|
|
|
|
|
|
|
HumanUtil.textDriven("您好,我没有听懂您说什么", roomId);
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
String resText = askPatientAnswer.getAnswer().get(RandomUtil.randomInt(0, askPatientAnswer.getAnswer().size()));
|
|
|
|
if (CollUtil.isEmpty(askPatientAnswer.getAnswer())) {
|
|
|
|
HumanUtil.textDriven(resText, roomId);
|
|
|
|
log.info("{}:病历配置的回答不为空,但在获取的时候,答案为空,尝试回复默认语句", rasaResult);
|
|
|
|
// 保存记录
|
|
|
|
if (CollUtil.isNotEmpty(library.getDefaultAnswer())) {
|
|
|
|
DiagnosisQaRecord record = new DiagnosisQaRecord();
|
|
|
|
String resText = library.getDefaultAnswer().get(RandomUtil.randomInt(0, library.getDefaultAnswer().size()));
|
|
|
|
record.setProcessId(talkReqVO.getProcessId());
|
|
|
|
log.info("{}:病历配置的回答不为空,但在获取的时候,答案为空,开始回复默认语句,默认语句内容:{}", rasaResult, resText);
|
|
|
|
record.setAnswerType("patient");
|
|
|
|
HumanUtil.textDriven(resText, roomId);
|
|
|
|
record.setAnswerId(askPatientAnswer.getId());
|
|
|
|
// 保存记录
|
|
|
|
record.setQuestion(talkReqVO.getText());
|
|
|
|
DiagnosisQaRecord record = new DiagnosisQaRecord();
|
|
|
|
record.setAnswer(resText);
|
|
|
|
record.setProcessId(talkReqVO.getProcessId());
|
|
|
|
record.setCreateUserId(UserUtil.getUser().getId());
|
|
|
|
record.setAnswerType("default");
|
|
|
|
record.insert();
|
|
|
|
// 注意,这里如果有默认回答,回答的结果是默认结果ID
|
|
|
|
|
|
|
|
record.setAnswerId(library.getId());
|
|
|
|
|
|
|
|
record.setQuestion(talkReqVO.getText());
|
|
|
|
|
|
|
|
record.setAnswer(resText);
|
|
|
|
|
|
|
|
record.setCreateUserId(UserUtil.getUser().getId());
|
|
|
|
|
|
|
|
record.insert();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
log.info("{}:病历配置的回答不为空,但在获取的时候,答案为空,但是获取默认语句也为空,那么回复未识别语句", rasaResult);
|
|
|
|
|
|
|
|
HumanUtil.textDriven("您好,我没有听懂您说什么", roomId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String resText = askPatientAnswer.getAnswer().get(RandomUtil.randomInt(0, askPatientAnswer.getAnswer().size()));
|
|
|
|
|
|
|
|
log.info("{}:找到了病历配置的回答语句,回答内容:{}", rasaResult, resText);
|
|
|
|
|
|
|
|
HumanUtil.textDriven(resText, roomId);
|
|
|
|
|
|
|
|
// 保存记录
|
|
|
|
|
|
|
|
DiagnosisQaRecord record = new DiagnosisQaRecord();
|
|
|
|
|
|
|
|
record.setProcessId(talkReqVO.getProcessId());
|
|
|
|
|
|
|
|
record.setAnswerType("patient");
|
|
|
|
|
|
|
|
record.setAnswerId(askPatientAnswer.getId());
|
|
|
|
|
|
|
|
record.setQuestion(talkReqVO.getText());
|
|
|
|
|
|
|
|
record.setAnswer(resText);
|
|
|
|
|
|
|
|
record.setCreateUserId(UserUtil.getUser().getId());
|
|
|
|
|
|
|
|
record.insert();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|