From 45b111c658b69eba67586ae4bc28785569f436c1 Mon Sep 17 00:00:00 2001 From: xueqingkun Date: Thu, 25 Jan 2024 10:20:50 +0800 Subject: [PATCH] manage: test --- .../VirtualPatientManageApplicationTests.java | 58 ++++++++++++++----- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/virtual-patient-manage/src/test/java/com/supervision/manage/VirtualPatientManageApplicationTests.java b/virtual-patient-manage/src/test/java/com/supervision/manage/VirtualPatientManageApplicationTests.java index 1b3b7ff4..97d26b68 100644 --- a/virtual-patient-manage/src/test/java/com/supervision/manage/VirtualPatientManageApplicationTests.java +++ b/virtual-patient-manage/src/test/java/com/supervision/manage/VirtualPatientManageApplicationTests.java @@ -4,6 +4,9 @@ package com.supervision.manage; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Pair; import cn.hutool.core.util.StrUtil; +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; @@ -12,14 +15,20 @@ 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 { @@ -40,27 +49,36 @@ class VirtualPatientManageApplicationTests { // 获取视频文件,及视频内容 List> videoFileAndContent = getVideoFileAndContent(null); - //填充数据库中的资源id + //填充数据库中疾病问诊的资源id Map patientAnserMap = askPatientAnswerService.lambdaQuery().eq(AskPatientAnswer::getMedicalId, medicalId).list() .stream().collect(Collectors.toMap(answer -> StrUtil.trim(answer.getAnswer()), answer -> answer)); + // 问诊模板数据 List askTemplateQuestionLibraryList = askTemplateQuestionLibraryService.lambdaQuery().list(); - for (Pair pair : videoFileAndContent) { - AskPatientAnswer askPatientAnswer = patientAnserMap.get(pair.getKey()); - if (Objects.isNull(askPatientAnswer)){ - AskPatientAnswer answer = new AskPatientAnswer(); - answer.setCode(null); - answer.setAnswer(pair.getKey()); - answer.setMedicalId(medicalId); - String resourceId = MinioUtil.uploadFile(null); - answer.setAnswerResourceId(resourceId); + List resourceIds = new ArrayList<>(); + try { + for (Pair 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); + }else { + //todo: 获取模板中的数据 + } + } + } catch (Exception e) { + // 文件处理过程中出现异常,删除文件 + for (String resourceId : resourceIds) { + try { + MinioUtil.deleteObject(resourceId); + } catch (Exception ex) { + log.info("删除资源失败:{}", resourceId); + } } } - - - - } @@ -70,12 +88,22 @@ class VirtualPatientManageApplicationTests { * @return pair.getKey():视频内容 pair.getValue():视频文件对象 */ - List> getVideoFileAndContent(String videoPath) { + List> getVideoFileAndContent(String videoPath) throws IOException { + + + ExcelReader reader = ExcelUtil.getReader(Files.newInputStream(new File("").toPath())); + org.apache.poi.ss.usermodel.Sheet sheet = reader.getSheet(); Pair pair = Pair.of("", new File("")); return CollUtil.newArrayList(pair); } + public static void main(String[] args) throws IOException { + ExcelReader reader = ExcelUtil.getReader(Files.newInputStream(new File("").toPath())); + + List> maps = reader.readAll(); + } +