|
|
|
@ -1,29 +1,42 @@
|
|
|
|
|
package com.supervision.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.codec.Base64;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.date.TimeInterval;
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.supervision.domain.IrFile;
|
|
|
|
|
import com.supervision.domain.IrRobotConfig;
|
|
|
|
|
import com.supervision.domain.IrSessionHistory;
|
|
|
|
|
import com.supervision.domain.IrVoice;
|
|
|
|
|
import com.supervision.dto.MatchQuestionAnswerDTO;
|
|
|
|
|
import com.supervision.domain.*;
|
|
|
|
|
import com.supervision.dto.paddlespeech.res.TtsResultDTO;
|
|
|
|
|
import com.supervision.dto.robot.*;
|
|
|
|
|
import com.supervision.dto.matchTool.ExtractInformationDTO;
|
|
|
|
|
import com.supervision.dto.matchTool.MatchQuestionAnswerDTO;
|
|
|
|
|
import com.supervision.dto.QueryProcessDTO;
|
|
|
|
|
import com.supervision.dto.RobotTalkDTO;
|
|
|
|
|
import com.supervision.mapper.RobotDataMapper;
|
|
|
|
|
import com.supervision.service.*;
|
|
|
|
|
import com.supervision.util.UserUtil;
|
|
|
|
|
import com.supervision.vo.robot.ArchivesReqVo;
|
|
|
|
|
import com.supervision.vo.talk.RobotTalkReq;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
@ -40,83 +53,176 @@ public class RobotTalkServiceImpl implements RobotTalkService {
|
|
|
|
|
|
|
|
|
|
private final IrSessionHistoryService sessionService;
|
|
|
|
|
|
|
|
|
|
private final IrSessionParamService irSessionParamService;
|
|
|
|
|
|
|
|
|
|
private final IrVoiceService irVoiceService;
|
|
|
|
|
|
|
|
|
|
private final IrFileService irFileService;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private final RobotDataMapper robotDataMapper;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public RobotTalkDTO textTalk2Robot(String sessionId, String message) {
|
|
|
|
|
public RobotTalkDTO textTalk2Robot(RobotTalkReq robotTalkReq) {
|
|
|
|
|
String sessionId = robotTalkReq.getSessionId();
|
|
|
|
|
String message = robotTalkReq.getMessage();
|
|
|
|
|
Assert.notEmpty(sessionId, "sessionId不能为空");
|
|
|
|
|
TimeInterval timeInterval = new TimeInterval();
|
|
|
|
|
timeInterval.start("all");
|
|
|
|
|
log.info("textTalk2Robot:开始问答,sessionId:{},message:{}",sessionId,message);
|
|
|
|
|
|
|
|
|
|
RobotTalkDTO robotTalkDTO = new RobotTalkDTO();
|
|
|
|
|
robotTalkDTO.setSessionId(sessionId);
|
|
|
|
|
robotTalkDTO.setAskMessage(message);
|
|
|
|
|
// 设置问答类型为文本
|
|
|
|
|
robotTalkDTO.setAskContentType(1);
|
|
|
|
|
robotTalkDTO.setAnswerContentType(2);
|
|
|
|
|
RobotTalkDTO robotTalkDTO = RobotTalkDTO.builder()
|
|
|
|
|
.sessionId(sessionId).doNext(true)
|
|
|
|
|
.askInfo(AskInfo.builder().contentType(1).message(robotTalkReq.getMessage()).build())
|
|
|
|
|
.answerInfo(AnswerInfo.builder().contentType(robotTalkReq.getAnswerType()).build())
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
List<MatchQuestionAnswerDTO> matchQuestionAnswerDTOS = null;
|
|
|
|
|
if (StrUtil.isNotEmpty(message)){
|
|
|
|
|
// 如果消息为空,则没必要进行意图匹配
|
|
|
|
|
try {
|
|
|
|
|
matchQuestionAnswerDTOS = matchToolService.execMatch(message);
|
|
|
|
|
log.info("问题:{} 匹配到的意图:{}",message, JSONUtil.toJsonStr(matchQuestionAnswerDTOS));
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("textTalk2Robot:内容:{} 相似度匹配失败",message,e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// todo:识别下载文件的语义
|
|
|
|
|
|
|
|
|
|
// 提取信息中的关键信息
|
|
|
|
|
if (Boolean.FALSE.equals(robotTalkReq.isConfirmFlag())){
|
|
|
|
|
extractInformation(sessionId, message, robotTalkDTO);
|
|
|
|
|
}
|
|
|
|
|
// 匹配问题意图
|
|
|
|
|
MatchQuestionAnswerDTO matchQuestionAnswerDTO = matchQuestionAnswer(message);
|
|
|
|
|
// 获取机器人配置
|
|
|
|
|
IrRobotConfig config = irRobotConfigService.lambdaQuery().one();
|
|
|
|
|
String answerText = null;
|
|
|
|
|
if (CollUtil.isEmpty(matchQuestionAnswerDTOS)){
|
|
|
|
|
if (Objects.isNull(matchQuestionAnswerDTO) && robotTalkDTO.isDoNext()){
|
|
|
|
|
// 未匹配到查询意图,设置默认错误语
|
|
|
|
|
log.info("问题:{}未匹配到意图",message);
|
|
|
|
|
answerText = config.getErrorLanguage();
|
|
|
|
|
robotTalkDTO.setAnswerMessage(config.getErrorLanguage());
|
|
|
|
|
robotTalkDTO.getAnswerInfo().setMessage(config.getErrorLanguage());
|
|
|
|
|
robotTalkDTO.setDoNext(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 匹配到查询意图,用第一个意图
|
|
|
|
|
QueryProcessDTO process = QueryProcessDTO.builder().state(2).build();
|
|
|
|
|
MatchQuestionAnswerDTO matchQuestionAnswerDTO = CollUtil.getFirst(matchQuestionAnswerDTOS);
|
|
|
|
|
if (Objects.nonNull(matchQuestionAnswerDTO)){
|
|
|
|
|
process = queryTemplateProcessor.process(matchQuestionAnswerDTO.getMatchQuestionCode(), sessionId);
|
|
|
|
|
if (robotTalkDTO.isDoNext()){
|
|
|
|
|
QueryProcessDTO matchAnswer = queryMatchAnswer(sessionId, matchQuestionAnswerDTO, robotTalkDTO, robotTalkReq.getTitleContent());
|
|
|
|
|
if (Integer.valueOf(0).equals(matchAnswer.getState()) &&
|
|
|
|
|
Integer.valueOf(3).equals(matchAnswer.getContentType())){
|
|
|
|
|
// 查询结果类型为字节数组
|
|
|
|
|
robotTalkDTO.getAnswerInfo().setContentType(3);
|
|
|
|
|
robotTalkDTO.getAnswerInfo().setAnswerByteId(matchAnswer.getByteContentId());
|
|
|
|
|
robotTalkDTO.getAnswerInfo().setAnswerByte(matchAnswer.getByteContent());
|
|
|
|
|
}else {
|
|
|
|
|
robotTalkDTO.getAnswerInfo().setMessage(decideAnswer(matchAnswer, config));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询结果类型为字节数组
|
|
|
|
|
if (Integer.valueOf(0).equals(process.getState()) &&
|
|
|
|
|
Integer.valueOf(3).equals(process.getContentType())){
|
|
|
|
|
// 返回的结果是字节,保存到文件表
|
|
|
|
|
IrFile irFile = process2File(process);
|
|
|
|
|
irFileService.save(irFile);
|
|
|
|
|
robotTalkDTO.setAnswerContentType(3);
|
|
|
|
|
robotTalkDTO.setAnswerByteId(irFile.getId());
|
|
|
|
|
}else {
|
|
|
|
|
answerText = decideAnswer(process, config);
|
|
|
|
|
}
|
|
|
|
|
logSessionInfo(robotTalkDTO, matchQuestionAnswerDTO);
|
|
|
|
|
|
|
|
|
|
log.info("textTalk2Robot:结束问答,耗时:{}ms",timeInterval.interval("all"));
|
|
|
|
|
return robotTalkDTO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void logSessionInfo(RobotTalkDTO robotTalkDTO, MatchQuestionAnswerDTO matchQuestionAnswerDTO) {
|
|
|
|
|
// 组装日志信息
|
|
|
|
|
IrSessionHistory irSessionHistory = talk2SessionHistory(sessionId, message,
|
|
|
|
|
CollUtil.getFirst(matchQuestionAnswerDTOS));
|
|
|
|
|
// todo:语音倍速设置
|
|
|
|
|
IrSessionHistory irSessionHistory = talk2SessionHistory(robotTalkDTO.getSessionId(),
|
|
|
|
|
robotTalkDTO.getAnswerInfo().getMessage(), matchQuestionAnswerDTO);
|
|
|
|
|
irSessionHistory.setAnswerType(robotTalkDTO.getAnswerInfo().getContentType());
|
|
|
|
|
|
|
|
|
|
// 保存回答音频文件
|
|
|
|
|
if (StrUtil.isNotEmpty(answerText)){
|
|
|
|
|
String audioBase = voiceService.textToVoice(answerText);
|
|
|
|
|
IrVoice irVoice = new IrVoice();
|
|
|
|
|
irVoice.setVoiceBase64(audioBase);
|
|
|
|
|
irVoiceService.save(irVoice);
|
|
|
|
|
robotTalkDTO.setAnswerVoiceBaseId(irVoice.getId());
|
|
|
|
|
IrVoice irVoice = saveAudioIfNoAbsent(robotTalkDTO.getAnswerInfo().getMessage());
|
|
|
|
|
if (Objects.nonNull(irVoice)) {
|
|
|
|
|
robotTalkDTO.getAnswerInfo().setVoiceBaseId(irVoice.getId());
|
|
|
|
|
robotTalkDTO.getAnswerInfo().setVoiceBase64(irVoice.getVoiceBase64());
|
|
|
|
|
robotTalkDTO.getAnswerInfo().setAudioLength(irVoice.getLength());
|
|
|
|
|
irSessionHistory.setAnswerVoiceId(irVoice.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Objects.nonNull(robotTalkDTO.getAnswerInfo().getAnswerByte())) {
|
|
|
|
|
// 如果返回的结果是字节,保存到文件表
|
|
|
|
|
IrFile irFile = saveFileIfNoAbsent(robotTalkDTO.getAnswerInfo().getAnswerByte());
|
|
|
|
|
if (Objects.nonNull(irFile)) {
|
|
|
|
|
robotTalkDTO.getAnswerInfo().setContentType(3);
|
|
|
|
|
robotTalkDTO.getAnswerInfo().setAnswerByteId(irFile.getId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 写入对话日志
|
|
|
|
|
sessionService.save(irSessionHistory);
|
|
|
|
|
robotTalkDTO.setAnswerMessage(answerText);
|
|
|
|
|
robotTalkDTO.setAskId(irSessionHistory.getId());
|
|
|
|
|
log.info("textTalk2Robot:结束问答,耗时:{}ms",timeInterval.interval("all"));
|
|
|
|
|
return robotTalkDTO;
|
|
|
|
|
robotTalkDTO.getAskInfo().setAskId(irSessionHistory.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IrVoice saveAudioIfNoAbsent(String message) {
|
|
|
|
|
|
|
|
|
|
if (StrUtil.isEmpty(message)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
TtsResultDTO resultDTO = voiceService.textToVoice(message);
|
|
|
|
|
IrVoice irVoice = new IrVoice();
|
|
|
|
|
irVoice.setVoiceBase64(resultDTO.getAudio());
|
|
|
|
|
if (NumberUtil.isNumber(resultDTO.getDuration())){
|
|
|
|
|
irVoice.setLength(NumberUtil.parseInt(resultDTO.getDuration()));
|
|
|
|
|
}
|
|
|
|
|
irVoiceService.save(irVoice);
|
|
|
|
|
return irVoice;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryProcessDTO queryMatchAnswer(String sessionId, MatchQuestionAnswerDTO matchQuestionAnswerDTO,
|
|
|
|
|
RobotTalkDTO robotTalkDTO,SuspectInfo suspectInfo) {
|
|
|
|
|
QueryProcessDTO process = QueryProcessDTO.builder().state(2).build();
|
|
|
|
|
if (Objects.nonNull(matchQuestionAnswerDTO) && robotTalkDTO.isDoNext()) {
|
|
|
|
|
process = queryTemplateProcessor.process(matchQuestionAnswerDTO.getMatchQuestionCode(), sessionId,
|
|
|
|
|
()->this.suspectInfo2IrSessionParam(sessionId,suspectInfo));
|
|
|
|
|
}
|
|
|
|
|
return process;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<IrSessionParam> suspectInfo2IrSessionParam(String sessionId,SuspectInfo suspectInfo) {
|
|
|
|
|
List<IrSessionParam> sessionParams = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
if (Objects.nonNull(suspectInfo)){
|
|
|
|
|
sessionParams.add(new IrSessionParam(sessionId,"jykh",StrUtil.join(",",suspectInfo.getCardNumber())));
|
|
|
|
|
sessionParams.add(new IrSessionParam(sessionId,"khrzjhm",suspectInfo.getIdNumber()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IrSessionParam sessionParam = irSessionParamService.lambdaQuery().eq(IrSessionParam::getSessionId, sessionId)
|
|
|
|
|
.eq(IrSessionParam::getParamName, "ajid").one();
|
|
|
|
|
if (Objects.nonNull(sessionParam)) {
|
|
|
|
|
sessionParams.add(sessionParam);
|
|
|
|
|
}
|
|
|
|
|
return sessionParams;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MatchQuestionAnswerDTO matchQuestionAnswer(String message) {
|
|
|
|
|
|
|
|
|
|
if (StrUtil.isNotEmpty(message)){
|
|
|
|
|
// 如果消息为空,则没必要进行意图匹配
|
|
|
|
|
try {
|
|
|
|
|
List<MatchQuestionAnswerDTO> matchQuestionAnswerDTOS = matchToolService.execMatch(message);
|
|
|
|
|
log.info("问题:{} 匹配到的意图:{}", message, JSONUtil.toJsonStr(matchQuestionAnswerDTOS));
|
|
|
|
|
return CollUtil.getFirst(matchQuestionAnswerDTOS);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("textTalk2Robot:内容:{} 相似度匹配失败", message,e);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void extractInformation(String sessionId, String message, RobotTalkDTO robotTalkDTO) {
|
|
|
|
|
ExtractInformationDTO extractInformationDTO = matchToolService.extractInformation(message);
|
|
|
|
|
if (Objects.isNull(extractInformationDTO) || extractInformationDTO.allEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 识别到重要信息
|
|
|
|
|
IrSessionParam sessionParam = irSessionParamService.lambdaQuery().eq(IrSessionParam::getSessionId, sessionId).eq(IrSessionParam::getParamName, "ajid").one();
|
|
|
|
|
AnswerInfo answerInfo = robotTalkDTO.getAnswerInfo();
|
|
|
|
|
if (Objects.isNull(sessionParam) || StrUtil.isEmpty(sessionParam.getParamValue())) {
|
|
|
|
|
// 案件id为空,需要设置案件id
|
|
|
|
|
answerInfo.setContentType(2);
|
|
|
|
|
answerInfo.setMessage("请先设置案件id");
|
|
|
|
|
robotTalkDTO.setDoNext(false);
|
|
|
|
|
} else {
|
|
|
|
|
Integer caseNo = StrUtil.isEmpty(sessionParam.getParamValue()) ? null : Integer.valueOf(sessionParam.getParamValue());
|
|
|
|
|
List<SuspectInfo> suspectInfos = robotDataMapper.querySuspect(caseNo,
|
|
|
|
|
extractInformationDTO.getIdNumber(),
|
|
|
|
|
extractInformationDTO.getName(),
|
|
|
|
|
extractInformationDTO.getCardNumber());
|
|
|
|
|
|
|
|
|
|
answerInfo.setContentType(6);
|
|
|
|
|
answerInfo.setSuspectInfo(CollUtil.getFirst(suspectInfos));
|
|
|
|
|
robotTalkDTO.setDoNext(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String decideAnswer(QueryProcessDTO process, IrRobotConfig config) {
|
|
|
|
@ -134,13 +240,16 @@ public class RobotTalkServiceImpl implements RobotTalkService {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IrFile process2File(QueryProcessDTO process) {
|
|
|
|
|
byte[] byteContent = process.getByteContent();
|
|
|
|
|
private IrFile saveFileIfNoAbsent(byte[] byteContent) {
|
|
|
|
|
if (Objects.isNull(byteContent)){
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
IrFile irFile = new IrFile();
|
|
|
|
|
irFile.setFileByte(byteContent);
|
|
|
|
|
irFile.setFileSize(byteContent.length);
|
|
|
|
|
irFile.setFileName("answer");
|
|
|
|
|
irFile.setFileType("F");
|
|
|
|
|
irFileService.save(irFile);
|
|
|
|
|
return irFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -160,20 +269,89 @@ public class RobotTalkServiceImpl implements RobotTalkService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public RobotTalkDTO videoTalk2Robot(String sessionId, MultipartFile multipartFile) {
|
|
|
|
|
public RobotTalkDTO videoTalk2Robot(MultipartFile multipartFile,RobotTalkReq robotTalkReq) {
|
|
|
|
|
|
|
|
|
|
String sessionId = robotTalkReq.getSessionId();
|
|
|
|
|
|
|
|
|
|
Assert.notEmpty(sessionId, "sessionId不能为空");
|
|
|
|
|
Assert.notNull(multipartFile, "multipartFile不能为空");
|
|
|
|
|
|
|
|
|
|
String message = null;
|
|
|
|
|
try {
|
|
|
|
|
message = voiceService.voiceToText(multipartFile, sessionId);
|
|
|
|
|
String message = voiceService.voiceToText(multipartFile, sessionId);
|
|
|
|
|
robotTalkReq.setMessage(message);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
log.error("语音转文字失败", e);
|
|
|
|
|
}
|
|
|
|
|
RobotTalkDTO robotTalkDTO = this.textTalk2Robot(sessionId, message);
|
|
|
|
|
robotTalkDTO.setAskContentType(2);
|
|
|
|
|
RobotTalkDTO robotTalkDTO = this.textTalk2Robot(robotTalkReq);
|
|
|
|
|
robotTalkDTO.getAskInfo().setContentType(2);
|
|
|
|
|
return robotTalkDTO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<RobotTalkDTO> talkList(String sessionId) {
|
|
|
|
|
|
|
|
|
|
Assert.notEmpty(sessionId, "sessionId不能为空");
|
|
|
|
|
List<IrSessionHistory> sessionHistoryList = sessionService.lambdaQuery().eq(IrSessionHistory::getSessionId, sessionId).list();
|
|
|
|
|
return sessionHistoryList.stream().map(this::sessionHistory2RobotTalkDTO).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private RobotTalkDTO sessionHistory2RobotTalkDTO(IrSessionHistory sessionHistory) {
|
|
|
|
|
if (Objects.isNull(sessionHistory)){
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
AskInfo askInfo = AskInfo.builder()
|
|
|
|
|
.askId(sessionHistory.getId())
|
|
|
|
|
.message(sessionHistory.getUserQuestion())
|
|
|
|
|
.contentType(sessionHistory.getAnswerType())
|
|
|
|
|
//.audioLength(sessionHistory)
|
|
|
|
|
.build();
|
|
|
|
|
AnswerInfo answerInfo = AnswerInfo.builder()
|
|
|
|
|
.contentType(sessionHistory.getAnswerType())
|
|
|
|
|
.answerByteId(sessionHistory.getAnswerVoiceId())
|
|
|
|
|
.message(sessionHistory.getAnswer())
|
|
|
|
|
.build();
|
|
|
|
|
return RobotTalkDTO.builder().sessionId(sessionHistory.getSessionId())
|
|
|
|
|
.askInfo(askInfo).answerInfo(answerInfo).build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void getAudio(HttpServletResponse response, String audioId) throws IOException {
|
|
|
|
|
Assert.notEmpty(audioId, "audioId不能为空");
|
|
|
|
|
|
|
|
|
|
IrVoice voice = irVoiceService.getById(audioId);
|
|
|
|
|
if (Objects.isNull(voice) || StrUtil.isEmpty(voice.getVoiceBase64())){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Base64.decodeToStream(voice.getVoiceBase64(), response.getOutputStream(),false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void downLoadArchives(HttpServletResponse response,ArchivesReqVo archivesReq) throws IOException {
|
|
|
|
|
String path = localArchivesFilePath(archivesReq);
|
|
|
|
|
if (StrUtil.isEmpty(path)){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
IoUtil.copy(Files.newInputStream(Paths.get(path)),response.getOutputStream());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void downLoadFile(HttpServletResponse response, String fileType, String imageId) throws IOException {
|
|
|
|
|
IrFile file = irFileService.getById(imageId);
|
|
|
|
|
if (Objects.isNull(file) || Objects.isNull(file.getFileByte())){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
IoUtil.write(response.getOutputStream(), true, Base64.decode(file.getFileByte()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String localArchivesFilePath(ArchivesReqVo archivesReq) {
|
|
|
|
|
String path = StrUtil.join(File.separator,archivesReq.getCaseId(),
|
|
|
|
|
StrUtil.join("-",archivesReq.getName(),archivesReq.getIdNumber()));
|
|
|
|
|
|
|
|
|
|
// 判断文件是否存在
|
|
|
|
|
if (FileUtil.exist(path)){
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|