|
|
|
@ -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<TestRecordMapper, TestRec |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 根据业务id获取实验检验记录 |
|
|
|
|
* |
|
|
|
|
* @param businessId |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
@ -1543,12 +1545,13 @@ public class TestRecordServiceImpl extends ServiceImpl<TestRecordMapper, TestRec |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 生成检验记录-贵阳禁毒 |
|
|
|
|
* |
|
|
|
|
* @param entrustId 委托id |
|
|
|
|
* @return |
|
|
|
|
* @throws Exception |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public R inspectionRecord(String entrustId) throws Exception { |
|
|
|
|
public R inspectionRecord(String entrustId, String materialType) throws Exception { |
|
|
|
|
EntrustInfo entrustInfo = entrustInfoService.getById(entrustId); |
|
|
|
|
if (entrustInfo == null) { |
|
|
|
|
return R.ok(false, "委托信息不存在!"); |
|
|
|
@ -1556,83 +1559,80 @@ public class TestRecordServiceImpl extends ServiceImpl<TestRecordMapper, TestRec |
|
|
|
|
String type = entrustInfo.getBusinessType(); |
|
|
|
|
if (type.equals(BusinessType.BOINT_CASE.getBusinessType())) { |
|
|
|
|
Map<String, Object> map = this.invivoRecord(entrustInfo); |
|
|
|
|
return R.ok(this.createInVivoFile(map, entrustId), "生成成功!"); |
|
|
|
|
return R.ok(this.createInVivoFile(map, entrustId, materialType), "生成成功!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Map<String, Object> invivoRecord(EntrustInfo entrustInfo) throws Exception { |
|
|
|
|
|
|
|
|
|
// 这里因为检验记录实体并未关联业务id, 只能先查询实验数据,在通过实验数据获取到检验记录信息
|
|
|
|
|
// 获取检验记录信息
|
|
|
|
|
TestRecord testRecord = getTestRecordByBusinessId(entrustInfo.getId()); |
|
|
|
|
if (testRecord == null) { |
|
|
|
|
throw new Exception("未找到检验记录信息"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
HashMap<String, Object> data = buildCommonInspectRecordDocMap(entrustInfo, testRecord); |
|
|
|
|
|
|
|
|
|
List<String> sampleIdList = sampleInfoService.list(Wrappers.<SampleInfo>lambdaQuery() |
|
|
|
|
.eq(SampleInfo::getBusinessId, entrustInfo.getId())) |
|
|
|
|
.stream().map(SampleInfo::getId) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
List<TestRecordInstrument> instruments = testRecordInstrumentService.list(Wrappers.<TestRecordInstrument>lambdaQuery() |
|
|
|
|
.in(TestRecordInstrument::getId, testRecord.getDeviceIdList())); |
|
|
|
|
|
|
|
|
|
// 获取仪器设备数据
|
|
|
|
|
List<String> deviceIdList = testRecord.getDeviceIdList(); |
|
|
|
|
List<TestRecordInstrument> instruments = CollectionUtils.isEmpty(deviceIdList) |
|
|
|
|
? Collections.emptyList() |
|
|
|
|
: testRecordInstrumentService.list(Wrappers.<TestRecordInstrument>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<HairSewageDataDto> hairDataDtos = (List<HairSewageDataDto>) 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<HairSewageDataDto> hairDataDtos = (List<HairSewageDataDto>) testRecordSampleDataService.getSampleTestDataByBusiness(entrustInfo.getId()); |
|
|
|
|
|
|
|
|
|
// 处理检测数据
|
|
|
|
|
Map<String, List<HairSewageDataDto>> dataMap = hairDataDtos.stream() |
|
|
|
|
.collect(Collectors.groupingBy(HairSewageDataDto::getCompoundName)); |
|
|
|
|
|
|
|
|
|
ArrayList<HairSewageDataDto> dataDtos = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
for (Map.Entry<String, List<HairSewageDataDto>> entry : dataMap.entrySet()) { |
|
|
|
|
|
|
|
|
|
List<HairSewageDataDto> 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<HairSewageDataDto> delList = new ArrayList<>(); |
|
|
|
|
for (HairSewageDataDto item : list) { |
|
|
|
|
if (StringUtils.isNotBlank(item.getSampleType()) && item.getSampleType().equals("STD")) { |
|
|
|
|
delList.add(item); |
|
|
|
|
List<HairSewageDataDto> 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<TestRecordMapper, TestRec |
|
|
|
|
list.get(i).setSampleName((i + 1) + "号检材样品"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dataDtos.addAll(list); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
data.put("dataDtos", dataDtos); |
|
|
|
|
data.put("sampleSize", dataDtos.size()); |
|
|
|
|
data.put("vo", testRecord); |
|
|
|
|
return data; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String createInVivoFile(Map<String, Object> data, String entrustId) throws Exception { |
|
|
|
|
|
|
|
|
|
public String createInVivoFile(Map<String, Object> 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<TestRecordMapper, TestRec |
|
|
|
|
//
|
|
|
|
|
// TableTools.mergeCellsVertically(table, 1, 1, sampleSize);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bis.close(); |
|
|
|
|
ByteArrayOutputStream fosWord = new ByteArrayOutputStream(); |
|
|
|
|
template.write(fosWord); |
|
|
|
@ -1745,6 +1749,7 @@ public class TestRecordServiceImpl extends ServiceImpl<TestRecordMapper, TestRec |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 构建常规毒品的检验记录数据 |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private Map<String, Object> buildCommonDrugDocMap(String entrustId) { |
|
|
|
@ -1760,7 +1765,6 @@ public class TestRecordServiceImpl extends ServiceImpl<TestRecordMapper, TestRec |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 构建通用的检验记录文档映射 |
|
|
|
|
* |
|
|
|
@ -1790,7 +1794,7 @@ public class TestRecordServiceImpl extends ServiceImpl<TestRecordMapper, TestRec |
|
|
|
|
|
|
|
|
|
if (references == null || references.size() == 0) { |
|
|
|
|
data.put("referenceMaterialName", "未找到试剂耗材数据!"); |
|
|
|
|
}else { |
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
String referenceMaterialName = references.stream() |
|
|
|
|
.map(reagent -> "\u2611" + " " + reagent.getReagentConsumableName()) |
|
|
|
|