master
杨海航 2 weeks ago
parent 83244629be
commit fd37cdde67
  1. 4
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/TestRecordController.java
  2. 2
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/TestRecordService.java
  3. 136
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordServiceImpl.java

@ -214,8 +214,8 @@ public class TestRecordController {
@ApiOperation("生成检验记录-贵阳禁毒") @ApiOperation("生成检验记录-贵阳禁毒")
@GetMapping("/inspectionRecord") @GetMapping("/inspectionRecord")
public R inspectionRecord(String entrustId) throws Exception { public R inspectionRecord(String entrustId, String materialType) throws Exception {
return testRecordService.inspectionRecord(entrustId); return testRecordService.inspectionRecord(entrustId, materialType);
} }
} }

@ -97,7 +97,7 @@ public interface TestRecordService extends IService<TestRecord> {
* @return * @return
* @throws Exception * @throws Exception
*/ */
R inspectionRecord(String entrustId) throws Exception; R inspectionRecord(String entrustId, String materialType) throws Exception;
/** /**
* 根据业务id获取实验检验记录 * 根据业务id获取实验检验记录

@ -7,6 +7,7 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage; 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.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@ -99,6 +100,7 @@ public class TestRecordServiceImpl extends ServiceImpl<TestRecordMapper, TestRec
/** /**
* 根据业务id获取实验检验记录 * 根据业务id获取实验检验记录
*
* @param businessId * @param businessId
* @return * @return
*/ */
@ -1543,12 +1545,13 @@ public class TestRecordServiceImpl extends ServiceImpl<TestRecordMapper, TestRec
/** /**
* 生成检验记录-贵阳禁毒 * 生成检验记录-贵阳禁毒
*
* @param entrustId 委托id * @param entrustId 委托id
* @return * @return
* @throws Exception * @throws Exception
*/ */
@Override @Override
public R inspectionRecord(String entrustId) throws Exception { public R inspectionRecord(String entrustId, String materialType) throws Exception {
EntrustInfo entrustInfo = entrustInfoService.getById(entrustId); EntrustInfo entrustInfo = entrustInfoService.getById(entrustId);
if (entrustInfo == null) { if (entrustInfo == null) {
return R.ok(false, "委托信息不存在!"); return R.ok(false, "委托信息不存在!");
@ -1556,83 +1559,80 @@ public class TestRecordServiceImpl extends ServiceImpl<TestRecordMapper, TestRec
String type = entrustInfo.getBusinessType(); String type = entrustInfo.getBusinessType();
if (type.equals(BusinessType.BOINT_CASE.getBusinessType())) { if (type.equals(BusinessType.BOINT_CASE.getBusinessType())) {
Map<String, Object> map = this.invivoRecord(entrustInfo); Map<String, Object> map = this.invivoRecord(entrustInfo);
return R.ok(this.createInVivoFile(map, entrustId), "生成成功!"); return R.ok(this.createInVivoFile(map, entrustId, materialType), "生成成功!");
} }
return null; return null;
} }
public Map<String, Object> invivoRecord(EntrustInfo entrustInfo) throws Exception { public Map<String, Object> invivoRecord(EntrustInfo entrustInfo) throws Exception {
// 获取检验记录信息
// 这里因为检验记录实体并未关联业务id, 只能先查询实验数据,在通过实验数据获取到检验记录信息
TestRecord testRecord = getTestRecordByBusinessId(entrustInfo.getId()); TestRecord testRecord = getTestRecordByBusinessId(entrustInfo.getId());
if (testRecord == null) {
throw new Exception("未找到检验记录信息");
}
HashMap<String, Object> data = buildCommonInspectRecordDocMap(entrustInfo, testRecord); HashMap<String, Object> data = buildCommonInspectRecordDocMap(entrustInfo, testRecord);
List<String> sampleIdList = sampleInfoService.list(Wrappers.<SampleInfo>lambdaQuery() // 获取仪器设备数据
.eq(SampleInfo::getBusinessId, entrustInfo.getId())) List<String> deviceIdList = testRecord.getDeviceIdList();
.stream().map(SampleInfo::getId) List<TestRecordInstrument> instruments = CollectionUtils.isEmpty(deviceIdList)
.collect(Collectors.toList()); ? Collections.emptyList()
: testRecordInstrumentService.list(Wrappers.<TestRecordInstrument>lambdaQuery()
List<TestRecordInstrument> instruments = testRecordInstrumentService.list(Wrappers.<TestRecordInstrument>lambdaQuery() .in(TestRecordInstrument::getId, deviceIdList));
.in(TestRecordInstrument::getId, testRecord.getDeviceIdList()));
data.put("instrumentName", CollectionUtils.isEmpty(instruments)
? "未找到仪器设备数据!"
: instruments.stream()
.map(TestRecordInstrument::getInstrumentName)
.collect(Collectors.joining("\n"))
);
if (instruments == null || instruments.size() == 0) { // 获取样品检测数据
data.put("instrumentName", "未找到仪器设备数据!"); List<HairSewageDataDto> hairDataDtos = (List<HairSewageDataDto>) testRecordSampleDataService
}else { .getSampleTestDataByBusiness(entrustInfo.getId());
String instrumentName = instruments.stream()
.map(TestRecordInstrument::getInstrumentName)
.collect(Collectors.joining("\n"));
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() Map<String, List<HairSewageDataDto>> dataMap = hairDataDtos.stream()
.collect(Collectors.groupingBy(HairSewageDataDto::getCompoundName)); .collect(Collectors.groupingBy(HairSewageDataDto::getCompoundName));
ArrayList<HairSewageDataDto> dataDtos = new ArrayList<>(); List<HairSewageDataDto> dataDtos = new ArrayList<>();
for (Map.Entry<String, List<HairSewageDataDto>> entry : dataMap.entrySet()) { dataMap.forEach((compoundName, list) -> {
// 添加空白数据
List<HairSewageDataDto> list = entry.getValue(); HairSewageDataDto blankDto = new HairSewageDataDto();
blankDto.setSampleName("空白");
HairSewageDataDto dto = new HairSewageDataDto(); blankDto.setCompoundName(compoundName);
blankDto.setTmpTargetRtTime("/");
dto.setSampleName("空白"); blankDto.setTmpRtTimeError("/");
dto.setCompoundName(entry.getKey()); blankDto.setRtTimeWithinError("否");
dto.setTmpTargetRtTime("/"); blankDto.setTmpIonAbundanceRatio("/");
dto.setTmpRtTimeError("/"); blankDto.setWhetherCheckOut("否");
dto.setRtTimeWithinError("否"); dataDtos.add(blankDto);
dto.setTmpIonAbundanceRatio("/");
dto.setWhetherCheckOut("否"); // 处理样品数据
dataDtos.add(dto); list.removeIf(item -> {
ArrayList<HairSewageDataDto> delList = new ArrayList<>(); if (StringUtils.equals(item.getSampleType(), "STD")) {
for (HairSewageDataDto item : list) {
if (StringUtils.isNotBlank(item.getSampleType()) && item.getSampleType().equals("STD")) {
delList.add(item);
item.setSampleName("空白添加"); item.setSampleName("空白添加");
item.setWhetherCheckOut("是"); item.setWhetherCheckOut("是");
dataDtos.add(item); dataDtos.add(item);
} else if (StringUtils.isNotBlank(item.getSampleType()) && item.getSampleType().equals("QC")) { return true;
delList.add(item); } 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) { if (list.size() == 1) {
list.get(0).setSampleName("检材样品"); list.get(0).setSampleName("检材样品");
} else { } else {
@ -1640,20 +1640,25 @@ public class TestRecordServiceImpl extends ServiceImpl<TestRecordMapper, TestRec
list.get(i).setSampleName((i + 1) + "号检材样品"); list.get(i).setSampleName((i + 1) + "号检材样品");
} }
} }
dataDtos.addAll(list); dataDtos.addAll(list);
} });
data.put("dataDtos", dataDtos); data.put("dataDtos", dataDtos);
data.put("sampleSize", dataDtos.size()); data.put("sampleSize", dataDtos.size());
data.put("vo", testRecord);
return data; 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(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
TestRecord vo = (TestRecord) data.get("vo"); String templatePath = "";
ossFile.fileGet("/template" + "/贵阳生物样本检验记录模板.docx", bos); if (materialType.equals("毛发")) {
templatePath = "/template" + "/贵阳生物样本毛发检验记录模板.docx";
} else {
templatePath = "/template" + "/贵阳生物样本尿液检验记录模板.docx";
}
ossFile.fileGet(templatePath, bos);
byte[] templateArray = bos.toByteArray(); byte[] templateArray = bos.toByteArray();
ByteArrayInputStream bis = new ByteArrayInputStream(templateArray); ByteArrayInputStream bis = new ByteArrayInputStream(templateArray);
bos.close(); bos.close();
@ -1684,7 +1689,6 @@ public class TestRecordServiceImpl extends ServiceImpl<TestRecordMapper, TestRec
// //
// TableTools.mergeCellsVertically(table, 1, 1, sampleSize); // TableTools.mergeCellsVertically(table, 1, 1, sampleSize);
bis.close(); bis.close();
ByteArrayOutputStream fosWord = new ByteArrayOutputStream(); ByteArrayOutputStream fosWord = new ByteArrayOutputStream();
template.write(fosWord); template.write(fosWord);
@ -1745,6 +1749,7 @@ public class TestRecordServiceImpl extends ServiceImpl<TestRecordMapper, TestRec
/** /**
* 构建常规毒品的检验记录数据 * 构建常规毒品的检验记录数据
*
* @return * @return
*/ */
private Map<String, Object> buildCommonDrugDocMap(String entrustId) { 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) { if (references == null || references.size() == 0) {
data.put("referenceMaterialName", "未找到试剂耗材数据!"); data.put("referenceMaterialName", "未找到试剂耗材数据!");
}else { } else {
String referenceMaterialName = references.stream() String referenceMaterialName = references.stream()
.map(reagent -> "\u2611" + " " + reagent.getReagentConsumableName()) .map(reagent -> "\u2611" + " " + reagent.getReagentConsumableName())

Loading…
Cancel
Save