master
杨海航 3 weeks ago
parent 0acf8a1588
commit 7938761637
  1. 76
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/InspectRecordServiceImpl.java

@ -106,8 +106,9 @@ public class InspectRecordServiceImpl implements InspectRecordService {
@Override
public void previewInspectionRecord(String businessId, String materialType, HttpServletResponse servletResponse) throws Exception {
String path = "";
path = (String) this.buildInspectionRecord(businessId, materialType).getData();
String path = (String) this.buildInspectionRecord(businessId, materialType).getData();
java.io.ByteArrayOutputStream fosWord = new java.io.ByteArrayOutputStream();
ossFile.fileGet(path, fosWord);
ByteArrayInputStream fisWord = new ByteArrayInputStream(fosWord.toByteArray());
@ -194,7 +195,7 @@ public class InspectRecordServiceImpl implements InspectRecordService {
if (expandList != null) {
for (TestRecordSampleDataExpand expand : expandList) {
if (!expand.getBasePeak()) {
stdVo.setPIonAbundanceRatio(expand.getIonAbundanceRatio() != null ? expand.getIonAbundanceRatio().toString() : "/");
stdVo.setPIonAbundanceRatio(expand.getIonAbundanceRatio() != null ? expand.getIonAbundanceRatio().setScale(2, RoundingMode.HALF_UP).toString() : "/");
stdVo.setPIonAbundanceRatioError("/"); // 设置空值为"/"
stdVo.setPIonAbundanceRatioWithinError("/"); // 设置空值为"/"
break; // 只取第一个符合条件的扩展数据
@ -202,7 +203,7 @@ public class InspectRecordServiceImpl implements InspectRecordService {
}
}
stdVo.setName("空白" + materialType + "加标");
stdVo.setPTargetRtTime(std.getTargetRtTime() != null ? std.getTargetRtTime().toString() : "/");
stdVo.setPTargetRtTime(std.getTargetRtTime() != null ? String.format("%.2f", std.getTargetRtTime()) : "/");
stdVo.setPRtTimeError("/"); // 设置空值为"/"
stdVo.setPRtTimeWithinError("/"); // 设置空值为"/"
stdVo.setPIsDetected("是"); // 默认"是"
@ -221,8 +222,8 @@ public class InspectRecordServiceImpl implements InspectRecordService {
TestRecordSampleDataDocDTO vo = new TestRecordSampleDataDocDTO();
BeanUtils.copyProperties(item, vo);
vo.setPTargetRtTime(item.getTargetRtTime() != null ? item.getTargetRtTime().toString() : "/");
vo.setPRtTimeError(item.getRtTimeError() != null ? item.getRtTimeError().toString() : "/");
vo.setPTargetRtTime(item.getTargetRtTime() != null ? String.format("%.2f", item.getTargetRtTime()) : "/");
vo.setPRtTimeError(item.getRtTimeError() != null ? item.getRtTimeError().setScale(2, RoundingMode.HALF_UP).toString() : "/");
vo.setPRtTimeWithinError(item.getRtTimeWithinError() != null ? item.getRtTimeWithinError().toString() : "/");
vo.setPIsDetected(item.getIsDetected() != null && item.getIsDetected() == 1 ? "是" : "否");
@ -230,8 +231,8 @@ public class InspectRecordServiceImpl implements InspectRecordService {
if (expandList != null) {
for (TestRecordSampleDataExpand expand : expandList) {
if (!expand.getBasePeak()) {
vo.setPIonAbundanceRatio(expand.getIonAbundanceRatio() != null ? expand.getIonAbundanceRatio().toString() : "/");
vo.setPIonAbundanceRatioError(expand.getIonAbundanceRatioError() != null ? expand.getIonAbundanceRatioError().toString() : "/");
vo.setPIonAbundanceRatio(expand.getIonAbundanceRatio() != null ? expand.getIonAbundanceRatio().setScale(2, RoundingMode.HALF_UP).toString() : "/");
vo.setPIonAbundanceRatioError(expand.getIonAbundanceRatioError() != null ? expand.getIonAbundanceRatioError().setScale(2, RoundingMode.HALF_UP).toString() : "/");
vo.setPIonAbundanceRatioWithinError(expand.getIonAbundanceRatioWithinError() != null ? expand.getIonAbundanceRatioWithinError() : "/");
break; // 只取第一个符合条件的扩展数据
}
@ -267,7 +268,6 @@ public class InspectRecordServiceImpl implements InspectRecordService {
// 返回处理后的数据
data.put("dataDtos", dataDtos);
data.put("compoundSize", dataDtos.stream().collect(Collectors.groupingBy(TestRecordSampleData::getCompoundName)).size());
data.put("type", "inVivo");
data.put("inspectOpinion", this.buildInspectOpinion(testRecordSampleDataService
.lambdaQuery()
@ -589,7 +589,7 @@ public class InspectRecordServiceImpl implements InspectRecordService {
String type = (String) data.get("type");
if (type.equals("inVitro")) {
if (StringUtils.isNotBlank(type) && type.equals("inVitro")) {
int startRow = 1; // 从第二行开始(表头是第一行,索引从0开始)
// **处理合并单元格**
int mergeStep = 4; // 每4行合并一次
@ -603,8 +603,6 @@ public class InspectRecordServiceImpl implements InspectRecordService {
}
}
} else {
int compoundSize = (int) data.get("compoundSize"); // 获取compoundSize值
// **处理合并单元格**
int startRow = 1; // 从第二行开始(表头是第一行,索引从0开始)
String currentCompoundName = null;
@ -631,6 +629,31 @@ public class InspectRecordServiceImpl implements InspectRecordService {
}
}
System.out.println("总共的表格数量:" + tables.size());
XWPFTable xwpfTable = tables.get(2);
List<XWPFTableRow> rows = xwpfTable.getRows();
// 跳过第一行(表头),从第二行开始处理
for (int i = 1; i < rows.size() - 1; i++) { // 注意:i 从 1 开始
XWPFTableRow currentRow = rows.get(i);
XWPFTableRow nextRow = rows.get(i + 1);
// 获取当前行和下一行的化合物名称
String currentCompoundName = currentRow.getCell(0).getText().trim();
String nextCompoundName = nextRow.getCell(0).getText().trim();
// 如果当前行和下一行的化合物名称相同,则合并它们的第一列
if (currentCompoundName.equals(nextCompoundName)) {
// 合并单元格
currentRow.getCell(0).getCTTc().addNewTcPr().addNewVMerge().setVal(org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge.RESTART);
nextRow.getCell(0).getCTTc().addNewTcPr().addNewVMerge().setVal(org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge.CONTINUE);
// 删除下一行的第一个单元格的内容(可选)
nextRow.getCell(0).setText("");
}
}
bis.close();
ByteArrayOutputStream fosWord = new ByteArrayOutputStream();
template.write(fosWord);
@ -728,13 +751,13 @@ public class InspectRecordServiceImpl implements InspectRecordService {
if (materialType.isEmpty()) {
data.put("instrumentName", CollectionUtils.isEmpty(instruments)
? "未找到仪器设备数据!"
? "\u3000\u3000未找到仪器设备数据!"
: instruments.stream()
.map(i -> "\u3000\u3000\u2611" + i.getInstrumentName()) // 使用 Unicode 全角空格
.collect(Collectors.joining("\n")));
} else {
data.put("instrumentName", CollectionUtils.isEmpty(instruments)
? "未找到仪器设备数据!"
? "\u3000\u3000未找到仪器设备数据!"
: instruments.stream()
.map(i -> "\u3000\u3000" + i.getInstrumentName()) // 使用 Unicode 全角空格
.collect(Collectors.joining("\n")));
@ -747,7 +770,7 @@ public class InspectRecordServiceImpl implements InspectRecordService {
.eq(TestRecordReagent::getCategory, "标准物质"));
if (references == null || references.isEmpty()) {
data.put("referenceMaterialName", "未找到试剂耗材数据!");
data.put("referenceMaterialName", "未找到标准物质数据!");
} else {
String referenceMaterialName = "";
@ -760,7 +783,7 @@ public class InspectRecordServiceImpl implements InspectRecordService {
.map(reagent -> "\u3000\u3000\u2611" + " " + reagent.getReagentConsumableName())
.collect(Collectors.joining("\n"));
}
data.put("referenceMaterialName", referenceMaterialName);
data.put("referenceMaterialName", referenceMaterialName);
data.put("materialIngredient", references.stream()
.map(reagent -> reagent.getReagentConsumableName())
@ -771,7 +794,7 @@ public class InspectRecordServiceImpl implements InspectRecordService {
.eq(TestRecordReagent::getCategory, "试剂"));
if (reagents == null || reagents.isEmpty()) {
data.put("reagentConsumableName", "未找到试剂耗材数据!");
data.put("reagentConsumableName", " 未找到试剂耗材数据!");
} else {
String reagentConsumableName = reagents.stream()
.map(TestRecordReagent::getReagentConsumableName)
@ -893,6 +916,20 @@ public class InspectRecordServiceImpl implements InspectRecordService {
}
private String formatSampleNumbers(List<String> sampleNumbers) {
List<Integer> numbers = sampleNumbers.stream()
.map(s -> s.replace("号", "")) // 移除"号"字
.map(Integer::parseInt) // 转换为整数
.sorted() // 排序
.collect(Collectors.toList());
if (numbers.size() > 1 && numbers.get(numbers.size() - 1) - numbers.get(0) == numbers.size() - 1) {
return numbers.get(0) + "至" + numbers.get(numbers.size() - 1) + "号";
}
return String.join("、", sampleNumbers);
}
public String buildInspectOpinion(List<TestRecordSampleData> dataList) {
if (dataList == null || dataList.isEmpty()) {
return "";
@ -906,7 +943,6 @@ public class InspectRecordServiceImpl implements InspectRecordService {
String sampleNo = record.getSampleNo();
String compoundName = record.getCompoundCnName();
// 确保样本编号有效
if (sampleNo == null || compoundName == null || sampleNo.trim().isEmpty()) {
continue;
}
@ -933,7 +969,7 @@ public class InspectRecordServiceImpl implements InspectRecordService {
}
for (Map.Entry<Set<String>, List<String>> entry : groupedDetectedSamples.entrySet()) {
String sampleNumbers = String.join("、", entry.getValue());
String sampleNumbers = formatSampleNumbers(entry.getValue()); // 这里也应用连续编号格式化
String compounds = String.join("、", entry.getKey());
if (entry.getValue().size() > 1) {
@ -950,14 +986,13 @@ public class InspectRecordServiceImpl implements InspectRecordService {
String sampleNo = entry.getKey();
Set<String> compoundSet = new HashSet<>(entry.getValue());
// 仅当该样本没有任何检出的物质时,才记录未检出
if (!detectedMap.containsKey(sampleNo)) {
groupedNotDetectedSamples.computeIfAbsent(compoundSet, k -> new ArrayList<>()).add(extractSampleNumber.apply(sampleNo));
}
}
for (Map.Entry<Set<String>, List<String>> entry : groupedNotDetectedSamples.entrySet()) {
String sampleNumbers = String.join("、", entry.getValue());
String sampleNumbers = formatSampleNumbers(entry.getValue()); // 这里也应用连续编号格式化
String compounds = String.join("、", entry.getKey());
if (entry.getValue().size() > 1) {
@ -972,4 +1007,5 @@ public class InspectRecordServiceImpl implements InspectRecordService {
return String.join(";", finalSentences);
}
}

Loading…
Cancel
Save