Merge remote-tracking branch 'origin/master'

master
陈江保 3 weeks ago
commit 11cd3e23cd
  1. 9
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/IdentifyBookController.java
  2. 2
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/TestRecordController.java
  3. 2
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/InspectRecordService.java
  4. 216
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/IdentifyBookDataServiceImpl.java
  5. 55
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/InspectRecordServiceImpl.java

@ -24,20 +24,23 @@ import java.util.List;
public class IdentifyBookController { public class IdentifyBookController {
@Resource @Resource
private IdentifyBookDataService identifyBookDataService; private IdentifyBookDataService identifyBookDataService;
//对文书系统提供获取实验数据 //对文书系统提供获取实验数据
@GetMapping("/getIdentifyBookDataByBusinessId") @GetMapping("/getIdentifyBookDataByBusinessId")
@ApiOperation(value = "获取检验数据") @ApiOperation(value = "获取检验数据")
public R<IdentificationBookDTO> getIdentifyBookDataByBusinessId(String businessId){ public R<IdentificationBookDTO> getIdentifyBookDataByBusinessId(String businessId) {
try { try {
return R.ok(identifyBookDataService.getIdentifyBookDataByBusinessId(businessId),"构建数据成功"); return R.ok(identifyBookDataService.getIdentifyBookDataByBusinessId(businessId), "构建数据成功");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
return R.failed("获取检验数据失败!"); return R.failed("获取检验数据失败!");
} }
} }
@PostMapping("/getTestFinishBusinessData") @PostMapping("/getTestFinishBusinessData")
@ApiOperation(value = "获取待制作文书列表") @ApiOperation(value = "获取待制作文书列表")
public R getTestFinishBusinessData(@RequestBody List<String> synedIdList){ public R getTestFinishBusinessData(@RequestBody List<String> synedIdList) {
return identifyBookDataService.getTestFinishBusinessData(synedIdList); return identifyBookDataService.getTestFinishBusinessData(synedIdList);
} }
} }

