|
|
|
@ -0,0 +1,143 @@
|
|
|
|
|
package com.supervision.manage.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import cn.hutool.core.date.TimeInterval;
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import cn.hutool.core.lang.Pair;
|
|
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import cn.hutool.poi.excel.ExcelReader;
|
|
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
|
|
|
import com.supervision.manage.service.AnswerVideoResourceService;
|
|
|
|
|
import com.supervision.model.AskPatientAnswer;
|
|
|
|
|
import com.supervision.model.AskTemplateQuestionLibrary;
|
|
|
|
|
import com.supervision.model.FileResource;
|
|
|
|
|
import com.supervision.service.AskPatientAnswerService;
|
|
|
|
|
import com.supervision.service.AskTemplateQuestionLibraryService;
|
|
|
|
|
import com.supervision.service.FileResourceService;
|
|
|
|
|
import com.supervision.util.MinioUtil;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 离线视频资源
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class OfflineAnswerVideoResource implements AnswerVideoResourceService {
|
|
|
|
|
|
|
|
|
|
@Value("${answer.offline.videoPath}")
|
|
|
|
|
private String videoPath;
|
|
|
|
|
|
|
|
|
|
@Value("${answer.offline.indexFile}")
|
|
|
|
|
private String indexFile;
|
|
|
|
|
|
|
|
|
|
@Value("${answer.offline.videoSuffix}")
|
|
|
|
|
private String videoSuffix;
|
|
|
|
|
|
|
|
|
|
private final AskPatientAnswerService askPatientAnswerService;
|
|
|
|
|
|
|
|
|
|
private final AskTemplateQuestionLibraryService askTemplateQuestionLibraryService;
|
|
|
|
|
|
|
|
|
|
private final FileResourceService fileResourceService;
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void preGenerationMedicalAnswerVideo(String medicalId) {
|
|
|
|
|
|
|
|
|
|
// 1. 获取视频文件,及视频内容
|
|
|
|
|
List<Pair<String, File>> videoFileAndContent = getVideoFileAndContent(videoPath,indexFile,videoSuffix);
|
|
|
|
|
if (CollUtil.isEmpty(videoFileAndContent)){
|
|
|
|
|
log.info("getVideoFileAndContent result is empty");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//2. 填充数据库中疾病问诊的资源id
|
|
|
|
|
Map<String, AskPatientAnswer> patientAnserMap = askPatientAnswerService.lambdaQuery().eq(AskPatientAnswer::getMedicalId, medicalId).list()
|
|
|
|
|
.stream().collect(Collectors.toMap(answer -> StrUtil.trim(answer.getAnswer()), answer -> answer));
|
|
|
|
|
// 问诊模板数据
|
|
|
|
|
List<AskTemplateQuestionLibrary> askTemplateQuestionLibraryList = askTemplateQuestionLibraryService.lambdaQuery().list();
|
|
|
|
|
List<String> resourceIds = new ArrayList<>();
|
|
|
|
|
try {
|
|
|
|
|
for (Pair<String, File> pair : videoFileAndContent) {
|
|
|
|
|
AskPatientAnswer askPatientAnswer = patientAnserMap.get(pair.getKey());
|
|
|
|
|
if (Objects.nonNull(askPatientAnswer)){
|
|
|
|
|
String resourceId = saveResource(pair.getValue());
|
|
|
|
|
askPatientAnswer.setAnswerResourceId(resourceId);
|
|
|
|
|
resourceIds.add(resourceId);
|
|
|
|
|
askPatientAnswerService.updateById(askPatientAnswer);
|
|
|
|
|
log.info("update askPatientAnswer:{}", JSONUtil.toJsonStr(askPatientAnswer));
|
|
|
|
|
}else {
|
|
|
|
|
//todo: 获取模板中的数据
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// 文件处理过程中出现异常,删除文件
|
|
|
|
|
log.error("preGenerationMedicalAnswerVideo:生成文件失败",e);
|
|
|
|
|
for (String resourceId : resourceIds) {
|
|
|
|
|
try {
|
|
|
|
|
MinioUtil.deleteObject(resourceId);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
log.info("删除资源失败:{}", resourceId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存资源
|
|
|
|
|
* @param file file
|
|
|
|
|
* @return 资源id
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
private String saveResource(File file) throws Exception {
|
|
|
|
|
String resourceId = MinioUtil.uploadFile(Files.newInputStream(file.toPath()));
|
|
|
|
|
|
|
|
|
|
FileResource fileResource = new FileResource();
|
|
|
|
|
fileResource.setMinioId(resourceId);
|
|
|
|
|
fileResource.setFileType(FileUtil.getMimeType(file.toPath()));
|
|
|
|
|
fileResource.setFileSize(FileUtil.size(file));
|
|
|
|
|
fileResourceService.save(fileResource);
|
|
|
|
|
return fileResource.getId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取视频文件及内容
|
|
|
|
|
* @param videoPath 视频存放路径
|
|
|
|
|
* @return pair.getKey():视频内容 pair.getValue():视频文件对象
|
|
|
|
|
*/
|
|
|
|
|
List<Pair<String, File>> getVideoFileAndContent(String videoPath, String indexFileName, String videoSuffix){
|
|
|
|
|
|
|
|
|
|
log.info("preGenerationMedicalAnswerVideo: 开始读取excel表格中数据{}",String.join(File.separator,videoPath,indexFileName));
|
|
|
|
|
TimeInterval timer = DateUtil.timer();
|
|
|
|
|
try (ExcelReader reader = ExcelUtil.getReader(FileUtil.file(String.join(File.separator,videoPath,indexFileName)))){
|
|
|
|
|
List<Map<String, Object>> allMapList = reader.readAll();
|
|
|
|
|
log.info("preGenerationMedicalAnswerVideo: 读取excel表格中数据耗时:{} s", timer.intervalSecond());
|
|
|
|
|
|
|
|
|
|
return allMapList.stream().map(map -> {
|
|
|
|
|
String answerText = MapUtil.getStr(map, "A(answer)");
|
|
|
|
|
String fileName = MapUtil.getStr(map, "知识库A-ID\n[病征]");
|
|
|
|
|
if (StrUtil.isEmpty(answerText) || StrUtil.isEmpty(fileName)) {
|
|
|
|
|
log.info("文件内容不完整:answerText:{},fileName:{}", answerText, fileName);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return Pair.of(answerText, FileUtil.file(String.join(File.separator,videoPath,fileName)+videoSuffix));
|
|
|
|
|
}).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|