|
|
|
@ -9,17 +9,21 @@ import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import cn.hutool.crypto.digest.MD5;
|
|
|
|
|
import com.supervision.domain.GlobalResult;
|
|
|
|
|
import com.supervision.exception.BusinessException;
|
|
|
|
|
import com.supervision.feign.AskQaSimilarityFeignClient;
|
|
|
|
|
import com.supervision.feign.RasaManageFeignClient;
|
|
|
|
|
import com.supervision.model.Process;
|
|
|
|
|
import com.supervision.model.*;
|
|
|
|
|
import com.supervision.pojo.qaSimilarity.QaSimilarityQuestion;
|
|
|
|
|
import com.supervision.pojo.qaSimilarity.QaSimilarityQuestionAnswer;
|
|
|
|
|
import com.supervision.pojo.vo.TalkResultResVO;
|
|
|
|
|
import com.supervision.pojo.vo.TalkVideoReqVO;
|
|
|
|
|
import com.supervision.service.*;
|
|
|
|
|
import com.supervision.util.*;
|
|
|
|
|
import com.supervision.util.AsrUtil;
|
|
|
|
|
import com.supervision.util.MinioUtil;
|
|
|
|
|
import com.supervision.util.UserUtil;
|
|
|
|
|
import com.supervision.vo.rasa.RasaTalkVo;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
@ -46,6 +50,8 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
|
|
|
|
|
private final RasaManageFeignClient rasaManageFeignClient;
|
|
|
|
|
|
|
|
|
|
private final AskQaSimilarityFeignClient askQaSimilarityFeignClient;
|
|
|
|
|
|
|
|
|
|
private final CommonDicService commonDicService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -117,12 +123,13 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
|
|
|
|
|
// 根据processId找到对应的病人
|
|
|
|
|
Process process = Optional.ofNullable(processService.getById(talkReqVO.getProcessId())).orElseThrow(() -> new BusinessException("未找到诊疗进程"));
|
|
|
|
|
String talkResult = talkQaSimilarity(talkReqVO.getText(), UserUtil.getUser().getId());
|
|
|
|
|
// 调用rasa获取文字内容
|
|
|
|
|
String rasaResult = talkRasa(talkReqVO.getText(), UserUtil.getUser().getId());
|
|
|
|
|
log.info("rasa的回复是:{}", rasaResult);
|
|
|
|
|
//String rasaResult = talkRasa(talkReqVO.getText(), UserUtil.getUser().getId());
|
|
|
|
|
log.info("调用对话的回复是:{}", talkResult);
|
|
|
|
|
TalkResultResVO talkResultResVO = new TalkResultResVO();
|
|
|
|
|
// 如果rasa没有识别出来,则返回默认值
|
|
|
|
|
if (StrUtil.isBlank(rasaResult)) {
|
|
|
|
|
if (StrUtil.isBlank(talkResult)) {
|
|
|
|
|
AskPatientAnswer medicalRecErrorAnswer = getMedicalRecErrorAnswer(process.getMedicalRecId());
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(medicalRecErrorAnswer.getAnswerResourceId()));
|
|
|
|
|
talkResultResVO.setAnswerMessage(medicalRecErrorAnswer.getAnswer());
|
|
|
|
@ -134,20 +141,20 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
// 这里校验,rasa回复的结果是不是action
|
|
|
|
|
// 这里设置的模板,对于action的动作全部是用ancillary_ | tool_进行标记,详情看生成rasa的yml的代码:RasaServiceImpl.generateDomain
|
|
|
|
|
// ancillary_ | tool_
|
|
|
|
|
if (rasaResult.startsWith("ancillary_") || rasaResult.startsWith("tool_")) {
|
|
|
|
|
log.info("呼出语句:{}", rasaResult);
|
|
|
|
|
List<String> actionList = StrUtil.split(rasaResult, '_');
|
|
|
|
|
if (talkResult.startsWith("ancillary_") || talkResult.startsWith("tool_")) {
|
|
|
|
|
log.info("呼出语句:{}", talkResult);
|
|
|
|
|
List<String> actionList = StrUtil.split(talkResult, '_');
|
|
|
|
|
if (actionList.size() > 1) {
|
|
|
|
|
// 在这里给socket回复,设置为动作
|
|
|
|
|
// 在这里设置为动作
|
|
|
|
|
talkResultResVO.setActionId(actionList.get(1));
|
|
|
|
|
talkResultResVO.setType("ancillary".equals(actionList.get(0)) ? 3 : 2);
|
|
|
|
|
setActionRelation(talkResultResVO);
|
|
|
|
|
return talkResultResVO;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
AskTemplateQuestionLibrary library = askTemplateQuestionLibraryService.getById(rasaResult);
|
|
|
|
|
AskTemplateQuestionLibrary library = askTemplateQuestionLibraryService.getById(talkResult);
|
|
|
|
|
if (ObjectUtil.isEmpty(library)) {
|
|
|
|
|
log.info("{}:未从问题库中找到,回答未识别语句", rasaResult);
|
|
|
|
|
log.info("{}:未从问题库中找到,回答未识别语句", talkResult);
|
|
|
|
|
AskPatientAnswer medicalRecErrorAnswer = getMedicalRecErrorAnswer(process.getMedicalRecId());
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(medicalRecErrorAnswer.getAnswerResourceId()));
|
|
|
|
|
talkResultResVO.setAnswerMessage(medicalRecErrorAnswer.getAnswer());
|
|
|
|
@ -157,15 +164,15 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
AskPatientAnswer askPatientAnswer = askPatientAnswerService.lambdaQuery().eq(AskPatientAnswer::getMedicalId, process.getMedicalRecId())
|
|
|
|
|
.eq(AskPatientAnswer::getLibraryQuestionId, library.getId()).last("limit 1").one();
|
|
|
|
|
|
|
|
|
|
if (ObjectUtil.isNotEmpty(askPatientAnswer) && StrUtil.isNotEmpty(askPatientAnswer.getAnswerResourceId())){
|
|
|
|
|
if (ObjectUtil.isNotEmpty(askPatientAnswer) && StrUtil.isNotEmpty(askPatientAnswer.getAnswerResourceId())) {
|
|
|
|
|
String resText = askPatientAnswer.getAnswer();
|
|
|
|
|
log.info("{}:找到了病历配置的回答语句:{},回答内容:{}", rasaResult, askPatientAnswer.getId(), resText);
|
|
|
|
|
log.info("{}:找到了病历配置的回答语句:{},回答内容:{}", talkResult, askPatientAnswer.getId(), resText);
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(askPatientAnswer.getAnswerResourceId()));
|
|
|
|
|
talkResultResVO.setAnswerMessage(askPatientAnswer.getAnswer());
|
|
|
|
|
// 保存记录
|
|
|
|
|
saveQaRecord(talkReqVO.getProcessId(), "patient", askPatientAnswer.getId(), talkReqVO.getText(), library, resText);
|
|
|
|
|
}else {
|
|
|
|
|
log.info("{}:病历配置,从AskPatientAnswer中未找到回答结果,回复未识别到语句", rasaResult);
|
|
|
|
|
} else {
|
|
|
|
|
log.info("{}:病历配置,从AskPatientAnswer中未找到回答结果,回复未识别到语句", talkResult);
|
|
|
|
|
AskPatientAnswer medicalRecErrorAnswer = getMedicalRecErrorAnswer(process.getMedicalRecId());
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(medicalRecErrorAnswer.getAnswerResourceId()));
|
|
|
|
|
talkResultResVO.setAnswerMessage(medicalRecErrorAnswer.getAnswer());
|
|
|
|
@ -196,6 +203,14 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String talkQaSimilarity(String question, String sessionId) {
|
|
|
|
|
GlobalResult<List<QaSimilarityQuestionAnswer>> result = askQaSimilarityFeignClient.askQuestionSimilarityAnswer(new QaSimilarityQuestion(question));
|
|
|
|
|
if (200 != result.getCode()) {
|
|
|
|
|
throw new BusinessException("相似度匹配失败");
|
|
|
|
|
}
|
|
|
|
|
return CollUtil.getFirst(result.getData()).getMatchQuestionCode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private AskPatientAnswer getMedicalRecErrorAnswer(String medicalRecId) {
|
|
|
|
|
//Optional.ofNullable(medicalRecErrorAnswer).orElseGet(() ->new AskPatientAnswer()).getAnswer()
|
|
|
|
|
Assert.notEmpty(medicalRecId, "病历id不能为空");
|
|
|
|
|