20250326 更新

master
陈江保 3 days ago
parent 496f88f3ce
commit 9d4f07512a
  1. 7
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/TestRecordSampleDataController.java
  2. 3
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/TestRecordSampleDataExpandController.java
  3. 4
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/convert/TestRecordSampleDataConverter.java
  4. 5
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/convert/TestSampleDataExpandConverter.java
  5. 12
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/dto/SampleInspectDataDTO.java
  6. 15
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/dto/TestSampleDataExpandDTO.java
  7. 3
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/entity/TestRecordSampleDataExpand.java
  8. 7
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/TestRecordSampledataExpandService.java
  9. 17
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordSampleDataServiceImpl.java
  10. 62
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordSampledataExpandServiceImpl.java
  11. 2
      dlp-drugtesting-biz/src/main/resources/mapper/TestRecordSampleDataExpandMapper.xml

@ -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<SampleInspectDataDTO> dtoList) {
public R updateEntrustTestData(@RequestBody List<SampleInspectDataDTO> dtoList) {
if (CollUtil.isEmpty(dtoList)) {
return R.failed("参数列表不能为空!");
}
try {
testRecordSampleDataService.validateTestStatus(dtoList.get(0).getTestId());
boolean success = testRecordSampleDataService.updateEntrustTestData(dtoList);

@ -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)));
}
}

@ -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());

@ -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;
}

@ -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;

@ -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;
}

