|
|
|
@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.supervision.exception.BusinessException;
|
|
|
|
|
import com.supervision.model.DiagnosisQaRecord;
|
|
|
|
|
import com.supervision.model.Process;
|
|
|
|
|
import com.supervision.pojo.vo.TalkReqVO;
|
|
|
|
|
import com.supervision.pojo.vo.TalkResultResVO;
|
|
|
|
|
import com.supervision.service.AskDefaultQuestionAnswerService;
|
|
|
|
|
import com.supervision.service.AskDiseaseQuestionAnswerService;
|
|
|
|
@ -34,15 +35,32 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
|
|
|
|
|
private final AskDefaultQuestionAnswerService askDefaultQuestionAnswerService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String receiveVoiceFile(MultipartFile file) {
|
|
|
|
|
if (file.getSize() <= 0) {
|
|
|
|
|
throw new BusinessException("语音内容为空");
|
|
|
|
|
}
|
|
|
|
|
// 获取音频对应的文字
|
|
|
|
|
String text = null;
|
|
|
|
|
try {
|
|
|
|
|
text = AsrUtil.asrTransformByBytes(file.getBytes());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new BusinessException("获取语音失败");
|
|
|
|
|
}
|
|
|
|
|
if (StrUtil.isEmpty(text)) {
|
|
|
|
|
throw new BusinessException("语音内容为空");
|
|
|
|
|
}
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public TalkResultResVO receiveVoiceFile(MultipartFile file, String processId, String roomKey, String roomToken) throws IOException {
|
|
|
|
|
public TalkResultResVO talk(TalkReqVO talkReqVO) throws IOException {
|
|
|
|
|
// 根据processId找到对应的病人
|
|
|
|
|
Process process = Optional.ofNullable(processService.getById(processId)).orElseThrow(() -> new BusinessException("未找到诊疗进程"));
|
|
|
|
|
// 获取音频对应的文字
|
|
|
|
|
String askQuestion = AsrUtil.asrTransformByBytes(file.getBytes());
|
|
|
|
|
Process process = Optional.ofNullable(processService.getById(talkReqVO.getProcessId())).orElseThrow(() -> new BusinessException("未找到诊疗进程"));
|
|
|
|
|
// 调用rasa获取文字内容
|
|
|
|
|
String rasaResult = RasaUtil.talkRasa(askQuestion, UserUtil.getUser().getId(), process.getPatientId());
|
|
|
|
|
String rasaResult = RasaUtil.talkRasa(talkReqVO.getText(), UserUtil.getUser().getId(), process.getPatientId());
|
|
|
|
|
TalkResultResVO talkResultResVO = new TalkResultResVO();
|
|
|
|
|
// 这里校验,rasa回复的结果是不是action
|
|
|
|
|
// 这里设置的模板,对于action的动作全部是用ancillary_ | tool_进行标记,详情看生成rasa的yml的代码:RasaServiceImpl.generateDomain
|
|
|
|
@ -61,7 +79,7 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
} else {
|
|
|
|
|
// 语音消息,这时调用京东的接口进行播放操作
|
|
|
|
|
// 这里调用京东数字人接口首先根据token获取房间号
|
|
|
|
|
String roomId = HumanUtil.queryRoomId(roomKey, roomToken);
|
|
|
|
|
String roomId = HumanUtil.queryRoomId(talkReqVO.getRoomKey(), talkReqVO.getRoomToken());
|
|
|
|
|
// 区分
|
|
|
|
|
List<String> answerIdList = StrUtil.split(rasaResult, '_');
|
|
|
|
|
String qaId = null;
|
|
|
|
@ -88,10 +106,10 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
HumanUtil.textDriven(rasaResult, roomId);
|
|
|
|
|
// 保存记录
|
|
|
|
|
DiagnosisQaRecord record = new DiagnosisQaRecord();
|
|
|
|
|
record.setProcessId(processId);
|
|
|
|
|
record.setProcessId(talkReqVO.getProcessId());
|
|
|
|
|
record.setQuestionAnswerType(qaType);
|
|
|
|
|
record.setQuestionAnswerId(qaId);
|
|
|
|
|
record.setQuestion(askQuestion);
|
|
|
|
|
record.setQuestion(talkReqVO.getText());
|
|
|
|
|
record.setAnswer(answer);
|
|
|
|
|
record.setCreateUserId(UserUtil.getUser().getId());
|
|
|
|
|
record.insert();
|
|
|
|
|