diff --git a/dlp-drugtesting-api/src/main/java/digital/laboratory/platform/inspetion/api/feign/RemoteTestToIdentifyService.java b/dlp-drugtesting-api/src/main/java/digital/laboratory/platform/inspetion/api/feign/RemoteTestToIdentifyService.java index 2e7f377..d4c69e7 100644 --- a/dlp-drugtesting-api/src/main/java/digital/laboratory/platform/inspetion/api/feign/RemoteTestToIdentifyService.java +++ b/dlp-drugtesting-api/src/main/java/digital/laboratory/platform/inspetion/api/feign/RemoteTestToIdentifyService.java @@ -28,7 +28,7 @@ public interface RemoteTestToIdentifyService { * @return */ @GetMapping(value="/identifyBookData/getIdentifyBookDataByBusinessId", headers = SecurityConstants.HEADER_FROM_IN) - public R getIdentifyBookDataByBusinessId(@RequestParam("businessId") String businessId); + public R getIdentifyBookDataByBusinessId(@RequestParam("businessId") String businessId); @PostMapping(value="/identifyBookData/getTestFinishBusinessData", headers = SecurityConstants.HEADER_FROM_IN) public R getTestFinishBusinessData(@RequestBody List synedIdList); diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/IdentifyBookController.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/IdentifyBookController.java index 86e1fdf..bbf2d0f 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/IdentifyBookController.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/IdentifyBookController.java @@ -1,7 +1,9 @@ package digital.laboratory.platform.inspection.controller; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import digital.laboratory.platform.common.core.util.R; import digital.laboratory.platform.inspection.service.IdentifyBookDataService; +import digital.laboratory.platform.inspetion.api.entity.IdentificationBookDTO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; @@ -25,8 +27,13 @@ public class IdentifyBookController { //对文书系统提供获取实验数据 @GetMapping("/getIdentifyBookDataByBusinessId") @ApiOperation(value = "获取检验数据") - public R getIdentifyBookDataByBusinessId(String businessId){ - return identifyBookDataService.getIdentifyBookDataByBusinessId(businessId); + public R getIdentifyBookDataByBusinessId(String businessId){ + try { + return R.ok(identifyBookDataService.getIdentifyBookDataByBusinessId(businessId),"构建数据成功"); + } catch (Exception e) { + return R.failed("获取检验数据失败!"); + } + } @PostMapping("/getTestFinishBusinessData") @ApiOperation(value = "获取待制作文书列表") diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/IdentifyBookDataService.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/IdentifyBookDataService.java index 823e2ed..101cdeb 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/IdentifyBookDataService.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/IdentifyBookDataService.java @@ -2,6 +2,7 @@ package digital.laboratory.platform.inspection.service; import com.baomidou.mybatisplus.extension.service.IService; import digital.laboratory.platform.common.core.util.R; +import digital.laboratory.platform.inspetion.api.entity.IdentificationBookDTO; import org.apache.poi.ss.formula.functions.T; import java.util.List; @@ -20,7 +21,7 @@ public interface IdentifyBookDataService { * @param businessId * @return */ - R getIdentifyBookDataByBusinessId(String businessId); + IdentificationBookDTO getIdentifyBookDataByBusinessId(String businessId); /** * 获取完成实验的数据 diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/IdentifyBookDataServiceImpl.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/IdentifyBookDataServiceImpl.java index c36ecdc..3999166 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/IdentifyBookDataServiceImpl.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/IdentifyBookDataServiceImpl.java @@ -67,44 +67,42 @@ public class IdentifyBookDataServiceImpl implements IdentifyBookDataService { entrustInfo.setMaterialNum(sampleInfos.size()); } } - return R.ok(entrustInfoList, "获取数据成功"); + return R.ok(entrustInfoList,"获取数据成功"); } - /** * 获取文书的数据 - * * @param businessId * @return */ @Override - public R getIdentifyBookDataByBusinessId(String businessId) { + public IdentificationBookDTO getIdentifyBookDataByBusinessId(String businessId) { //一个委托案件,只能属于一个实验,不允许一个委托中的检材分配到2个实验中做实验,这个是前提 - if (ObjectUtils.isNotEmpty(businessId)) { + if(ObjectUtils.isNotEmpty(businessId)){ IdentificationBookDTO identificationBookDTO = buildBookDataDetail(businessId); - return R.ok(identificationBookDTO, "构建数据成功"); - } else { - log.info("参数业务id不能为空,请检查参数{}", businessId); - return R.failed("参数业务id不能为空,请检查参数" + businessId); + return identificationBookDTO; + }else { + log.info("参数业务id不能为空,请检查参数{}",businessId); + return null; } } - //构建文书数据 - private IdentificationBookDTO buildBookDataDetail(String businessId) { - IdentificationBookDTO bookData = new IdentificationBookDTO(); + private IdentificationBookDTO buildBookDataDetail(String businessId){ + IdentificationBookDTO bookData=new IdentificationBookDTO(); //委托信息 EntrustInfo entrustInfo = entrustInfoService.getById(businessId); bookData.setEntrustInfo(entrustInfo); //检材 - List sampleList = sampleInfoService.list(Wrappers.lambdaQuery() + List sampleList= sampleInfoService.list(Wrappers.lambdaQuery() .eq(SampleInfo::getBusinessId, businessId).orderByAsc(SampleInfo::getAcceptNo)); bookData.setSampleInfoList(sampleList); //设置检验结果 + List testRecordSampleSolutionList = getTestRecordSampleSolution(sampleList);//样本溶液 List testRecordSampleDataList = getTestRecordSampleData(sampleList);//样本溶液对应的数据 - List testResultsList = buildTestResult(testRecordSampleDataList, sampleList);//构建检验结果 - TestRecord testRecordInfo = testRecordService.getById(testRecordSampleDataList.get(0).getTestId()); + List testResultsList = buildTestResult(testRecordSampleDataList, testRecordSampleSolutionList, sampleList);//构建检验结果 + TestRecord testRecordInfo = getTestRecordInfo(testRecordSampleSolutionList); //实验信息 - bookData.setTestMethod(getTestMethods(testRecordInfo));//设置用到的实验方法 + bookData.setTestMethod(getTestMethods(testRecordSampleSolutionList));//设置用到的实验方法 //设置检验过程 bookData.setTestProcessDes(testRecordInfo.getTestProcessDes());//设置检验过程 bookData.setTestResult(testRecordSampleDataService.generateQualitativeResults(businessId)); @@ -117,53 +115,46 @@ public class IdentifyBookDataServiceImpl implements IdentifyBookDataService { bookData.setTestFinishDate(sdf.format(testRecordInfo.getUpdateTime())); return bookData; } - //获取业务的实验对象 - private TestRecord getTestRecordInfo(List testRecordSampleSolutionList) { - List testIdList = testRecordSampleSolutionList.stream().map(s -> s.getTestId()).collect(Collectors.toList()); - List distinctTestId = testIdList.stream().distinct().collect(Collectors.toList());//去重复 - if (distinctTestId.size() != 1) { + private TestRecord getTestRecordInfo(List testRecordSampleSolutionList){ + List testIdList= testRecordSampleSolutionList.stream().map(s -> s.getTestId()).collect(Collectors.toList()); + List distinctTestId= testIdList.stream().distinct().collect(Collectors.toList());//去重复 + if(distinctTestId.size()!=1){ throw new RuntimeException("一个案件中的检材只能允许分配到一个实验中去做"); } - String testId = distinctTestId.get(0); - TestRecord testRecord = testRecordService.getById(testId); + String testId= distinctTestId.get(0); + TestRecord testRecord= testRecordService.getById(testId); return testRecord; } - //获取实验方法 - private String getTestMethods(TestRecord testRecord) { - List testMethodList = testRecord.getTestMethodList(); - if (testMethodList == null || testMethodList.isEmpty()) { - return String.format("没有对应的方法数据!"); // 直接返回空列表,避免 SQL 语法错误 - } - - List methodsList = testRecordMethodService.list( - Wrappers.lambdaQuery().in(TestRecordMethod::getId, testMethodList) - ); - + private String getTestMethods(List testRecordSampleSolutionList){ + TestRecord testRecordInfo= getTestRecordInfo(testRecordSampleSolutionList); + List testMethodList= testRecordInfo.getTestMethodList(); + List methodsList = testRecordMethodService.list(Wrappers.lambdaQuery() + .in(TestRecordMethod::getId, testMethodList)); List methodsName = methodsList.stream().map(s -> s.getMethodName()).collect(Collectors.toList()); - StringBuffer sbMethodNameStr = new StringBuffer(); - methodsName.forEach(item -> { + StringBuffer sbMethodNameStr=new StringBuffer(); + methodsName.forEach(item->{ sbMethodNameStr.append(item).append(","); }); - sbMethodNameStr.delete(sbMethodNameStr.length() - 1, sbMethodNameStr.length()); + sbMethodNameStr.delete(sbMethodNameStr.length()-1,sbMethodNameStr.length()); return sbMethodNameStr.toString(); } - //获取sampleData - private List getTestRecordSampleData(List sampleInfoList) { - if (!sampleInfoList.isEmpty()) { - List sampleNoList = sampleInfoList.stream().map(m -> m.getAcceptNo()).collect(Collectors.toList());//得到样本溶液编号 + private List getTestRecordSampleData(List sampleInfoList){ + List testRecordSampleSolution = getTestRecordSampleSolution(sampleInfoList); + if (CollUtil.isNotEmpty(testRecordSampleSolution)) { + List sampleNoList= testRecordSampleSolution.stream().map(m -> m.getSampleNo()).collect(Collectors.toList());//得到样本溶液编号 //根据样本溶液编号查出对应的样本溶液检验数据 - List sampleTestDataList = getTestRecordData(sampleNoList); + List sampleTestDataList= getTestRecordData(sampleNoList); return sampleTestDataList; } + return null; } - //获取样本溶液 - private List getTestRecordSampleSolution(List sampleInfoList) { - List materialIdList = sampleInfoList.stream().map(m -> m.getId()).collect(Collectors.toList()); + private List getTestRecordSampleSolution( List sampleInfoList){ + List materialIdList= sampleInfoList.stream().map(m -> m.getId()).collect(Collectors.toList()); if (CollUtil.isEmpty(materialIdList)) { log.error("检材列表为空!"); return null; @@ -173,22 +164,27 @@ public class IdentifyBookDataServiceImpl implements IdentifyBookDataService { .in(TestRecordSampleSolution::getMaterialId, materialIdList)); return sampleSolutionList; } - //构建TestResult - private List buildTestResult(List testRecordSampleDataList, - List sampleInfoList) { + private List buildTestResult(List testRecordSampleDataList, + List testRecordSampleSolutionList,List sampleInfoList){ //结果:应该是加入实验的检材的结果,目前暂定受理的检材我们按照受理顺序,全部定义为 1号检材,2号检材,3号检材等 //拿出实验数据中的所有实验样本编号,就是数据文件中的sampleId,也是溶液编号中的溶液编号, - List sampleNoList = testRecordSampleDataList.stream().map(s -> s.getSampleNo()).collect(Collectors.toList()); + List sampleNoList= testRecordSampleDataList.stream().map(s -> s.getSampleNo()).collect(Collectors.toList()); //取出检材ID - Map map = sampleInfoList.stream().collect(Collectors.toMap(s -> s.getAcceptNo(), s -> s)); - - List retTestResult = new ArrayList<>(); + List okTestRecordSampleSolutionIdList=new ArrayList<>(); + testRecordSampleSolutionList.forEach(item->{ + //如果溶液在提供的溶液编号中,则取出来 + if(sampleNoList.contains(item.getSampleNo())){ + okTestRecordSampleSolutionIdList.add(item.getMaterialId()); + } + }); + List retTestResult=new ArrayList<>(); for (TestRecordSampleData testRecordSampleData : testRecordSampleDataList) { - TestResult eg = new TestResult(); - SampleInfo sampleInfo = map.get(testRecordSampleData.getSampleNo()); + TestResult eg=new TestResult(); + SampleInfo sampleInfo=getSampleInfoBySampleId(testRecordSampleSolutionList, + sampleInfoList,testRecordSampleData.getSampleNo()); eg.setCompoundName(testRecordSampleData.getCompoundName()); - eg.setMaterialNo(sampleInfo.getOrderNo() + "号"); + eg.setMaterialNo(sampleInfo.getOrderNo()+"号"); eg.setOrderNo(sampleInfo.getOrderNo()); eg.setIsFind(testRecordSampleData.getIsDetected()); eg.setTestId(testRecordSampleData.getTestId()); @@ -196,147 +192,141 @@ public class IdentifyBookDataServiceImpl implements IdentifyBookDataService { } return retTestResult; } - //根据sampleID获取对应的检材信息 private SampleInfo getSampleInfoBySampleId(List testRecordSampleSolutionList, - List sampleInfoList, String sampleId) { + List sampleInfoList,String sampleId){ List sampleSolutionList = testRecordSampleSolutionList.stream() .filter(s -> s.getSampleNo().equals(sampleId)).collect(Collectors.toList()); - String materialId = ""; - if (sampleSolutionList.size() > 0) { - if (sampleSolutionList.size() > 1) { - log.info("溶液编号重复 {} ", sampleId); - } else { - materialId = sampleSolutionList.get(0).getMaterialId(); + String materialId=""; + if(sampleSolutionList.size()>0){ + if(sampleSolutionList.size()>1){ + log.info("溶液编号重复 {} ",sampleId); + }else{ + materialId= sampleSolutionList.get(0).getMaterialId(); } } - List retObj = new ArrayList<>(); + List retObj=new ArrayList<>(); for (SampleInfo sampleInfo : sampleInfoList) { - if (sampleInfo.getId().equals(materialId)) { + if(sampleInfo.getId().equals(materialId)){ //找到 retObj.add(sampleInfo); } } - if (retObj.size() != 1) { + if(retObj.size()!=1){ log.info("存在重复的检材"); return null; } - if (retObj.size() == 0) { + if(retObj.size()==0){ log.info("未查询到检材"); return null; - } else { + }else { return retObj.get(0); } } - //构建实验结果 - private List buildTestResultDes(List resultList) { + private List buildTestResultDes(List resultList){ //按照检材编号先分组,这样的话,如果有n个检材,m个化合物,那么就会分成n组,每组中就m条数据 Map> resultMap1 = resultList.stream().collect(Collectors.groupingBy(m -> m.getMaterialNo())); //我们把每组中的List 数据再次分组,分组按检出和未检出分,这样就会得到2个组,一个组是检出的,一个组是未检出的 - Map>> resultMap2 = new HashMap<>(); - resultMap1.forEach((k, v) -> { + Map>> resultMap2=new HashMap<>(); + resultMap1.forEach((k,v)->{ //按检材编号分组,分成检出和未检出2组 - Map> tmp1Map = v.stream().collect(Collectors.groupingBy(m -> m.getIsFind())); - resultMap2.put(k, tmp1Map);//1号 检出 与未检出 + Map> tmp1Map= v.stream().collect(Collectors.groupingBy(m -> m.getIsFind())); + resultMap2.put(k,tmp1Map);//1号 检出 与未检出 }); // 对 resultMap2进行合并,然后再次分组 - List testResultDetailList = new ArrayList<>(); - resultMap2.forEach((k, v) -> { - Map> tmp2Map = v;//这个map中只有2个key,key为0代表未检出的集合,key为1表示检出的集合 - TestResultDetail testResultDetail = buildCompoundList(tmp2Map, k); + List testResultDetailList=new ArrayList<>(); + resultMap2.forEach((k,v)->{ + Map> tmp2Map=v;//这个map中只有2个key,key为0代表未检出的集合,key为1表示检出的集合 + TestResultDetail testResultDetail= buildCompoundList(tmp2Map, k); testResultDetailList.add(testResultDetail); }); // 对 testResultDetailList 进行 分组 //现在对上面的数据进行从新分组,按检出+化合物的形式 Map> temp2 = testResultDetailList.stream().collect( Collectors.groupingBy(m -> m.getFindCompounds() + m.getNoFindCompounds())); - List testResultDes = testResultSorted(temp2); + List testResultDes= testResultSorted(temp2); return testResultDes; } - //对第一个结果进行排序 - private List testResultSorted(Map> tmpMap) { - List>> targetList = new ArrayList>>(tmpMap.entrySet()); + private List testResultSorted(Map> tmpMap){ + List>> targetList=new ArrayList>>(tmpMap.entrySet()); targetList.sort(new Comparator>>() { @Override public int compare(Map.Entry> mp1, Map.Entry> mp2) { int materialNo1 = getMinMaterialNo(mp1.getValue()); int materialNo2 = getMinMaterialNo(mp2.getValue()); - return materialNo1 - materialNo2; + return materialNo1-materialNo2; } }); - List testResultDes = new ArrayList<>(); - targetList.forEach((target) -> { - StringBuffer sbNo = new StringBuffer(); - target.getValue().forEach(item -> { + List testResultDes=new ArrayList<>(); + targetList.forEach((target)->{ + StringBuffer sbNo=new StringBuffer(); + target.getValue().forEach(item->{ sbNo.append(item.getMaterialNo()).append(","); }); - if (sbNo.length() > 0) { - sbNo.delete(sbNo.length() - 1, sbNo.length());//删除最后一个 , + if(sbNo.length()>0){ + sbNo.delete(sbNo.length()-1,sbNo.length());//删除最后一个 , } - testResultDes.add(sbNo.toString() + "检材未检出" + target.getValue().get(0).getNoFindCompounds() + ",检出了" + target.getValue().get(0).getFindCompounds()); + testResultDes.add(sbNo.toString()+"检材未检出"+target.getValue().get(0).getNoFindCompounds()+",检出了"+target.getValue().get(0).getFindCompounds()); }); return testResultDes; } - /** * 构造出一个检材一共检出了多少个化合物和未检出多少化合物 - * * @param mapCompound * @param materialNo * @return */ - private TestResultDetail buildCompoundList(Map> mapCompound, String materialNo) { + private TestResultDetail buildCompoundList(Map> mapCompound,String materialNo){ - StringBuffer findCompounds = new StringBuffer();//检出化合物的集合 - StringBuffer noFindCompounds = new StringBuffer();//未检出化合物的集合 - mapCompound.forEach((k1, v1) -> { - if (k1 == 0) { + StringBuffer findCompounds=new StringBuffer();//检出化合物的集合 + StringBuffer noFindCompounds=new StringBuffer();//未检出化合物的集合 + mapCompound.forEach((k1,v1)->{ + if(k1==0){ //未检出 - v1.forEach(item -> { + v1.forEach(item->{ noFindCompounds.append(item.getCompoundName()).append(","); }); } - if (k1 == 1) { + if(k1==1){ //检出 - v1.forEach(item -> { + v1.forEach(item->{ findCompounds.append(item.getCompoundName()).append(","); }); } }); - if (findCompounds.length() > 0) { - findCompounds.delete(findCompounds.length() - 1, findCompounds.length());//删除最后一个 , + if(findCompounds.length()>0){ + findCompounds.delete(findCompounds.length()-1,findCompounds.length());//删除最后一个 , } - if (noFindCompounds.length() > 0) { - noFindCompounds.delete(noFindCompounds.length() - 1, noFindCompounds.length());//删除最后一个 , + if(noFindCompounds.length()>0){ + noFindCompounds.delete(noFindCompounds.length()-1,noFindCompounds.length());//删除最后一个 , } - TestResultDetail eg = new TestResultDetail(); + TestResultDetail eg=new TestResultDetail(); eg.setMaterialNo(materialNo); eg.setFindCompounds(findCompounds.toString()); eg.setNoFindCompounds(noFindCompounds.toString()); return eg; } - private int getMinMaterialNo(List materialList) { + private int getMinMaterialNo(List materialList){ materialList.sort(new Comparator() { @Override public int compare(TestResultDetail t1, TestResultDetail t2) { - int mNo1 = Integer.parseInt(getNumberByMaterialNo(t1.getMaterialNo())); - int mNo2 = Integer.parseInt(getNumberByMaterialNo(t2.getMaterialNo())); - return mNo1 - mNo2; + int mNo1= Integer.parseInt(getNumberByMaterialNo(t1.getMaterialNo())); + int mNo2= Integer.parseInt(getNumberByMaterialNo(t2.getMaterialNo())); + return mNo1-mNo2; } }); - return Integer.parseInt(getNumberByMaterialNo(materialList.get(0).getMaterialNo())); + return Integer.parseInt(getNumberByMaterialNo(materialList.get(0).getMaterialNo())); } /** * 根据编号获取排序值 - * * @param materialNo * @return */ - private String getNumberByMaterialNo(String materialNo) { + private String getNumberByMaterialNo(String materialNo){ Pattern pattern = Pattern.compile("\\d+"); Matcher matcher = pattern.matcher(materialNo); while (matcher.find()) { @@ -344,14 +334,12 @@ public class IdentifyBookDataServiceImpl implements IdentifyBookDataService { } return ""; } - /** * 根据溶液编号(sampleNo)获取仪器检测数据 - * * @param sampleNoList * @return */ - private List getTestRecordData(List sampleNoList) { + private List getTestRecordData(List sampleNoList){ return testRecordSampleDataService.list(Wrappers.lambdaQuery() .in(TestRecordSampleData::getSampleNo, sampleNoList)); } diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/PushDataToLabsCareServiceImpl.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/PushDataToLabsCareServiceImpl.java index 221e1d9..13114e1 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/PushDataToLabsCareServiceImpl.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/PushDataToLabsCareServiceImpl.java @@ -90,7 +90,7 @@ public class PushDataToLabsCareServiceImpl implements PushDataToLabsCareService private final static String BIOLOGY_QUALITATIVE_RECORD = "BiologyQualitativeRecord"; // 普通检材定性记录非红外报告标识 - private final static String NON_INFRARED_GENERAL_QUALITATIVE_RECORD = "nonInfraredGeneralQualitativeRecord"; + private final static String NON_INFRARED_GENERAL_QUALITATIVE_RECORD = "NonInfraredGeneralQualitativeRecord"; /** * 做一个定时推送,对于推送失败的委托进行重新推送, 每天凌晨1点推送