@ -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 {
/**
* 主键标识

@ -43,13 +43,6 @@ public interface TestRecordSampledataExpandService extends IService<TestRecordSa
*/
List<TestRecordSampleDataExpand> saveExpDataByBusinessType(String testDataId, Drug drug, String businessType);
/**
*根据DTO去更新
* @param updateDTO
* @return
*/
Boolean updateByDTO(TestSampleDataExpandDTO updateDTO);
/**
* 根据DTO去批量更新
*

@ -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<TestRecordSampl
public List<?> getSampleTestDataByTestId(String testId, String type) {
List<TestRecordSampleDataVO> list = baseMapper.queryTestRecordSampleDataVOList(Wrappers.<TestRecordSampleData>lambdaQuery()
.eq(TestRecordSampleData::getTestId, testId)
.orderByDesc(TestRecordSampleData::getCompoundName)
.last("ORDER BY SUBSTRING_INDEX(name, '-', -1) + 0"));
// List<Object> retList = new ArrayList<>();
// switch (BusinessType.getBusinessTypeByType(type)) {
@ -1562,6 +1562,7 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl<TestRecordSampl
Drug drug = reagentVO.getDrug();
String compoundName = drug.getEnglishName();
String cnName = drug.getName();
List<String> sampleIdList = testRecord.getSampleTestList();
List<SampleInfo> sampleInfos = sampleInfoService.list(Wrappers.<SampleInfo>lambdaQuery()
@ -1569,11 +1570,11 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl<TestRecordSampl
List<TestRecordSampleData> 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<TestRecordSampl
* 创建一个检验数据样本数据对象
*
* @param compoundName 化合物名称
* @param sampleType 样本类型
* @param sampleNo 样本编号
* @param testId 实验id
* @param sampleType 样本类型
* @param sampleNo 样本编号
* @param testId 实验id
* @param cnName
* @return 返回创建的测试记录样本数据对象
*/
private TestRecordSampleData createSampleData(String compoundName, String sampleType, String sampleNo, String testId) {
private TestRecordSampleData createSampleData(String compoundName, String sampleType, String sampleNo, String testId, String cnName) {
TestRecordSampleData data = new TestRecordSampleData();
data.setCompoundName(compoundName);
data.setSampleNo(sampleNo);
@ -1606,6 +1608,7 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl<TestRecordSampl
data.setStatus(TaskTestDataStatus.WAIT_REVIEW.getCode());
data.setTestId(testId);
data.setId(IdWorker.getIdStr());
data.setCompoundCnName(cnName);
return data;
}

@ -21,6 +21,7 @@ import digital.laboratory.platform.inspection.service.TestRecordService;
import digital.laboratory.platform.inspection.utils.datafile.nps.NPSTestDetailDataStruct;
import digital.laboratory.platform.inspetion.api.entity.TestRecord;
import digital.laboratory.platform.sys.entity.Drug;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -37,6 +38,7 @@ import java.util.stream.Collectors;
* @description 针对表b_test_record_sampledata_expand(样本检验数据的扩展信息)的数据库操作Service实现
* @createDate 2025-03-19 14:58:17
*/
@Slf4j
@Service
public class TestRecordSampledataExpandServiceImpl extends ServiceImpl<TestRecordSampleDataExpandMapper, TestRecordSampleDataExpand>
implements TestRecordSampledataExpandService {
@ -148,42 +150,6 @@ public class TestRecordSampledataExpandServiceImpl extends ServiceImpl<TestRecor
return testRecordSampleDataExpandList;
}
/**
* 根据DTO去更新
*
* @param updateDTO
* @return
*/
@Override
public Boolean updateByDTO(TestSampleDataExpandDTO updateDTO) {
TestRecordSampleDataExpand testRecordSampleDataExpand = TestSampleDataExpandConverter.dtoToEntity(updateDTO);
boolean update = super.updateById(testRecordSampleDataExpand);
if (update) {
TestRecordSampleDataExpand sampleDataExpand = super.getById(updateDTO.getId());
// 查询对应的基峰数据是否存在
TestRecordSampleDataExpand basePeakData = super.getOne(Wrappers.<TestRecordSampleDataExpand>lambdaQuery()
.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<TestRecordSampleDataExpand> stdDataExpandList = null;
if (!testRecordSampleData.getSampleType().equals(TestRecordSampleDataConstant.SAMPLE_TYPE_STD)) {
TestRecordSampleData stdTestSampleData = testRecordSampleDataService.getOne(Wrappers.<TestRecordSampleData>lambdaQuery().eq(TestRecordSampleData::getTestId, testRecordSampleData.getTestId()).eq(TestRecordSampleData::getCompoundName, testRecordSampleData.getCompoundName()).eq(TestRecordSampleData::getSampleType, TestRecordSampleDataConstant.SAMPLE_TYPE_STD));
stdDataExpandList = super.list(Wrappers.<TestRecordSampleDataExpand>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<TestRecor
public Boolean updateBatchByDTO(List<TestSampleDataExpandDTO> dtoList) {
List<TestRecordSampleDataExpand> expandList = TestSampleDataExpandConverter.dtoToEntityList(dtoList);
if (super.updateBatchById(expandList)) {
CompletableFuture.runAsync(() -> {
List<TestRecordSampleDataExpand> newExpandDatList = super.listByIds(expandList.stream().map(TestRecordSampleDataExpand::getId).collect(Collectors.toList()));
// 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<>();
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<TestRecordSampleDataExpand> stdDataExpandList = null;
if (!testRecordSampleData.getSampleType().equals(TestRecordSampleDataConstant.SAMPLE_TYPE_STD)) {
if (!isSTDSample) {
TestRecordSampleData stdTestSampleData = testRecordSampleDataService.getOne(Wrappers.<TestRecordSampleData>lambdaQuery().eq(TestRecordSampleData::getTestId, testRecordSampleData.getTestId()).eq(TestRecordSampleData::getCompoundName, testRecordSampleData.getCompoundName()).eq(TestRecordSampleData::getSampleType, TestRecordSampleDataConstant.SAMPLE_TYPE_STD));
stdDataExpandList = super.list(Wrappers.<TestRecordSampleDataExpand>lambdaQuery().eq(TestRecordSampleDataExpand::getTestDataId, stdTestSampleData.getId()));
}
List<TestRecordSampleDataExpand> 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<TestRecor
*/
private void calculateIonAbundanceRatio(TestRecordSampleDataExpand basePeakData, TestRecord testRecord, List<TestRecordSampleDataExpand> 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())) {

@ -45,7 +45,7 @@
LEFT JOIN b_test_record_sampledata test ON exp.test_data_id = test.id
</sql>
<select id="queryExpandDataByTestDataId" resultType="digital.laboratory.platform.inspection.entity.TestRecordSampleDataExpand">
<select id="queryExpandDataByTestDataId" resultMap="BaseResultMap" resultType="digital.laboratory.platform.inspection.entity.TestRecordSampleDataExpand">
SELECT
<include refid="Base_Column_List"></include>
FROM b_test_record_sampledata_expand exp WHERE exp.test_data_id = #{testDataId}

Loading…
Cancel
Save