诊断流程提交

dev_v1.0.1
liu 2 years ago
parent 4f6ec95d25
commit 1b29bbd9bc

@ -1,5 +1,6 @@
package com.supervision.controller;
import com.supervision.pojo.vo.TalkReqVO;
import com.supervision.pojo.vo.TalkResultResVO;
import com.supervision.service.AskService;
import io.swagger.annotations.Api;
@ -19,15 +20,16 @@ public class AskController {
@Autowired
private AskService askService;
@ApiOperation("接收页面的语音消息(这个接口使用京东数字人接口来做)")
@PostMapping("/receiveVoiceFile")
public String receiveVoiceFile(@RequestParam("file") MultipartFile file) {
return askService.receiveVoiceFile(file);
}
@ApiOperation("接收页面的语音消息(这个接口使用京东数字人接口来做)")
@PostMapping("/receiveVoiceFile")
public TalkResultResVO receiveVoiceFile(@RequestParam("file") MultipartFile file,
@ApiParam("流程ID") String processId,
@ApiParam("数字人房间的数字人ID") String roomKey,
@ApiParam("数字人的TOKEN") String roomToken) throws IOException {
return askService.receiveVoiceFile(file, processId, roomKey, roomToken);
public TalkResultResVO talk(TalkReqVO talkReqVO) throws IOException {
return askService.talk(talkReqVO);
}
@ApiOperation("回复语音及文字消息")

@ -0,0 +1,21 @@
package com.supervision.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import org.springframework.web.bind.annotation.RequestParam;
@Data
public class TalkReqVO {
@ApiModelProperty("对话内容")
private String text;
@ApiModelProperty("流程ID")
private String processId;
@ApiModelProperty("数字人房间的数字人ID")
private String roomKey;
@ApiModelProperty("数字人的TOKEN")
private String roomToken;
}

@ -10,9 +10,9 @@ public class TalkResultResVO {
private ActionDTO action;
/**
* 使,action,1,2
* 使,action,1,2
*/
@ApiModelProperty("后端返回给前端时使用,表示该是消息还是action动作,1消息,2动作")
@ApiModelProperty("后端返回给前端时使用,表示该是语音回复还是action动作,1语音回复,2动作")
private Integer type;
}

@ -1,13 +1,17 @@
package com.supervision.service;
import com.supervision.pojo.vo.TalkReqVO;
import com.supervision.pojo.vo.TalkResultResVO;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
public interface AskService {
TalkResultResVO receiveVoiceFile(MultipartFile file, String processId, String roomKey, String roomToken) throws IOException;
String receiveVoiceFile(MultipartFile file);
TalkResultResVO talk(TalkReqVO talkReqVO) throws IOException;
String replyVoice();

@ -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();

Loading…
Cancel
Save