|
|
|
@ -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<TestRecor |
|
|
|
|
* 根据DTO去批量更新 |
|
|
|
|
* |
|
|
|
|
* @param dtoList |
|
|
|
|
* @param testId 这里实验id之所以需要是因为如果当前更新的也有标准品的,则应该先计算标准品的,避免计算样本检测的空指针异常 |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Boolean updateBatchByDTO(List<TestSampleDataExpandDTO> dtoList) { |
|
|
|
|
public Boolean updateBatchByDTO(List<TestSampleDataExpandDTO> dtoList, String testId) { |
|
|
|
|
List<TestRecordSampleDataExpand> expandList = TestSampleDataExpandConverter.dtoToEntityList(dtoList); |
|
|
|
|
if (super.updateBatchById(expandList)) { |
|
|
|
|
CompletableFuture.runAsync(() -> { |
|
|
|
|
// CompletableFuture.runAsync(() -> {
|
|
|
|
|
List<TestRecordSampleDataExpand> newExpandDatList = super.list(Wrappers.<TestRecordSampleDataExpand>lambdaQuery() |
|
|
|
|
.in(TestRecordSampleDataExpand::getId, expandList.stream().map(TestRecordSampleDataExpand::getId).collect(Collectors.toList())) |
|
|
|
|
.isNotNull(TestRecordSampleDataExpand::getPeakArea) |
|
|
|
|
); |
|
|
|
|
Map<String, List<TestRecordSampleDataExpand>> expandDataGroupByDataId = newExpandDatList.stream().collect(Collectors.groupingBy(TestRecordSampleDataExpand::getTestDataId)); |
|
|
|
|
List<TestRecordSampleDataExpand> calculateAfterResult = new ArrayList<>(); |
|
|
|
|
Map<String, List<TestRecordSampleDataExpand>> expandDataGroupByDataId = getexpandDataGroup(testId, newExpandDatList); |
|
|
|
|
|
|
|
|
|
// List<TestRecordSampleDataExpand> calculateAfterResult = new ArrayList<>();
|
|
|
|
|
expandDataGroupByDataId.forEach((key, value) -> { |
|
|
|
|
log.info("Key: " + key + ", Value Size: " + value.size()); |
|
|
|
|
// 查询对应的基峰数据是否存在
|
|
|
|
@ -189,29 +188,64 @@ public class TestRecordSampledataExpandServiceImpl extends ServiceImpl<TestRecor |
|
|
|
|
if (!isSTDSample && testRecordSampleData.getIsDetected().equals(1) && sampleDataExpand.getIonAbundanceRatioWithinError().equals(TestRecordSampleDataConstant.NO)) { |
|
|
|
|
testRecordSampleData.setIsDetected(0); |
|
|
|
|
} |
|
|
|
|
calculateAfterResult.add(sampleDataExpand); |
|
|
|
|
// calculateAfterResult.add(sampleDataExpand);
|
|
|
|
|
}); |
|
|
|
|
testRecordSampleData.setWhetherCheckOut( |
|
|
|
|
(testRecordSampleData.getIsDetected().equals(1) ? TestRecordSampleDataConstant.CHECK_OUT : TestRecordSampleDataConstant.NOT_CHECK_OUT) |
|
|
|
|
+ testRecordSampleData.getCompoundCnName() |
|
|
|
|
); |
|
|
|
|
testRecordSampleDataService.updateById(testRecordSampleData); |
|
|
|
|
super.updateBatchById(value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
if (CollUtil.isNotEmpty(calculateAfterResult)) { |
|
|
|
|
super.updateBatchById(calculateAfterResult); |
|
|
|
|
} |
|
|
|
|
}).exceptionally(e -> { |
|
|
|
|
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<String, List<TestRecordSampleDataExpand>> getexpandDataGroup(String testId, List<TestRecordSampleDataExpand> newExpandDatList) { |
|
|
|
|
List<String> stdTestDataIds = null; |
|
|
|
|
if (StrUtil.isNotBlank(testId)) { |
|
|
|
|
List<TestRecordSampleData> stdSampleDataList = testRecordSampleDataService.list(Wrappers.<TestRecordSampleData>lambdaQuery().eq(TestRecordSampleData::getTestId, testId).eq(TestRecordSampleData::getSampleType, TestRecordSampleDataConstant.SAMPLE_TYPE_STD)); |
|
|
|
|
stdTestDataIds = stdSampleDataList.stream().map(TestRecordSampleData::getId).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
Map<String, List<TestRecordSampleDataExpand>> expandDataGroupByDataId = newExpandDatList.stream().collect(Collectors.groupingBy(TestRecordSampleDataExpand::getTestDataId, LinkedHashMap::new, Collectors.toList())); |
|
|
|
|
if (stdTestDataIds != null && !stdTestDataIds.isEmpty()) { |
|
|
|
|
Map<String, List<TestRecordSampleDataExpand>> 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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 计算离子丰度比 |
|
|
|
|
* |
|
|
|
|