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 db02417..6cd6497 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 @@ -30,6 +30,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; import java.security.Principal; import java.util.Collections; import java.util.List; @@ -144,15 +145,11 @@ public class TestRecordSampleDataController { @PutMapping("/updateEntrustTestData") @ApiOperation(value = "修改导入的实验数据", notes = "修改导入的实验数据") - public R> updateEntrustTestData(@RequestBody UpdateEntrustTestDataDTO dto) { + public R updateEntrustTestData(@RequestBody @Valid @NotEmpty(message = "参数列表不能为空!") List dtoList) { try { - testRecordSampleDataService.validateTestStatus(dto.getTestId()); - List list = dto.getList(); - if (CollUtil.isNotEmpty(list)) { - return R.ok(list.stream().map(testRecordSampleDataService::updateEntrustTestData).collect(Collectors.toList()),"实验数据保存成功"); - } else { - return R.ok(Collections.singletonList(testRecordSampleDataService.updateEntrustTestData(dto))); - } + testRecordSampleDataService.validateTestStatus(dtoList.get(0).getTestId()); + boolean success = testRecordSampleDataService.updateEntrustTestData(dtoList); + return success ? R.ok("实验数据保存成功") : R.failed("实验数据保存失败"); } catch (Exception e) { e.printStackTrace(); return R.failed("实验数据保存失败!" + e.getMessage()); @@ -287,6 +284,5 @@ public class TestRecordSampleDataController { return R.ok("更新成功!"); } - } 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 new file mode 100644 index 0000000..006807c --- /dev/null +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/convert/TestRecordSampleDataConverter.java @@ -0,0 +1,51 @@ +package digital.laboratory.platform.inspection.convert; + +import digital.laboratory.platform.inspection.dto.SampleInspectDataDTO; +import digital.laboratory.platform.inspection.entity.TestRecordSampleData; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author ChenJiangBao + * @version 1.0 + * @description: 检验数据转换器 + * @date 2025/3/25 17:08 + */ +public class TestRecordSampleDataConverter { + + /** + * dot 转 entity + * @param dto + * @return + */ + public static TestRecordSampleData dtoToEntity(SampleInspectDataDTO dto) { + if (dto == null) return null; + 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()); + return testRecordSampleData; + } + + /** + * dto列表转实体列表 + * @param dtoList + * @return + */ + public static List dtoToEntityList(List dtoList) { + if (dtoList == null) return Collections.emptyList(); + return dtoList.stream().map(TestRecordSampleDataConverter::dtoToEntity).collect(Collectors.toList()); + } +} 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 1402a39..cfc3be7 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 @@ -3,6 +3,10 @@ package digital.laboratory.platform.inspection.convert; import digital.laboratory.platform.inspection.dto.TestSampleDataExpandDTO; import digital.laboratory.platform.inspection.entity.TestRecordSampleDataExpand; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + /** * @author ChenJiangBao * @version 1.0 @@ -30,4 +34,14 @@ public class TestSampleDataExpandConverter { return testRecordSampleDataExpand; } + /** + * dto列表转实体列表 + * @param dtoList + * @return + */ + public static List dtoToEntityList(List dtoList) { + if (dtoList == null) return Collections.emptyList(); + return dtoList.stream().map(TestSampleDataExpandConverter::dtoToEntity).collect(Collectors.toList()); + } + } 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 new file mode 100644 index 0000000..325ea93 --- /dev/null +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/dto/SampleInspectDataDTO.java @@ -0,0 +1,58 @@ +package digital.laboratory.platform.inspection.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * 实验中样本检测结果数据 DTO类,包含扩展数据 + * @TableName b_test_record_sampledata + */ +@Data +@ApiModel(value = "SampleInspectDataDTO", description = "实验中样本检测结果数据 DTO类,包含扩展数据") +public class SampleInspectDataDTO { + + @ApiModelProperty(value = "主键标识", example = "123456789") + private String id; + + @ApiModelProperty(value = "数据从机器中导出的唯一标识", example = "Sample123") + private String name; + + @ApiModelProperty(value = "样本编号", example = "SMP001") + private String sampleNo; + + @ApiModelProperty(value = "实验ID", example = "TEST001") + private String testId; + + @ApiModelProperty(value = "样品浓度", example = "8.9") + private String sampleConcentration; + + @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; + + @ApiModelProperty(value = "检测的化合物的中文名字", example = "海洛因") + private String compoundCnName; + + @ApiModelProperty("是否检出, 定性结果") + private String whetherCheckOut; + + @ApiModelProperty("样本检验扩展数据列表") + private List expandList; +} diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/dto/TestRecordSampleDataDocDTO.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/dto/TestRecordSampleDataDocDTO.java new file mode 100644 index 0000000..7dbdb1e --- /dev/null +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/dto/TestRecordSampleDataDocDTO.java @@ -0,0 +1,56 @@ +package digital.laboratory.platform.inspection.dto; + +import digital.laboratory.platform.inspection.entity.TestRecordSampleData; +import lombok.Data; + +@Data +public class TestRecordSampleDataDocDTO extends TestRecordSampleData { + + /** + * 离子丰度比 | 峰面积之比 + * p 表示打印 (Print) + */ + private String pIonAbundanceRatio; + + /** + * 离子丰度比相对偏差(%) + * 计算公式:(目标物离子丰度比 - 标准物离子丰度比) / 标准物质离子丰度比 * 100 + * p 表示打印 (Print) + */ + private String pIonAbundanceRatioError; + + /** + * 离子丰度比偏差是否在误差范围内 + * p 表示打印 (Print) + */ + private String pIonAbundanceRatioWithinError; + + /** + * 目标物保留时间 + * p 表示打印 (Print) + */ + private String pTargetRtTime; + + /** + * 保留时间偏差 + * p 表示打印 (Print) + */ + private String pRtTimeError; + + /** + * 保留时间偏差是否在误差范围内 + * p 表示打印 (Print) + */ + private String pRtTimeWithinError; + + /** + * 是否检测到目标物 + * p 表示打印 (Print) + */ + private String pIsDetected; + + /** + * 样本索引编号 + */ + private String indexNum; +} diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/entity/TestRecordSampleData.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/entity/TestRecordSampleData.java index 8c76281..38659ae 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/entity/TestRecordSampleData.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/entity/TestRecordSampleData.java @@ -69,6 +69,9 @@ public class TestRecordSampleData extends BaseEntity { @ApiModelProperty(value = "检测的化合物的中文名字", example = "海洛因") private String compoundCnName; + @ApiModelProperty("是否检出, 定性结果") + private String whetherCheckOut; + public TestRecordSampleData() { } diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/mapper/TestRecordSampleDataMapper.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/mapper/TestRecordSampleDataMapper.java index 2c268ac..ae49aa3 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/mapper/TestRecordSampleDataMapper.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/mapper/TestRecordSampleDataMapper.java @@ -1,5 +1,6 @@ package digital.laboratory.platform.inspection.mapper; +import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -9,6 +10,7 @@ import digital.laboratory.platform.inspection.dto.DataSolutionSampleDTO; import digital.laboratory.platform.inspection.dto.TaskTestDataDTO; import digital.laboratory.platform.inspection.entity.TestRecordSampleData; import digital.laboratory.platform.inspection.vo.ESTBusinessInfoVO; +import digital.laboratory.platform.inspection.vo.TestRecordSampleDataVO; import digital.laboratory.platform.inspection.vo.TestResultBusinessVO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -25,6 +27,13 @@ import java.util.List; @Mapper public interface TestRecordSampleDataMapper extends BaseMapper { + /** + * 查询检验数据vo类,会携带扩展数据的list属性 + * @param wrapper + * @return + */ + List queryTestRecordSampleDataVOList(@Param(Constants.WRAPPER) Wrapper wrapper); + /** * 通过业务id查询委托表、筛查表、任务表 * @param qw diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/TestRecordSampleDataService.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/TestRecordSampleDataService.java index 86795bb..a54ab42 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/TestRecordSampleDataService.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/TestRecordSampleDataService.java @@ -93,10 +93,10 @@ public interface TestRecordSampleDataService extends IService dtoList); /** * 获取任务实验结果数据 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 63dd34e..31bf610 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 @@ -50,4 +50,11 @@ public interface TestRecordSampledataExpandService extends IService dtoList); } diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/InspectRecordServiceImpl.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/InspectRecordServiceImpl.java index bc71205..e965ed2 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/InspectRecordServiceImpl.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/InspectRecordServiceImpl.java @@ -18,7 +18,7 @@ import digital.laboratory.platform.inspection.entity.TestRecordSampleDataExpand; import digital.laboratory.platform.inspection.enums.BusinessType; import digital.laboratory.platform.inspection.enums.TestRecordFileUrl; import digital.laboratory.platform.inspection.service.*; -import digital.laboratory.platform.inspection.vo.TestRecordSampleDataVO; +import digital.laboratory.platform.inspection.dto.TestRecordSampleDataDocDTO; import digital.laboratory.platform.inspetion.api.entity.EntrustInfo; import digital.laboratory.platform.inspetion.api.entity.SampleInfo; import digital.laboratory.platform.inspetion.api.entity.TargetObject; @@ -143,7 +143,7 @@ public class InspectRecordServiceImpl implements InspectRecordService { Map> dataMap = dataList.stream() .collect(Collectors.groupingBy(TestRecordSampleData::getCompoundName)); - List dataDtos = new ArrayList<>(); + List dataDtos = new ArrayList<>(); // 遍历化合物组 for (Map.Entry> entry : dataMap.entrySet()) { @@ -151,7 +151,7 @@ public class InspectRecordServiceImpl implements InspectRecordService { List list = entry.getValue(); // 添加空白数据 - TestRecordSampleDataVO blankVo = new TestRecordSampleDataVO(); + TestRecordSampleDataDocDTO blankVo = new TestRecordSampleDataDocDTO(); blankVo.setName("空白" + materialType); blankVo.setCompoundName(compoundName); blankVo.setPTargetRtTime("/"); @@ -170,7 +170,7 @@ public class InspectRecordServiceImpl implements InspectRecordService { // 处理标准样品(STD) if (map.containsKey("STD")) { TestRecordSampleData std = map.get("STD").get(0); - TestRecordSampleDataVO stdVo = new TestRecordSampleDataVO(); + TestRecordSampleDataDocDTO stdVo = new TestRecordSampleDataDocDTO(); BeanUtils.copyProperties(std, stdVo); List expandList = dataExpandMap.get(std.getId()); if (expandList != null) { @@ -196,10 +196,10 @@ public class InspectRecordServiceImpl implements InspectRecordService { List analyte = map.get("Analyte"); analyte.sort(testRecordSampleDataService.getSortBySampleNo()); - List dataVOS = new ArrayList<>(); + List dataVOS = new ArrayList<>(); for (int i = 0; i < analyte.size(); i++) { TestRecordSampleData item = analyte.get(i); - TestRecordSampleDataVO vo = new TestRecordSampleDataVO(); + TestRecordSampleDataDocDTO vo = new TestRecordSampleDataDocDTO(); BeanUtils.copyProperties(item, vo); vo.setPTargetRtTime(vo.getTargetRtTime().toString()); vo.setPRtTimeError(vo.getRtTimeError().toString()); 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 55d950e..bf612e1 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 @@ -21,6 +21,7 @@ import digital.laboratory.platform.common.core.util.R; import digital.laboratory.platform.common.mybatis.security.service.DLPUser; import digital.laboratory.platform.comservice.entity.DlpDictData; import digital.laboratory.platform.comservice.feign.RemoteDictDataService; +import digital.laboratory.platform.inspection.convert.TestRecordSampleDataConverter; import digital.laboratory.platform.inspection.enums.BusinessType; import digital.laboratory.platform.inspection.enums.StdSolutionNum; import digital.laboratory.platform.inspection.enums.TaskTestDataStatus; @@ -37,10 +38,7 @@ import digital.laboratory.platform.inspection.service.*; import digital.laboratory.platform.inspection.utils.datafile.hair.HairSewageCompoundData; import digital.laboratory.platform.inspection.utils.datafile.nps.NPSDataFileStruct; import digital.laboratory.platform.inspection.utils.datafile.nps.NPSTestDetailDataStruct; -import digital.laboratory.platform.inspection.vo.ESTBusinessInfoVO; -import digital.laboratory.platform.inspection.vo.ResultConcentrationVO; -import digital.laboratory.platform.inspection.vo.TestRecordReagentVO; -import digital.laboratory.platform.inspection.vo.TestResultBusinessVO; +import digital.laboratory.platform.inspection.vo.*; import digital.laboratory.platform.inspetion.api.entity.EntrustInfo; import digital.laboratory.platform.inspetion.api.entity.SampleInfo; import digital.laboratory.platform.inspetion.api.entity.TestRecord; @@ -246,7 +244,7 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl getSampleTestDataByTestId(String testId, String type) { - List list = this.list(Wrappers.lambdaQuery() + List list = baseMapper.queryTestRecordSampleDataVOList(Wrappers.lambdaQuery() .eq(TestRecordSampleData::getTestId, testId) .last("ORDER BY SUBSTRING_INDEX(name, '-', -1) + 0")); // List retList = new ArrayList<>(); @@ -419,64 +417,20 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl dtoList) { + List testRecordSampleDataList = TestRecordSampleDataConverter.dtoToEntityList(dtoList); + if (super.updateBatchById(testRecordSampleDataList)) { + // 开启异步执行 + CompletableFuture.runAsync(() -> { + testRecordSampleDataList.forEach(item -> calculateInspectData(item.getId())); + }); + return testRecordSampledataExpandService.updateBatchByDTO(dtoList.stream().flatMap(dto -> dto.getExpandList().stream()).collect(Collectors.toList())); } -// // 根据成功标识返回 -// if (saved) { -// // 保存成功, 返回成功的json对象 -// return dtoParam; -// } else { -// // 保存失败, 返回之前的json对象 -// return oldObject; -// } + 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 1ee2d40..1abebec 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 @@ -28,16 +28,18 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Map; +import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; /** -* @author ChenJiangBao -* @description 针对表【b_test_record_sampledata_expand(样本检验数据的扩展信息)】的数据库操作Service实现 -* @createDate 2025-03-19 14:58:17 -*/ + * @author ChenJiangBao + * @description 针对表【b_test_record_sampledata_expand(样本检验数据的扩展信息)】的数据库操作Service实现 + * @createDate 2025-03-19 14:58:17 + */ @Service public class TestRecordSampledataExpandServiceImpl extends ServiceImpl - implements TestRecordSampledataExpandService{ + implements TestRecordSampledataExpandService { @Resource private TestRecordService testRecordService; @@ -50,6 +52,7 @@ public class TestRecordSampledataExpandServiceImpl extends ServiceImpllambdaQuery().eq(TestRecordSampleDataExpand::getTestDataId, stdTestSampleData.getId())); } if (sampleDataExpand.getPeakArea() != null && basePeakData.getPeakArea() != null) { - sampleDataExpand.setIonAbundanceRatio(sampleDataExpand.getPeakArea().divide(basePeakData.getPeakArea(), 5, BigDecimal.ROUND_HALF_UP)); - if (CollUtil.isNotEmpty(stdDataExpandList)) { - stdDataExpandList.forEach(stdDataExpand -> { - if (stdDataExpand.getMassToChargeRatio().equals(sampleDataExpand.getMassToChargeRatio())) { - BigDecimal ionAbundanceRatioError = sampleDataExpand.getIonAbundanceRatio() - .subtract(stdDataExpand.getIonAbundanceRatio()) - .divide(stdDataExpand.getIonAbundanceRatio(), 5, BigDecimal.ROUND_HALF_UP) - .multiply(BigDecimal.valueOf(100)); - sampleDataExpand.setIonAbundanceRatioError(ionAbundanceRatioError); - if (testRecord.getBusinessType().equals(BusinessType.NPS_CASE.getBusinessType())) { - sampleDataExpand.setIonAbundanceRatioWithinError(processInspectDataService.getWithinErrorText(ionAbundanceRatioError, processInspectDataService.getErrorRange(sampleDataExpand.getIonAbundanceRatio()))); - } else { - sampleDataExpand.setIonAbundanceRatioWithinError(processInspectDataService.calculateHairCaseIonAbundanceRatioWithinError(ionAbundanceRatioError.doubleValue(), stdDataExpand.getIonAbundanceRatio().doubleValue())); - } - } - }); - } + calculateIonAbundanceRatio(basePeakData, testRecord, stdDataExpandList, sampleDataExpand); update = super.updateById(sampleDataExpand); } @@ -195,6 +184,79 @@ 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())); + Map> expandDataGroupByDataId = newExpandDatList.stream().collect(Collectors.groupingBy(TestRecordSampleDataExpand::getTestDataId)); + List calculateAfterResult = new ArrayList<>(); + expandDataGroupByDataId.forEach((key, value) -> { + // 查询对应的基峰数据是否存在 + TestRecordSampleDataExpand basePeakData = value.stream().filter(TestRecordSampleDataExpand::getBasePeak).findFirst().orElse(null); + + if (basePeakData != null) { + // 获取标准物质的扩展信息,1 先查询对应的实验数据 2 根据实验数据的实验id以及化合物以及类型获取标准物质的实验数据信息 3 根据标准物质实验数据id取对应的扩展数据 + TestRecordSampleData testRecordSampleData = testRecordSampleDataService.getById(key); + 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())); + } + List finalStdDataExpandList = stdDataExpandList; + value.forEach(sampleDataExpand -> { + calculateIonAbundanceRatio(basePeakData, testRecord, finalStdDataExpandList, sampleDataExpand); + calculateAfterResult.add(sampleDataExpand); + }); + } + + }); + if (CollUtil.isNotEmpty(calculateAfterResult)) { + super.updateBatchById(calculateAfterResult); + } + }); + return Boolean.TRUE; + } + return Boolean.FALSE; + } + + /** + * 计算离子丰度比 + * + * @param basePeakData 基准峰数据 + * @param testRecord 测试记录 + * @param finalStdDataExpandList 最终标准数据扩展列表 + * @param sampleDataExpand 样本数据扩展 + */ + private void calculateIonAbundanceRatio(TestRecordSampleDataExpand basePeakData, TestRecord testRecord, List finalStdDataExpandList, TestRecordSampleDataExpand sampleDataExpand) { + if (sampleDataExpand.getPeakArea() != null && basePeakData.getPeakArea() != null) { + sampleDataExpand.setIonAbundanceRatio(sampleDataExpand.getPeakArea().divide(basePeakData.getPeakArea(), 5, BigDecimal.ROUND_HALF_UP)); + if (CollUtil.isNotEmpty(finalStdDataExpandList)) { + finalStdDataExpandList.forEach(stdDataExpand -> { + if (stdDataExpand.getMassToChargeRatio().equals(sampleDataExpand.getMassToChargeRatio())) { + BigDecimal ionAbundanceRatioError = sampleDataExpand.getIonAbundanceRatio() + .subtract(stdDataExpand.getIonAbundanceRatio()) + .divide(stdDataExpand.getIonAbundanceRatio(), 5, BigDecimal.ROUND_HALF_UP) + .multiply(BigDecimal.valueOf(100)); + sampleDataExpand.setIonAbundanceRatioError(ionAbundanceRatioError); + if (testRecord.getBusinessType().equals(BusinessType.NPS_CASE.getBusinessType())) { + sampleDataExpand.setIonAbundanceRatioWithinError(processInspectDataService.getWithinErrorText(ionAbundanceRatioError, processInspectDataService.getErrorRange(sampleDataExpand.getIonAbundanceRatio()))); + } else { + sampleDataExpand.setIonAbundanceRatioWithinError(processInspectDataService.calculateHairCaseIonAbundanceRatioWithinError(ionAbundanceRatioError.doubleValue(), stdDataExpand.getIonAbundanceRatio().doubleValue())); + } + } + }); + } + } + } /** * 根据提供的参数创建一个TestRecordSampleDataExpand对象。 diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/vo/TestRecordSampleDataVO.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/vo/TestRecordSampleDataVO.java index 1b67bdc..2e7e752 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/vo/TestRecordSampleDataVO.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/vo/TestRecordSampleDataVO.java @@ -1,57 +1,74 @@ package digital.laboratory.platform.inspection.vo; -import digital.laboratory.platform.inspection.entity.TestRecordSampleData; +import digital.laboratory.platform.inspection.entity.TestRecordSampleDataExpand; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import java.math.BigDecimal; +import java.util.List; +/** + * 样本检验数据 VO类 + * @TableName b_test_record_sampledata + */ @Data -public class TestRecordSampleDataVO extends TestRecordSampleData { - /** - * 离子丰度比 | 峰面积之比 - * p 表示打印 (Print) - */ - private String pIonAbundanceRatio; - - /** - * 离子丰度比相对偏差(%) - * 计算公式:(目标物离子丰度比 - 标准物离子丰度比) / 标准物质离子丰度比 * 100 - * p 表示打印 (Print) - */ - private String pIonAbundanceRatioError; - - /** - * 离子丰度比偏差是否在误差范围内 - * p 表示打印 (Print) - */ - private String pIonAbundanceRatioWithinError; - - /** - * 目标物保留时间 - * p 表示打印 (Print) - */ - private String pTargetRtTime; - - /** - * 保留时间偏差 - * p 表示打印 (Print) - */ - private String pRtTimeError; - - /** - * 保留时间偏差是否在误差范围内 - * p 表示打印 (Print) - */ - private String pRtTimeWithinError; - - /** - * 是否检测到目标物 - * p 表示打印 (Print) - */ - private String pIsDetected; - - /** - * 样本索引编号 - */ - private String indexNum; +@ApiModel(value = "TestRecordSampleDataVO", description = "实验中样本检测结果数据 VO类") +public class TestRecordSampleDataVO { + + @ApiModelProperty(value = "主键标识", example = "123456789") + private String id; + + @ApiModelProperty(value = "数据从机器中导出的唯一标识", example = "Sample123") + private String name; + + @ApiModelProperty(value = "样本编号", example = "SMP001") + private String sampleNo; + + @ApiModelProperty(value = "实验ID", example = "TEST001") + private String testId; + + @ApiModelProperty(value = "标准品浓度", example = "10.5") + private String stdConcentration; + + @ApiModelProperty(value = "样品浓度", example = "8.9") + private String sampleConcentration; + + @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 = "标准品保留时间(min)", example = "2.6") + private Double stdRtTime; + + @ApiModelProperty(value = "是否检出该物质 1 检出, 0 未检出", example = "1") + private Integer isDetected; + + @ApiModelProperty(value = "样本类型 - QC(质控), STD(标准品), Analyte(待测样品)", example = "QC") + private String sampleType; + + @ApiModelProperty(value = "检验数据 JSON", example = "{\"mass\": 146, \"intensity\": 200}") + private String dataJson; + + @ApiModelProperty(value = "检验结果数据 JSON", example = "{\"result\": \"Positive\"}") + private String dataResultJson; + + @ApiModelProperty(value = "状态:0-待审核, 1-已审核, 2-已审批, 3-已上传", example = "1") + private Integer status; + + @ApiModelProperty(value = "检测的化合物的中文名字", example = "海洛因") + private String compoundCnName; + + @ApiModelProperty("是否检出, 定性结果") + private String whetherCheckOut; + + @ApiModelProperty("样本检验扩展数据列表") + private List expandList; } diff --git a/dlp-drugtesting-biz/src/main/resources/mapper/TestRecordSampleDataExpandMapper.xml b/dlp-drugtesting-biz/src/main/resources/mapper/TestRecordSampleDataExpandMapper.xml index b64b95c..487ab11 100644 --- a/dlp-drugtesting-biz/src/main/resources/mapper/TestRecordSampleDataExpandMapper.xml +++ b/dlp-drugtesting-biz/src/main/resources/mapper/TestRecordSampleDataExpandMapper.xml @@ -28,7 +28,7 @@ exp.base_peak, exp.ion_abundance_ratio, exp.ion_abundance_ratio_error, - exp.fragment_ret_time + exp.fragment_ret_time, exp.ion_abundance_ratio_within_error, exp.mass_to_charge_ratio, exp.qualitative_ion_pair, @@ -45,4 +45,10 @@ LEFT JOIN b_test_record_sampledata test ON exp.test_data_id = test.id + + diff --git a/dlp-drugtesting-biz/src/main/resources/mapper/TestRecordSampleDataMapper.xml b/dlp-drugtesting-biz/src/main/resources/mapper/TestRecordSampleDataMapper.xml index 32b8872..327de4f 100644 --- a/dlp-drugtesting-biz/src/main/resources/mapper/TestRecordSampleDataMapper.xml +++ b/dlp-drugtesting-biz/src/main/resources/mapper/TestRecordSampleDataMapper.xml @@ -25,6 +25,34 @@ + + + + + + + + + + + + + + + + + + + + + + + @@ -48,8 +76,17 @@ create_by, update_time, update_by, - compound_cn_name + compound_cn_name, + whether_check_out + + + SELECT T.id,