diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/TestRecordController.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/TestRecordController.java index ac36954..aeb0f82 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/TestRecordController.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/TestRecordController.java @@ -214,8 +214,8 @@ public class TestRecordController { @ApiOperation("生成检验记录-贵阳禁毒") @GetMapping("/inspectionRecord") - public R inspectionRecord(String entrustId) throws Exception { - return testRecordService.inspectionRecord(entrustId); + public R inspectionRecord(String entrustId, String materialType) throws Exception { + return testRecordService.inspectionRecord(entrustId, materialType); } } diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/TestRecordService.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/TestRecordService.java index 3f5690c..672d8f7 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/TestRecordService.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/TestRecordService.java @@ -97,7 +97,7 @@ public interface TestRecordService extends IService { * @return * @throws Exception */ - R inspectionRecord(String entrustId) throws Exception; + R inspectionRecord(String entrustId, String materialType) throws Exception; /** * 根据业务id获取实验检验记录 diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordServiceImpl.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordServiceImpl.java index 8965b8a..b6519a7 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordServiceImpl.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordServiceImpl.java @@ -7,6 +7,7 @@ import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -99,6 +100,7 @@ public class TestRecordServiceImpl extends ServiceImpl map = this.invivoRecord(entrustInfo); - return R.ok(this.createInVivoFile(map, entrustId), "生成成功!"); + return R.ok(this.createInVivoFile(map, entrustId, materialType), "生成成功!"); } - return null; - } public Map invivoRecord(EntrustInfo entrustInfo) throws Exception { - - // 这里因为检验记录实体并未关联业务id, 只能先查询实验数据,在通过实验数据获取到检验记录信息 + // 获取检验记录信息 TestRecord testRecord = getTestRecordByBusinessId(entrustInfo.getId()); + if (testRecord == null) { + throw new Exception("未找到检验记录信息"); + } HashMap data = buildCommonInspectRecordDocMap(entrustInfo, testRecord); - List sampleIdList = sampleInfoService.list(Wrappers.lambdaQuery() - .eq(SampleInfo::getBusinessId, entrustInfo.getId())) - .stream().map(SampleInfo::getId) - .collect(Collectors.toList()); - - List instruments = testRecordInstrumentService.list(Wrappers.lambdaQuery() - .in(TestRecordInstrument::getId, testRecord.getDeviceIdList())); - + // 获取仪器设备数据 + List deviceIdList = testRecord.getDeviceIdList(); + List instruments = CollectionUtils.isEmpty(deviceIdList) + ? Collections.emptyList() + : testRecordInstrumentService.list(Wrappers.lambdaQuery() + .in(TestRecordInstrument::getId, deviceIdList)); + + data.put("instrumentName", CollectionUtils.isEmpty(instruments) + ? "未找到仪器设备数据!" + : instruments.stream() + .map(TestRecordInstrument::getInstrumentName) + .collect(Collectors.joining("\n")) + ); - if (instruments == null || instruments.size() == 0) { - data.put("instrumentName", "未找到仪器设备数据!"); - }else { - String instrumentName = instruments.stream() - .map(TestRecordInstrument::getInstrumentName) - .collect(Collectors.joining("\n")); + // 获取样品检测数据 + List hairDataDtos = (List) testRecordSampleDataService + .getSampleTestDataByBusiness(entrustInfo.getId()); - data.put("instrumentName", instrumentName); + if (CollectionUtils.isEmpty(hairDataDtos)) { + data.put("dataDtos", Collections.emptyList()); + data.put("sampleSize", 0); + data.put("vo", testRecord); + return data; } - - List hairDataDtos = (List) testRecordSampleDataService.getSampleTestDataByBusiness(entrustInfo.getId()); - + // 处理检测数据 Map> dataMap = hairDataDtos.stream() .collect(Collectors.groupingBy(HairSewageDataDto::getCompoundName)); - ArrayList dataDtos = new ArrayList<>(); - - for (Map.Entry> entry : dataMap.entrySet()) { - - List list = entry.getValue(); - - HairSewageDataDto dto = new HairSewageDataDto(); - - dto.setSampleName("空白"); - dto.setCompoundName(entry.getKey()); - dto.setTmpTargetRtTime("/"); - dto.setTmpRtTimeError("/"); - dto.setRtTimeWithinError("否"); - dto.setTmpIonAbundanceRatio("/"); - dto.setWhetherCheckOut("否"); - dataDtos.add(dto); - ArrayList delList = new ArrayList<>(); - for (HairSewageDataDto item : list) { - if (StringUtils.isNotBlank(item.getSampleType()) && item.getSampleType().equals("STD")) { - delList.add(item); + List dataDtos = new ArrayList<>(); + + dataMap.forEach((compoundName, list) -> { + // 添加空白数据 + HairSewageDataDto blankDto = new HairSewageDataDto(); + blankDto.setSampleName("空白"); + blankDto.setCompoundName(compoundName); + blankDto.setTmpTargetRtTime("/"); + blankDto.setTmpRtTimeError("/"); + blankDto.setRtTimeWithinError("否"); + blankDto.setTmpIonAbundanceRatio("/"); + blankDto.setWhetherCheckOut("否"); + dataDtos.add(blankDto); + + // 处理样品数据 + list.removeIf(item -> { + if (StringUtils.equals(item.getSampleType(), "STD")) { item.setSampleName("空白添加"); item.setWhetherCheckOut("是"); dataDtos.add(item); - } else if (StringUtils.isNotBlank(item.getSampleType()) && item.getSampleType().equals("QC")) { - delList.add(item); + return true; + } else if (StringUtils.equals(item.getSampleType(), "QC")) { + return true; } - } + return false; + }); + + // 排序 + list.sort(this.getSortBySampleNo("inVivo")); -// list.forEach(item -> { -// if (StringUtils.isNotBlank(item.getSampleType())&&item.getSampleType().equals("STD")) { -// item.setSampleName("空白添加"); -// item.setWhetherCheckOut("是"); -// dataDtos.add(item); -// list.remove(item); -// } -// }); - list.removeAll(delList); - Collections.sort(list, this.getSortBySampleNo("inVivo")); + // 重新命名样品 if (list.size() == 1) { list.get(0).setSampleName("检材样品"); } else { @@ -1640,20 +1640,25 @@ public class TestRecordServiceImpl extends ServiceImpl data, String entrustId) throws Exception { + + public String createInVivoFile(Map data, String entrustId, String materialType) throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); - TestRecord vo = (TestRecord) data.get("vo"); - ossFile.fileGet("/template" + "/贵阳生物样本检验记录模板.docx", bos); + String templatePath = ""; + if (materialType.equals("毛发")) { + templatePath = "/template" + "/贵阳生物样本毛发检验记录模板.docx"; + } else { + templatePath = "/template" + "/贵阳生物样本尿液检验记录模板.docx"; + } + ossFile.fileGet(templatePath, bos); byte[] templateArray = bos.toByteArray(); ByteArrayInputStream bis = new ByteArrayInputStream(templateArray); bos.close(); @@ -1684,7 +1689,6 @@ public class TestRecordServiceImpl extends ServiceImpl buildCommonDrugDocMap(String entrustId) { @@ -1760,7 +1765,6 @@ public class TestRecordServiceImpl extends ServiceImpl "\u2611" + " " + reagent.getReagentConsumableName())