|
|
|
@ -1,9 +1,12 @@
|
|
|
|
|
package com.supervision.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.codec.Base64Encoder;
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import cn.hutool.crypto.digest.MD5;
|
|
|
|
|
import cn.hutool.setting.dialect.Props;
|
|
|
|
|
import com.supervision.exception.BusinessException;
|
|
|
|
|
import com.supervision.model.Process;
|
|
|
|
|
import com.supervision.model.*;
|
|
|
|
@ -20,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.util.List;
|
|
|
|
@ -42,9 +46,12 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
|
|
|
|
|
private final FileResourceService fileResourceService;
|
|
|
|
|
|
|
|
|
|
@Value("${defaultNoMatchId}")
|
|
|
|
|
@Value("${answer.defaultNoMatchId}")
|
|
|
|
|
private String defaultNoMatchId;
|
|
|
|
|
|
|
|
|
|
@Value("${answer.video.basePath}")
|
|
|
|
|
private String videoPath;
|
|
|
|
|
|
|
|
|
|
@Value("${video-url}")
|
|
|
|
|
private String videoUrl;
|
|
|
|
|
|
|
|
|
@ -206,6 +213,7 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
// 如果rasa没有识别出来,则返回默认值
|
|
|
|
|
if (StrUtil.isBlank(rasaResult)) {
|
|
|
|
|
talkResultResVO.setVideoUrl(videoUrl + defaultNoMatchId);
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(defaultNoMatchId,null));
|
|
|
|
|
saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), null, "您好,我没有听懂您说什么");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -227,6 +235,7 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
if (ObjectUtil.isEmpty(library)) {
|
|
|
|
|
log.info("{}:未从问题库中找到,回答未识别语句", rasaResult);
|
|
|
|
|
talkResultResVO.setVideoUrl(videoUrl + defaultNoMatchId);
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(defaultNoMatchId,null));
|
|
|
|
|
saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), null, "您好,我没有听懂您说什么");
|
|
|
|
|
} else {
|
|
|
|
|
AskPatientAnswer askPatientAnswer = askPatientAnswerService.lambdaQuery().eq(AskPatientAnswer::getMedicalId, process.getMedicalRecId())
|
|
|
|
@ -238,6 +247,7 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
if (StrUtil.isNotEmpty(library.getDefaultAnswer()) && StrUtil.isNotBlank(library.getDefaultAnswerResourceId())) {
|
|
|
|
|
String resText = library.getDefaultAnswer();
|
|
|
|
|
talkResultResVO.setVideoUrl(videoUrl + library.getDefaultAnswerResourceId());
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId(),null));
|
|
|
|
|
// 保存记录
|
|
|
|
|
saveQaRecord(talkReqVO.getProcessId(), "default", library.getId(), talkReqVO.getText(), library, resText);
|
|
|
|
|
log.info("{}:找到了默认答案:{}", rasaResult, talkReqVO.getText());
|
|
|
|
@ -245,6 +255,7 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
log.info("{}:没有从默认答案中找到找到默认内容,回复未识别语句", rasaResult);
|
|
|
|
|
talkResultResVO.setVideoUrl(videoUrl + (StrUtil.isEmpty(library.getDefaultAnswerResourceId()) ? defaultNoMatchId
|
|
|
|
|
:library.getDefaultAnswerResourceId()));
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId(),defaultNoMatchId));
|
|
|
|
|
saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), library, "您好,我没有听懂您说什么");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
@ -255,11 +266,13 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
log.info("{}:病历配置的回答:{}:为空不为空不为空,但在获取的时候,答案为空,开始回复默认语句,默认语句内容:{}", rasaResult, askPatientAnswer.getId(), resText);
|
|
|
|
|
// 这里返回视频
|
|
|
|
|
talkResultResVO.setVideoUrl(videoUrl + library.getDefaultAnswerResourceId());
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId(),defaultNoMatchId));
|
|
|
|
|
// 保存记录
|
|
|
|
|
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));
|
|
|
|
|
saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), library, "您好,我没有听懂您说什么");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -267,6 +280,7 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
String resText = askPatientAnswer.getAnswer();
|
|
|
|
|
log.info("{}:找到了病历配置的回答语句:{},回答内容:{}", rasaResult, askPatientAnswer.getId(), resText);
|
|
|
|
|
talkResultResVO.setVideoUrl(videoUrl + askPatientAnswer.getAnswerResourceId());
|
|
|
|
|
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(askPatientAnswer.getAnswerResourceId(),defaultNoMatchId));
|
|
|
|
|
// 保存记录
|
|
|
|
|
saveQaRecord(talkReqVO.getProcessId(), "patient", askPatientAnswer.getId(), talkReqVO.getText(), library, resText);
|
|
|
|
|
}
|
|
|
|
@ -291,4 +305,24 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|