update
This commit is contained in:
+88
-54
@@ -33,6 +33,8 @@ import digital.laboratory.platform.sys.enums.entrust.EntrustBiologyType;
|
|||||||
import feign.Response;
|
import feign.Response;
|
||||||
import org.apache.commons.io.output.ByteArrayOutputStream;
|
import org.apache.commons.io.output.ByteArrayOutputStream;
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFTable;
|
import org.apache.poi.xwpf.usermodel.XWPFTable;
|
||||||
|
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
|
||||||
|
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.mock.web.MockMultipartFile;
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -125,17 +127,8 @@ public class InspectRecordServiceImpl implements InspectRecordService {
|
|||||||
System.out.println(String.format("转换为 PDF 结束"));
|
System.out.println(String.format("转换为 PDF 结束"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成生物样本检验记录数据map
|
|
||||||
*
|
|
||||||
* @param entrustInfo 委托实体信息
|
|
||||||
* @param materialType 检材类型
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public Map<String, Object> buildInVivoRecordData(EntrustInfo entrustInfo, String materialType) throws Exception {
|
public Map<String, Object> buildInVivoRecordData(EntrustInfo entrustInfo, String materialType) throws Exception {
|
||||||
|
|
||||||
|
|
||||||
// 获取检验记录信息
|
// 获取检验记录信息
|
||||||
TestRecord testRecord = testRecordService.getTestRecordByBusinessId(entrustInfo.getId());
|
TestRecord testRecord = testRecordService.getTestRecordByBusinessId(entrustInfo.getId());
|
||||||
|
|
||||||
@@ -146,7 +139,6 @@ public class InspectRecordServiceImpl implements InspectRecordService {
|
|||||||
// 生成基础数据
|
// 生成基础数据
|
||||||
HashMap<String, Object> data = buildCommonInspectRecordDocMap(entrustInfo, testRecord, materialType);
|
HashMap<String, Object> data = buildCommonInspectRecordDocMap(entrustInfo, testRecord, materialType);
|
||||||
|
|
||||||
|
|
||||||
// 获取样品数据
|
// 获取样品数据
|
||||||
List<TestRecordSampleData> dataList = testRecordSampleDataService.list(
|
List<TestRecordSampleData> dataList = testRecordSampleDataService.list(
|
||||||
Wrappers.<TestRecordSampleData>lambdaQuery().eq(TestRecordSampleData::getTestId, testRecord.getId()));
|
Wrappers.<TestRecordSampleData>lambdaQuery().eq(TestRecordSampleData::getTestId, testRecord.getId()));
|
||||||
@@ -179,13 +171,13 @@ public class InspectRecordServiceImpl implements InspectRecordService {
|
|||||||
TestRecordSampleDataDocDTO blankVo = new TestRecordSampleDataDocDTO();
|
TestRecordSampleDataDocDTO blankVo = new TestRecordSampleDataDocDTO();
|
||||||
blankVo.setName("空白" + materialType);
|
blankVo.setName("空白" + materialType);
|
||||||
blankVo.setCompoundName(compoundName);
|
blankVo.setCompoundName(compoundName);
|
||||||
blankVo.setPTargetRtTime("/");
|
blankVo.setPTargetRtTime("/"); // 设置空值为"/"
|
||||||
blankVo.setPRtTimeError("/");
|
blankVo.setPRtTimeError("/"); // 设置空值为"/"
|
||||||
blankVo.setPRtTimeWithinError("否");
|
blankVo.setPRtTimeWithinError("否"); // 默认"否"
|
||||||
blankVo.setPIonAbundanceRatio("/");
|
blankVo.setPIonAbundanceRatio("/"); // 设置空值为"/"
|
||||||
blankVo.setPIonAbundanceRatioError("/");
|
blankVo.setPIonAbundanceRatioError("/"); // 设置空值为"/"
|
||||||
blankVo.setPIonAbundanceRatioWithinError("否");
|
blankVo.setPIonAbundanceRatioWithinError("否"); // 默认"否"
|
||||||
blankVo.setPIsDetected("否");
|
blankVo.setPIsDetected("否"); // 默认"否"
|
||||||
dataDtos.add(blankVo);
|
dataDtos.add(blankVo);
|
||||||
|
|
||||||
// 根据样品类型分组
|
// 根据样品类型分组
|
||||||
@@ -197,22 +189,24 @@ public class InspectRecordServiceImpl implements InspectRecordService {
|
|||||||
TestRecordSampleData std = map.get("STD").get(0);
|
TestRecordSampleData std = map.get("STD").get(0);
|
||||||
TestRecordSampleDataDocDTO stdVo = new TestRecordSampleDataDocDTO();
|
TestRecordSampleDataDocDTO stdVo = new TestRecordSampleDataDocDTO();
|
||||||
BeanUtils.copyProperties(std, stdVo);
|
BeanUtils.copyProperties(std, stdVo);
|
||||||
|
|
||||||
List<TestRecordSampleDataExpand> expandList = dataExpandMap.get(std.getId());
|
List<TestRecordSampleDataExpand> expandList = dataExpandMap.get(std.getId());
|
||||||
if (expandList != null) {
|
if (expandList != null) {
|
||||||
for (TestRecordSampleDataExpand expand : expandList) {
|
for (TestRecordSampleDataExpand expand : expandList) {
|
||||||
if (!expand.getBasePeak()) {
|
if (!expand.getBasePeak()) {
|
||||||
stdVo.setPIonAbundanceRatio(expand.getIonAbundanceRatio().toString());
|
stdVo.setPIonAbundanceRatio(expand.getIonAbundanceRatio() != null ? expand.getIonAbundanceRatio().toString() : "/");
|
||||||
stdVo.setPIonAbundanceRatioError("/");
|
stdVo.setPIonAbundanceRatioError("/"); // 设置空值为"/"
|
||||||
stdVo.setPIonAbundanceRatioWithinError("/");
|
stdVo.setPIonAbundanceRatioWithinError("/"); // 设置空值为"/"
|
||||||
break; // 只取第一个符合条件的扩展数据
|
break; // 只取第一个符合条件的扩展数据
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stdVo.setName("空白" + materialType + "加标");
|
stdVo.setName("空白" + materialType + "加标");
|
||||||
stdVo.setPTargetRtTime(std.getTargetRtTime().toString());
|
stdVo.setPTargetRtTime(std.getTargetRtTime() != null ? std.getTargetRtTime().toString() : "/");
|
||||||
stdVo.setPRtTimeError("/");
|
stdVo.setPRtTimeError("/"); // 设置空值为"/"
|
||||||
stdVo.setPRtTimeWithinError("/");
|
stdVo.setPRtTimeWithinError("/"); // 设置空值为"/"
|
||||||
stdVo.setPIsDetected("是");
|
stdVo.setPIsDetected("是"); // 默认"是"
|
||||||
|
stdVo.setCompoundName(compoundName);
|
||||||
dataDtos.add(stdVo);
|
dataDtos.add(stdVo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,38 +220,43 @@ public class InspectRecordServiceImpl implements InspectRecordService {
|
|||||||
TestRecordSampleData item = analyte.get(i);
|
TestRecordSampleData item = analyte.get(i);
|
||||||
TestRecordSampleDataDocDTO vo = new TestRecordSampleDataDocDTO();
|
TestRecordSampleDataDocDTO vo = new TestRecordSampleDataDocDTO();
|
||||||
BeanUtils.copyProperties(item, vo);
|
BeanUtils.copyProperties(item, vo);
|
||||||
vo.setPTargetRtTime(vo.getTargetRtTime().toString());
|
|
||||||
vo.setPRtTimeError(vo.getRtTimeError().toString());
|
vo.setPTargetRtTime(item.getTargetRtTime() != null ? item.getTargetRtTime().toString() : "/");
|
||||||
vo.setPRtTimeWithinError(vo.getRtTimeWithinError().toString());
|
vo.setPRtTimeError(item.getRtTimeError() != null ? item.getRtTimeError().toString() : "/");
|
||||||
vo.setPIsDetected(item.getIsDetected() == 1 ? "是" : "否");
|
vo.setPRtTimeWithinError(item.getRtTimeWithinError() != null ? item.getRtTimeWithinError().toString() : "/");
|
||||||
|
vo.setPIsDetected(item.getIsDetected() != null && item.getIsDetected() == 1 ? "是" : "否");
|
||||||
|
|
||||||
List<TestRecordSampleDataExpand> expandList = dataExpandMap.get(item.getId());
|
List<TestRecordSampleDataExpand> expandList = dataExpandMap.get(item.getId());
|
||||||
if (expandList != null) {
|
if (expandList != null) {
|
||||||
for (TestRecordSampleDataExpand expand : expandList) {
|
for (TestRecordSampleDataExpand expand : expandList) {
|
||||||
if (!expand.getBasePeak()) {
|
if (!expand.getBasePeak()) {
|
||||||
vo.setPIonAbundanceRatio(expand.getIonAbundanceRatio().toString());
|
vo.setPIonAbundanceRatio(expand.getIonAbundanceRatio() != null ? expand.getIonAbundanceRatio().toString() : "/");
|
||||||
vo.setPIonAbundanceRatioError(expand.getIonAbundanceRatioError().toString());
|
vo.setPIonAbundanceRatioError(expand.getIonAbundanceRatioError() != null ? expand.getIonAbundanceRatioError().toString() : "/");
|
||||||
vo.setPIonAbundanceRatioWithinError(expand.getIonAbundanceRatioWithinError());
|
vo.setPIonAbundanceRatioWithinError(expand.getIonAbundanceRatioWithinError() != null ? expand.getIonAbundanceRatioWithinError() : "/");
|
||||||
break; // 只取第一个符合条件的扩展数据
|
break; // 只取第一个符合条件的扩展数据
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重新命名样品
|
// 重新命名样品
|
||||||
vo.setName((dataList
|
vo.setName((dataList
|
||||||
.stream()
|
.stream()
|
||||||
.collect(Collectors.groupingBy(TestRecordSampleData::getSampleNo))
|
.collect(Collectors.groupingBy(TestRecordSampleData::getSampleNo))
|
||||||
.keySet()
|
.keySet()
|
||||||
.size() == 1) ? "检材样品" : (i + 1) + "号检材样品");
|
.size() == 1) ? "检材样品" : (i + 1) + "号检材样品");
|
||||||
|
vo.setCompoundName(compoundName);
|
||||||
dataVOS.add(vo);
|
dataVOS.add(vo);
|
||||||
}
|
}
|
||||||
dataDtos.addAll(dataVOS);
|
dataDtos.addAll(dataVOS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加入图谱序号值
|
// 加入图谱序号值
|
||||||
int indexNum = 1;
|
int indexNum = 1;
|
||||||
for (int i = 0; i < dataDtos.size(); i++) {
|
for (int i = 0; i < dataDtos.size(); i++) {
|
||||||
dataDtos.get(i).setIndexNum(String.valueOf(indexNum++));
|
dataDtos.get(i).setIndexNum(String.valueOf(indexNum++));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.buildIonPairAndCE(data, testRecordReagentService
|
this.buildIonPairAndCE(data, testRecordReagentService
|
||||||
.list(Wrappers.<TestRecordReagent>lambdaQuery()
|
.list(Wrappers.<TestRecordReagent>lambdaQuery()
|
||||||
.in(TestRecordReagent::getId, testRecord.getReagentConsumablesList())
|
.in(TestRecordReagent::getId, testRecord.getReagentConsumablesList())
|
||||||
@@ -265,9 +264,11 @@ public class InspectRecordServiceImpl implements InspectRecordService {
|
|||||||
.stream()
|
.stream()
|
||||||
.map(item -> item.getId())
|
.map(item -> item.getId())
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
|
|
||||||
// 返回处理后的数据
|
// 返回处理后的数据
|
||||||
data.put("dataDtos", dataDtos);
|
data.put("dataDtos", dataDtos);
|
||||||
data.put("sampleSize", dataDtos.size() / 2);
|
data.put("compoundSize", dataDtos.stream().collect(Collectors.groupingBy(TestRecordSampleData::getCompoundName)).size());
|
||||||
|
data.put("type", "inVivo");
|
||||||
data.put("inspectOpinion", this.buildInspectOpinion(testRecordSampleDataService
|
data.put("inspectOpinion", this.buildInspectOpinion(testRecordSampleDataService
|
||||||
.lambdaQuery()
|
.lambdaQuery()
|
||||||
.eq(TestRecordSampleData::getTestId, testRecord.getId())
|
.eq(TestRecordSampleData::getTestId, testRecord.getId())
|
||||||
@@ -276,6 +277,7 @@ public class InspectRecordServiceImpl implements InspectRecordService {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<String, Object> buildInVitroRecordData(EntrustInfo entrustInfo, TestRecord testRecord, Map<String, Object> data) {
|
public Map<String, Object> buildInVitroRecordData(EntrustInfo entrustInfo, TestRecord testRecord, Map<String, Object> data) {
|
||||||
|
|
||||||
|
|
||||||
@@ -423,6 +425,7 @@ public class InspectRecordServiceImpl implements InspectRecordService {
|
|||||||
// 9️⃣ 返回处理后的数据
|
// 9️⃣ 返回处理后的数据
|
||||||
data.put("dataDtos", dataDtos);
|
data.put("dataDtos", dataDtos);
|
||||||
data.put("sampleSize", dataDtos.size());
|
data.put("sampleSize", dataDtos.size());
|
||||||
|
data.put("type", "inVitro");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Map<Integer, List<TestRecordSampleData>> isDetectedMap = testRecordSampleDataService
|
Map<Integer, List<TestRecordSampleData>> isDetectedMap = testRecordSampleDataService
|
||||||
@@ -473,12 +476,12 @@ public class InspectRecordServiceImpl implements InspectRecordService {
|
|||||||
if (!isDetectedStrs.isEmpty()) {
|
if (!isDetectedStrs.isEmpty()) {
|
||||||
data.put("isDetectedStrs", "阳性结果:" + "\n" + isDetectedStrs.stream()
|
data.put("isDetectedStrs", "阳性结果:" + "\n" + isDetectedStrs.stream()
|
||||||
.map(item -> "\u3000\u3000" + item)
|
.map(item -> "\u3000\u3000" + item)
|
||||||
.collect(Collectors.joining("\u2611")));
|
.collect(Collectors.joining("\n")));
|
||||||
}
|
}
|
||||||
if (!notDetectedStrs.isEmpty()) {
|
if (!notDetectedStrs.isEmpty()) {
|
||||||
data.put("notDetectedStrs", "阴性结果:" + "\n" + notDetectedStrs.stream()
|
data.put("notDetectedStrs", "阴性结果:" + "\n" + notDetectedStrs.stream()
|
||||||
.map(item -> "\u3000\u3000" + item)
|
.map(item -> "\u3000\u3000" + item)
|
||||||
.collect(Collectors.joining("\u2611")));
|
.collect(Collectors.joining("\n")));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
@@ -556,7 +559,8 @@ public class InspectRecordServiceImpl implements InspectRecordService {
|
|||||||
System.out.println(data);
|
System.out.println(data);
|
||||||
LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
|
LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
|
||||||
Configure config = Configure.builder().
|
Configure config = Configure.builder().
|
||||||
bind("dataDtos", policy).build();
|
bind("dataDtos", policy)
|
||||||
|
.bind("ionPairAndCEVOS", policy).build();
|
||||||
return buildDocFileAndUploadToOss(entrustInfo.getId(), templatePath, config, data);
|
return buildDocFileAndUploadToOss(entrustInfo.getId(), templatePath, config, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -579,25 +583,51 @@ public class InspectRecordServiceImpl implements InspectRecordService {
|
|||||||
|
|
||||||
XWPFTemplate template = XWPFTemplate.compile(bis, config).render(data);
|
XWPFTemplate template = XWPFTemplate.compile(bis, config).render(data);
|
||||||
NiceXWPFDocument document = template.getXWPFDocument();
|
NiceXWPFDocument document = template.getXWPFDocument();
|
||||||
|
|
||||||
List<XWPFTable> tables = document.getTables();
|
List<XWPFTable> tables = document.getTables();
|
||||||
XWPFTable table = tables.get(tables.size() - 1); // 获取最后一个表格
|
XWPFTable table = tables.get(tables.size() - 1); // 获取最后一个表格
|
||||||
|
|
||||||
int sampleSize = (int) data.get("sampleSize");
|
|
||||||
|
|
||||||
// **处理合并单元格**
|
String type = (String) data.get("type");
|
||||||
int startRow = 1; // 从第二行开始(索引从0开始,所以第二行是索引1)
|
|
||||||
int mergeStep = 4; // 每4行合并一次
|
|
||||||
|
|
||||||
// 指定需要合并的列(注意索引从0开始)
|
if (type.equals("inVitro")) {
|
||||||
int[] mergeColumns = {0, 1, 2, 3, 4, 9}; // 1、2、3、4、5、10列的索引分别是 0, 1, 2, 3, 4, 9
|
int startRow = 1; // 从第二行开始(表头是第一行,索引从0开始)
|
||||||
|
// **处理合并单元格**
|
||||||
|
int mergeStep = 4; // 每4行合并一次
|
||||||
|
int[] mergeColumns = {0, 1, 2, 3, 4, 9}; // 合并的列:第1、2、3、4、5、10列,索引分别是 0, 1, 2, 3, 4, 9
|
||||||
|
|
||||||
// 遍历表格数据行
|
// 遍历表格数据行
|
||||||
for (int rowIndex = startRow; rowIndex < table.getNumberOfRows(); rowIndex += mergeStep) {
|
for (int rowIndex = startRow; rowIndex < table.getNumberOfRows(); rowIndex += mergeStep) {
|
||||||
int endRow = Math.min(rowIndex + mergeStep - 1, table.getNumberOfRows() - 1); // 计算合并的终止行,防止越界
|
int endRow = Math.min(rowIndex + mergeStep - 1, table.getNumberOfRows() - 1); // 计算合并的终止行,防止越界
|
||||||
|
for (int col : mergeColumns) {
|
||||||
|
TableTools.mergeCellsVertically(table, col, rowIndex, endRow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
int compoundSize = (int) data.get("compoundSize"); // 获取compoundSize值
|
||||||
|
|
||||||
for (int col : mergeColumns) {
|
// **处理合并单元格**
|
||||||
TableTools.mergeCellsVertically(table, col, rowIndex, endRow);
|
int startRow = 1; // 从第二行开始(表头是第一行,索引从0开始)
|
||||||
|
String currentCompoundName = null;
|
||||||
|
int mergeStartRow = -1;
|
||||||
|
|
||||||
|
for (int rowIndex = startRow; rowIndex < table.getNumberOfRows(); rowIndex++) {
|
||||||
|
XWPFTableRow row = table.getRow(rowIndex);
|
||||||
|
XWPFTableCell cell = row.getCell(1); // 获取第二列的单元格(索引1)
|
||||||
|
String compoundName = cell.getText().trim();
|
||||||
|
|
||||||
|
if (currentCompoundName == null || !currentCompoundName.equals(compoundName)) {
|
||||||
|
// 如果当前化合物名称与上一行不同,则结束之前的合并
|
||||||
|
if (mergeStartRow >= 0 && rowIndex > mergeStartRow + 1) {
|
||||||
|
TableTools.mergeCellsVertically(table, 1, mergeStartRow, rowIndex - 1); // 合并第二列(列索引1)
|
||||||
|
}
|
||||||
|
currentCompoundName = compoundName;
|
||||||
|
mergeStartRow = rowIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理最后一组合并(循环结束后可能残留未合并的区域)
|
||||||
|
if (mergeStartRow >= 0 && mergeStartRow < table.getNumberOfRows() - 1) {
|
||||||
|
TableTools.mergeCellsVertically(table, 1, mergeStartRow, table.getNumberOfRows() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -615,7 +645,6 @@ public class InspectRecordServiceImpl implements InspectRecordService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成常规毒品的检验记录(贵阳禁毒)
|
* 生成常规毒品的检验记录(贵阳禁毒)
|
||||||
*/
|
*/
|
||||||
@@ -720,13 +749,18 @@ public class InspectRecordServiceImpl implements InspectRecordService {
|
|||||||
if (references == null || references.isEmpty()) {
|
if (references == null || references.isEmpty()) {
|
||||||
data.put("referenceMaterialName", "未找到试剂耗材数据!");
|
data.put("referenceMaterialName", "未找到试剂耗材数据!");
|
||||||
} else {
|
} else {
|
||||||
String firstStr = "\u2611" + " " + references.get(0).getReagentConsumableName() + "\n";
|
|
||||||
references.remove(references.get(0));
|
|
||||||
String referenceMaterialName = references.stream()
|
|
||||||
.map(reagent -> "\u3000\u3000\u2611" + " " + reagent.getReagentConsumableName())
|
|
||||||
.collect(Collectors.joining("\n"));
|
|
||||||
|
|
||||||
data.put("referenceMaterialName", firstStr + referenceMaterialName);
|
String referenceMaterialName = "";
|
||||||
|
if (references.size() == 1) {
|
||||||
|
referenceMaterialName = "\u2611" + " " + references.get(0).getReagentConsumableName();
|
||||||
|
} else {
|
||||||
|
String firstStr = "\u2611" + " " + references.get(0).getReagentConsumableName() + "\n";
|
||||||
|
references.remove(references.get(0));
|
||||||
|
referenceMaterialName = firstStr + references.stream()
|
||||||
|
.map(reagent -> "\u3000\u3000\u2611" + " " + reagent.getReagentConsumableName())
|
||||||
|
.collect(Collectors.joining("\n"));
|
||||||
|
}
|
||||||
|
data.put("referenceMaterialName", referenceMaterialName);
|
||||||
|
|
||||||
data.put("materialIngredient", references.stream()
|
data.put("materialIngredient", references.stream()
|
||||||
.map(reagent -> reagent.getReagentConsumableName())
|
.map(reagent -> reagent.getReagentConsumableName())
|
||||||
|
|||||||
Reference in New Issue
Block a user