|
|
|
@ -0,0 +1,122 @@
|
|
|
|
|
package com.supervision.manage;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
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.log.Log;
|
|
|
|
|
import cn.hutool.poi.excel.ExcelReader;
|
|
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
|
|
|
import com.supervision.manage.service.AskQuestionLibraryManageService;
|
|
|
|
|
import com.supervision.manage.service.DiseasePhysicalManageService;
|
|
|
|
|
import com.supervision.model.AskPatientAnswer;
|
|
|
|
|
import com.supervision.model.AskTemplateQuestionLibrary;
|
|
|
|
|
import com.supervision.service.AskPatientAnswerService;
|
|
|
|
|
import com.supervision.service.AskTemplateQuestionLibraryService;
|
|
|
|
|
import com.supervision.util.MinioUtil;
|
|
|
|
|
import com.supervision.vo.manage.DiseasePhysicalLocationNodeVo;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@SpringBootTest
|
|
|
|
|
class VirtualPatientManageApplicationTests {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private AskPatientAnswerService askPatientAnswerService;;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private AskTemplateQuestionLibraryService askTemplateQuestionLibraryService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void generateVideo(){
|
|
|
|
|
|
|
|
|
|
String medicalId = "ww";
|
|
|
|
|
|
|
|
|
|
String videoPath = "F:\\tmp\\video";
|
|
|
|
|
String indexFile = "标准病人语料库v1.3.xlsx";
|
|
|
|
|
|
|
|
|
|
// 1. 获取视频文件,及视频内容
|
|
|
|
|
List<Pair<String, File>> videoFileAndContent = getVideoFileAndContent(videoPath,indexFile,".mp4");
|
|
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(videoFileAndContent)){
|
|
|
|
|
log.info("getVideoFileAndContent result is empty");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//填充数据库中疾病问诊的资源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 = MinioUtil.uploadFile(Files.newInputStream(pair.getValue().toPath()));
|
|
|
|
|
askPatientAnswer.setAnswerResourceId(resourceId);
|
|
|
|
|
resourceIds.add(resourceId);
|
|
|
|
|
askPatientAnswerService.updateById(askPatientAnswer);
|
|
|
|
|
log.info("update askPatientAnswer:{}", JSONUtil.toJsonStr(askPatientAnswer));
|
|
|
|
|
}else {
|
|
|
|
|
//todo: 获取模板中的数据
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// 文件处理过程中出现异常,删除文件
|
|
|
|
|
for (String resourceId : resourceIds) {
|
|
|
|
|
try {
|
|
|
|
|
MinioUtil.deleteObject(resourceId);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
log.info("删除资源失败:{}", resourceId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取视频文件及内容
|
|
|
|
|
* @param videoPath 视频存放路径
|
|
|
|
|
* @return pair.getKey():视频内容 pair.getValue():视频文件对象
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
List<Pair<String, File>> getVideoFileAndContent(String videoPath,String indexFileName,String videoSuffix){
|
|
|
|
|
|
|
|
|
|
try (ExcelReader reader = ExcelUtil.getReader(FileUtil.file(String.join(File.separator,videoPath,indexFileName)))){
|
|
|
|
|
|
|
|
|
|
return reader.readAll().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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|