@ -223,7 +223,7 @@ public class TestRecordController {
@ApiOperation("生成检验记录-贵阳禁毒") @ApiOperation("生成检验记录-贵阳禁毒")
@GetMapping("/inspectionRecord") @GetMapping("/inspectionRecord")
public R inspectionRecord(String businessId, String materialType) throws Exception { public R inspectionRecord(String businessId, String materialType) throws Exception {
return inspectRecordService.buildInspectionRecord(businessId, materialType); return inspectRecordService.buildInspectionRecord(businessId, materialType, false);
} }
@ApiOperation("预览检验记录-贵阳禁毒") @ApiOperation("预览检验记录-贵阳禁毒")

@ -21,7 +21,7 @@ public interface InspectRecordService {
* @return * @return
* @throws Exception * @throws Exception
*/ */
R buildInspectionRecord(String businessId, String materialType) throws Exception; R buildInspectionRecord(String businessId, String materialType,boolean isPreview) throws Exception;
void previewInspectionRecord(String businessId, String materialType, HttpServletResponse servletResponse) throws Exception; void previewInspectionRecord(String businessId, String materialType, HttpServletResponse servletResponse) throws Exception;

@ -14,6 +14,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.function.Function;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -45,13 +46,14 @@ public class IdentifyBookDataServiceImpl implements IdentifyBookDataService {
/** /**
* 获取完成实验的数据/获取符合制作文书的数据 * 获取完成实验的数据/获取符合制作文书的数据
*
* @return * @return
*/ */
@Override @Override
public R getTestFinishBusinessData(List<String> synedIdList) { public R getTestFinishBusinessData(List<String> synedIdList) {
List<EntrustInfo> entrustInfoList = entrustInfoService.list(Wrappers.<EntrustInfo>lambdaQuery() List<EntrustInfo> entrustInfoList = entrustInfoService.list(Wrappers.<EntrustInfo>lambdaQuery()
.ge(EntrustInfo::getStatus, 3) .ge(EntrustInfo::getStatus, 3)
.notIn(CollectionUtils.isNotEmpty(synedIdList),EntrustInfo::getId,synedIdList)); .notIn(CollectionUtils.isNotEmpty(synedIdList), EntrustInfo::getId, synedIdList));
if (CollUtil.isNotEmpty(entrustInfoList)) { if (CollUtil.isNotEmpty(entrustInfoList)) {
Map<String, List<SampleInfo>> sampleGroupByBusinessId = sampleInfoService Map<String, List<SampleInfo>> sampleGroupByBusinessId = sampleInfoService
.list(Wrappers.<SampleInfo>lambdaQuery() .list(Wrappers.<SampleInfo>lambdaQuery()
@ -67,42 +69,49 @@ public class IdentifyBookDataServiceImpl implements IdentifyBookDataService {
entrustInfo.setMaterialNum(sampleInfos.size()); entrustInfo.setMaterialNum(sampleInfos.size());
} }
} }
return R.ok(entrustInfoList,"获取数据成功"); return R.ok(entrustInfoList, "获取数据成功");
} }
/** /**
* 获取文书的数据 * 获取文书的数据
*
* @param businessId * @param businessId
* @return * @return
*/ */
@Override @Override
public IdentificationBookDTO getIdentifyBookDataByBusinessId(String businessId) { public IdentificationBookDTO getIdentifyBookDataByBusinessId(String businessId) {
//一个委托案件,只能属于一个实验,不允许一个委托中的检材分配到2个实验中做实验,这个是前提 //一个委托案件,只能属于一个实验,不允许一个委托中的检材分配到2个实验中做实验,这个是前提
if(ObjectUtils.isNotEmpty(businessId)){ if (ObjectUtils.isNotEmpty(businessId)) {
IdentificationBookDTO identificationBookDTO = buildBookDataDetail(businessId); IdentificationBookDTO identificationBookDTO = buildBookDataDetail(businessId);
return identificationBookDTO; return identificationBookDTO;
}else { } else {
log.info("参数业务id不能为空,请检查参数{}",businessId); log.info("参数业务id不能为空,请检查参数{}", businessId);
return null; return null;
} }
} }
//构建文书数据 //构建文书数据
private IdentificationBookDTO buildBookDataDetail(String businessId){ private IdentificationBookDTO buildBookDataDetail(String businessId) {
IdentificationBookDTO bookData=new IdentificationBookDTO(); IdentificationBookDTO bookData = new IdentificationBookDTO();
//委托信息 //委托信息
EntrustInfo entrustInfo = entrustInfoService.getById(businessId); EntrustInfo entrustInfo = entrustInfoService.getById(businessId);
bookData.setEntrustInfo(entrustInfo); bookData.setEntrustInfo(entrustInfo);
//检材 //检材
List<SampleInfo> sampleList= sampleInfoService.list(Wrappers.<SampleInfo>lambdaQuery() List<SampleInfo> sampleList = sampleInfoService.list(Wrappers.<SampleInfo>lambdaQuery()
.eq(SampleInfo::getBusinessId, businessId).orderByAsc(SampleInfo::getAcceptNo)); .eq(SampleInfo::getBusinessId, businessId).orderByAsc(SampleInfo::getAcceptNo));
bookData.setSampleInfoList(sampleList); bookData.setSampleInfoList(sampleList);
//设置检验结果 //设置检验结果
List<TestRecordSampleSolution> testRecordSampleSolutionList = getTestRecordSampleSolution(sampleList);//样本溶液
List<TestRecordSampleData> testRecordSampleDataList = getTestRecordSampleData(sampleList);//样本溶液对应的数据 List<TestRecordSampleData> testRecordSampleDataList = getTestRecordSampleData(sampleList);//样本溶液对应的数据
List<TestResult> testResultsList = buildTestResult(testRecordSampleDataList, testRecordSampleSolutionList, sampleList);//构建检验结果 if (CollUtil.isEmpty(testRecordSampleDataList)) {
TestRecord testRecordInfo = getTestRecordInfo(testRecordSampleSolutionList); return null;
}
List<TestResult> testResultsList = buildTestResult(testRecordSampleDataList, sampleList);//构建检验结果
TestRecord testRecordInfo = testRecordService.lambdaQuery()
.eq(TestRecord::getBusinessId, businessId)
.one();
//实验信息 //实验信息
bookData.setTestMethod(getTestMethods(testRecordSampleSolutionList));//设置用到的实验方法 bookData.setTestMethod(getTestMethods(testRecordInfo));//设置用到的实验方法
//设置检验过程 //设置检验过程
bookData.setTestProcessDes(testRecordInfo.getTestProcessDes());//设置检验过程 bookData.setTestProcessDes(testRecordInfo.getTestProcessDes());//设置检验过程
bookData.setTestResult(testRecordSampleDataService.generateQualitativeResults(businessId)); bookData.setTestResult(testRecordSampleDataService.generateQualitativeResults(businessId));
@ -115,46 +124,51 @@ public class IdentifyBookDataServiceImpl implements IdentifyBookDataService {
bookData.setTestFinishDate(sdf.format(testRecordInfo.getUpdateTime())); bookData.setTestFinishDate(sdf.format(testRecordInfo.getUpdateTime()));
return bookData; return bookData;
} }
//获取业务的实验对象 //获取业务的实验对象
private TestRecord getTestRecordInfo(List<TestRecordSampleSolution> testRecordSampleSolutionList){ private TestRecord getTestRecordInfo(List<TestRecordSampleSolution> testRecordSampleSolutionList) {
List<String> testIdList= testRecordSampleSolutionList.stream().map(s -> s.getTestId()).collect(Collectors.toList()); List<String> testIdList = testRecordSampleSolutionList.stream().map(s -> s.getTestId()).collect(Collectors.toList());
List<String> distinctTestId= testIdList.stream().distinct().collect(Collectors.toList());//去重复 List<String> distinctTestId = testIdList.stream().distinct().collect(Collectors.toList());//去重复
if(distinctTestId.size()!=1){ if (distinctTestId.size() != 1) {
throw new RuntimeException("一个案件中的检材只能允许分配到一个实验中去做"); throw new RuntimeException("一个案件中的检材只能允许分配到一个实验中去做");
} }
String testId= distinctTestId.get(0); String testId = distinctTestId.get(0);
TestRecord testRecord= testRecordService.getById(testId); TestRecord testRecord = testRecordService.getById(testId);
return testRecord; return testRecord;
} }
//获取实验方法 //获取实验方法
private String getTestMethods(List<TestRecordSampleSolution> testRecordSampleSolutionList){ private String getTestMethods(TestRecord testRecordInfo) {
TestRecord testRecordInfo= getTestRecordInfo(testRecordSampleSolutionList); List<String> testMethodList = testRecordInfo.getTestMethodList();
List<String> testMethodList= testRecordInfo.getTestMethodList(); if (CollUtil.isEmpty(testMethodList)) {
return "暂未找到实验过程中的方法数据!";
}
List<TestRecordMethod> methodsList = testRecordMethodService.list(Wrappers.<TestRecordMethod>lambdaQuery() List<TestRecordMethod> methodsList = testRecordMethodService.list(Wrappers.<TestRecordMethod>lambdaQuery()
.in(TestRecordMethod::getId, testMethodList)); .in(TestRecordMethod::getId, testMethodList));
List<String> methodsName = methodsList.stream().map(s -> s.getMethodName()).collect(Collectors.toList()); List<String> methodsName = methodsList.stream().map(s -> s.getMethodName()).collect(Collectors.toList());
StringBuffer sbMethodNameStr=new StringBuffer(); StringBuffer sbMethodNameStr = new StringBuffer();
methodsName.forEach(item->{ methodsName.forEach(item -> {
sbMethodNameStr.append(item).append(","); sbMethodNameStr.append(item).append(",");
}); });
sbMethodNameStr.delete(sbMethodNameStr.length()-1,sbMethodNameStr.length()); sbMethodNameStr.delete(sbMethodNameStr.length() - 1, sbMethodNameStr.length());
return sbMethodNameStr.toString(); return sbMethodNameStr.toString();
} }
//获取sampleData //获取sampleData
private List<TestRecordSampleData> getTestRecordSampleData(List<SampleInfo> sampleInfoList){ private List<TestRecordSampleData> getTestRecordSampleData(List<SampleInfo> sampleInfoList) {
List<TestRecordSampleSolution> testRecordSampleSolution = getTestRecordSampleSolution(sampleInfoList); if (CollUtil.isNotEmpty(sampleInfoList)) {
if (CollUtil.isNotEmpty(testRecordSampleSolution)) { List<String> sampleNoList = sampleInfoList.stream().map(m -> m.getAcceptNo()).collect(Collectors.toList());//得到样本溶液编号
List<String> sampleNoList= testRecordSampleSolution.stream().map(m -> m.getSampleNo()).collect(Collectors.toList());//得到样本溶液编号
//根据样本溶液编号查出对应的样本溶液检验数据 //根据样本溶液编号查出对应的样本溶液检验数据
List<TestRecordSampleData> sampleTestDataList= getTestRecordData(sampleNoList); List<TestRecordSampleData> sampleTestDataList = getTestRecordData(sampleNoList);
return sampleTestDataList; return sampleTestDataList;
} }
return null; return null;
} }
//获取样本溶液 //获取样本溶液
private List<TestRecordSampleSolution> getTestRecordSampleSolution( List<SampleInfo> sampleInfoList){ private List<TestRecordSampleSolution> getTestRecordSampleSolution(List<SampleInfo> sampleInfoList) {
List<String> materialIdList= sampleInfoList.stream().map(m -> m.getId()).collect(Collectors.toList()); List<String> materialIdList = sampleInfoList.stream().map(m -> m.getId()).collect(Collectors.toList());
if (CollUtil.isEmpty(materialIdList)) { if (CollUtil.isEmpty(materialIdList)) {
log.error("检材列表为空!"); log.error("检材列表为空!");
return null; return null;
@ -164,27 +178,23 @@ public class IdentifyBookDataServiceImpl implements IdentifyBookDataService {
.in(TestRecordSampleSolution::getMaterialId, materialIdList)); .in(TestRecordSampleSolution::getMaterialId, materialIdList));
return sampleSolutionList; return sampleSolutionList;
} }
//构建TestResult //构建TestResult
private List<TestResult> buildTestResult(List<TestRecordSampleData> testRecordSampleDataList, private List<TestResult> buildTestResult(List<TestRecordSampleData> testRecordSampleDataList,
List<TestRecordSampleSolution> testRecordSampleSolutionList,List<SampleInfo> sampleInfoList){ List<SampleInfo> sampleInfoList) {
//结果:应该是加入实验的检材的结果,目前暂定受理的检材我们按照受理顺序,全部定义为 1号检材,2号检材,3号检材等 //结果:应该是加入实验的检材的结果,目前暂定受理的检材我们按照受理顺序,全部定义为 1号检材,2号检材,3号检材等
//拿出实验数据中的所有实验样本编号,就是数据文件中的sampleId,也是溶液编号中的溶液编号, //拿出实验数据中的所有实验样本编号,就是数据文件中的sampleId,也是溶液编号中的溶液编号,
List<String> sampleNoList= testRecordSampleDataList.stream().map(s -> s.getSampleNo()).collect(Collectors.toList()); List<String> sampleNoList = testRecordSampleDataList.stream().map(s -> s.getSampleNo()).collect(Collectors.toList());
//取出检材ID
List<String> okTestRecordSampleSolutionIdList=new ArrayList<>(); List<TestResult> retTestResult = new ArrayList<>();
testRecordSampleSolutionList.forEach(item->{ Map<String, SampleInfo> sampleInfoMap = sampleInfoList
//如果溶液在提供的溶液编号中,则取出来 .stream()
if(sampleNoList.contains(item.getSampleNo())){ .collect(Collectors.toMap(SampleInfo::getAcceptNo, Function.identity()));
okTestRecordSampleSolutionIdList.add(item.getMaterialId());
}
});
List<TestResult> retTestResult=new ArrayList<>();
for (TestRecordSampleData testRecordSampleData : testRecordSampleDataList) { for (TestRecordSampleData testRecordSampleData : testRecordSampleDataList) {
TestResult eg=new TestResult(); TestResult eg = new TestResult();
SampleInfo sampleInfo=getSampleInfoBySampleId(testRecordSampleSolutionList, SampleInfo sampleInfo = sampleInfoMap.get(testRecordSampleData.getSampleNo());
sampleInfoList,testRecordSampleData.getSampleNo());
eg.setCompoundName(testRecordSampleData.getCompoundName()); eg.setCompoundName(testRecordSampleData.getCompoundName());
eg.setMaterialNo(sampleInfo.getOrderNo()+"号"); eg.setMaterialNo(sampleInfo.getOrderNo() + "号");
eg.setOrderNo(sampleInfo.getOrderNo()); eg.setOrderNo(sampleInfo.getOrderNo());
eg.setIsFind(testRecordSampleData.getIsDetected()); eg.setIsFind(testRecordSampleData.getIsDetected());
eg.setTestId(testRecordSampleData.getTestId()); eg.setTestId(testRecordSampleData.getTestId());
@ -192,141 +202,147 @@ public class IdentifyBookDataServiceImpl implements IdentifyBookDataService {
} }
return retTestResult; return retTestResult;
} }
//根据sampleID获取对应的检材信息 //根据sampleID获取对应的检材信息
private SampleInfo getSampleInfoBySampleId(List<TestRecordSampleSolution> testRecordSampleSolutionList, private SampleInfo getSampleInfoBySampleId(List<TestRecordSampleSolution> testRecordSampleSolutionList,
List<SampleInfo> sampleInfoList,String sampleId){ List<SampleInfo> sampleInfoList, String sampleId) {
List<TestRecordSampleSolution> sampleSolutionList = testRecordSampleSolutionList.stream() List<TestRecordSampleSolution> sampleSolutionList = testRecordSampleSolutionList.stream()
.filter(s -> s.getSampleNo().equals(sampleId)).collect(Collectors.toList()); .filter(s -> s.getSampleNo().equals(sampleId)).collect(Collectors.toList());
String materialId=""; String materialId = "";
if(sampleSolutionList.size()>0){ if (sampleSolutionList.size() > 0) {
if(sampleSolutionList.size()>1){ if (sampleSolutionList.size() > 1) {
log.info("溶液编号重复 {} ",sampleId); log.info("溶液编号重复 {} ", sampleId);
}else{ } else {
materialId= sampleSolutionList.get(0).getMaterialId(); materialId = sampleSolutionList.get(0).getMaterialId();
} }
} }
List<SampleInfo> retObj=new ArrayList<>(); List<SampleInfo> retObj = new ArrayList<>();
for (SampleInfo sampleInfo : sampleInfoList) { for (SampleInfo sampleInfo : sampleInfoList) {
if(sampleInfo.getId().equals(materialId)){ if (sampleInfo.getId().equals(materialId)) {
//找到 //找到
retObj.add(sampleInfo); retObj.add(sampleInfo);
} }
} }
if(retObj.size()!=1){ if (retObj.size() != 1) {
log.info("存在重复的检材"); log.info("存在重复的检材");
return null; return null;
} }
if(retObj.size()==0){ if (retObj.size() == 0) {
log.info("未查询到检材"); log.info("未查询到检材");
return null; return null;
}else { } else {
return retObj.get(0); return retObj.get(0);
} }
} }
//构建实验结果 //构建实验结果
private List<String> buildTestResultDes(List<TestResult> resultList){ private List<String> buildTestResultDes(List<TestResult> resultList) {
//按照检材编号先分组,这样的话,如果有n个检材,m个化合物,那么就会分成n组,每组中就m条数据 //按照检材编号先分组,这样的话,如果有n个检材,m个化合物,那么就会分成n组,每组中就m条数据
Map<String, List<TestResult>> resultMap1 = resultList.stream().collect(Collectors.groupingBy(m -> m.getMaterialNo())); Map<String, List<TestResult>> resultMap1 = resultList.stream().collect(Collectors.groupingBy(m -> m.getMaterialNo()));
//我们把每组中的List 数据再次分组,分组按检出和未检出分,这样就会得到2个组,一个组是检出的,一个组是未检出的 //我们把每组中的List 数据再次分组,分组按检出和未检出分,这样就会得到2个组,一个组是检出的,一个组是未检出的
Map<String, Map<Integer, List<TestResult>>> resultMap2=new HashMap<>(); Map<String, Map<Integer, List<TestResult>>> resultMap2 = new HashMap<>();
resultMap1.forEach((k,v)->{ resultMap1.forEach((k, v) -> {
//按检材编号分组,分成检出和未检出2组 //按检材编号分组,分成检出和未检出2组
Map<Integer, List<TestResult>> tmp1Map= v.stream().collect(Collectors.groupingBy(m -> m.getIsFind())); Map<Integer, List<TestResult>> tmp1Map = v.stream().collect(Collectors.groupingBy(m -> m.getIsFind()));
resultMap2.put(k,tmp1Map);//1号 检出 与未检出 resultMap2.put(k, tmp1Map);//1号 检出 与未检出
}); });
// 对 resultMap2进行合并,然后再次分组 // 对 resultMap2进行合并,然后再次分组
List<TestResultDetail> testResultDetailList=new ArrayList<>(); List<TestResultDetail> testResultDetailList = new ArrayList<>();
resultMap2.forEach((k,v)->{ resultMap2.forEach((k, v) -> {
Map<Integer, List<TestResult>> tmp2Map=v;//这个map中只有2个key,key为0代表未检出的集合,key为1表示检出的集合 Map<Integer, List<TestResult>> tmp2Map = v;//这个map中只有2个key,key为0代表未检出的集合,key为1表示检出的集合
TestResultDetail testResultDetail= buildCompoundList(tmp2Map, k); TestResultDetail testResultDetail = buildCompoundList(tmp2Map, k);
testResultDetailList.add(testResultDetail); testResultDetailList.add(testResultDetail);
}); });
// 对 testResultDetailList 进行 分组 // 对 testResultDetailList 进行 分组
//现在对上面的数据进行从新分组,按检出+化合物的形式 //现在对上面的数据进行从新分组,按检出+化合物的形式
Map<String, List<TestResultDetail>> temp2 = testResultDetailList.stream().collect( Map<String, List<TestResultDetail>> temp2 = testResultDetailList.stream().collect(
Collectors.groupingBy(m -> m.getFindCompounds() + m.getNoFindCompounds())); Collectors.groupingBy(m -> m.getFindCompounds() + m.getNoFindCompounds()));
List<String> testResultDes= testResultSorted(temp2); List<String> testResultDes = testResultSorted(temp2);
return testResultDes; return testResultDes;
} }
//对第一个结果进行排序 //对第一个结果进行排序
private List<String> testResultSorted(Map<String, List<TestResultDetail>> tmpMap){ private List<String> testResultSorted(Map<String, List<TestResultDetail>> tmpMap) {
List<Map.Entry<String, List<TestResultDetail>>> targetList=new ArrayList<Map.Entry<String, List<TestResultDetail>>>(tmpMap.entrySet()); List<Map.Entry<String, List<TestResultDetail>>> targetList = new ArrayList<Map.Entry<String, List<TestResultDetail>>>(tmpMap.entrySet());
targetList.sort(new Comparator<Map.Entry<String, List<TestResultDetail>>>() { targetList.sort(new Comparator<Map.Entry<String, List<TestResultDetail>>>() {
@Override @Override
public int compare(Map.Entry<String, List<TestResultDetail>> mp1, Map.Entry<String, List<TestResultDetail>> mp2) { public int compare(Map.Entry<String, List<TestResultDetail>> mp1, Map.Entry<String, List<TestResultDetail>> mp2) {
int materialNo1 = getMinMaterialNo(mp1.getValue()); int materialNo1 = getMinMaterialNo(mp1.getValue());
int materialNo2 = getMinMaterialNo(mp2.getValue()); int materialNo2 = getMinMaterialNo(mp2.getValue());
return materialNo1-materialNo2; return materialNo1 - materialNo2;
} }
}); });
List<String> testResultDes=new ArrayList<>(); List<String> testResultDes = new ArrayList<>();
targetList.forEach((target)->{ targetList.forEach((target) -> {
StringBuffer sbNo=new StringBuffer(); StringBuffer sbNo = new StringBuffer();
target.getValue().forEach(item->{ target.getValue().forEach(item -> {
sbNo.append(item.getMaterialNo()).append(","); sbNo.append(item.getMaterialNo()).append(",");
}); });
if(sbNo.length()>0){ if (sbNo.length() > 0) {
sbNo.delete(sbNo.length()-1,sbNo.length());//删除最后一个 , 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; return testResultDes;
} }
/** /**
* 构造出一个检材一共检出了多少个化合物和未检出多少化合物 * 构造出一个检材一共检出了多少个化合物和未检出多少化合物
*
* @param mapCompound * @param mapCompound
* @param materialNo * @param materialNo
* @return * @return
*/ */
private TestResultDetail buildCompoundList(Map<Integer, List<TestResult>> mapCompound,String materialNo){ private TestResultDetail buildCompoundList(Map<Integer, List<TestResult>> mapCompound, String materialNo) {
StringBuffer findCompounds=new StringBuffer();//检出化合物的集合 StringBuffer findCompounds = new StringBuffer();//检出化合物的集合
StringBuffer noFindCompounds=new StringBuffer();//未检出化合物的集合 StringBuffer noFindCompounds = new StringBuffer();//未检出化合物的集合
mapCompound.forEach((k1,v1)->{ mapCompound.forEach((k1, v1) -> {
if(k1==0){ if (k1 == 0) {
//未检出 //未检出
v1.forEach(item->{ v1.forEach(item -> {
noFindCompounds.append(item.getCompoundName()).append(","); noFindCompounds.append(item.getCompoundName()).append(",");
}); });
} }
if(k1==1){ if (k1 == 1) {
//检出 //检出
v1.forEach(item->{ v1.forEach(item -> {
findCompounds.append(item.getCompoundName()).append(","); findCompounds.append(item.getCompoundName()).append(",");
}); });
} }
}); });
if(findCompounds.length()>0){ if (findCompounds.length() > 0) {
findCompounds.delete(findCompounds.length()-1,findCompounds.length());//删除最后一个 , findCompounds.delete(findCompounds.length() - 1, findCompounds.length());//删除最后一个 ,
} }
if(noFindCompounds.length()>0){ if (noFindCompounds.length() > 0) {
noFindCompounds.delete(noFindCompounds.length()-1,noFindCompounds.length());//删除最后一个 , noFindCompounds.delete(noFindCompounds.length() - 1, noFindCompounds.length());//删除最后一个 ,
} }
TestResultDetail eg=new TestResultDetail(); TestResultDetail eg = new TestResultDetail();
eg.setMaterialNo(materialNo); eg.setMaterialNo(materialNo);
eg.setFindCompounds(findCompounds.toString()); eg.setFindCompounds(findCompounds.toString());
eg.setNoFindCompounds(noFindCompounds.toString()); eg.setNoFindCompounds(noFindCompounds.toString());
return eg; return eg;
} }
private int getMinMaterialNo(List<TestResultDetail> materialList){ private int getMinMaterialNo(List<TestResultDetail> materialList) {
materialList.sort(new Comparator<TestResultDetail>() { materialList.sort(new Comparator<TestResultDetail>() {
@Override @Override
public int compare(TestResultDetail t1, TestResultDetail t2) { public int compare(TestResultDetail t1, TestResultDetail t2) {
int mNo1= Integer.parseInt(getNumberByMaterialNo(t1.getMaterialNo())); int mNo1 = Integer.parseInt(getNumberByMaterialNo(t1.getMaterialNo()));
int mNo2= Integer.parseInt(getNumberByMaterialNo(t2.getMaterialNo())); int mNo2 = Integer.parseInt(getNumberByMaterialNo(t2.getMaterialNo()));
return mNo1-mNo2; return mNo1 - mNo2;
} }
}); });
return Integer.parseInt(getNumberByMaterialNo(materialList.get(0).getMaterialNo())); return Integer.parseInt(getNumberByMaterialNo(materialList.get(0).getMaterialNo()));
} }
/** /**
* 根据编号获取排序值 * 根据编号获取排序值
*
* @param materialNo * @param materialNo
* @return * @return
*/ */
private String getNumberByMaterialNo(String materialNo){ private String getNumberByMaterialNo(String materialNo) {
Pattern pattern = Pattern.compile("\\d+"); Pattern pattern = Pattern.compile("\\d+");
Matcher matcher = pattern.matcher(materialNo); Matcher matcher = pattern.matcher(materialNo);
while (matcher.find()) { while (matcher.find()) {
@ -334,12 +350,14 @@ public class IdentifyBookDataServiceImpl implements IdentifyBookDataService {
} }
return ""; return "";
} }
/** /**
* 根据溶液编号(sampleNo)获取仪器检测数据 * 根据溶液编号(sampleNo)获取仪器检测数据
*
* @param sampleNoList * @param sampleNoList
* @return * @return
*/ */
private List<TestRecordSampleData> getTestRecordData(List<String> sampleNoList){ private List<TestRecordSampleData> getTestRecordData(List<String> sampleNoList) {
return testRecordSampleDataService.list(Wrappers.<TestRecordSampleData>lambdaQuery() return testRecordSampleDataService.list(Wrappers.<TestRecordSampleData>lambdaQuery()
.in(TestRecordSampleData::getSampleNo, sampleNoList)); .in(TestRecordSampleData::getSampleNo, sampleNoList));
} }

@ -93,41 +93,88 @@ public class InspectRecordServiceImpl implements InspectRecordService {
* @throws Exception * @throws Exception
*/ */
@Override @Override
public R buildInspectionRecord(String businessId, String materialType) throws Exception { /**
* 构建检验记录
*
* @param businessId 业务ID用于查询委托信息和检验记录
* @param materialType 材料类型用于生成特定类型的检验记录
* @return 返回封装的响应对象如果已存在 `.docx` 文件则直接返回其路径否则根据业务类型生成新的检验记录
* @throws Exception 可能抛出的异常
*/
public R buildInspectionRecord(String businessId, String materialType, boolean isPreview) throws Exception {
// 根据业务ID查询委托信息
EntrustInfo entrustInfo = entrustInfoService.getById(businessId); EntrustInfo entrustInfo = entrustInfoService.getById(businessId);
if (entrustInfo == null) { if (entrustInfo == null) {
return R.ok(false, "委托信息不存在!"); return R.ok(false, "委托信息不存在!");
} }
// 查询该业务ID对应的检验记录
TestRecord testRecord = testRecordService.lambdaQuery()
.eq(TestRecord::getBusinessId, businessId)
.one();
// 判断是否是预览,如果是预览,则每次都要重新生成,如果不是预览,那就是已经结束实验后生成的检验记录,就去判断是否生成过了,如果生成过就不再生成了
if (!isPreview) {
// 获取OSS存储中的检验记录目录下的文件列表
List<String> list = ossFile.fileList(TestRecordFileUrl.TEST_RECORD_CATALOGUE.getFileUrl() + "/" + businessId + "/");
// 如果该目录下存在文件,则遍历查找是否有 .docx 结尾的文件
if (CollUtil.isNotEmpty(list)) {
for (String fileName : list) {
// 提取文件后缀名
String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
// 如果找到 .docx 文件,则直接返回文件路径
if (suffix.equals("docx")) {
return R.ok(TestRecordFileUrl.TEST_RECORD_CATALOGUE.getFileUrl() + "/" + businessId + "/" + fileName, "生成成功!");
}
}
}
}
// 如果业务类型为 "BOINT_CASE",生成体内检验记录
if (entrustInfo.getBusinessType().equals(BusinessType.BOINT_CASE.getBusinessType())) { if (entrustInfo.getBusinessType().equals(BusinessType.BOINT_CASE.getBusinessType())) {
return R.ok(this.buildInVivoDocFile(entrustInfo, materialType), "生成成功!"); return R.ok(this.buildInVivoDocFile(entrustInfo, materialType), "生成成功!");
} }
// 默认情况,生成通用的药品检验记录
return R.ok(this.generateCommonDrugInpectRecord(businessId)); return R.ok(this.generateCommonDrugInpectRecord(businessId));
} }
@Override @Override
public void previewInspectionRecord(String businessId, String materialType, HttpServletResponse servletResponse) throws Exception { public void previewInspectionRecord(String businessId, String materialType, HttpServletResponse servletResponse) throws Exception {
String path = ""; String path = "";
path = (String) this.buildInspectionRecord(businessId, materialType).getData(); path = (String) this.buildInspectionRecord(businessId, materialType, true).getData();
java.io.ByteArrayOutputStream fosWord = new java.io.ByteArrayOutputStream(); java.io.ByteArrayOutputStream fosWord = new java.io.ByteArrayOutputStream();
ossFile.fileGet(path, fosWord); ossFile.fileGet(path, fosWord);
ByteArrayInputStream fisWord = new ByteArrayInputStream(fosWord.toByteArray()); ByteArrayInputStream fisWord = new ByteArrayInputStream(fosWord.toByteArray());
fosWord.close(); fosWord.close();
// 转换临时目录中的 word 文档为 PDF
MockMultipartFile mockMultipartFile = new MockMultipartFile("file", "检验记录" + ".docx", "image/jpg", fisWord); // 转换 Word 文档为 PDF
MockMultipartFile mockMultipartFile = new MockMultipartFile("file", "检验记录" + ".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", fisWord);
String pdfFilePath = path.substring(0, path.lastIndexOf(".")) + ".pdf"; String pdfFilePath = path.substring(0, path.lastIndexOf(".")) + ".pdf";
Response response = remoteWord2PDFService.word2pdf(mockMultipartFile); Response response = remoteWord2PDFService.word2pdf(mockMultipartFile);
fisWord.close(); fisWord.close();
org.apache.commons.io.output.ByteArrayOutputStream outPDF = new org.apache.commons.io.output.ByteArrayOutputStream(); org.apache.commons.io.output.ByteArrayOutputStream outPDF = new org.apache.commons.io.output.ByteArrayOutputStream();
IoUtil.copy(response.body().asInputStream(), outPDF, IoUtil.DEFAULT_MIDDLE_BUFFER_SIZE); IoUtil.copy(response.body().asInputStream(), outPDF, IoUtil.DEFAULT_MIDDLE_BUFFER_SIZE);
ByteArrayInputStream isPDF = new ByteArrayInputStream(outPDF.toByteArray()); ByteArrayInputStream isPDF = new ByteArrayInputStream(outPDF.toByteArray());
outPDF.close(); outPDF.close();
// 保存 PDF 文件
ossFile.fileSave(pdfFilePath, isPDF); ossFile.fileSave(pdfFilePath, isPDF);
isPDF.close(); isPDF.close();
// 删除原 Word 文件
ossFile.fileDelete(path);
System.out.println(String.format("已删除 Word 文件: %s", path));
// 发送 PDF 文件到响应流
ossFile.fileGet(pdfFilePath, servletResponse.getOutputStream()); ossFile.fileGet(pdfFilePath, servletResponse.getOutputStream());
System.out.println(String.format("转换为 PDF 结束")); System.out.println(String.format("转换为 PDF 结束"));
} }
/** /**
* 构建体内检验记录数据 * 构建体内检验记录数据
* *

Loading…
Cancel
Save