From ad0f2c7e929b6f33094f002bd98a8e8c1b8694db Mon Sep 17 00:00:00 2001 From: yangmaofu Date: Tue, 21 Apr 2026 21:34:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E4=B8=8B=E8=BD=BD=E5=A7=94?= =?UTF-8?q?=E6=89=98=E6=8A=A5=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springblade/system/enums/DictBizEnum.java | 8 +- .../org/springblade/lims/LimsApplication.java | 2 + .../lims/Scheduled/GlobalScheduledTasks.java | 96 + .../lims/controller/EntrustController.java | 1 + .../lims/service/IEntrtrustService.java | 8 + .../lims/service/impl/EntrustServiceImpl.java | 2444 ++++++++++++++++- .../org/springblade/lims/utils/ZipUtils.java | 66 + 7 files changed, 2621 insertions(+), 4 deletions(-) create mode 100644 lab-service/lab-lims/src/main/java/org/springblade/lims/Scheduled/GlobalScheduledTasks.java create mode 100644 lab-service/lab-lims/src/main/java/org/springblade/lims/utils/ZipUtils.java diff --git a/lab-service-api/lab-dict-api/src/main/java/org/springblade/system/enums/DictBizEnum.java b/lab-service-api/lab-dict-api/src/main/java/org/springblade/system/enums/DictBizEnum.java index 0753eb5..5f5be0f 100644 --- a/lab-service-api/lab-dict-api/src/main/java/org/springblade/system/enums/DictBizEnum.java +++ b/lab-service-api/lab-dict-api/src/main/java/org/springblade/system/enums/DictBizEnum.java @@ -88,9 +88,11 @@ public enum DictBizEnum { /** * 样品处理方式 */ - SAMPLE_HANDLING("sample_handling") - - ; + SAMPLE_HANDLING("sample_handling"), + /** + * 定时任务 + */ + SCHEDULED_TASK("scheduled_task"); final String name; diff --git a/lab-service/lab-lims/src/main/java/org/springblade/lims/LimsApplication.java b/lab-service/lab-lims/src/main/java/org/springblade/lims/LimsApplication.java index e7c4968..be846b6 100644 --- a/lab-service/lab-lims/src/main/java/org/springblade/lims/LimsApplication.java +++ b/lab-service/lab-lims/src/main/java/org/springblade/lims/LimsApplication.java @@ -6,6 +6,7 @@ import org.springblade.core.cloud.feign.EnableBladeFeign; import org.springblade.core.launch.BladeApplication; import org.springframework.cloud.client.SpringCloudApplication; +import org.springframework.scheduling.annotation.EnableScheduling; /** * Lims启动器 @@ -14,6 +15,7 @@ import org.springframework.cloud.client.SpringCloudApplication; */ @EnableBladeFeign @SpringCloudApplication +@EnableScheduling public class LimsApplication { public static void main(String[] args) { diff --git a/lab-service/lab-lims/src/main/java/org/springblade/lims/Scheduled/GlobalScheduledTasks.java b/lab-service/lab-lims/src/main/java/org/springblade/lims/Scheduled/GlobalScheduledTasks.java new file mode 100644 index 0000000..e22c66b --- /dev/null +++ b/lab-service/lab-lims/src/main/java/org/springblade/lims/Scheduled/GlobalScheduledTasks.java @@ -0,0 +1,96 @@ +package org.springblade.lims.Scheduled; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import lombok.extern.slf4j.Slf4j; +import org.springblade.lims.entry.Entrust; +import org.springblade.lims.service.IEntrtrustService; +import org.springblade.system.cache.DictBizCache; +import org.springblade.system.enums.DictBizEnum; + +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.util.*; + +/** + * @BelongsProject: project_husbandry_back + * @BelongsPackage:org.springblade.lims.Scheduled + * @Annotation:定时任务 + * @Author:YangMaoFu + * @date :Created in 2023/7/6 14:18 + * @CreateTime: 2026-04-16 23:27 + * @Description: TODO + * @Version: 1.0 + */ + +@Slf4j +@Component +public class GlobalScheduledTasks { + private final IEntrtrustService service; + + public GlobalScheduledTasks(IEntrtrustService service) { + this.service = service; + } + + /** + * 每晚 00:00 执行报告自动生成 + */ + @Scheduled(cron = "0 0 0 * * ?") + public void downloadFileAtMidnight() { + // ===================== 核心:开关判断 ===================== + String enabled = DictBizCache.getKey(DictBizEnum.SCHEDULED_TASK.getName(), "openScheduled"); + if ("1".equals(enabled)) { + log.info("===== 报告生成任务已关闭,不执行 ====="); + return; + } + log.info("===== 凌晨0点,开始执行报告生成任务 =====: {}" ,LocalDateTime.now()); + try { + int successCount = 0; + int failCount = 0; + List failMessages = new ArrayList<>(); + String startCreateTime = DictBizCache.getKey(DictBizEnum.SCHEDULED_TASK.getName(), "startCreateTime"); + // 空值检查 + if (startCreateTime == null || startCreateTime.trim().isEmpty()) { + log.error("开始创建时间配置为空,无法执行报告生成任务"); + return; + } + + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date creatTime = sdf.parse(startCreateTime + " 00:00:00"); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.in(Entrust::getEntrustStatus, Arrays.asList("7", "8")); + wrapper.eq(Entrust::getIsGenreport, "1"); + wrapper.eq(Entrust::getIsDeleted, "0"); + wrapper.between(Entrust::getCreateTime, creatTime, new Date()); + List entrustList = service.list(wrapper); + String creatTimeStr = sdf.format(creatTime); + log.info("开始时间: {}", creatTimeStr); + log.info("查询到需要生成报告的委托单数量: {}", entrustList.size()); + + // 遍历生成报告 + for (Entrust entrust : entrustList) { + try { + String fullPath = service.generReport(entrust); + successCount++; + log.info("报告生成成功: {}", entrust.getAcceptanceNum()); + log.info("报告生成路径: {}", fullPath); + } catch (Exception e) { + failCount++; + String errorMsg = "委托单ID:" + entrust.getId() + + "- 编号:" + entrust.getAcceptanceNum() + + "- 错误:" + e.getMessage(); + failMessages.add(errorMsg); + log.error("报告生成失败: {}", errorMsg, e); + } + } + log.info("===== 报告生成任务完成 =====: {}, 成功: {}, 失败: {}" ,LocalDateTime.now(), successCount, failCount); + if (!failMessages.isEmpty()) { + log.error("失败的委托单列表: {}", failMessages); + } + } catch (Exception e) { + log.error("===== 报告生成任务异常 =====: {}" ,LocalDateTime.now(), e); + } + } +} diff --git a/lab-service/lab-lims/src/main/java/org/springblade/lims/controller/EntrustController.java b/lab-service/lab-lims/src/main/java/org/springblade/lims/controller/EntrustController.java index 62a107d..cb3637a 100644 --- a/lab-service/lab-lims/src/main/java/org/springblade/lims/controller/EntrustController.java +++ b/lab-service/lab-lims/src/main/java/org/springblade/lims/controller/EntrustController.java @@ -987,6 +987,7 @@ public class EntrustController extends BladeController { public List reportPrint(String id) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(Examine::getEntrustId, id); + wrapper.ne(Examine::getStatus, "2");//去除已取消的检验项目 return examineService.list(wrapper); } diff --git a/lab-service/lab-lims/src/main/java/org/springblade/lims/service/IEntrtrustService.java b/lab-service/lab-lims/src/main/java/org/springblade/lims/service/IEntrtrustService.java index 923ee6c..1f4a5a9 100644 --- a/lab-service/lab-lims/src/main/java/org/springblade/lims/service/IEntrtrustService.java +++ b/lab-service/lab-lims/src/main/java/org/springblade/lims/service/IEntrtrustService.java @@ -50,4 +50,12 @@ public interface IEntrtrustService extends BaseService { List simpleReceiveExport(Entrust ent); + /** + * 生成报告ZIP包并保存到服务器指定目录(用于定时任务) + * + * @param row 委托单对象 + * @return 保存的完整文件路径 + * @throws Exception 异常统一处理 + */ + String generReport(Entrust row) throws Exception; } diff --git a/lab-service/lab-lims/src/main/java/org/springblade/lims/service/impl/EntrustServiceImpl.java b/lab-service/lab-lims/src/main/java/org/springblade/lims/service/impl/EntrustServiceImpl.java index a2e88a0..cff438a 100644 --- a/lab-service/lab-lims/src/main/java/org/springblade/lims/service/impl/EntrustServiceImpl.java +++ b/lab-service/lab-lims/src/main/java/org/springblade/lims/service/impl/EntrustServiceImpl.java @@ -20,6 +20,7 @@ import org.springblade.lims.excel.*; import org.springblade.lims.mapper.EntrustMapper; import org.springblade.lims.service.*; import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.lims.utils.ZipUtils; import org.springblade.system.cache.DictBizCache; import org.springblade.system.enums.DictBizEnum; import org.springblade.system.feign.ISysClient; @@ -328,6 +329,7 @@ public class EntrustServiceImpl extends BaseServiceImpl // 获取委托单下所有检测 LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(Examine::getEntrustId, id); + wrapper.ne(Examine::getStatus, "2");//去除已取消的检验项目 List examineList = examineService.list(wrapper); // 填充检验项目、方法、依据 @@ -3748,6 +3750,7 @@ public class EntrustServiceImpl extends BaseServiceImpl LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Examine::getEntrustId, id); queryWrapper.eq(Examine::getDeptId, deptId); + queryWrapper.ne(Examine::getStatus, "2");//去除已取消的检验项目 List examineList = examineService.list(queryWrapper); if (CollectionUtils.isNotEmpty(examineList)) { for (Examine examine : examineList) { @@ -3991,6 +3994,7 @@ public class EntrustServiceImpl extends BaseServiceImpl // 获取委托单下所有检测 LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(Examine::getEntrustId, id); + wrapper.ne(Examine::getStatus, "2");//去除已取消的检验项目 取消的项目没有检验结果 List examineList = examineService.list(wrapper); if (CollectionUtils.isNotEmpty(examineList)) { for (Examine examine : examineList) { @@ -4854,4 +4858,2442 @@ public class EntrustServiceImpl extends BaseServiceImpl private String fullByZero(int i) { return i < 10 ? "0" + i : String.valueOf(i); } -} + + /** + * 生成报告ZIP包并下载到服务器指定目录 + * @param row 委托单对象 + * @return 保存的完整文件路径 + * @throws Exception 异常统一处理 + */ + @Override + public String generReport(Entrust row) throws Exception { + + + Long id = row.getId(); + String prefix = row.getAcceptanceNum() + "-" + row.getEntrustCustomerName(); + + // 更新委托单状态 + Entrust entry = new Entrust(); + entry.setId(id); + entry.setEntrustStatus("8"); + this.updateById(entry); + + // 用于存储所有文件的字节数据(文件名 -> 文件字节) + Map fileMap = new LinkedHashMap<>(); + + try { + // 生成报告 + byte[] reportData = printForZip(row.getId().toString()); + fileMap.put(prefix + "报告1.docx", reportData); + + // 查询检验列表 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(Examine::getEntrustId, id); + wrapper.ne(Examine::getStatus, "2");//去除已取消的检验项目 + List examineList = examineService.list(wrapper); + + if (examineList != null && !examineList.isEmpty()) { + // 部门去重(和前端逻辑完全一致:计划书按部门去重) + Set deptIdSet = new HashSet<>(); + int planIndex = 0; + int recordIndex = 0; + + for (Examine item : examineList) { + Long deptId = item.getDeptId(); + // 3.1 生成计划书(部门去重后生成) + if (!deptIdSet.contains(deptId)) { + deptIdSet.add(deptId); + planIndex++; + byte[] planData = eTaskPrintForZip(row.getId().toString(), item.getDeptId().toString()); + fileMap.put(prefix + "计划书" + planIndex + ".docx", planData); + } + + // 3.2 生成原始数据记录(每条检验都生成,不去重) + recordIndex++; + byte[] recordData = reportPrintForZip(item.getId().toString()); + fileMap.put(prefix + "原始数据记录" + recordIndex + ".docx", recordData); + } + } + + // 打包Zip并保存到服务器指定目录 + String zipFileName = prefix + "报告.zip"; + String fullPath = ZipUtils.saveZipToServer(fileMap, zipFileName); + + return fullPath; + } catch (Exception e) { + throw new RuntimeException("生成报告失败:" + e.getMessage(), e); + } + } + + /** + * 生成报告文档字节数组(用于ZIP打包) + * 复制自 print 方法,业务逻辑保持一致 + */ + private byte[] printForZip(String id) throws Exception { + // 委托单 + Entrust entrust = this.getById(id); + + // 获取委托单下所有检测 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(Examine::getEntrustId, id); + wrapper.ne(Examine::getStatus, "2");//去除已取消的检验项目 + List examineList = examineService.list(wrapper); + + // 填充检验项目、方法、依据 + List> ItemAndAllList = fillExamineItemAndAll(examineList); + + // 填充报告的主体内容 + Map reportMainBody = fillReportMainBody(entrust, ItemAndAllList, examineList); + // ------------------------------------------------------------------------ + + // 当前使用的模板 + String currTemplate = ""; + + int examineCount = examineList.size(); + + // 根据检测的数量判断用按个模板 + switch (examineCount) { + case 1: + currTemplate = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "print1"); + break; + case 2: + currTemplate = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "print2"); + break; + case 3: + currTemplate = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "print3"); + break; + case 4: + currTemplate = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "print4"); + break; + case 5: + currTemplate = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "print5"); + break; + case 6: + currTemplate = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "print6"); + break; + case 7: + currTemplate = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "print7"); + break; + case 8: + currTemplate = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "print8"); + break; + case 9: + currTemplate = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "print9"); + break; + case 10: + currTemplate = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "print10"); + break; + default: + currTemplate = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "print10"); + } + List resultList = new ArrayList<>(); + System.out.println("examineList: " + examineList); + + List simples = simpleService.list(new LambdaQueryWrapper().eq(Simple::getEntrustId, id)); + + // 根据检验判断有几个name + for (int i = 1; i <= examineList.size(); i++) { + Examine examine = examineList.get(i - 1); + ExamineItem examineItem = examineItemService.getById(examine.getExamineItemId()); + ExamineWay examineWay = examineWayService.getById(examine.getExamineWayId()); + // 检测项目名称 + if ("6".equals(examineWay.getInputMode())) { + reportMainBody.put("name" + i, examineItem.getName() + examineWay.getName()); + } else { + // 如果是复检需要加上“(复检)” + if (examine.getIsRecheck() != null && examine.getIsRecheck() == 1) { + reportMainBody.put("name" + i, examineItem.getName() + "(复检)"); + } else { + reportMainBody.put("name" + i, examineItem.getName()); + } + } + // 判断是哪种检测 +// String inputMode = examineItem.getInputMode(); + + // 根据检测检测项目拿检测结果 + ExamineResult examineResult = getExamineResultByExamineId(examine.getId()); + System.out.println("examineResult: " + examineResult); + // 布鲁氏检测 + if ("2".equals(examineWay.getInputMode()) || "6".equals(examineWay.getInputMode()) || "7".equals(examineWay.getInputMode())) { + List list = JSON.parseArray(examineResult.getExamineDataArr(), ExamineTemplate2Excel.class); + System.out.println("list: " + list); + if (CollectionUtils.isNotEmpty(list)) { + for (int i1 = 0; i1 < list.size(); i1++) { + ExamineTemplate2Excel excel = list.get(i1); + System.out.println("excel: " + excel); + ExamineResultVo resultVo = new ExamineResultVo(); + List collect = simples.stream().filter(simple1 -> simple1.getExperieNum().equals(excel.getExperieNum())).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(collect)) { + Simple simple = collect.get(0); + if (simple != null) { + resultVo.setOriginalNum(simple.getOriginalNum()); + resultVo.setNum(simple.getExperieNum()); + resultVo.setRecessiveNum(simple.getRecessiveNum()); + resultVo.setIndex(i); + resultVo.setValue(excel.getValue()); + resultVo.setResult(excel.getResult()); + resultList.add(resultVo); + } + } + } + } + } + // PCR检测 + else if ("4".equals(examineWay.getInputMode())) { + List list = JSON.parseArray(examineResult.getExamineDataArr(), PCR2Excel.class); + System.out.println("list: " + list); + if (list != null && list.size() > 0) { + if (examineResult.getConformityType() != null && examineResult.getConformityType() > 1) { + for (int j = 0; j < list.size() - 2; j++) { + String originalNum = ""; + PCR2Excel pcr2Excel = list.get(j); + String[] split = pcr2Excel.getExperieNum().split("-"); + int startIndex; + if (split.length == 3) { + startIndex = Integer.parseInt(split[split.length - 1]); + } else { + startIndex = Integer.parseInt(split[split.length - 2]); + } + int endIndex = Integer.parseInt(split[split.length - 1]); + for (int e = startIndex; e <= endIndex; e++) { +// LambdaQueryWrapper wrapper1 = new LambdaQueryWrapper<>(); +// wrapper1.eq(Simple::getEntrustId, id); +// wrapper1.eq(Simple::getExperieNum, split[0] + "-" + split[1] + "-" + e); +// Simple simple = simpleService.getOne(wrapper1); + + int finalE = e; + List collect = simples.stream().filter(simple1 -> simple1.getExperieNum().equals(split[0] + "-" + split[1] + "-" + finalE)).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(collect)) { + Simple simple = collect.get(0); + if (simple != null) { + if (e == endIndex) { + originalNum += simple.getOriginalNum(); + } else { + originalNum += simple.getOriginalNum() + ","; + } + } + } + } + + ExamineResultVo resultVo = new ExamineResultVo(); + resultVo.setOriginalNum(originalNum); + resultVo.setNum(pcr2Excel.getExperieNum()); + resultVo.setIndex(i); + resultVo.setValue(pcr2Excel.getCtValue()); + resultVo.setResult(pcr2Excel.getResult()); + resultList.add(resultVo); + } + } else { + for (PCR2Excel excel : list) { + System.out.println("excel: " + excel); + ExamineResultVo resultVo = new ExamineResultVo(); +// LambdaQueryWrapper wrapper1 = new LambdaQueryWrapper<>(); +// wrapper1.eq(Simple::getEntrustId, id); +// wrapper1.eq(Simple::getExperieNum, excel.getExperieNum()); +// Simple simple = simpleService.getOne(wrapper1); + + List collect = simples.stream().filter(simple1 -> simple1.getExperieNum().equals(excel.getExperieNum())).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(collect)) { + Simple simple = collect.get(0); + if (simple != null) { + resultVo.setOriginalNum(simple.getOriginalNum()); + resultVo.setNum(simple.getExperieNum()); + resultVo.setIndex(i); + resultVo.setValue(excel.getCtValue()); + resultVo.setResult(excel.getResult()); + resultVo.setRecessiveNum(simple.getRecessiveNum()); + resultList.add(resultVo); + } + } + } + } + } + } + // XN检测 + else if ("5".equals(examineWay.getInputMode())) { + List list = JSON.parseArray(examineResult.getExamineDataArr(), XN2Excel.class); + if (list != null && list.size() > 0) { + for (XN2Excel excel : list) { + ExamineResultVo resultVo = new ExamineResultVo(); +// LambdaQueryWrapper wrapper1 = new LambdaQueryWrapper<>(); +// wrapper1.eq(Simple::getEntrustId, id); +// wrapper1.eq(Simple::getExperieNum, excel.getExperieNum()); +// Simple simple = simpleService.getOne(wrapper1); + + List collect = simples.stream().filter(simple1 -> simple1.getExperieNum().equals(excel.getExperieNum())).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(collect)) { + Simple simple = collect.get(0); + if (simple != null) { + resultVo.setOriginalNum(simple.getOriginalNum()); + resultVo.setRecessiveNum(simple.getRecessiveNum()); + resultVo.setNum(simple.getExperieNum()); + resultVo.setIndex(i); + resultVo.setValue(excel.getCtValue()); + resultVo.setResult(excel.getResult()); + resultList.add(resultVo); + } + } + } + } + } + // XN检测 + else if ("8".equals(examineWay.getInputMode())) { + List list = JSON.parseArray(examineResult.getExamineDataArr(), BiochemicalIdentificationExcel.class); + if (list != null && list.size() > 0) { + for (BiochemicalIdentificationExcel excel : list) { + ExamineResultVo resultVo = new ExamineResultVo(); +// LambdaQueryWrapper wrapper1 = new LambdaQueryWrapper<>(); +// wrapper1.eq(Simple::getEntrustId, id); +// wrapper1.eq(Simple::getExperieNum, excel.getExperieNum()); +// Simple simple = simpleService.getOne(wrapper1); + + List collect = simples.stream().filter(simple1 -> simple1.getExperieNum().equals(excel.getExperieNum())).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(collect)) { + Simple simple = collect.get(0); + if (simple != null) { + resultVo.setOriginalNum(simple.getOriginalNum()); + resultVo.setRecessiveNum(simple.getRecessiveNum()); + resultVo.setNum(simple.getExperieNum()); + resultVo.setIndex(i); + resultVo.setValue(excel.getValue()); + resultVo.setResult(excel.getResult()); + resultList.add(resultVo); + } + } + } + } + } + // 普通和口蹄疫检测 + else { + List list1 = new ArrayList<>(); + List list = JSON.parseArray(examineResult.getExamineDataArr(), ExamineDataArrVO.class); + // 对普通检测原始记录进行按照order排序 + sortByOrder(list); + // 口蹄疫 + if ("3".equals(examineWay.getInputMode())) { + // 口蹄疫兰所单板 + if ("1".equals(examine.getTemplateType())) { + + // OriginRecordResult 检验结果 + List voList = JSON.parseArray(examineResult.getOriginRecordResult(), ExamineDataArrVO.class); + + // 对 按照order排序 + sortByOrder(voList); + + // 求临界值 + String format2 = calcCriticalValue(list); + + // 处理临界值 + list1.add(assembleCriticalValue(format2)); + + // 把检验结果: + list1.addAll(voList); + + if (list1.size() > 0) { + for (ExamineDataArrVO excel : list1) { + ExamineResultVo resultVo = new ExamineResultVo(); + // 根据*取样品 +// LambdaQueryWrapper wrapper1 = new LambdaQueryWrapper<>(); +// wrapper1.eq(Simple::getEntrustId, id); +// wrapper1.eq(Simple::getExperieNum, excel.getNum()); +// Simple simple = simpleService.getOne(wrapper1); + List collect = simples.stream().filter(simple1 -> simple1.getExperieNum().equals(excel.getNum())).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(collect)) { + Simple simple = collect.get(0); + if (simple != null) { + resultVo.setOriginalNum(simple.getOriginalNum()); + resultVo.setRecessiveNum(simple.getRecessiveNum()); + resultVo.setNum(simple.getExperieNum()); + resultVo.setIndex(i); + resultVo.setValue(excel.getLog2()); + resultVo.setResult(excel.getResult()); + resultList.add(resultVo); + } + } + } + } + } + // 口蹄疫 兰所多板 + else if ("2".equals(examine.getTemplateType())) { + if (list.size() > 0) { + for (int j = 0; j < list.size() / 96; j++) { + // 求临界值 + String format2 = calcKTYCriticalValue(list, j); + + // 处理临界值 + list1.add(assembleCriticalValue(format2)); + + // 取有检测编号的值放到list1里面 + list1 = addInVoWhichHasExamNum(list1, list, j); + } + } + + if (list1.size() > 0) { + for (ExamineDataArrVO excel : list1) { + ExamineResultVo resultVo = new ExamineResultVo(); +// LambdaQueryWrapper wrapper1 = new LambdaQueryWrapper<>(); +// wrapper1.eq(Simple::getEntrustId, id); +// wrapper1.eq(Simple::getExperieNum, excel.getNum()); +// Simple simple = simpleService.getOne(wrapper1); + List collect = simples.stream().filter(simple1 -> simple1.getExperieNum().equals(excel.getNum())).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(collect)) { + Simple simple = collect.get(0); + if (simple != null) { + resultVo.setOriginalNum(simple.getOriginalNum()); + resultVo.setRecessiveNum(simple.getRecessiveNum()); + resultVo.setNum(simple.getExperieNum()); + resultVo.setIndex(i); + resultVo.setValue(excel.getLog2()); + resultVo.setResult(excel.getResult()); + resultList.add(resultVo); + } + } + } + } + } + // 口蹄疫 非兰所 + else { + if (list.size() > 0) { + for (int j = 0; j < list.size() / 96; j++) { + // 求临界值 + String format2 = calcKTYCriticalValue(list, j); + + // 处理临界值 + list1.add(assembleCriticalValue(format2)); + + // 取有检测编号的值放到list1里面 + list1 = addInVoWhichHasExamNum(list1, list, j); + } + } + + if (list1.size() > 0) { + for (ExamineDataArrVO excel : list1) { + ExamineResultVo resultVo = new ExamineResultVo(); +// LambdaQueryWrapper wrapper1 = new LambdaQueryWrapper<>(); +// wrapper1.eq(Simple::getEntrustId, id); +// wrapper1.eq(Simple::getExperieNum, excel.getNum()); +// Simple simple = simpleService.getOne(wrapper1); + List collect = simples.stream().filter(simple1 -> simple1.getExperieNum().equals(excel.getNum())).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(collect)) { + Simple simple = collect.get(0); + if (simple != null) { + resultVo.setOriginalNum(simple.getOriginalNum()); + resultVo.setRecessiveNum(simple.getRecessiveNum()); + resultVo.setNum(simple.getExperieNum()); + resultVo.setIndex(i); + resultVo.setValue(excel.getLog2()); + resultVo.setResult(excel.getResult()); + resultList.add(resultVo); + } + } + } + } + } + } + // 牛结核 + else if (examineResult.getReagentId().contains("1570297053211455490") || examineResult.getReagentId().contains("1631222146321997826")) { + list = list.stream().distinct().collect(Collectors.collectingAndThen + (Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing + (ExamineDataArrVO::getNum))), ArrayList::new)); + + for (ExamineDataArrVO excel : list) { + ExamineResultVo resultVo = new ExamineResultVo(); +// LambdaQueryWrapper wrapper1 = new LambdaQueryWrapper<>(); +// wrapper1.eq(Simple::getEntrustId, id); +// wrapper1.eq(Simple::getExperieNum, excel.getNum()); +// Simple simple = simpleService.getOne(wrapper1); + List collect = simples.stream().filter(simple1 -> simple1.getExperieNum().equals(excel.getNum())).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(collect)) { + Simple simple = collect.get(0); + if (simple != null) { + resultVo.setOriginalNum(simple.getOriginalNum()); + resultVo.setRecessiveNum(simple.getRecessiveNum()); + resultVo.setNum(simple.getExperieNum()); + resultVo.setIndex(i); + resultVo.setValue(excel.getValue()); + resultVo.setResult(excel.getResult()); + resultList.add(resultVo); + } + } + } + reportMainBody.put("list", resultList); + } + // 普通 + else { + // 判断是满版吗 + if (list.size() % 96 == 0) { + for (int k = 0; k < list.size() / 96; k++) { + // 求阴性对照平均OD值 + String format = getYinOdAvg(list, k); + list.get(k * 96).setNum("阴性对照平均OD值"); + list.get(k * 96).setValue(format); + list.get(k * 96).setResult(" "); + list1.add(list.get(k * 96)); + + // 求阳性对照平均OD值 + String format1 = getYangOdAvg(list, k); + list.get((k * 96) + 1).setNum("阳性对照平均OD值"); + list.get((k * 96) + 1).setValue(format1); + list.get((k * 96) + 1).setResult(" "); + list1.add(list.get((k * 96) + 1)); + + // 从第六个值开始往list1里加值 + list1 = fillList1IntoValue(list1, list, k, 1); + } + } + // 非满版 + else { + for (int k = 0; k < list.size() / 96 + 1; k++) { + // 求阴性对照平均OD值 + String format = getYinOdAvg(list, k); + list.get(k * 96).setNum("阴性对照平均OD值"); + list.get(k * 96).setValue(format); + list.get(k * 96).setResult(" "); + list1.add(list.get(k * 96)); + + // 求阳性对照平均OD值 + String format1 = getYangOdAvg(list, k); + list.get((k * 96) + 1).setNum("阳性对照平均OD值"); + list.get((k * 96) + 1).setValue(format1); + list.get((k * 96) + 1).setResult(" "); + list1.add(list.get((k * 96) + 1)); + + // 非满版时 从第六个值开始往list1里加值 + list1 = fillList1IntoValue(list1, list, k, 0); + + } + } + + if (list1.size() > 0) { + for (ExamineDataArrVO excel : list) { + ExamineResultVo resultVo = new ExamineResultVo(); +// LambdaQueryWrapper wrapper1 = new LambdaQueryWrapper<>(); +// wrapper1.eq(Simple::getEntrustId, id); +// wrapper1.eq(Simple::getExperieNum, excel.getNum()); +// Simple simple = simpleService.getOne(wrapper1); + List collect = simples.stream().filter(simple1 -> simple1.getExperieNum().equals(excel.getNum())).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(collect)) { + Simple simple = collect.get(0); + if (simple != null) { + resultVo.setOriginalNum(simple.getOriginalNum()); + resultVo.setRecessiveNum(simple.getRecessiveNum()); + resultVo.setNum(simple.getExperieNum()); + resultVo.setIndex(i); + resultVo.setValue(excel.getValue()); + resultVo.setResult(excel.getResult()); + resultList.add(resultVo); + } + } + } + //给检测结果赋值 start +// ItemAndAllList.forEach(item ->{ +// if (StringUtils.isNoneBlank(item.get("examineItem").toString()) && StringUtils.equals(examineItem.getName(),item.get("examineItem").toString())){ +// //遍历resultList 获取阴阳结果的数量 +// long yangNum = resultList.stream().filter(re -> StringUtils.equals("阳性" , re.getResult())).count(); +// long yinNum = resultList.stream().filter(re -> StringUtils.equals("阴性" , re.getResult())).count(); +// item.put("examineResult", yangNum + "份为阳性," + yinNum + "份为阴性"); +// } +// }); + //给检验结果赋值 end + reportMainBody.put("list", resultList); + } + } + } + } + // 转换可展示的list + List> tempResultList = new ArrayList<>(); + List> resultResultList = new ArrayList<>(); + + // 1.生成坐标(给每一个数据单元赋予坐标) + + System.out.println("resultList: " + resultList); + + // 1.1.根据原始编号分组 +// Map> collect = resultList.stream().collect(Collectors.groupingBy(ExamineResultVo::getRecessiveNum)); + Map> collect = resultList.stream().collect(Collectors.groupingBy(ExamineResultVo::getNum)); + + Set keys = collect.keySet(); + List recessiveNumList = new ArrayList<>(); + recessiveNumList.addAll(keys); + // TODO 排序方式不对,现在是:1,10,11,12...,会有中文的情况 + Collections.sort(recessiveNumList, new Comparator() { + @Override + public int compare(String o1, String o2) { + Integer expirNum1 = Integer.valueOf(o1.split("-")[o1.split("-").length - 1]); + Integer expirNum2 = Integer.valueOf(o2.split("-")[o2.split("-").length - 1]); + return expirNum1 - expirNum2; + } + }); + + // 循环分组后的数据给到每个单元的的值 (例如:2-1-3) + // 定义行数 + int rowCount = 0; + for (String originalNum : recessiveNumList) { + List everyResultUnit = collect.get(originalNum); + Map row = new HashMap<>(); + row.put("originalNum", everyResultUnit.get(0).getOriginalNum()); + row.put("num", everyResultUnit.get(0).getNum()); + rowCount++; + + // 对检测按照index分组 + Map> voGroupByIndex = everyResultUnit.stream().collect(Collectors.groupingBy(ExamineResultVo::getIndex)); + Set indexKeys = voGroupByIndex.keySet(); + List indexList = new ArrayList<>(); + indexList.addAll(indexKeys); + Collections.sort(indexList); + + for (Integer index : indexList) { + // 当前每一个index对应的检验 + List currExamResVoList = voGroupByIndex.get(index);//W-2022-1,W-2022-2 + // 按照检测编号排序 + Collections.sort(currExamResVoList, new Comparator() { + @Override + public int compare(ExamineResultVo o1, ExamineResultVo o2) { + Integer expirNum1 = Integer.valueOf(o1.getNum().split("-")[o1.getNum().split("-").length - 1]); + Integer expirNum2 = Integer.valueOf(o2.getNum().split("-")[o1.getNum().split("-").length - 1]); + return expirNum1 - expirNum2; + } + }); + +// String num = ""; + String value = ""; + String result = ""; + for (int i = 0; i < currExamResVoList.size(); i++) { + ExamineResultVo resultVo = currExamResVoList.get(i); +// num += resultVo.getNum(); + value += resultVo.getValue(); + result += resultVo.getResult(); + } +// row.put("num" + index, num); + row.put("value" + index, value); + row.put("result" + index, result); + } + + for (int i = 1; i <= examineCount; i++) { + if (row.get("value" + examineCount) == null) { + row.put("value" + examineCount, "/"); + } + if (row.get("result" + examineCount) == null) { + row.put("result" + examineCount, "/"); + } + } + // 将每一行加入到模板循环列表 + tempResultList.add(row); + + // TODO 需要将 W-2022-1,W-2022-2 和原始编号在同一行的数据拆分成两行 +// for (int i = 0; i < tempResultList.size(); i++) { +// Map map = tempResultList.get(i); +// // 如果有一行里有多个检验的情况,如:W-2022-1,W-2022-2 +// // TODO 不对↓ +// String[] split = map.get("num1").split(","); +// if (split.length > 1) { +// // 除去原始编号、备注,再除以3,就是组数 +// Set> entries = map.entrySet(); +// int groups = (entries.size() - 2) / 3; +// // 得到每一组的数据 +// for (int j = 1; j <= groups; j++) { +// // 每一组的在一行里的没个单元数据 +// for (int y = 0; y < split.length; y++) { +// +// } +// Map tempRow = new HashMap<>(); +// +// resultResultList.add(tempRow); +// } +// } else { +// resultResultList.add(map); +// } +// } + } + // 将附表所需list加进最终map + reportMainBody.put("list", tempResultList); + System.out.println("reportMainBody: " + tempResultList); + + // 生成文档并返回字节数组 + XWPFDocument doc = null; + try { + doc = WordExportUtil.exportWord07(currTemplate, reportMainBody); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + doc.write(baos); + return baos.toByteArray(); + } finally { + if (null != doc) { + try { + doc.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + /** + * 生成计划书文档字节数组(用于ZIP打包) + * 复制自 eTaskPrint 方法,业务逻辑保持一致 + */ + private byte[] eTaskPrintForZip(String id, String deptId) throws Exception { + Map result = new HashMap<>(); + Entrust entrust = this.getById(id); + //任务书 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(TaskBlueprint::getEntrustId, id); + TaskBlueprint taskBlueprint = blueprintService.getOne(wrapper); + if (taskBlueprint != null) { + //子任务 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(ETask::getTaskBlueprintId, taskBlueprint.getId()); + queryWrapper.eq(ETask::getDeptId, deptId); + ETask eTask = eTaskService.getOne(queryWrapper); + if (eTask == null) { + return new byte[0]; + } + R deptName1 = sysClient.getDeptName(eTask.getDeptId()); + if (deptName1 == null || deptName1.getData() == null || deptName1.getData().equals("")) { + return new byte[0]; + } + String deptName = sysClient.getDeptName(eTask.getDeptId()).getData(); + result.put("deptName", deptName); +// result.put("acceptanceNum", entrust.getAcceptanceNum()); + + if (eTask != null) { + // position1 + if ("1".equals(eTask.getSimpleType())) { + result.put("simpleType", "☑正样 □留样"); + } else { + result.put("simpleType", "□正样 ☑留样"); + } + if ("1".equals(eTask.getSimpleStatus())) { + result.put("simpleStatus", "☑初检 □复检"); + } else { + result.put("simpleStatus", "□初检 ☑复检"); + } + if ("1".equals(eTask.getTestingOrder())) { + result.put("testingOrder", "☑主检 □副检"); + } else { + result.put("testingOrder", "□主检 ☑副检"); + } + result.put("simpleSource", eTask.getSimpleSource()); + if ("1".equals(eTask.getIsFlow())) { + result.put("isFlow", "☑是 □否"); + } else { + result.put("isFlow", "□是 ☑否"); + } + if (eTask.getFlowTo() != null) { + String flowTo = sysClient.getDeptName(eTask.getFlowTo()).getData(); + result.put("flowTo", flowTo); + } else { + result.put("flowTo", "/"); + } + String name = userClient.userInfoById(Long.parseLong(taskBlueprint.getTaskIssuedBy())).getData().getName(); + result.put("taskIssued", name);//任务下达人 + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); + result.put("demandCompletionTime", format.format(eTask.getDemandCompletionTime())); + result.put("simpleReceiverName", eTask.getSimpleReceiverName()); + if (eTask.getSimpleReceiveTime() != null) { + result.put("simpleReceiveTime", format.format(eTask.getSimpleReceiveTime())); + } + if (!"".equals(eTask.getFlowRecipient()) && eTask.getFlowRecipient() != null) { + String name3 = userClient.userInfoById(Long.parseLong(eTask.getFlowRecipient())).getData().getName(); + result.put("flowRecipient", name3); + } else { + result.put("flowRecipient", "/"); + } + if (!"".equals(eTask.getFlowTime()) && eTask.getFlowTime() != null) { + //接收日期 + result.put("flowTime", format.format(eTask.getFlowTime())); + } else { + result.put("flowTime", "/"); + } + //检测任务书交回日期 + if (eTask.getBackCrossTime() != null) { + result.put("backCrossTime", format.format(eTask.getBackCrossTime())); + } + if (eTask.getBackCrossRecipientBy() != null) { + String name1 = userClient.userInfoById(Long.parseLong(eTask.getBackCrossRecipientBy())).getData().getName(); + //接收人 + result.put("backCrossRecipient", name1); + } + } + } + + List> resultList = new ArrayList<>(); + + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(Examine::getEntrustId, id); + queryWrapper.eq(Examine::getDeptId, deptId); + queryWrapper.ne(Examine::getStatus, "2");//去除已取消的检验项目 + List examineList = examineService.list(queryWrapper); + if (CollectionUtils.isNotEmpty(examineList)) { + for (Examine examine : examineList) { + Map map = new HashMap<>(); + map.put("simpleName", StringUtils.remove(examine.getSimpleName(), "-")); + map.put("simpleCount", examine.getSimpleCount()); + // 获取当前检测对应的检测编号 + String[] split = examine.getExperieNum().split(","); +// String[] split1 = split[0].split("-"); + // 组装检测编号(只要开头和结尾) + String num = split[0] + "~" + split[split.length - 1]; +// if (split.length > 1) { +// num = split1[0] + "-" + split1[1]; +// } +// map.put("experieNum", num + examine.getMin() + "~" + num + examine.getMax()); + map.put("experieNum", num); + //检测项目 + ExamineItem examineItem = examineItemService.getById(examine.getExamineItemId()); + if (examineItem != null) { + map.put("examineItemName", examineItem.getName()); + } + //检测方法 + ExamineWay examineWay = examineWayService.getById(examine.getExamineWayId()); + if (examineWay != null) { + map.put("examineWayName", examineWay.getName()); + } + //检测依据 + ExamineBasis examineBasis = examineBasisService.getById(examine.getExamineBasisId()); + if (examineBasis != null) { + map.put("examineBasisName", examineBasis.getName()); + } + resultList.add(map); + } + if (examineList.size() < 6) { + for (int i = 0; i < 6 - examineList.size(); i++) { + Map map = new HashMap<>(); + map.put("simpleName", ""); + map.put("simpleCount", ""); + map.put("experieNum", ""); + map.put("examineItemName", ""); + map.put("examineWayName", ""); + map.put("examineBasisName", ""); + resultList.add(map); + } + } + + String s = examineList.get(0).getExperieNum().split(",")[0]; + result.put("acceptanceNum", getExperieNumPrefix(s)); + } + result.put("resultList", resultList); + + //模板地址 +// String handleUrl = "C://Users//AAA//Desktop//烁今//打印模板//检测任务书(模板).docx"; + String url; + if (entrust.getEntrustType() == 1) { + url = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "eTaskPrint"); + } else { + url = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "eTaskPrintContract"); + } + + XWPFDocument doc = null; + try { + doc = WordExportUtil.exportWord07(url, result); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + doc.write(baos); + return baos.toByteArray(); + } finally { + if (null != doc) { + try { + doc.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + /** + * 生成原始数据记录文档字节数组(用于ZIP打包) + * 复制自 reportPrint 方法,业务逻辑保持一致 + */ + private byte[] reportPrintForZip(String examineId) throws Exception { + + Map result = new HashMap<>(); + List> resultList1 = new ArrayList<>(); + List> resultList2 = new ArrayList<>(); + List> resultList3 = new ArrayList<>(); + String url = ""; + // 检测数据 + Examine examine = examineService.getById(examineId); + // 检测结果 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ExamineResult::getExamineId, examine.getId()); + ExamineResult examineResult = examineResultService.getOne(wrapper); + + // 如果检测结果为空,初始化一个空对象避免空指针异常 + if (examineResult == null) { + examineResult = new ExamineResult(); + } + + // 检测项目 + ExamineItem byId = examineItemService.getById(examine.getExamineItemId()); + // 检测方法 + ExamineWay examineWay = examineWayService.getById(examine.getExamineWayId()); + // 检测依据 + ExamineBasis examineBasis = examineBasisService.getById(examine.getExamineBasisId()); + String[] split = examine.getExperieNum().split(","); + // 获取检测编号前缀 + String s = getExperieNumPrefix(split[0]); + result.put("1", s); + result.put("2", examineResult.getDisposal()); + result.put("3", StringUtils.remove(examine.getSimpleName(), "-")); + result.put("4", examine.getSimpleCount()); + // 标题名称 + if ("4".equals(examineWay.getInputMode())) { + result.put("5", byId.getName().substring(0, byId.getName().length() - 2)); + // 检测项目 + result.put("19", byId.getName()); + } else { + result.put("5", byId.getName()); + } + // 检测依据 + if (examineBasis != null) { + result.put("6", examineBasis.getName()); + } + // 诊断试剂 + String[] split1 = examineResult.getReagentId().split(","); + String regentName = ""; + for (int i = 0; i < split1.length; i++) { + Reagent reagent = reagentService.getById(split1[i]); + if (i == (split1.length - 1)) { + regentName += reagent.getName() + "(生产批号:" + reagent.getBatchNo() + ")" + reagent.getManufacturer(); + } else { + regentName += reagent.getName() + "(生产批号:" + reagent.getBatchNo() + ")" + reagent.getManufacturer() + "\r\n"; + } + } + + result.put("7", regentName); + + String[] split2 = examineResult.getInstrumentId().split(","); + String instrumentName = ""; + List strings = new ArrayList<>(); + for (int i = 0; i < split2.length; i++) { + Instrument instrument = instrumentService.getById(split2[i]); + String s2 = instrument.getName() + instrument.getCode(); + strings.add(s2); + } + // 按照仪器编号排序 + Collections.sort(strings, new Comparator() { + @Override + public int compare(String o1, String o2) { + Integer expirNum1 = Integer.valueOf(o1.split("-")[o1.split("-").length - 1]); + Integer expirNum2 = Integer.valueOf(o2.split("-")[o2.split("-").length - 1]); + return expirNum1 - expirNum2; + } + }); + for (int i = 0; i < strings.size(); i++) { + if (i == (strings.size() - 1)) { + instrumentName += strings.get(i); + } else { + instrumentName += strings.get(i) + ","; + } + } + + result.put("9", instrumentName.replace(",", "\r\n")); +// String value = DictBizCache.getValue(DictBizEnum.SIMPLE_STATUS, examineResult.getSimpleStatus()); + result.put("10", examineResult.getSimpleStatus()); + result.put("11", "温度" + examineResult.getTemperature() + "℃; " + "湿度" + examineResult.getHumidity() + "%RH"); + // 操作程序内容 + result.put("12", examineResult.getOperateContent().replace("\n", "\r\n")); + // 结果判定方法和依据 + result.put("13", examineResult.getExamineBasisContent().replace("\n", "\r\n")); + String path = sysClient.getParamValue("electronic_signature_real_path").getData(); + // 检测人 + if (!"".equals(examine.getExamineBy()) && examine.getExamineBy() != null) { + User user = userClient.userInfoById(Long.parseLong(examine.getExamineBy())).getData(); + ImageEntity farView = new ImageEntity(); + farView.setHeight(50);//设置高度 + farView.setWidth(90);//设置宽度 + farView.setType(ImageEntity.Data);//类型 + String s1 = path + user.getElectronicSignature(); + FileInputStream fis = null; + try { + fis = new FileInputStream(new File(s1)); + byte[] bytes = readInputStream(fis); + farView.setData(bytes); + } catch (Exception e) { + e.printStackTrace(); + } + result.put("14", farView); + } + // 校核人 + if (examineResult.getVerificationUser() != null) { + User user1 = userClient.userInfoById(examineResult.getVerificationUser()).getData(); + ImageEntity farView1 = new ImageEntity(); + farView1.setHeight(50);//设置高度 + farView1.setWidth(90);//设置宽度 + farView1.setType(ImageEntity.Data);//类型 + + String s1 = path + user1.getElectronicSignature(); + FileInputStream fis = null; + try { + fis = new FileInputStream(new File(s1)); + byte[] bytes = readInputStream(fis); + farView1.setData(bytes); + } catch (Exception e) { + e.printStackTrace(); + } + result.put("15", farView1); + } + // 校核时间 + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日"); + if (examineResult.getVerificationTime() != null) { + String s1 = dateFormat.format(examineResult.getVerificationTime()); + result.put("17", s1); + } + // 检测时间\\]]]] + if (examineResult.getInspectionTime() != null) { + String s1 = dateFormat.format(examineResult.getInspectionTime()); + result.put("16", s1); + } + + // 如果是布鲁氏检测 (列排单+式和列排多+式) + if ("2".equals(examineWay.getInputMode()) || "6".equals(examineWay.getInputMode()) || "7".equals(examineWay.getInputMode())) { + if ("2".equals(examineWay.getInputMode())) { + result.put("18", "平板凝集"); + } else { + result.put("18", "试管凝集"); + } + + List list = JSON.parseArray(examineResult.getExamineDataArr(), ExamineTemplate2Excel.class); + + ExamineTemplate2Excel yinExcel = list.get(list.size() - 2); + yinExcel.setResult("阴性"); + list.set(list.size() - 2, yinExcel); + ExamineTemplate2Excel yangExcel = list.get(list.size() - 1); + yangExcel.setResult("阳性"); + list.set(list.size() - 1, yangExcel); + + if (list.size() > 0) { + Map> resultMap = new HashMap<>(); + int count = 0; + List everyGroupData = new ArrayList<>(); + for (int j = 0; j < list.size(); j++) { + if (count == 60 || j == list.size() - 1) { + int keyCount = (j / 60); + if (j == list.size() - 1) { + keyCount = keyCount + 1; + everyGroupData.add(list.get(j)); + } + resultMap.put(keyCount + "", everyGroupData); + everyGroupData = new ArrayList<>(); + count = 0; + } + everyGroupData.add(list.get(j)); + count++; + } + for (int j = 1; j <= resultMap.size(); j++) { + List arrVOList = resultMap.get(String.valueOf(j)); + // 使用每一页的数据 + if (arrVOList.size() % 2 == 0) { + for (int i = 0; i < arrVOList.size() / 2; i++) { + Map map = new HashMap<>(); + map.put("num1", arrVOList.get(i).getExperieNum()); + map.put("value1", arrVOList.get(i).getValue()); + map.put("result1", arrVOList.get(i).getResult()); + map.put("num2", arrVOList.get(arrVOList.size() / 2 + i).getExperieNum()); + map.put("value2", arrVOList.get(arrVOList.size() / 2 + i).getValue()); + map.put("result2", arrVOList.get(arrVOList.size() / 2 + i).getResult()); + resultList1.add(map); + } + } else { + for (int i = 0; i < arrVOList.size() / 2 + 1; i++) { + Map map = new HashMap<>(); + map.put("num1", arrVOList.get(i).getExperieNum()); + map.put("value1", arrVOList.get(i).getValue()); + map.put("result1", arrVOList.get(i).getResult()); + if (i < arrVOList.size() / 2) { + map.put("num2", arrVOList.get(arrVOList.size() / 2 + i + 1).getExperieNum()); + map.put("value2", arrVOList.get(arrVOList.size() / 2 + i + 1).getValue()); + map.put("result2", arrVOList.get(arrVOList.size() / 2 + i + 1).getResult()); + } + resultList1.add(map); + } + } + } + result.put("list", resultList1); + url = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "BLSreportPrint"); + } + } + // PCR检测 + else if ("4".equals(examineWay.getInputMode())) { + List list = JSON.parseArray(examineResult.getExamineDataArr(), PCR2Excel.class); + url = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "PCRreportPrint"); + + if (examine.getIsRecheck() != null && examine.getIsRecheck() == 1) { + list = JSON.parseArray(examineResult.getOriginRecordData(), PCR2Excel.class); + url = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "PCRreportPrintFJ"); + } + + if (list.size() > 0) { + Map> resultMap = new HashMap<>(); + int count = 0; + List everyGroupData = new ArrayList<>(); + for (int j = 0; j < list.size(); j++) { + if (count == 60 || j == list.size() - 1) { + int keyCount = (j / 60); + if (j == list.size() - 1) { + keyCount = keyCount + 1; + everyGroupData.add(list.get(j)); + } + resultMap.put(keyCount + "", everyGroupData); + everyGroupData = new ArrayList<>(); + count = 0; + } + everyGroupData.add(list.get(j)); + count++; + + } + for (int j = 1; j <= resultMap.size(); j++) { + List arrVOList = resultMap.get(String.valueOf(j)); + if (arrVOList.size() % 2 == 0) { + for (int i = 0; i < arrVOList.size() / 2; i++) { + Map map = new HashMap<>(); + map.put("num1", arrVOList.get(i).getExperieNum()); + map.put("value1", replaceNullBySpace(arrVOList.get(i).getCtValue())); + map.put("result1", arrVOList.get(i).getResult()); + map.put("num2", arrVOList.get(arrVOList.size() / 2 + i).getExperieNum()); + map.put("value2", replaceNullBySpace(arrVOList.get(arrVOList.size() / 2 + i).getCtValue())); + map.put("result2", arrVOList.get(arrVOList.size() / 2 + i).getResult()); + resultList1.add(map); + } + } else { + for (int i = 0; i < arrVOList.size() / 2 + 1; i++) { + Map map = new HashMap<>(); + map.put("num1", arrVOList.get(i).getExperieNum()); + map.put("value1", replaceNullBySpace(arrVOList.get(i).getCtValue())); + map.put("result1", arrVOList.get(i).getResult()); + if (i < arrVOList.size() / 2) { + map.put("num2", arrVOList.get(arrVOList.size() / 2 + i + 1).getExperieNum()); + map.put("value2", replaceNullBySpace(arrVOList.get(arrVOList.size() / 2 + i + 1).getCtValue())); + map.put("result2", arrVOList.get(arrVOList.size() / 2 + i + 1).getResult()); + } + resultList1.add(map); + } + } + } + if (StringUtils.isNotBlank(examineResult.getPicturePath())) { + String[] sp = examineResult.getPicturePath().split(","); + for (String picturePath : sp) { + String fileSuffix = picturePath.substring(picturePath.lastIndexOf(".") + 1); + System.out.println("fileSuffix:" + fileSuffix); + if ("pdf".equals(fileSuffix) || "PDF".equals(fileSuffix)) { + System.out.println("pdf执行了。。。。"); + List urls = pdfResule(picturePath, path); + for (String pngUrl : urls) { + Map map = new HashMap<>(); + ImageEntity farView1 = new ImageEntity(); + farView1.setHeight(800);//设置高度 + farView1.setWidth(580);//设置宽度 + farView1.setType(ImageEntity.Data);//类型 + String s1 = path + pngUrl; + FileInputStream fis = null; + try { + fis = new FileInputStream(new File(s1)); + byte[] bytes = readInputStream(fis); + farView1.setData(bytes); + } catch (Exception e) { + e.printStackTrace(); + } + map.put("p", farView1); + resultList2.add(map); + + // 删除临时文件 + File file = new File(s1); + if (file.exists()) { + file.delete(); + } + } + } else { + System.out.println("png执行了。。。。"); + Map map = new HashMap<>(); + ImageEntity farView1 = new ImageEntity(); + farView1.setHeight(350);//设置高度 + farView1.setWidth(550);//设置宽度 + farView1.setType(ImageEntity.Data);//类型 + String s1 = path + picturePath; + FileInputStream fis = null; + try { + fis = new FileInputStream(new File(s1)); + byte[] bytes = readInputStream(fis); + farView1.setData(bytes); + } catch (Exception e) { + e.printStackTrace(); + } + map.put("p", farView1); + resultList2.add(map); + } + } + } + } + result.put("list1", resultList2); + result.put("list", resultList1); + } + // XN检测 + else if ("5".equals(examineWay.getInputMode())) { + List list = JSON.parseArray(examineResult.getExamineDataArr(), XN2Excel.class); + if (list.size() > 0) { + Map> resultMap = new HashMap<>(); + int count = 0; + List everyGroupData = new ArrayList<>(); + for (int j = 0; j < list.size(); j++) { + if (count == 60 || j == list.size() - 1) { + int keyCount = (j / 60); + if (j == list.size() - 1) { + keyCount = keyCount + 1; + everyGroupData.add(list.get(j)); + } + resultMap.put(keyCount + "", everyGroupData); + everyGroupData = new ArrayList<>(); + count = 0; + } + everyGroupData.add(list.get(j)); + count++; + + } + for (int j = 1; j <= resultMap.size(); j++) { + List arrVOList = resultMap.get(String.valueOf(j)); + // 使用每一页的数据 + if (arrVOList.size() % 2 == 0) { + for (int i = 0; i < arrVOList.size() / 2; i++) { + Map map = new HashMap<>(); + map.put("num1", arrVOList.get(i).getExperieNum()); + map.put("value1", arrVOList.get(i).getCtValue()); + map.put("result1", arrVOList.get(i).getResult()); + map.put("num2", arrVOList.get(arrVOList.size() / 2 + i).getExperieNum()); + map.put("value2", arrVOList.get(arrVOList.size() / 2 + i).getCtValue()); + map.put("result2", arrVOList.get(arrVOList.size() / 2 + i).getResult()); + resultList1.add(map); + } + } else { + for (int i = 0; i < arrVOList.size() / 2 + 1; i++) { + Map map = new HashMap<>(); + map.put("num1", arrVOList.get(i).getExperieNum()); + map.put("value1", arrVOList.get(i).getCtValue()); + map.put("result1", arrVOList.get(i).getResult()); + if (i < arrVOList.size() / 2) { + map.put("num2", arrVOList.get(arrVOList.size() / 2 + i + 1).getExperieNum()); + map.put("value2", arrVOList.get(arrVOList.size() / 2 + i + 1).getCtValue()); + map.put("result2", arrVOList.get(arrVOList.size() / 2 + i + 1).getResult()); + } + resultList1.add(map); + } + } + } + } + result.put("list", resultList1); + url = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "XNreportPrint"); + } + // 生化鉴定 + else if ("8".equals(examineWay.getInputMode())) { + List list = JSON.parseArray(examineResult.getExamineDataArr(), BiochemicalIdentificationExcel.class); + if (list.size() > 0) { + Map> resultMap = new HashMap<>(); + int count = 0; + List everyGroupData = new ArrayList<>(); + for (int j = 0; j < list.size(); j++) { + if (count == 60 || j == list.size() - 1) { + int keyCount = (j / 60); + if (j == list.size() - 1) { + keyCount = keyCount + 1; + everyGroupData.add(list.get(j)); + } + resultMap.put(keyCount + "", everyGroupData); + everyGroupData = new ArrayList<>(); + count = 0; + } + everyGroupData.add(list.get(j)); + count++; + + } + for (int j = 1; j <= resultMap.size(); j++) { + List arrVOList = resultMap.get(String.valueOf(j)); + // 使用每一页的数据 + if (arrVOList.size() % 2 == 0) { + for (int i = 0; i < arrVOList.size() / 2; i++) { + Map map = new HashMap<>(); + map.put("num1", arrVOList.get(i).getExperieNum()); + map.put("value1", arrVOList.get(i).getValue()); + map.put("result1", arrVOList.get(i).getResult()); + map.put("num2", arrVOList.get(arrVOList.size() / 2 + i).getExperieNum()); + map.put("value2", arrVOList.get(arrVOList.size() / 2 + i).getValue()); + map.put("result2", arrVOList.get(arrVOList.size() / 2 + i).getResult()); + resultList1.add(map); + } + } else { + for (int i = 0; i < arrVOList.size() / 2 + 1; i++) { + Map map = new HashMap<>(); + map.put("num1", arrVOList.get(i).getExperieNum()); + map.put("value1", arrVOList.get(i).getValue()); + map.put("result1", arrVOList.get(i).getResult()); + if (i < arrVOList.size() / 2) { + map.put("num2", arrVOList.get(arrVOList.size() / 2 + i + 1).getExperieNum()); + map.put("value2", arrVOList.get(arrVOList.size() / 2 + i + 1).getValue()); + map.put("result2", arrVOList.get(arrVOList.size() / 2 + i + 1).getResult()); + } + resultList1.add(map); + } + } + } + } + result.put("list", resultList1); + url = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "SHJDreportPrint"); + } + // 普通和口蹄疫检测 + else { + DecimalFormat df = new DecimalFormat("#0.000"); + List list = JSON.parseArray(examineResult.getExamineDataArr(), ExamineDataArrVO.class); + List list1 = new ArrayList<>(); + // 普通检测原始记录 + Collections.sort(list, new Comparator() { + @Override + public int compare(ExamineDataArrVO o1, ExamineDataArrVO o2) { + return o1.getOrder() - o2.getOrder(); + } + }); + // position1 + if ("3".equals(examineWay.getInputMode())) { + // 口蹄疫兰所单板 + if ("1".equals(examine.getTemplateType())) { + List voList = JSON.parseArray(examineResult.getOriginRecordResult(), ExamineDataArrVO.class); + Collections.sort(voList, new Comparator() { + @Override + public int compare(ExamineDataArrVO o1, ExamineDataArrVO o2) { + return o1.getOrder() - o2.getOrder(); + } + }); + int group = list.size() / 96; + for (int i = 0; i < group; i++) { + List doubles = new ArrayList<>(); + double a1 = Double.parseDouble(list.get((i * 96) + 95).getValue()); + double a2 = Double.parseDouble(list.get((i * 96) + 94).getValue()); + double a3 = Double.parseDouble(list.get((i * 96) + 93).getValue()); + double a4 = Double.parseDouble(list.get((i * 96) + 92).getValue()); + doubles.add(a1); + doubles.add(a2); + doubles.add(a3); + doubles.add(a4); + List collect = doubles.stream().sorted().collect(Collectors.toList()); + String format2 = df.format((collect.get(1) + collect.get(2)) / 4); + ExamineDataArrVO examineDataArrVO = new ExamineDataArrVO(); + examineDataArrVO.setNum("临界值"); + examineDataArrVO.setLog2(format2); + examineDataArrVO.setResult(""); + list1.add(examineDataArrVO); + int finalI = i; + list1.addAll(voList.stream().filter(vo -> vo.getOrder() > finalI * 96 && vo.getOrder() <= (finalI + 1) * 96).collect(Collectors.toList())); + + // 阳性对照值 + double avg = Double.parseDouble(format2); + ExamineDataArrVO yang = new ExamineDataArrVO(); + yang.setNum("阳性对照"); + yang.setResult("成立"); + if (avg == 1.0 / 512) { + yang.setLog2("1:512"); + } else if (avg < 1.0 / 512 && avg > 1.0 / 1024) { + yang.setLog2("1:720"); + } else if (avg == 1.0 / 1024) { + yang.setLog2("1:1024"); + } else if (avg < 1.0 / 1024 && avg > 1.0 / 2048) { + yang.setLog2("1:1440"); + } else if (avg == 1.0 / 2048) { + yang.setLog2("1:2048"); + } + list1.add(yang); + + // 阴性对照值 + ExamineDataArrVO yin = new ExamineDataArrVO(); + yin.setNum("阴性对照"); + yin.setLog2("<1:8"); + yin.setResult("成立"); + list1.add(yin); + } + + if (list1.size() > 0) { + Map> resultMap = new HashMap<>(); + int count = 0; + List everyGroupData = new ArrayList<>(); + for (int j = 0; j < list1.size(); j++) { + if (count == 90 || j == list1.size() - 1) { + int keyCount = (j / 90); + if (j == list1.size() - 1) { + keyCount = keyCount + 1; + everyGroupData.add(list1.get(j)); + } + resultMap.put(keyCount + "", everyGroupData); + everyGroupData = new ArrayList<>(); + count = 0; + } + everyGroupData.add(list1.get(j)); + count++; + + } + + for (int j = 1; j <= resultMap.size(); j++) { + List arrVOList = resultMap.get(String.valueOf(j)); + // 使用每一页的数据 + if (arrVOList.size() % 3 == 0) { + for (int i = 0; i < arrVOList.size() / 3; i++) { + Map map = new HashMap<>(); + map.put("num1", arrVOList.get(i).getNum()); + map.put("value1", arrVOList.get(i).getLog2()); + map.put("result1", arrVOList.get(i).getResult()); + + map.put("num2", arrVOList.get(arrVOList.size() / 3 + i).getNum()); + map.put("value2", arrVOList.get(arrVOList.size() / 3 + i).getLog2()); + map.put("result2", arrVOList.get(arrVOList.size() / 3 + i).getResult()); + + map.put("num3", arrVOList.get(arrVOList.size() / 3 * 2 + i).getNum()); + map.put("value3", arrVOList.get(arrVOList.size() / 3 * 2 + i).getLog2()); + map.put("result3", arrVOList.get(arrVOList.size() / 3 * 2 + i).getResult()); + resultList1.add(map); + } + } else { + for (int i = 0; i < arrVOList.size() / 3 + 1; i++) { + if (arrVOList.size() % 3 == 1) { + Map map = new HashMap<>(); + map.put("num1", arrVOList.get(i).getNum()); + map.put("value1", arrVOList.get(i).getLog2()); + map.put("result1", arrVOList.get(i).getResult()); + if (i < arrVOList.size() / 3) { + map.put("num2", arrVOList.get(arrVOList.size() / 3 + i + 1).getNum()); + map.put("value2", arrVOList.get(arrVOList.size() / 3 + i + 1).getLog2()); + map.put("result2", arrVOList.get(arrVOList.size() / 3 + i + 1).getResult()); + map.put("num3", arrVOList.get(arrVOList.size() / 3 * 2 + i + 1).getNum()); + map.put("value3", arrVOList.get(arrVOList.size() / 3 * 2 + i + 1).getLog2()); + map.put("result3", arrVOList.get(arrVOList.size() / 3 * 2 + i + 1).getResult()); + } + resultList1.add(map); + } else if (arrVOList.size() % 3 == 2) { + Map map = new HashMap<>(); + map.put("num1", arrVOList.get(i).getNum()); + map.put("value1", arrVOList.get(i).getLog2()); + map.put("result1", arrVOList.get(i).getResult()); + map.put("num2", arrVOList.get(arrVOList.size() / 3 + i + 1).getNum()); + map.put("value2", arrVOList.get(arrVOList.size() / 3 + i + 1).getLog2()); + map.put("result2", arrVOList.get(arrVOList.size() / 3 + i + 1).getResult()); + if (i < arrVOList.size() / 3) { + map.put("num3", arrVOList.get(arrVOList.size() / 3 * 2 + i + 2).getNum()); + map.put("value3", arrVOList.get(arrVOList.size() / 3 * 2 + i + 2).getLog2()); + map.put("result3", arrVOList.get(arrVOList.size() / 3 * 2 + i + 2).getResult()); + } + resultList1.add(map); + } + } + } + } + result.put("list1", resultList1); + } + for (int i = 0; i < (list.size() / 96); i++) { + int start = i * 96; + if (i == 0) { + start = 0; + } + String startNum = ""; + String endNum = ""; + for (int k = 0; k < 96; k++) { + String num = list.get((i * 96) + k).getNum(); + if (num != null && !"".equals(num) && num.split("-").length > 1) { + startNum = num.split("-")[num.split("-").length - 1]; + break; + } + } + for (int k = 95; k >= 0; k--) { + if ((i * 96) + k < list.size()) { + String num = list.get((i * 96) + k).getNum(); + if (num != null && !"".equals(num) && num.split("-").length > 1) { + endNum = num.split("-")[num.split("-").length - 1]; + break; + } + } + } + for (int j = 0; j < 10; j++) { + int x = 0; + Map map = new HashMap<>(); + if (j == 0) { + map.put("1", s + "(" + startNum + "-" + endNum + ")"); + map.put("13", "布板图"); + } else if (j == 1) { + map.put("0", " "); + map.put("1", "1"); + map.put("2", "2"); + map.put("3", "3"); + map.put("4", "4"); + map.put("5", "5"); + map.put("6", "6"); + map.put("7", "7"); + map.put("8", "8"); + map.put("9", "9"); + map.put("10", "10"); + map.put("11", "11"); + map.put("12", "12"); + map.put("13", "1"); + map.put("14", "2"); + map.put("15", "3"); + map.put("16", "4"); + map.put("17", "5"); + map.put("18", "6"); + map.put("19", "7"); + map.put("20", "8"); + map.put("21", "9"); + map.put("22", "10"); + map.put("23", "11"); + map.put("24", "12"); + } else { + if (j == 2) { + map.put("0", "A"); + } else if (j == 3) { + map.put("0", "B"); + } else if (j == 4) { + map.put("0", "C"); + } else if (j == 5) { + map.put("0", "D"); + } else if (j == 6) { + map.put("0", "E"); + } else if (j == 7) { + map.put("0", "F"); + } else if (j == 8) { + map.put("0", "G"); + } else if (j == 9) { + map.put("0", "H"); + } + for (int k = 1; k <= 12; k++) { + map.put(k + "", list.get(start + (8 * x + j) - 2).getValue()); + String num = list.get(start + (8 * x + j) - 2).getNum(); + if (num != null && !"".equals(num) && num.split("-").length > 1) { + map.put((k + 12) + "", num.split("-")[num.split("-").length - 1]); + } else { + map.put((k + 12) + "", " "); + } + x++; + } + } + resultList2.add(map); + } + } + result.put("list2", resultList2); + url = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "LDanreportPrint"); + } + // 口蹄疫兰所多板 + else if ("2".equals(examine.getTemplateType())) { + List arrVOList = JSON.parseArray(examineResult.getOriginRecordData(), ExamineDataArrVO.class); + Collections.sort(arrVOList, new Comparator() { + @Override + public int compare(ExamineDataArrVO o1, ExamineDataArrVO o2) { + return o1.getOrder() - o2.getOrder(); + } + }); + if (list.size() > 0) { + for (int i = 0; i < list.size() / 96; i++) { + List doubles = new ArrayList<>(); + double a1 = Double.parseDouble(list.get((i + 1) * 96 - 1).getValue()); + double a2 = Double.parseDouble(list.get((i + 1) * 96 - 2).getValue()); + double a3 = Double.parseDouble(list.get((i + 1) * 96 - 3).getValue()); + double a4 = Double.parseDouble(list.get((i + 1) * 96 - 4).getValue()); + doubles.add(a1); + doubles.add(a2); + doubles.add(a3); + doubles.add(a4); + List collect = doubles.stream().sorted().collect(Collectors.toList()); + String format2 = df.format((collect.get(1) + collect.get(2)) / 4); + ExamineDataArrVO examineDataArrVO = new ExamineDataArrVO(); + examineDataArrVO.setNum("临界值"); + examineDataArrVO.setValue(""); + examineDataArrVO.setLog2(format2); + list1.add(examineDataArrVO); + for (int j = 0; j < 96; j++) { + ExamineDataArrVO vo = list.get((i * 96) + j); + if (vo.getNum() != null) { + list1.add(vo); + } + } + } + } + + if (list1.size() > 0) { + Map> resultMap = new HashMap<>(); + int count = 0; + List everyGroupData = new ArrayList<>(); + for (int j = 0; j < list1.size(); j++) { + if (count == 90 || j == list1.size() - 1) { + int keyCount = (j / 90); + if (j == list1.size() - 1) { + keyCount = keyCount + 1; + everyGroupData.add(list1.get(j)); + } + resultMap.put(keyCount + "", everyGroupData); + everyGroupData = new ArrayList<>(); + count = 0; + } + everyGroupData.add(list1.get(j)); + count++; + + } + + for (int j = 1; j <= resultMap.size(); j++) { + List voList = resultMap.get(String.valueOf(j)); + // 使用每一页的数据 + if (voList.size() % 3 == 0) { + for (int i = 0; i < voList.size() / 3; i++) { + Map map = new HashMap<>(); + map.put("num1", voList.get(i).getNum()); + map.put("log1", voList.get(i).getLog2()); + map.put("result1", voList.get(i).getResult()); + + map.put("num2", voList.get(voList.size() / 3 + i).getNum()); + map.put("log2", voList.get(voList.size() / 3 + i).getLog2()); + map.put("result2", voList.get(voList.size() / 3 + i).getResult()); + + map.put("num3", voList.get(voList.size() / 3 * 2 + i).getNum()); + map.put("log3", voList.get(voList.size() / 3 * 2 + i).getLog2()); + map.put("result3", voList.get(voList.size() / 3 * 2 + i).getResult()); + resultList1.add(map); + } + } else { + for (int i = 0; i < voList.size() / 3 + 1; i++) { + if (voList.size() % 3 == 1) { + Map map = new HashMap<>(); + map.put("num1", voList.get(i).getNum()); + map.put("log1", voList.get(i).getLog2()); + map.put("result1", voList.get(i).getResult()); + if (i < voList.size() / 3) { + map.put("num2", voList.get(voList.size() / 3 + i + 1).getNum()); + map.put("log2", voList.get(voList.size() / 3 + i + 1).getLog2()); + map.put("result2", voList.get(voList.size() / 3 + i + 1).getResult()); + map.put("num3", voList.get(voList.size() / 3 * 2 + i + 1).getNum()); + map.put("log3", voList.get(voList.size() / 3 * 2 + i + 1).getLog2()); + map.put("result3", voList.get(voList.size() / 3 * 2 + i + 1).getResult()); + } + resultList1.add(map); + } else if (voList.size() % 3 == 2) { + Map map = new HashMap<>(); + map.put("num1", voList.get(i).getNum()); + map.put("log1", voList.get(i).getLog2()); + map.put("result1", voList.get(i).getResult()); + map.put("num2", voList.get(voList.size() / 3 + i + 1).getNum()); + map.put("log2", voList.get(voList.size() / 3 + i + 1).getLog2()); + map.put("result2", voList.get(voList.size() / 3 + i + 1).getResult()); + if (i < voList.size() / 3) { + map.put("num3", voList.get(voList.size() / 3 * 2 + i + 2).getNum()); + map.put("log3", voList.get(voList.size() / 3 * 2 + i + 2).getLog2()); + map.put("result3", voList.get(voList.size() / 3 * 2 + i + 2).getResult()); + } + resultList1.add(map); + } + } + } + } + result.put("list1", resultList1); + } + for (int i = 0; i < (arrVOList.size() / 96); i++) { + int start = i * 96; + if (i == 0) { + start = 0; + } + String startNum = ""; + String endNum = ""; + for (int k = 0; k < 96; k++) { + String num = arrVOList.get((i * 96) + k).getNum(); + if (num != null && !"".equals(num) && num.split("-").length > 1) { + startNum = num.split("-")[num.split("-").length - 1]; + break; + } + } + for (int k = 95; k >= 0; k--) { + if ((i * 96) + k < arrVOList.size()) { + String num = arrVOList.get((i * 96) + k).getNum(); + if (num != null && !"".equals(num) && num.split("-").length > 1) { + endNum = num.split("-")[num.split("-").length - 1]; + break; + } + } + } + for (int j = 0; j < 10; j++) { + int x = 0; + Map map = new HashMap<>(); + if (j == 0) { + map.put("1", s + "(" + startNum + "-" + endNum + ")"); + map.put("13", "布板图"); + } else if (j == 1) { + map.put("0", " "); + map.put("1", "1"); + map.put("2", "2"); + map.put("3", "3"); + map.put("4", "4"); + map.put("5", "5"); + map.put("6", "6"); + map.put("7", "7"); + map.put("8", "8"); + map.put("9", "9"); + map.put("10", "10"); + map.put("11", "11"); + map.put("12", "12"); + map.put("13", "1"); + map.put("14", "2"); + map.put("15", "3"); + map.put("16", "4"); + map.put("17", "5"); + map.put("18", "6"); + map.put("19", "7"); + map.put("20", "8"); + map.put("21", "9"); + map.put("22", "10"); + map.put("23", "11"); + map.put("24", "12"); + } else { + if (j == 2) { + map.put("0", "A"); + } else if (j == 3) { + map.put("0", "B"); + } else if (j == 4) { + map.put("0", "C"); + } else if (j == 5) { + map.put("0", "D"); + } else if (j == 6) { + map.put("0", "E"); + } else if (j == 7) { + map.put("0", "F"); + } else if (j == 8) { + map.put("0", "G"); + } else if (j == 9) { + map.put("0", "H"); + } + for (int k = 1; k <= 12; k++) { + map.put(k + "", arrVOList.get(start + (8 * x + j) - 2).getValue()); + String num = arrVOList.get(start + (8 * x + j) - 2).getNum(); + if (num != null && !"".equals(num) && num.split("-").length > 1) { + map.put((k + 12) + "", num.split("-")[num.split("-").length - 1]); + } else { + map.put((k + 12) + "", " "); + } + x++; + } + } + resultList2.add(map); + } + } + result.put("list2", resultList2); + url = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "LDuoreportPrint"); + } + // 口蹄疫非兰所 + else { + List arrVOList = JSON.parseArray(examineResult.getOriginRecordData(), ExamineDataArrVO.class); + Collections.sort(arrVOList, new Comparator() { + @Override + public int compare(ExamineDataArrVO o1, ExamineDataArrVO o2) { + return o1.getOrder() - o2.getOrder(); + } + }); + if (list.size() > 0) { + for (int i = 0; i < list.size() / 96; i++) { + List doubles = new ArrayList<>(); + double a1 = Double.parseDouble(list.get((i + 1) * 96 - 1).getValue()); + double a2 = Double.parseDouble(list.get((i + 1) * 96 - 2).getValue()); + double a3 = Double.parseDouble(list.get((i + 1) * 96 - 3).getValue()); + double a4 = Double.parseDouble(list.get((i + 1) * 96 - 4).getValue()); + doubles.add(a1); + doubles.add(a2); + doubles.add(a3); + doubles.add(a4); + List collect = doubles.stream().sorted().collect(Collectors.toList()); + String format2 = df.format((collect.get(1) + collect.get(2)) / 4); + ExamineDataArrVO examineDataArrVO = new ExamineDataArrVO(); + examineDataArrVO.setNum("临界值"); + examineDataArrVO.setValue(""); + examineDataArrVO.setLog2(format2); + list1.add(examineDataArrVO); + for (int j = 0; j < 96; j++) { + ExamineDataArrVO vo = list.get((i * 96) + j); + if (vo.getNum() != null) { + list1.add(vo); + } + } + } + } + + + if (list1.size() > 0) { + Map> resultMap = new HashMap<>(); + int count = 0; + List everyGroupData = new ArrayList<>(); + for (int j = 0; j < list1.size(); j++) { + if (count == 90 || j == list1.size() - 1) { + int keyCount = (j / 90); + if (j == list1.size() - 1) { + keyCount = keyCount + 1; + everyGroupData.add(list1.get(j)); + } + resultMap.put(keyCount + "", everyGroupData); + everyGroupData = new ArrayList<>(); + count = 0; + } + everyGroupData.add(list1.get(j)); + count++; + + } + + for (int j = 1; j <= resultMap.size(); j++) { + List voList = resultMap.get(String.valueOf(j)); + // 使用每一页的数据 + if (voList.size() % 3 == 0) { + for (int i = 0; i < voList.size() / 3; i++) { + Map map = new HashMap<>(); + map.put("num1", voList.get(i).getNum()); + map.put("log1", voList.get(i).getLog2()); + map.put("result1", voList.get(i).getResult()); + + map.put("num2", voList.get(voList.size() / 3 + i).getNum()); + map.put("log2", voList.get(voList.size() / 3 + i).getLog2()); + map.put("result2", voList.get(voList.size() / 3 + i).getResult()); + + map.put("num3", voList.get(voList.size() / 3 * 2 + i).getNum()); + map.put("log3", voList.get(voList.size() / 3 * 2 + i).getLog2()); + map.put("result3", voList.get(voList.size() / 3 * 2 + i).getResult()); + resultList1.add(map); + } + } else { + for (int i = 0; i < voList.size() / 3 + 1; i++) { + if (voList.size() % 3 == 1) { + Map map = new HashMap<>(); + map.put("num1", voList.get(i).getNum()); + map.put("log1", voList.get(i).getLog2()); + map.put("result1", voList.get(i).getResult()); + if (i < voList.size() / 3) { + map.put("num2", voList.get(voList.size() / 3 + i + 1).getNum()); + map.put("log2", voList.get(voList.size() / 3 + i + 1).getLog2()); + map.put("result2", voList.get(voList.size() / 3 + i + 1).getResult()); + map.put("num3", voList.get(voList.size() / 3 * 2 + i + 1).getNum()); + map.put("log3", voList.get(voList.size() / 3 * 2 + i + 1).getLog2()); + map.put("result3", voList.get(voList.size() / 3 * 2 + i + 1).getResult()); + } + resultList1.add(map); + } else if (voList.size() % 3 == 2) { + Map map = new HashMap<>(); + map.put("num1", voList.get(i).getNum()); + map.put("log1", voList.get(i).getLog2()); + map.put("result1", voList.get(i).getResult()); + map.put("num2", voList.get(voList.size() / 3 + i + 1).getNum()); + map.put("log2", voList.get(voList.size() / 3 + i + 1).getLog2()); + map.put("result2", voList.get(voList.size() / 3 + i + 1).getResult()); + if (i < voList.size() / 3) { + map.put("num3", voList.get(voList.size() / 3 * 2 + i + 2).getNum()); + map.put("log3", voList.get(voList.size() / 3 * 2 + i + 2).getLog2()); + map.put("result3", voList.get(voList.size() / 3 * 2 + i + 2).getResult()); + } + resultList1.add(map); + } + } + } + } + result.put("list1", resultList1); + } + for (int i = 0; i < (arrVOList.size() / 96); i++) { + int start = i * 96; + if (i == 0) { + start = 0; + } + String startNum = ""; + String endNum = ""; + for (int k = 0; k < 96; k++) { + String num = arrVOList.get((i * 96) + k).getNum(); + if (num != null && !"".equals(num) && num.split("-").length > 1) { + startNum = num.split("-")[num.split("-").length - 1]; + break; + } + } + for (int k = 95; k >= 0; k--) { + if ((i * 96) + k < arrVOList.size()) { + String num = arrVOList.get((i * 96) + k).getNum(); + if (num != null && !"".equals(num) && num.split("-").length > 1) { + endNum = num.split("-")[num.split("-").length - 1]; + break; + } + } + } + for (int j = 0; j < 10; j++) { + int x = 0; + Map map = new HashMap<>(); + if (j == 0) { + map.put("1", s + "(" + startNum + "-" + endNum + ")"); + map.put("13", "布板图"); + } else if (j == 1) { + map.put("0", " "); + map.put("1", "1"); + map.put("2", "2"); + map.put("3", "3"); + map.put("4", "4"); + map.put("5", "5"); + map.put("6", "6"); + map.put("7", "7"); + map.put("8", "8"); + map.put("9", "9"); + map.put("10", "10"); + map.put("11", "11"); + map.put("12", "12"); + map.put("13", "1"); + map.put("14", "2"); + map.put("15", "3"); + map.put("16", "4"); + map.put("17", "5"); + map.put("18", "6"); + map.put("19", "7"); + map.put("20", "8"); + map.put("21", "9"); + map.put("22", "10"); + map.put("23", "11"); + map.put("24", "12"); + } else { + if (j == 2) { + map.put("0", "A"); + } else if (j == 3) { + map.put("0", "B"); + } else if (j == 4) { + map.put("0", "C"); + } else if (j == 5) { + map.put("0", "D"); + } else if (j == 6) { + map.put("0", "E"); + } else if (j == 7) { + map.put("0", "F"); + } else if (j == 8) { + map.put("0", "G"); + } else if (j == 9) { + map.put("0", "H"); + } + for (int k = 1; k <= 12; k++) { + map.put(k + "", arrVOList.get(start + (8 * x + j) - 2).getValue()); + String num = arrVOList.get(start + (8 * x + j) - 2).getNum(); + if (num != null && !"".equals(num) && num.split("-").length > 1) { + map.put((k + 12) + "", num.split("-")[num.split("-").length - 1]); + } else { + map.put((k + 12) + "", " "); + } + x++; + } + } + resultList2.add(map); + } + } + result.put("list2", resultList2); + url = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "LDuoreportPrint"); + } + } + // 普通检测 + else { + // 根据试剂给不同检测数值命名 + if ( + "1580730163250188290".equals(examineResult.getReagentId()) + || "1570297916894146562".equals(examineResult.getReagentId()) + || "1570667729797705730".equals(examineResult.getReagentId()) + || "1570671477110534145".equals(examineResult.getReagentId()) + || "1659464963116519426".equals(examineResult.getReagentId()) + || "1589877000410296322".equals(examineResult.getReagentId()) + || "1677607364850900993".equals(examineResult.getReagentId()) + || "1677607364859289601".equals(examineResult.getReagentId()) + || "1682203934330204161".equals(examineResult.getReagentId()) + || "1582988982068027393".equals(examineResult.getReagentId()) + || "1691712889624555522".equals(examineResult.getReagentId()) + || "1680136574547013633".equals(examineResult.getReagentId()) + || "1691710090853576706".equals(examineResult.getReagentId()) + || "2002014518899601409".equals(examineResult.getReagentId()) + || "2002188351753383937".equals(examineResult.getReagentId()) + || "2002188672294678529".equals(examineResult.getReagentId()) + || "2010597883512958981".equals(examineResult.getReagentId()) + || "2010597883512958983".equals(examineResult.getReagentId()) + || "2010597883512958984".equals(examineResult.getReagentId()) + || "2010597883512958985".equals(examineResult.getReagentId()) + || "2010597883512958986".equals(examineResult.getReagentId()) + || "2010597883512958987".equals(examineResult.getReagentId()) + || "2010597883512958988".equals(examineResult.getReagentId()) + || "2010597883512958989".equals(examineResult.getReagentId()) + || "2010597883512958990".equals(examineResult.getReagentId()) + ) { + result.put("18", "S/P"); + } else if ("1580815808211578882".equals(examineResult.getReagentId()) + ||"2010597883441655809".equals(examineResult.getReagentId())) { + result.put("18", "PI"); + } else if ("1570666183341043714".equals(examineResult.getReagentId()) + || "1692066046158401537".equals(examineResult.getReagentId())) { + result.put("18", "PB"); + } else if ("1570283733628678145".equals(examineResult.getReagentId()) + || "1533624738296389636".equals(examineResult.getReagentId()) + || "1691714318883975170".equals(examineResult.getReagentId()) + || "2010597883441655810".equals(examineResult.getReagentId()) + || "2010597883512958982".equals(examineResult.getReagentId()) + ) { + result.put("18", "阻断率"); + } else if ("1665968083879366657".equals(examineResult.getReagentId()) + || "1665964229817307138".equals(examineResult.getReagentId())) { + result.put("18", "抑制率"); + } else if ("1570295395605737473".equals(examineResult.getReagentId())) { + result.put("18", "KQ"); + } else if ("1570296117147660290".equals(examineResult.getReagentId()) + || "1570295846749270017".equals(examineResult.getReagentId()) + || "1570664922961080322".equals(examineResult.getReagentId()) + || "1656852607882579970".equals(examineResult.getReagentId()) + || "1570666622551781378".equals(examineResult.getReagentId()) + || "1692059030258020354".equals(examineResult.getReagentId()) + || "1682203201220390913".equals(examineResult.getReagentId()) + || "1692060337681297410".equals(examineResult.getReagentId()) + || "1570667398619656194".equals(examineResult.getReagentId()) + || "2010597883441655811".equals(examineResult.getReagentId()) + || "2010597883512958977".equals(examineResult.getReagentId()) + || "2010597883512958978".equals(examineResult.getReagentId()) + || "2010597883512958979".equals(examineResult.getReagentId()) + || "2010597883512958980".equals(examineResult.getReagentId()) + ) { + result.put("18", "S/N"); + } else if ("1570297053211455490".equals(examineResult.getReagentId()) + || "1631222146321997826".equals(examineResult.getReagentId())) { + result.put("18", "牛PPD-PBS"); + result.put("19", "牛PPD-禽PPD"); + } else { + result.put("18", "样品OD"); + } + + if (list.size() % 96 == 0) { + for (int i = 0; i < list.size() / 96; i++) { + double a1 = Double.parseDouble(list.get(i * 96).getOriginResult()); + double b1 = Double.parseDouble(list.get((i * 96) + 1).getOriginResult()); + String format = df.format((a1 + b1) / 2); + ExamineDataArrVO arrVO = new ExamineDataArrVO(); + arrVO.setNum("阴性对照平均OD值"); + arrVO.setValue(format); + arrVO.setResult(" "); + arrVO.setOrder(0); + list1.add(arrVO); + double a2 = Double.parseDouble(list.get((i * 96) + 2).getOriginResult()); + double b2 = Double.parseDouble(list.get((i * 96) + 3).getOriginResult()); + String format1 = df.format((a2 + b2) / 2); + ExamineDataArrVO arrVO1 = new ExamineDataArrVO(); + arrVO1.setNum("阳性对照平均OD值"); + arrVO1.setValue(format1); + arrVO1.setResult(" "); + arrVO1.setOrder(0); + list1.add(arrVO1); + for (int j = 0; j < 96; j++) { + ExamineDataArrVO vo = list.get((i * 96) + j); + if (vo.getNum() != null && !"".equals(vo.getNum())) { + list1.add(vo); + } + } + } + } else { + for (int i = 0; i < list.size() / 96 + 1; i++) { + double a1 = Double.parseDouble(list.get(i * 96).getOriginResult()); + double b1 = Double.parseDouble(list.get((i * 96) + 1).getOriginResult()); + String format = df.format((a1 + b1) / 2); + ExamineDataArrVO arrVO = new ExamineDataArrVO(); + arrVO.setNum("阴性对照平均OD值"); + arrVO.setValue(format); + arrVO.setResult(" "); + arrVO.setOrder(0); + list1.add(arrVO); + double a2 = Double.parseDouble(list.get((i * 96) + 2).getOriginResult()); + double b2 = Double.parseDouble(list.get((i * 96) + 3).getOriginResult()); + String format1 = df.format((a2 + b2) / 2); + ExamineDataArrVO arrVO1 = new ExamineDataArrVO(); + arrVO1.setNum("阳性对照平均OD值"); + arrVO1.setValue(format1); + arrVO1.setResult(" "); + arrVO1.setOrder(0); + list1.add(arrVO1); + for (int j = 0; j < 96; j++) { + if ((i * 96) + j > list.size() - 1) { + break; + } + ExamineDataArrVO vo = list.get((i * 96) + j); + if (vo.getNum() != null && !"".equals(vo.getNum())) { + list1.add(vo); + } + } + } + } + + // 阴阳性数量 +// long yin = list1.stream().filter((ExamineDataArrVO e) -> "阴性".equals(e.getResult())).count(); +// long yang = list1.stream().filter((ExamineDataArrVO e) -> "阳性".equals(e.getResult())).count(); +// ExamineDataArrVO dataArrVO1 = new ExamineDataArrVO(); +// ExamineDataArrVO dataArrVO2 = new ExamineDataArrVO(); +// dataArrVO1.setNum("阴性数量"); +// dataArrVO1.setValue(String.valueOf(yin)); +// dataArrVO2.setNum("阳性数量"); +// dataArrVO2.setValue(String.valueOf(yang)); +// list1.add(dataArrVO1); +// list1.add(dataArrVO2); + + if ("1570297053211455490".equals(examineResult.getReagentId()) || "1631222146321997826".equals(examineResult.getReagentId())) { + // 根据样品编号去重 + list1 = list1.stream().collect(Collectors + .collectingAndThen( + Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(ExamineDataArrVO::getNum))), + ArrayList::new)); + // 根据order排序 + System.out.println("list1:" + list1); + sortByOrder(list1); + + if (list1.size() > 0) { + Map> resultMap = new HashMap<>(); + int count = 0; + List everyGroupData = new ArrayList<>(); + for (int j = 0; j < list1.size(); j++) { + if (count == 60 || j == list1.size() - 1) { + int keyCount = (j / 60); + if (j == list1.size() - 1) { + keyCount = keyCount + 1; + everyGroupData.add(list1.get(j)); + } + resultMap.put(keyCount + "", everyGroupData); + everyGroupData = new ArrayList<>(); + count = 0; + } + everyGroupData.add(list1.get(j)); + count++; + } + + for (int j = 1; j <= resultMap.size(); j++) { + List arrVOList = resultMap.get(String.valueOf(j)); + // 使用每一页的数据 + if (arrVOList.size() % 2 == 0) { + for (int i = 0; i < arrVOList.size() / 2; i++) { + Map map = new HashMap<>(); + map.put("num1", arrVOList.get(i).getNum()); + String[] split4 = arrVOList.get(i).getValue().split(","); + map.put("value1", split4[0]); + if (split4.length > 1) { + map.put("value2", split4[1]); + } + map.put("result1", arrVOList.get(i).getResult()); + map.put("num2", arrVOList.get(arrVOList.size() / 2 + i).getNum()); + String[] split3 = arrVOList.get(arrVOList.size() / 2 + i).getValue().split(","); + map.put("value3", split3[0]); + if (split3.length > 1) { + map.put("value4", split3[1]); + } + map.put("result2", arrVOList.get(arrVOList.size() / 2 + i).getResult()); + resultList1.add(map); + } + } else { + for (int i = 0; i < arrVOList.size() / 2 + 1; i++) { + Map map = new HashMap<>(); + map.put("num1", arrVOList.get(i).getNum()); + String[] split3 = arrVOList.get(i).getValue().split(","); + map.put("value1", split3[0]); + if (split3.length > 1) { + map.put("value2", split3[1]); + } + map.put("result1", arrVOList.get(i).getResult()); + if (i < arrVOList.size() / 2) { + map.put("num2", arrVOList.get(arrVOList.size() / 2 + i + 1).getNum()); + String[] split4 = arrVOList.get(arrVOList.size() / 2 + i + 1).getValue().split(","); + map.put("value3", split4[0]); + if (split4.length > 1) { + map.put("value4", split4[1]); + } + map.put("result2", arrVOList.get(arrVOList.size() / 2 + i + 1).getResult()); + } + resultList1.add(map); + } + } + } + result.put("list1", resultList1); + } + } else { + if (list1.size() > 0) { + Map> resultMap = new HashMap<>(); + int count = 0; + List everyGroupData = new ArrayList<>(); + for (int j = 0; j < list1.size(); j++) { + if (count == 90 || j == list1.size() - 1) { + int keyCount = (j / 90); + if (j == list1.size() - 1) { + keyCount = keyCount + 1; + everyGroupData.add(list1.get(j)); + } + resultMap.put(keyCount + "", everyGroupData); + everyGroupData = new ArrayList<>(); + count = 0; + } + everyGroupData.add(list1.get(j)); + count++; + } + + for (int j = 1; j <= resultMap.size(); j++) { + List arrVOList = resultMap.get(String.valueOf(j)); + // 使用每一页的数据 + if (arrVOList.size() % 3 == 0) { + for (int i = 0; i < arrVOList.size() / 3; i++) { + Map map = new HashMap<>(); + map.put("num1", arrVOList.get(i).getNum()); + map.put("value1", arrVOList.get(i).getValue()); + map.put("result1", arrVOList.get(i).getResult()); + + map.put("num2", arrVOList.get(arrVOList.size() / 3 + i).getNum()); + map.put("value2", arrVOList.get(arrVOList.size() / 3 + i).getValue()); + map.put("result2", arrVOList.get(arrVOList.size() / 3 + i).getResult()); + + map.put("num3", arrVOList.get(arrVOList.size() / 3 * 2 + i).getNum()); + map.put("value3", arrVOList.get(arrVOList.size() / 3 * 2 + i).getValue()); + map.put("result3", arrVOList.get(arrVOList.size() / 3 * 2 + i).getResult()); + resultList1.add(map); + } + } else { + for (int i = 0; i < arrVOList.size() / 3 + 1; i++) { + if (arrVOList.size() % 3 == 1) { + Map map = new HashMap<>(); + map.put("num1", arrVOList.get(i).getNum()); + map.put("value1", arrVOList.get(i).getValue()); + map.put("result1", arrVOList.get(i).getResult()); + if (i < arrVOList.size() / 3) { + map.put("num2", arrVOList.get(arrVOList.size() / 3 + i + 1).getNum()); + map.put("value2", arrVOList.get(arrVOList.size() / 3 + i + 1).getValue()); + map.put("result2", arrVOList.get(arrVOList.size() / 3 + i + 1).getResult()); + map.put("num3", arrVOList.get(arrVOList.size() / 3 * 2 + i + 1).getNum()); + map.put("value3", arrVOList.get(arrVOList.size() / 3 * 2 + i + 1).getValue()); + map.put("result3", arrVOList.get(arrVOList.size() / 3 * 2 + i + 1).getResult()); + } + resultList1.add(map); + } else if (arrVOList.size() % 3 == 2) { + Map map = new HashMap<>(); + map.put("num1", arrVOList.get(i).getNum()); + map.put("value1", arrVOList.get(i).getValue()); + map.put("result1", arrVOList.get(i).getResult()); + map.put("num2", arrVOList.get(arrVOList.size() / 3 + i + 1).getNum()); + map.put("value2", arrVOList.get(arrVOList.size() / 3 + i + 1).getValue()); + map.put("result2", arrVOList.get(arrVOList.size() / 3 + i + 1).getResult()); + if (i < arrVOList.size() / 3) { + map.put("num3", arrVOList.get(arrVOList.size() / 3 * 2 + i + 2).getNum()); + map.put("value3", arrVOList.get(arrVOList.size() / 3 * 2 + i + 2).getValue()); + map.put("result3", arrVOList.get(arrVOList.size() / 3 * 2 + i + 2).getResult()); + } + resultList1.add(map); + } + } + } + } + result.put("list1", resultList1); + } + } + + // 原始酶标板数据 + if (list.size() % 96 != 0) { + for (int i = 0; i < (list.size() / 96 + 1); i++) { + int start = i * 96; + if (i == 0) { + start = 0; + } + String startNum = ""; + String endNum = ""; + for (int k = 0; k < 96; k++) { + String num = list.get((i * 96) + k).getNum(); + if (num != null && !"".equals(num) && num.split("-").length > 1) { + startNum = num.split("-")[num.split("-").length - 1]; + break; + } + } + for (int k = 95; k >= 0; k--) { + if ((i * 96) + k < list.size()) { + String num = list.get((i * 96) + k).getNum(); + if (num != null && !"".equals(num) && num.split("-").length > 1) { + endNum = num.split("-")[num.split("-").length - 1]; + break; + } + } + } + + // 原始记录成立条件内容 + resultList3 = getCondition(list, i, df, s, startNum, endNum, examineResult.getReagentId(), resultList3); + for (int j = 0; j < 10; j++) { + int x = 0; + Map map = new HashMap<>(); + if (j == 0) { + map.put("1", s + "(" + startNum + "-" + endNum + ")"); + map.put("13", "布板图"); + } else if (j == 1) { + map.put("0", " "); + map.put("1", "1"); + map.put("2", "2"); + map.put("3", "3"); + map.put("4", "4"); + map.put("5", "5"); + map.put("6", "6"); + map.put("7", "7"); + map.put("8", "8"); + map.put("9", "9"); + map.put("10", "10"); + map.put("11", "11"); + map.put("12", "12"); + map.put("13", "1"); + map.put("14", "2"); + map.put("15", "3"); + map.put("16", "4"); + map.put("17", "5"); + map.put("18", "6"); + map.put("19", "7"); + map.put("20", "8"); + map.put("21", "9"); + map.put("22", "10"); + map.put("23", "11"); + map.put("24", "12"); + } else { + if (j == 2) { + map.put("0", "A"); + } else if (j == 3) { + map.put("0", "B"); + } else if (j == 4) { + map.put("0", "C"); + } else if (j == 5) { + map.put("0", "D"); + } else if (j == 6) { + map.put("0", "E"); + } else if (j == 7) { + map.put("0", "F"); + } else if (j == 8) { + map.put("0", "G"); + } else if (j == 9) { + map.put("0", "H"); + } + for (int k = 1; k <= 12; k++) { + if (list.size() - 1 >= start + (8 * x + j) - 2) { + map.put(k + "", list.get(start + (8 * x + j) - 2).getOriginResult()); + String num = list.get(start + (8 * x + j) - 2).getNum(); + if (num != null && !"".equals(num) && num.split("-").length > 1) { + map.put((k + 12) + "", num.split("-")[num.split("-").length - 1]); + } else { + map.put((k + 12) + "", " "); + } + } + x++; + } + } + resultList2.add(map); + } + } + } else { + for (int i = 0; i < (list.size() / 96); i++) { + int start = i * 96; + if (i == 0) { + start = 0; + } + String startNum = ""; + String endNum = ""; + for (int k = 0; k < 96; k++) { + String num = list.get((i * 96) + k).getNum(); + if (num != null && !"".equals(num) && num.split("-").length > 1) { + startNum = num.split("-")[num.split("-").length - 1]; + break; + } + } + for (int k = 95; k >= 0; k--) { + if ((i * 96) + k < list.size()) { + String num = list.get((i * 96) + k).getNum(); + if (num != null && !"".equals(num) && num.split("-").length > 1) { + endNum = num.split("-")[num.split("-").length - 1]; + break; + } + } + } + + // 原始记录成立条件内容 + resultList3 = getCondition(list, i, df, s, startNum, endNum, examineResult.getReagentId(), resultList3); + for (int j = 0; j < 10; j++) { + int x = 0; + Map map = new HashMap<>(); + if (j == 0) { + map.put("1", s + "(" + startNum + "-" + endNum + ")"); + map.put("13", "布板图"); + } else if (j == 1) { + map.put("0", " "); + map.put("1", "1"); + map.put("2", "2"); + map.put("3", "3"); + map.put("4", "4"); + map.put("5", "5"); + map.put("6", "6"); + map.put("7", "7"); + map.put("8", "8"); + map.put("9", "9"); + map.put("10", "10"); + map.put("11", "11"); + map.put("12", "12"); + map.put("13", "1"); + map.put("14", "2"); + map.put("15", "3"); + map.put("16", "4"); + map.put("17", "5"); + map.put("18", "6"); + map.put("19", "7"); + map.put("20", "8"); + map.put("21", "9"); + map.put("22", "10"); + map.put("23", "11"); + map.put("24", "12"); + } else { + if (j == 2) { + map.put("0", "A"); + } else if (j == 3) { + map.put("0", "B"); + } else if (j == 4) { + map.put("0", "C"); + } else if (j == 5) { + map.put("0", "D"); + } else if (j == 6) { + map.put("0", "E"); + } else if (j == 7) { + map.put("0", "F"); + } else if (j == 8) { + map.put("0", "G"); + } else if (j == 9) { + map.put("0", "H"); + } + for (int k = 1; k <= 12; k++) { + map.put(k + "", list.get(start + (8 * x + j) - 2).getOriginResult()); + String num = list.get(start + (8 * x + j) - 2).getNum(); + if (num != null && !"".equals(num) && num.split("-").length > 1) { + map.put((k + 12) + "", num.split("-")[num.split("-").length - 1]); + } else { + map.put((k + 12) + "", " "); + } + x++; + } + } + resultList2.add(map); + } + } + } + result.put("list2", resultList2); + result.put("list3", resultList3); + if ("1570297053211455490".equals(examineResult.getReagentId()) || "1631222146321997826".equals(examineResult.getReagentId())) { + url = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "reportPrint2"); + } else { + url = DictBizCache.getKey(DictBizEnum.PRINT_URL.getName(), "reportPrint"); + } + } + } + + // 生成文档并返回字节数组 + XWPFDocument doc = null; + try { + // 检查url是否为空 + if (url == null || url.trim().isEmpty()) { + throw new RuntimeException("报告模板URL未配置,请检查字典配置"); + } + System.out.println("url:" + url); + System.out.println("result:" + result); + doc = WordExportUtil.exportWord07(url, result); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + doc.write(baos); + return baos.toByteArray(); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("生成报告文档失败: " + e.getMessage(), e); + } finally { + if (null != doc) { + try { + doc.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + +} \ No newline at end of file diff --git a/lab-service/lab-lims/src/main/java/org/springblade/lims/utils/ZipUtils.java b/lab-service/lab-lims/src/main/java/org/springblade/lims/utils/ZipUtils.java new file mode 100644 index 0000000..a123e31 --- /dev/null +++ b/lab-service/lab-lims/src/main/java/org/springblade/lims/utils/ZipUtils.java @@ -0,0 +1,66 @@ +package org.springblade.lims.utils; + +import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; +import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; +import org.springblade.system.cache.DictBizCache; +import org.springblade.system.enums.DictBizEnum; + +import java.io.File; +import java.io.FileOutputStream; +import java.util.Map; + +/** + * @BelongsProject: project_husbandry_back + * @BelongsPackage:org.springblade.lims.utils + * @Annotation: ZIP压缩工具类 + * @Author:YangMaoFu + * @date :Created in 2023/7/6 14:18 + * @CreateTime: 2026-04-14 23:14 + * @Description: TODO + * @Version: 1.0 + */ +public class ZipUtils { + + /** + * 将ZIP文件保存到服务器指定目录 + * + * @param fileMap 文件映射 + * @param zipName ZIP文件名 + * @return 完整文件路径 + */ + public static String saveZipToServer(Map fileMap, String zipName) throws Exception { + String saveDir = DictBizCache.getKey(DictBizEnum.SCHEDULED_TASK.getName(), "saveDirFile"); + // 确保目录存在 + File dir = new File(saveDir); + if (!dir.exists()) { + dir.mkdirs(); + } + + // 生成完整路径 + String fullPath = saveDir + File.separator + zipName; + File zipFile = new File(fullPath); + + // 写入ZIP文件 + try (FileOutputStream fos = new FileOutputStream(zipFile); + ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(fos)) { + + // 写入所有文件 + for (Map.Entry entry : fileMap.entrySet()) { + String fileName = entry.getKey(); + byte[] fileData = entry.getValue(); + + // 创建Zip条目 + ZipArchiveEntry zipEntry = new ZipArchiveEntry(fileName); + zipOut.putArchiveEntry(zipEntry); + + // 写入文件数据 + zipOut.write(fileData); + zipOut.closeArchiveEntry(); + } + + zipOut.finish(); + } + + return fullPath; + } +}