|
|
@ -144,6 +144,7 @@ public class RobotTalkServiceImpl implements RobotTalkService {
|
|
|
|
if (Objects.nonNull(irFile)) {
|
|
|
|
if (Objects.nonNull(irFile)) {
|
|
|
|
robotTalkDTO.getAnswerInfo().setContentType(3);
|
|
|
|
robotTalkDTO.getAnswerInfo().setContentType(3);
|
|
|
|
robotTalkDTO.getAnswerInfo().setByteId(irFile.getId());
|
|
|
|
robotTalkDTO.getAnswerInfo().setByteId(irFile.getId());
|
|
|
|
|
|
|
|
irSessionHistory.setAnswerFileId(irFile.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 写入对话日志
|
|
|
|
// 写入对话日志
|
|
|
@ -258,8 +259,11 @@ public class RobotTalkServiceImpl implements RobotTalkService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 参数异常或查询结果异常
|
|
|
|
// 参数异常或查询结果异常
|
|
|
|
if (Integer.valueOf(1).equals(process.getState())
|
|
|
|
if (Integer.valueOf(1).equals(process.getState())){
|
|
|
|
|| Integer.valueOf(2).equals(process.getState())){
|
|
|
|
return StrUtil.join(",",process.paramCheckToMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Integer.valueOf(2).equals(process.getState())){
|
|
|
|
return config.getUnrecognizedOne();
|
|
|
|
return config.getUnrecognizedOne();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
@ -294,7 +298,8 @@ public class RobotTalkServiceImpl implements RobotTalkService {
|
|
|
|
AnswerInfo answerInfo = robotTalkDTO.getAnswerInfo();
|
|
|
|
AnswerInfo answerInfo = robotTalkDTO.getAnswerInfo();
|
|
|
|
sessionHistory.setAnswer(answerInfo.getMessage());
|
|
|
|
sessionHistory.setAnswer(answerInfo.getMessage());
|
|
|
|
sessionHistory.setAnswerType(answerInfo.getContentType());
|
|
|
|
sessionHistory.setAnswerType(answerInfo.getContentType());
|
|
|
|
sessionHistory.setUserQuestion(answerInfo.getMessage());
|
|
|
|
|
|
|
|
|
|
|
|
sessionHistory.setUserQuestion(robotTalkDTO.getAnswerInfo().getMessage());
|
|
|
|
sessionHistory.setCreateUserId(UserUtil.getUser().getId());
|
|
|
|
sessionHistory.setCreateUserId(UserUtil.getUser().getId());
|
|
|
|
if (Objects.nonNull(matchQuestionAnswerDTO)){
|
|
|
|
if (Objects.nonNull(matchQuestionAnswerDTO)){
|
|
|
|
sessionHistory.setMatchKnowledgeId(matchQuestionAnswerDTO.getMatchQuestionCode());
|
|
|
|
sessionHistory.setMatchKnowledgeId(matchQuestionAnswerDTO.getMatchQuestionCode());
|
|
|
@ -312,8 +317,10 @@ public class RobotTalkServiceImpl implements RobotTalkService {
|
|
|
|
Assert.notEmpty(sessionId, "sessionId不能为空");
|
|
|
|
Assert.notEmpty(sessionId, "sessionId不能为空");
|
|
|
|
Assert.notNull(multipartFile, "multipartFile不能为空");
|
|
|
|
Assert.notNull(multipartFile, "multipartFile不能为空");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
byte[] bytes = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String message = voiceService.voiceToText(multipartFile, sessionId);
|
|
|
|
bytes = multipartFile.getBytes();
|
|
|
|
|
|
|
|
String message = voiceService.voiceToText(bytes, sessionId);
|
|
|
|
robotTalkReq.setMessage(message);
|
|
|
|
robotTalkReq.setMessage(message);
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
log.error("语音转文字失败", e);
|
|
|
|
log.error("语音转文字失败", e);
|
|
|
@ -321,6 +328,18 @@ public class RobotTalkServiceImpl implements RobotTalkService {
|
|
|
|
// todo: 设置问题语音长度和 历史记录中的语音id
|
|
|
|
// todo: 设置问题语音长度和 历史记录中的语音id
|
|
|
|
RobotTalkDTO robotTalkDTO = this.textTalk2Robot(robotTalkReq);
|
|
|
|
RobotTalkDTO robotTalkDTO = this.textTalk2Robot(robotTalkReq);
|
|
|
|
robotTalkDTO.getAskInfo().setContentType(2);
|
|
|
|
robotTalkDTO.getAskInfo().setContentType(2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Objects.nonNull(bytes)){
|
|
|
|
|
|
|
|
IrVoice irVoice = new IrVoice();
|
|
|
|
|
|
|
|
irVoice.setVoiceBase64(Base64.encode(bytes));
|
|
|
|
|
|
|
|
irVoiceService.save(irVoice);
|
|
|
|
|
|
|
|
if (StrUtil.isNotEmpty(robotTalkDTO.getAskInfo().getAskId())){
|
|
|
|
|
|
|
|
sessionService.lambdaUpdate()
|
|
|
|
|
|
|
|
.eq(IrSessionHistory::getId,robotTalkDTO.getAskInfo().getAskId())
|
|
|
|
|
|
|
|
.set(IrSessionHistory::getAnswerVoiceId,irVoice.getId()).update();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return robotTalkDTO;
|
|
|
|
return robotTalkDTO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -328,16 +347,14 @@ public class RobotTalkServiceImpl implements RobotTalkService {
|
|
|
|
public List<CommonDialogVo> talkList(String sessionId) {
|
|
|
|
public List<CommonDialogVo> talkList(String sessionId) {
|
|
|
|
|
|
|
|
|
|
|
|
Assert.notEmpty(sessionId, "sessionId不能为空");
|
|
|
|
Assert.notEmpty(sessionId, "sessionId不能为空");
|
|
|
|
List<IrSessionHistory> sessionHistoryList = sessionService.lambdaQuery().eq(IrSessionHistory::getSessionId, sessionId).orderBy(true, false,IrSessionHistory::getCreateTime).list();
|
|
|
|
List<IrSessionHistory> sessionHistoryList = sessionService.lambdaQuery().eq(IrSessionHistory::getSessionId, sessionId).orderBy(true, true,IrSessionHistory::getCreateTime).list();
|
|
|
|
|
|
|
|
|
|
|
|
// 获取音频的长度
|
|
|
|
// 获取音频的长度
|
|
|
|
List<String> voiceIds = sessionHistoryList.stream()
|
|
|
|
List<String> voiceIds = sessionHistoryList.stream()
|
|
|
|
.map(session -> CollUtil.toList(session.getAnswerVoiceId(), session.getUserQuestionVoiceId()))
|
|
|
|
.map(session -> CollUtil.toList(session.getAnswerVoiceId(), session.getUserQuestionVoiceId()))
|
|
|
|
.flatMap(Collection::stream).filter(StrUtil::isNotEmpty).collect(Collectors.toList());
|
|
|
|
.flatMap(Collection::stream).filter(StrUtil::isNotEmpty).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Integer> voiceLengthMap = CollUtil.isEmpty(voiceIds) ? new HashMap<>() :
|
|
|
|
Map<String, Integer> voiceLengthMap = CollUtil.isEmpty(voiceIds) ? new HashMap<>() :
|
|
|
|
irVoiceService.listByIds(voiceIds).stream().collect(Collectors.toMap(IrVoice::getId, IrVoice::getLength));
|
|
|
|
irVoiceService.listByIds(voiceIds).stream().filter(i->Objects.nonNull(i.getLength())).collect(Collectors.toMap(IrVoice::getId, IrVoice::getLength));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return sessionHistoryList.stream().map(session->this.sessionHistory2RobotTalkDTO(session,voiceLengthMap))
|
|
|
|
return sessionHistoryList.stream().map(session->this.sessionHistory2RobotTalkDTO(session,voiceLengthMap))
|
|
|
|
.filter(Objects::nonNull).flatMap(Collection::stream).collect(Collectors.toList());
|
|
|
|
.filter(Objects::nonNull).flatMap(Collection::stream).collect(Collectors.toList());
|
|
|
|