From 9d4f07512a36fd332b77383ab935755f596e7e4e Mon Sep 17 00:00:00 2001 From: chen <2710907404@qq.com> Date: Wed, 26 Mar 2025 16:30:26 +0800 Subject: [PATCH] =?UTF-8?q?20250326=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TestRecordSampleDataController.java | 7 ++- .../TestRecordSampleDataExpandController.java | 3 +- .../TestRecordSampleDataConverter.java | 4 -- .../TestSampleDataExpandConverter.java | 5 -- .../inspection/dto/SampleInspectDataDTO.java | 12 ---- .../dto/TestSampleDataExpandDTO.java | 15 ----- .../entity/TestRecordSampleDataExpand.java | 3 +- .../TestRecordSampledataExpandService.java | 7 --- .../impl/TestRecordSampleDataServiceImpl.java | 17 ++--- ...TestRecordSampledataExpandServiceImpl.java | 62 +++++++------------ .../TestRecordSampleDataExpandMapper.xml | 2 +- 11 files changed, 42 insertions(+), 95 deletions(-) diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/TestRecordSampleDataController.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/TestRecordSampleDataController.java index 6cd6497..96f692e 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/TestRecordSampleDataController.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/TestRecordSampleDataController.java @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import digital.laboratory.platform.common.aop.annotation.DlpAccessLimit; import digital.laboratory.platform.common.core.util.R; import digital.laboratory.platform.common.mybatis.security.service.DLPUser; import digital.laboratory.platform.inspection.enums.BusinessType; @@ -143,9 +144,13 @@ public class TestRecordSampleDataController { return R.ok(deleted); } + @DlpAccessLimit(seconds = 60) // 设置该接口60秒内只能请求5次 @PutMapping("/updateEntrustTestData") @ApiOperation(value = "修改导入的实验数据", notes = "修改导入的实验数据") - public R updateEntrustTestData(@RequestBody @Valid @NotEmpty(message = "参数列表不能为空!") List dtoList) { + public R updateEntrustTestData(@RequestBody List dtoList) { + if (CollUtil.isEmpty(dtoList)) { + return R.failed("参数列表不能为空!"); + } try { testRecordSampleDataService.validateTestStatus(dtoList.get(0).getTestId()); boolean success = testRecordSampleDataService.updateEntrustTestData(dtoList); 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 5467975..cb228e6 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 @@ -11,6 +11,7 @@ import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.util.Collections; import java.util.List; /** @@ -42,7 +43,7 @@ public class TestRecordSampleDataExpandController { if (StrUtil.isBlank(updateDTO.getId())) { return R.failed("扩展数据id不能为空!"); } - return R.ok(testRecordSampledataExpandService.updateByDTO(updateDTO)); + return R.ok(testRecordSampledataExpandService.updateBatchByDTO(Collections.singletonList(updateDTO))); } } diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/convert/TestRecordSampleDataConverter.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/convert/TestRecordSampleDataConverter.java index 006807c..541d583 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/convert/TestRecordSampleDataConverter.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/convert/TestRecordSampleDataConverter.java @@ -25,14 +25,10 @@ public class TestRecordSampleDataConverter { TestRecordSampleData testRecordSampleData = new TestRecordSampleData(); testRecordSampleData.setId(dto.getId()); testRecordSampleData.setName(dto.getName()); - testRecordSampleData.setSampleNo(dto.getSampleNo()); testRecordSampleData.setTestId(dto.getTestId()); testRecordSampleData.setSampleConcentration(dto.getSampleConcentration()); testRecordSampleData.setCompoundName(dto.getCompoundName()); - testRecordSampleData.setRtTimeWithinError(dto.getRtTimeWithinError()); - testRecordSampleData.setRtTimeError(dto.getRtTimeError()); testRecordSampleData.setTargetRtTime(dto.getTargetRtTime()); - testRecordSampleData.setIsDetected(dto.getIsDetected()); testRecordSampleData.setSampleType(dto.getSampleType()); testRecordSampleData.setCompoundCnName(dto.getCompoundCnName()); testRecordSampleData.setWhetherCheckOut(dto.getWhetherCheckOut()); diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/convert/TestSampleDataExpandConverter.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/convert/TestSampleDataExpandConverter.java index cfc3be7..3439a89 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/convert/TestSampleDataExpandConverter.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/convert/TestSampleDataExpandConverter.java @@ -24,12 +24,7 @@ public class TestSampleDataExpandConverter { testRecordSampleDataExpand.setId(dto.getId()); testRecordSampleDataExpand.setTestDataId(dto.getTestDataId()); testRecordSampleDataExpand.setPeakArea(dto.getPeakArea()); - testRecordSampleDataExpand.setBasePeak(dto.getBasePeak()); - testRecordSampleDataExpand.setIonAbundanceRatio(dto.getIonAbundanceRatio()); - testRecordSampleDataExpand.setIonAbundanceRatioError(dto.getIonAbundanceRatioError()); - testRecordSampleDataExpand.setIonAbundanceRatioWithinError(dto.getIonAbundanceRatioWithinError()); testRecordSampleDataExpand.setFragmentRetTime(dto.getFragmentRetTime()); - testRecordSampleDataExpand.setMassToChargeRatio(dto.getMassToChargeRatio()); testRecordSampleDataExpand.setQualitativeIonPair(dto.getQualitativeIonPair()); return testRecordSampleDataExpand; } diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/dto/SampleInspectDataDTO.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/dto/SampleInspectDataDTO.java index 325ea93..6db9cf8 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/dto/SampleInspectDataDTO.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/dto/SampleInspectDataDTO.java @@ -20,9 +20,6 @@ public class SampleInspectDataDTO { @ApiModelProperty(value = "数据从机器中导出的唯一标识", example = "Sample123") private String name; - @ApiModelProperty(value = "样本编号", example = "SMP001") - private String sampleNo; - @ApiModelProperty(value = "实验ID", example = "TEST001") private String testId; @@ -32,18 +29,9 @@ public class SampleInspectDataDTO { @ApiModelProperty(value = "化合物名称", example = "Heroin") private String compoundName; - @ApiModelProperty(value = "保留时间是否在误差范围内,缴获物(-1~1), 生物样本(-2.5~2.5)", example = "0.5") - private String rtTimeWithinError; - - @ApiModelProperty(value = "保留时间相对误差(%)", example = "1.2") - private Double rtTimeError; - @ApiModelProperty(value = "检材保留时间(min)", example = "2.5") private Double targetRtTime; - @ApiModelProperty(value = "是否检出该物质 1 检出, 0 未检出", example = "1") - private Integer isDetected; - @ApiModelProperty(value = "样本类型 - QC(质控), STD(标准品), Analyte(待测样品)", example = "QC") private String sampleType; diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/dto/TestSampleDataExpandDTO.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/dto/TestSampleDataExpandDTO.java index f94059f..477ed83 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/dto/TestSampleDataExpandDTO.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/dto/TestSampleDataExpandDTO.java @@ -23,24 +23,9 @@ public class TestSampleDataExpandDTO { @ApiModelProperty(value = "峰面积", example = "12345.6789") private BigDecimal peakArea; - @ApiModelProperty(value = "是否是基峰, 1 是 | 0 不是", example = "true") - private Boolean basePeak; - - @ApiModelProperty(value = "离子丰度比(峰面积之比)", example = "0.85") - private BigDecimal ionAbundanceRatio; - - @ApiModelProperty(value = "离子丰度比相对偏差(%)", example = "-2.5") - private BigDecimal ionAbundanceRatioError; - - @ApiModelProperty(value = "离子丰度比偏差是否在误差范围内", example = "是") - private String ionAbundanceRatioWithinError; - @ApiModelProperty(value = "碎片保留时间(仅对 NPS 实验有用),求具体样本保留时间 = 碎片保留时间的平均值", example = "3.75") private BigDecimal fragmentRetTime; - @ApiModelProperty(value = "质荷比 (m/z),适用于 NPS 案件", example = "250.1") - private BigDecimal massToChargeRatio; - @ApiModelProperty(value = "定性离子对,生物案件使用", example = "m/z 100 > 50") private String qualitativeIonPair; } diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/entity/TestRecordSampleDataExpand.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/entity/TestRecordSampleDataExpand.java index a8367ab..b6be4d6 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/entity/TestRecordSampleDataExpand.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/entity/TestRecordSampleDataExpand.java @@ -1,6 +1,7 @@ package digital.laboratory.platform.inspection.entity; import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import digital.laboratory.platform.common.mybatis.base.BaseEntity; @@ -12,7 +13,7 @@ import lombok.Data; * @TableName b_test_record_sampledata_expand */ @Data -@TableName(value ="b_test_record_sampledata_expand") +@TableName(value ="b_test_record_sampledata_expand", autoResultMap = true) public class TestRecordSampleDataExpand extends BaseEntity { /** * 主键标识 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 31bf610..4206d27 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 @@ -43,13 +43,6 @@ public interface TestRecordSampledataExpandService extends IService saveExpDataByBusinessType(String testDataId, Drug drug, String businessType); - /** - *根据DTO去更新 - * @param updateDTO - * @return - */ - Boolean updateByDTO(TestSampleDataExpandDTO updateDTO); - /** * 根据DTO去批量更新 * 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 7febb59..5141c93 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 @@ -3,7 +3,6 @@ package digital.laboratory.platform.inspection.service.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; -import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -246,6 +245,7 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl getSampleTestDataByTestId(String testId, String type) { List list = baseMapper.queryTestRecordSampleDataVOList(Wrappers.lambdaQuery() .eq(TestRecordSampleData::getTestId, testId) + .orderByDesc(TestRecordSampleData::getCompoundName) .last("ORDER BY SUBSTRING_INDEX(name, '-', -1) + 0")); // List retList = new ArrayList<>(); // switch (BusinessType.getBusinessTypeByType(type)) { @@ -1562,6 +1562,7 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl sampleIdList = testRecord.getSampleTestList(); List sampleInfos = sampleInfoService.list(Wrappers.lambdaQuery() @@ -1569,11 +1570,11 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl sampleDataList = new ArrayList<>(); - TestRecordSampleData stdSampleData = createSampleData(compoundName, TestRecordSampleDataConstant.SAMPLE_TYPE_STD, TestRecordSampleDataConstant.SAMPLE_TYPE_STD + "-" + compoundName, testId); + TestRecordSampleData stdSampleData = createSampleData(compoundName, TestRecordSampleDataConstant.SAMPLE_TYPE_STD, TestRecordSampleDataConstant.SAMPLE_TYPE_STD + "-" + compoundName, testId, cnName); sampleDataList.add(stdSampleData); sampleInfos.forEach(item -> { - TestRecordSampleData sampleData = createSampleData(compoundName, TestRecordSampleDataConstant.SAMPLE_TYPE_ANALYTE, item.getAcceptNo(), testId); + TestRecordSampleData sampleData = createSampleData(compoundName, TestRecordSampleDataConstant.SAMPLE_TYPE_ANALYTE, item.getAcceptNo(), testId, cnName); sampleDataList.add(sampleData); }); @@ -1592,12 +1593,13 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl implements TestRecordSampledataExpandService { @@ -148,42 +150,6 @@ public class TestRecordSampledataExpandServiceImpl extends ServiceImpllambdaQuery() - .eq(TestRecordSampleDataExpand::getTestDataId, sampleDataExpand.getTestDataId()) - .eq(TestRecordSampleDataExpand::getBasePeak, Boolean.TRUE) - ); - if (!sampleDataExpand.getBasePeak() && basePeakData != null) { - // 获取标准物质的扩展信息,1 先查询对应的实验数据 2 根据实验数据的实验id以及化合物以及类型获取标准物质的实验数据信息 3 根据标准物质实验数据id取对应的扩展数据 - TestRecordSampleData testRecordSampleData = testRecordSampleDataService.getById(sampleDataExpand.getTestDataId()); - TestRecord testRecord = testRecordService.getById(testRecordSampleData.getTestId()); - List stdDataExpandList = null; - if (!testRecordSampleData.getSampleType().equals(TestRecordSampleDataConstant.SAMPLE_TYPE_STD)) { - TestRecordSampleData stdTestSampleData = testRecordSampleDataService.getOne(Wrappers.lambdaQuery().eq(TestRecordSampleData::getTestId, testRecordSampleData.getTestId()).eq(TestRecordSampleData::getCompoundName, testRecordSampleData.getCompoundName()).eq(TestRecordSampleData::getSampleType, TestRecordSampleDataConstant.SAMPLE_TYPE_STD)); - stdDataExpandList = super.list(Wrappers.lambdaQuery().eq(TestRecordSampleDataExpand::getTestDataId, stdTestSampleData.getId())); - } - if (sampleDataExpand.getPeakArea() != null && basePeakData.getPeakArea() != null) { - calculateIonAbundanceRatio(basePeakData, testRecord, stdDataExpandList, sampleDataExpand); - update = super.updateById(sampleDataExpand); - } - - } - } - return update; - } - /** * 根据DTO去批量更新 * @@ -194,35 +160,49 @@ public class TestRecordSampledataExpandServiceImpl extends ServiceImpl dtoList) { List expandList = TestSampleDataExpandConverter.dtoToEntityList(dtoList); if (super.updateBatchById(expandList)) { - CompletableFuture.runAsync(() -> { - List newExpandDatList = super.listByIds(expandList.stream().map(TestRecordSampleDataExpand::getId).collect(Collectors.toList())); +// 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<>(); expandDataGroupByDataId.forEach((key, value) -> { + log.info("Key: " + key + ", Value Size: " + value.size()); // 查询对应的基峰数据是否存在 TestRecordSampleDataExpand basePeakData = value.stream().filter(TestRecordSampleDataExpand::getBasePeak).findFirst().orElse(null); if (basePeakData != null) { // 获取标准物质的扩展信息,1 先查询对应的实验数据 2 根据实验数据的实验id以及化合物以及类型获取标准物质的实验数据信息 3 根据标准物质实验数据id取对应的扩展数据 TestRecordSampleData testRecordSampleData = testRecordSampleDataService.getById(key); + boolean isSTDSample = testRecordSampleData.getSampleType().equals(TestRecordSampleDataConstant.SAMPLE_TYPE_STD); TestRecord testRecord = testRecordService.getById(testRecordSampleData.getTestId()); List stdDataExpandList = null; - if (!testRecordSampleData.getSampleType().equals(TestRecordSampleDataConstant.SAMPLE_TYPE_STD)) { + if (!isSTDSample) { TestRecordSampleData stdTestSampleData = testRecordSampleDataService.getOne(Wrappers.lambdaQuery().eq(TestRecordSampleData::getTestId, testRecordSampleData.getTestId()).eq(TestRecordSampleData::getCompoundName, testRecordSampleData.getCompoundName()).eq(TestRecordSampleData::getSampleType, TestRecordSampleDataConstant.SAMPLE_TYPE_STD)); stdDataExpandList = super.list(Wrappers.lambdaQuery().eq(TestRecordSampleDataExpand::getTestDataId, stdTestSampleData.getId())); } List finalStdDataExpandList = stdDataExpandList; + testRecordSampleData.setIsDetected(1); // 默认检出 value.forEach(sampleDataExpand -> { calculateIonAbundanceRatio(basePeakData, testRecord, finalStdDataExpandList, sampleDataExpand); + if (!isSTDSample && testRecordSampleData.getIsDetected().equals(1) && sampleDataExpand.getIonAbundanceRatioWithinError().equals(TestRecordSampleDataConstant.NO)) { + testRecordSampleData.setIsDetected(0); + } calculateAfterResult.add(sampleDataExpand); }); + testRecordSampleData.setWhetherCheckOut( + (testRecordSampleData.getIsDetected().equals(1) ? TestRecordSampleDataConstant.CHECK_OUT : TestRecordSampleDataConstant.NOT_CHECK_OUT) + + testRecordSampleData.getCompoundCnName() + ); + testRecordSampleDataService.updateById(testRecordSampleData); } }); if (CollUtil.isNotEmpty(calculateAfterResult)) { super.updateBatchById(calculateAfterResult); } - }); +// }); return Boolean.TRUE; } return Boolean.FALSE; @@ -238,7 +218,7 @@ public class TestRecordSampledataExpandServiceImpl extends ServiceImpl finalStdDataExpandList, TestRecordSampleDataExpand sampleDataExpand) { if (sampleDataExpand.getPeakArea() != null && basePeakData.getPeakArea() != null) { - sampleDataExpand.setIonAbundanceRatio(sampleDataExpand.getPeakArea().divide(basePeakData.getPeakArea(), 5, BigDecimal.ROUND_HALF_UP)); + sampleDataExpand.setIonAbundanceRatio(sampleDataExpand.getPeakArea().divide(basePeakData.getPeakArea(), 5, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100))); if (CollUtil.isNotEmpty(finalStdDataExpandList)) { finalStdDataExpandList.forEach(stdDataExpand -> { if (stdDataExpand.getMassToChargeRatio().equals(sampleDataExpand.getMassToChargeRatio())) { diff --git a/dlp-drugtesting-biz/src/main/resources/mapper/TestRecordSampleDataExpandMapper.xml b/dlp-drugtesting-biz/src/main/resources/mapper/TestRecordSampleDataExpandMapper.xml index 487ab11..2721ac7 100644 --- a/dlp-drugtesting-biz/src/main/resources/mapper/TestRecordSampleDataExpandMapper.xml +++ b/dlp-drugtesting-biz/src/main/resources/mapper/TestRecordSampleDataExpandMapper.xml @@ -45,7 +45,7 @@ LEFT JOIN b_test_record_sampledata test ON exp.test_data_id = test.id - SELECT FROM b_test_record_sampledata_expand exp WHERE exp.test_data_id = #{testDataId}