|
|
|
@ -49,13 +49,6 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
@Value("${answer.defaultNoMatchId}")
|
|
|
|
|
private String defaultNoMatchId;
|
|
|
|
|
|
|
|
|
|
@Value("${answer.video.basePath}")
|
|
|
|
|
private String videoPath;
|
|
|
|
|
|
|
|
|
|
@Value("${video-url}")
|
|
|
|
|
private String videoUrl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String receiveVoiceFile(MultipartFile file) {
|
|
|
|
|
if (file.getSize() <= 0) {
|
|
|
|
@ -203,7 +196,7 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public TalkResultResVO talkByVideo(TalkVideoReqVO talkReqVO) throws IOException {
|
|
|
|
|
public TalkResultResVO talkByVideo(TalkVideoReqVO talkReqVO) {
|
|
|
|
|
// 根据processId找到对应的病人
|
|
|
|
|
Process process = Optional.ofNullable(processService.getById(talkReqVO.getProcessId())).orElseThrow(() -> new BusinessException("未找到诊疗进程"));
|
|
|
|
|
// 调用rasa获取文字内容
|
|
|
|
@ -212,8 +205,7 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
TalkResultResVO talkResultResVO = new TalkResultResVO();
|
|
|
|
|
// 如果rasa没有识别出来,则返回默认值
|
|
|
|
|
if (StrUtil.isBlank(rasaResult)) {
|
|
|
|
|
talkResultResVO.setVideoUrl(videoUrl + defaultNoMatchId);
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(defaultNoMatchId,null));
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(defaultNoMatchId));
|
|
|
|
|
saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), null, "您好,我没有听懂您说什么");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -234,8 +226,7 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
AskTemplateQuestionLibrary library = askTemplateQuestionLibraryService.getById(rasaResult);
|
|
|
|
|
if (ObjectUtil.isEmpty(library)) {
|
|
|
|
|
log.info("{}:未从问题库中找到,回答未识别语句", rasaResult);
|
|
|
|
|
talkResultResVO.setVideoUrl(videoUrl + defaultNoMatchId);
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(defaultNoMatchId,null));
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(defaultNoMatchId));
|
|
|
|
|
saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), null, "您好,我没有听懂您说什么");
|
|
|
|
|
} else {
|
|
|
|
|
AskPatientAnswer askPatientAnswer = askPatientAnswerService.lambdaQuery().eq(AskPatientAnswer::getMedicalId, process.getMedicalRecId())
|
|
|
|
@ -246,16 +237,13 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
// 首先看看default里面是不是存在,如果存在,就从default里面去找
|
|
|
|
|
if (StrUtil.isNotEmpty(library.getDefaultAnswer()) && StrUtil.isNotBlank(library.getDefaultAnswerResourceId())) {
|
|
|
|
|
String resText = library.getDefaultAnswer();
|
|
|
|
|
talkResultResVO.setVideoUrl(videoUrl + library.getDefaultAnswerResourceId());
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId(),null));
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId()));
|
|
|
|
|
// 保存记录
|
|
|
|
|
saveQaRecord(talkReqVO.getProcessId(), "default", library.getId(), talkReqVO.getText(), library, resText);
|
|
|
|
|
log.info("{}:找到了默认答案:{}", rasaResult, talkReqVO.getText());
|
|
|
|
|
} else {
|
|
|
|
|
log.info("{}:没有从默认答案中找到找到默认内容,回复未识别语句", rasaResult);
|
|
|
|
|
talkResultResVO.setVideoUrl(videoUrl + (StrUtil.isEmpty(library.getDefaultAnswerResourceId()) ? defaultNoMatchId
|
|
|
|
|
:library.getDefaultAnswerResourceId()));
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId(),defaultNoMatchId));
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId()));
|
|
|
|
|
saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), library, "您好,我没有听懂您说什么");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
@ -265,22 +253,19 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
String resText = library.getDefaultAnswer();
|
|
|
|
|
log.info("{}:病历配置的回答:{}:为空不为空不为空,但在获取的时候,答案为空,开始回复默认语句,默认语句内容:{}", rasaResult, askPatientAnswer.getId(), resText);
|
|
|
|
|
// 这里返回视频
|
|
|
|
|
talkResultResVO.setVideoUrl(videoUrl + library.getDefaultAnswerResourceId());
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId(),defaultNoMatchId));
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId()));
|
|
|
|
|
// 保存记录
|
|
|
|
|
saveQaRecord(talkReqVO.getProcessId(), "default", library.getId(), talkReqVO.getText(), library, resText);
|
|
|
|
|
} else {
|
|
|
|
|
log.info("{}:病历配置的回答:{}:为空不为空,但在获取的时候,答案为空,但是获取默认语句也为空,那么回复未识别语句", rasaResult, askPatientAnswer.getId());
|
|
|
|
|
talkResultResVO.setVideoUrl(videoUrl + defaultNoMatchId);
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(defaultNoMatchId,null));
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(defaultNoMatchId));
|
|
|
|
|
saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), library, "您好,我没有听懂您说什么");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
String resText = askPatientAnswer.getAnswer();
|
|
|
|
|
log.info("{}:找到了病历配置的回答语句:{},回答内容:{}", rasaResult, askPatientAnswer.getId(), resText);
|
|
|
|
|
talkResultResVO.setVideoUrl(videoUrl + askPatientAnswer.getAnswerResourceId());
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(askPatientAnswer.getAnswerResourceId(),defaultNoMatchId));
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(askPatientAnswer.getAnswerResourceId()));
|
|
|
|
|
// 保存记录
|
|
|
|
|
saveQaRecord(talkReqVO.getProcessId(), "patient", askPatientAnswer.getId(), talkReqVO.getText(), library, resText);
|
|
|
|
|
}
|
|
|
|
@ -292,37 +277,28 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
return talkResultResVO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void downloadTalkVideo(String fileResourceId, HttpServletResponse response) {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取应答视频的base64位编码
|
|
|
|
|
*
|
|
|
|
|
* @param fileResourceId 应答id
|
|
|
|
|
* @return 应答视频base64位编码
|
|
|
|
|
*/
|
|
|
|
|
private String getAnswerVideoBase64OrDefault(String fileResourceId) {
|
|
|
|
|
if (StrUtil.isBlank(fileResourceId)) {
|
|
|
|
|
fileResourceId = defaultNoMatchId;
|
|
|
|
|
}
|
|
|
|
|
FileResource fileResource = fileResourceService.getById(fileResourceId);
|
|
|
|
|
if (ObjectUtil.isEmpty(fileResource)) {
|
|
|
|
|
throw new BusinessException("未找到回复视频");
|
|
|
|
|
log.info("未找到视频,走默认视频");
|
|
|
|
|
fileResource = fileResourceService.getById(defaultNoMatchId);
|
|
|
|
|
}
|
|
|
|
|
try (InputStream inputStream = MinioUtil.download(fileResource.getMinioId())) {
|
|
|
|
|
IoUtil.copy(inputStream, response.getOutputStream());
|
|
|
|
|
return Base64Encoder.encode(IoUtil.readBytes(inputStream));
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("获取视频失败", e);
|
|
|
|
|
throw new BusinessException("未找到回复视频");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取应答视频的base64位编码
|
|
|
|
|
* @param answerId 应答id
|
|
|
|
|
* @param defaultValue 默认应答id
|
|
|
|
|
* @return 应答视频base64位编码
|
|
|
|
|
*/
|
|
|
|
|
private String getAnswerVideoBase64OrDefault(String answerId, String defaultValue) {
|
|
|
|
|
Props props = new Props(videoPath + File.separator + "index");
|
|
|
|
|
String fileName = "";
|
|
|
|
|
if (StrUtil.isNotEmpty(answerId) && StrUtil.isNotEmpty(props.getStr(answerId))){
|
|
|
|
|
fileName = props.getStr(answerId);
|
|
|
|
|
}else if (StrUtil.isNotEmpty(defaultValue)){
|
|
|
|
|
fileName = props.getStr(defaultValue);
|
|
|
|
|
}
|
|
|
|
|
if (StrUtil.isEmpty(fileName)){
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return Base64Encoder.encode(FileUtil.readBytes(videoPath + File.separator + fileName));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|