diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/TestRecordSampleDataExpandController.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/TestRecordSampleDataExpandController.java index cb228e6..6c4b056 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/TestRecordSampleDataExpandController.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/TestRecordSampleDataExpandController.java @@ -43,7 +43,7 @@ public class TestRecordSampleDataExpandController { if (StrUtil.isBlank(updateDTO.getId())) { return R.failed("扩展数据id不能为空!"); } - return R.ok(testRecordSampledataExpandService.updateBatchByDTO(Collections.singletonList(updateDTO))); + return R.ok(testRecordSampledataExpandService.updateBatchByDTO(Collections.singletonList(updateDTO), null)); } } diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/TestRecordSampledataExpandService.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/TestRecordSampledataExpandService.java index 4206d27..42a4666 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/TestRecordSampledataExpandService.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/TestRecordSampledataExpandService.java @@ -47,7 +47,8 @@ public interface TestRecordSampledataExpandService extends IService dtoList); + Boolean updateBatchByDTO(List dtoList, String testId); } diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordSampleDataServiceImpl.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordSampleDataServiceImpl.java index 869eb0b..b731e8b 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordSampleDataServiceImpl.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordSampleDataServiceImpl.java @@ -211,6 +211,13 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl collect = TypeCasting(retList); + /** + * 根据测试ID和扩展数据列表获取分组后的扩展数据。 + * + * @param testId 测试ID + * @param newExpandDatList 新的扩展数据列表 + * @return 分组后的扩展数据 + */ return testRecordSampleDataList; } @@ -414,7 +421,7 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpllambdaUpdate().eq(TestRecord::getId, dtoList.get(0).getTestId()).set(TestRecord::getStatus, 2)); } // 开启异步执行 - CompletableFuture.runAsync(() -> { +// CompletableFuture.runAsync(() -> { testRecordSampleDataList.forEach(item -> calculateInspectData(item.getId())); - }).exceptionally(e -> { - log.error("计算保留时间以及相对误差出错!"); - e.printStackTrace(); - return null; - }); - return testRecordSampledataExpandService.updateBatchByDTO(dtoList.stream().flatMap(dto -> dto.getExpandList().stream()).collect(Collectors.toList())); +// }).exceptionally(e -> { +// log.error("计算保留时间以及相对误差出错!"); +// e.printStackTrace(); +// return null; +// }); + return testRecordSampledataExpandService.updateBatchByDTO(dtoList.stream().flatMap(dto -> dto.getExpandList().stream()).collect(Collectors.toList()), testRecord.getId()); } return false; } diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordSampledataExpandServiceImpl.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordSampledataExpandServiceImpl.java index 9bc6aa0..79819ff 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordSampledataExpandServiceImpl.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordSampledataExpandServiceImpl.java @@ -26,10 +26,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; @@ -154,19 +151,21 @@ public class TestRecordSampledataExpandServiceImpl extends ServiceImpl dtoList) { + public Boolean updateBatchByDTO(List dtoList, String testId) { List expandList = TestSampleDataExpandConverter.dtoToEntityList(dtoList); if (super.updateBatchById(expandList)) { - CompletableFuture.runAsync(() -> { +// CompletableFuture.runAsync(() -> { List newExpandDatList = super.list(Wrappers.lambdaQuery() .in(TestRecordSampleDataExpand::getId, expandList.stream().map(TestRecordSampleDataExpand::getId).collect(Collectors.toList())) .isNotNull(TestRecordSampleDataExpand::getPeakArea) ); - Map> expandDataGroupByDataId = newExpandDatList.stream().collect(Collectors.groupingBy(TestRecordSampleDataExpand::getTestDataId)); - List calculateAfterResult = new ArrayList<>(); + Map> expandDataGroupByDataId = getexpandDataGroup(testId, newExpandDatList); + +// List calculateAfterResult = new ArrayList<>(); expandDataGroupByDataId.forEach((key, value) -> { log.info("Key: " + key + ", Value Size: " + value.size()); // 查询对应的基峰数据是否存在 @@ -189,29 +188,64 @@ public class TestRecordSampledataExpandServiceImpl extends ServiceImpl { - log.error("离子丰度比相关计算出错!"); - e.printStackTrace(); - return null; - }); +// if (CollUtil.isNotEmpty(calculateAfterResult)) { +// super.updateBatchById(calculateAfterResult); +// } +// }).exceptionally(e -> { +// log.error("离子丰度比相关计算出错!"); +// e.printStackTrace(); +// return null; +// }); return Boolean.TRUE; } return Boolean.FALSE; } + /** + * 根据测试ID和新的扩展数据列表,获取按数据ID分组的扩展数据, 如果testId不为空, 则会根据标准物质进行排序,先计算标准物质的 + * + * @param testId 测试ID + * @param newExpandDatList 新的扩展数据列表 + * @return 按数据ID分组的扩展数据 + */ + private Map> getexpandDataGroup(String testId, List newExpandDatList) { + List stdTestDataIds = null; + if (StrUtil.isNotBlank(testId)) { + List stdSampleDataList = testRecordSampleDataService.list(Wrappers.lambdaQuery().eq(TestRecordSampleData::getTestId, testId).eq(TestRecordSampleData::getSampleType, TestRecordSampleDataConstant.SAMPLE_TYPE_STD)); + stdTestDataIds = stdSampleDataList.stream().map(TestRecordSampleData::getId).collect(Collectors.toList()); + } + Map> expandDataGroupByDataId = newExpandDatList.stream().collect(Collectors.groupingBy(TestRecordSampleDataExpand::getTestDataId, LinkedHashMap::new, Collectors.toList())); + if (stdTestDataIds != null && !stdTestDataIds.isEmpty()) { + Map> sortedMap = new LinkedHashMap<>(); + + // 先按 stdTestDataIds 的顺序放入 + for (String stdTestDataId : stdTestDataIds) { + if (expandDataGroupByDataId.containsKey(stdTestDataId)) { + sortedMap.put(stdTestDataId, expandDataGroupByDataId.get(stdTestDataId)); + } + } + + // 再放入剩余的 key(不在 stdTestDataIds 里的) + expandDataGroupByDataId.entrySet().stream() + .filter(entry -> !sortedMap.containsKey(entry.getKey())) + .forEach(entry -> sortedMap.put(entry.getKey(), entry.getValue())); + + // 替换原 map + expandDataGroupByDataId = sortedMap; + } + return expandDataGroupByDataId; + } + /** * 计算离子丰度比 *