fix:旧beta增加能量刻度自动校正数据;旧beta 自动处理分析失败的能谱也能查询加载

This commit is contained in:
xiaoguangbin 2024-11-28 16:54:47 +08:00
parent c9b406633d
commit 92f471955d
9 changed files with 236 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package org.jeecg.modules.entity.vo;
import lombok.Data;
import org.jeecg.common.util.NumUtil;
import java.io.Serializable;
@ -17,4 +18,7 @@ public class TableWidget implements Serializable {
private String fwhmKeV;
public void setChannel(Double channel) {
this.channel = NumUtil.fixedMax(6, channel);
}
}

View File

@ -1,7 +1,19 @@
package org.jeecg.modules.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.base.entity.original.GardsSampleData;
import java.util.List;
public interface GardsSampleDataSpectrumMapper extends BaseMapper<GardsSampleData> {
@Select(value = "select " +
"gsd.SAMPLE_ID as sampleId,gsd.input_file_name as inputFileName " +
"from ORIGINAL.GARDS_SAMPLE_AUX gsa inner join ORIGINAL.GARDS_SAMPLE_DATA gsd on gsa.sample_id = gsd.sample_id " +
"where gsa.measurement_id = #{measurementId} and gsd.SAMPLE_TYPE = #{systemType} and gsd.data_type=#{dataType} " +
"AND SPECTRAL_QUALIFIE='FULL' and TRIM(gsd.SITE_DET_CODE) = #{detectorId}")
public List<GardsSampleData> getSampleIdAndInputFileName(@Param("measurementId") String measurementId,
@Param("dataType") String dataType, @Param("systemType") String systemType, String detectorId);
}

View File

@ -22,6 +22,13 @@ public interface SpectrumAnalysisMapper {
Page<GardsSampleDataSpectrum> getDBSpectrumList(IPage<GardsSampleDataSpectrum> page, GardsSampleDataSpectrum gardsSampleData, String dbName, List<String> stationTypes, boolean CollectStopB, boolean AcqStartB, String startTime, String endTime, List<String> userStations, boolean AllUsers, String orderField, String orderType);
Page<GardsSampleDataSpectrum> getDBSpectrumListByLeftJoin(IPage<GardsSampleDataSpectrum> page,
GardsSampleDataSpectrum gardsSampleData, String dbName,
List<String> stationTypes, boolean CollectStopB,
boolean AcqStartB, String startTime, String endTime,
List<String> userStations, boolean AllUsers,
String orderField, String orderType);
Page<GardsSampleDataSpectrum> loadSampleData(IPage<GardsSampleDataSpectrum> page, GardsSampleDataSpectrum gardsSampleData, List<String> stationTypes, boolean CollectStopB, boolean AcqStartB, String startTime, String endTime, List<String> userStations, boolean AllUsers, String orderField, String orderType);
SpectrumFileRecord getDBSpectrumFilePath(String dbName, Integer sampleId, Integer analysisID);

View File

@ -106,6 +106,75 @@
</if>
</select>
<select id="getDBSpectrumListByLeftJoin" resultType="org.jeecg.modules.entity.GardsSampleDataSpectrum">
select c.sample_id sampleId,
b.station_code stationName,
a.detector_code detectorsName,
c.sample_type sampleType,
c.data_type dataType,
c.spectral_qualifie spectralQualifie,
c.collect_stop collectStop,
c.acquisition_start acquisitionStart,
c.acquisition_real_sec acquisitionRealSec,
c.acquisition_live_sec acquisitionLiveSec,
d.IDANALYSIS analysitId,
d.analyst analyst,
c.status status,
c.input_file_name inputFileName
from
ORIGINAL.GARDS_SAMPLE_DATA c
left JOIN ${dbName} d on c.sample_id = d.sample_id
left JOIN CONFIGURATION.GARDS_DETECTORS a on c.detector_id = a.detector_id
left JOIN CONFIGURATION.GARDS_STATIONS b on c.station_id = b.station_id
<where>
c.data_type = 'S'
<if test=" gardsSampleData.sampleId != null ">
and c.sample_id = #{gardsSampleData.sampleId}
</if>
<if test=" gardsSampleData.stationName != null and gardsSampleData.stationName != '' ">
and b.station_code = #{gardsSampleData.stationName}
</if>
<if test=" gardsSampleData.detectorsName != null and gardsSampleData.detectorsName != '' ">
and a.detector_code = #{gardsSampleData.detectorsName}
</if>
<if test=" gardsSampleData.sampleType != null and gardsSampleData.sampleType != '' ">
and c.sample_type = #{gardsSampleData.sampleType}
</if>
<if test=" gardsSampleData.dataType != null and gardsSampleData.dataType != '' ">
and c.data_type = #{gardsSampleData.dataType}
</if>
<if test=" gardsSampleData.spectralQualifie != null and gardsSampleData.spectralQualifie != '' ">
and c.spectral_qualifie = #{gardsSampleData.spectralQualifie}
</if>
<if test=" gardsSampleData.status != null and gardsSampleData.status != '' ">
and c.status = #{gardsSampleData.status}
</if>
<if test=" CollectStopB == true ">
and c.collect_stop between TO_DATE(#{startTime}, 'yyyy-mm-dd hh24:mi:ss') and TO_DATE(#{endTime}, 'yyyy-mm-dd hh24:mi:ss')
</if>
<if test=" AcqStartB == true ">
and c.acquisition_start between TO_DATE(#{startTime}, 'yyyy-mm-dd hh24:mi:ss') and TO_DATE(#{endTime}, 'yyyy-mm-dd hh24:mi:ss')
</if>
<if test="AllUsers == false">
<if test=" userStations.size == 0 and userStations != null ">
and c.station_id in ('')
</if>
<if test=" userStations.size > 0 and userStations != null ">
and c.station_id in
<foreach collection="userStations" item="userStation" open="(" close=")" separator=",">
#{userStation}
</foreach>
</if>
</if>
</where>
<if test=" orderField != 'createTime' and orderField != '' and orderField != null and orderType != '' and orderType != null ">
ORDER BY ${orderField} ${orderType}
</if>
<if test=" orderField == 'createTime' or orderField == '' or orderField == null or orderType == '' or orderType == null ">
ORDER BY collectStop DESC
</if>
</select>
<select id="loadSampleData" resultType="org.jeecg.modules.entity.GardsSampleDataSpectrum">
select
c.sample_id sampleId,

View File

@ -13,4 +13,6 @@ public interface IGardsSampleAuxSpectrumService extends IService<GardsSampleAux>
Integer saveSampleAuxGamma(PHDFile phd, Integer sampleId);
GardsSampleAux getSampleAuxBySampleId(Integer sampleId);
}

View File

@ -13,4 +13,5 @@ public interface IGardsSampleDataSpectrumService extends IService<GardsSampleDat
Integer saveSampleDataGamma(PHDFile phd, String input_file_name, Integer station_id, Integer detect_id);
GardsSampleData getSampleByMId(String measurementId, String dataType, String systemType);
}

View File

@ -1,6 +1,7 @@
package org.jeecg.modules.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.util.DateUtils;
@ -115,4 +116,11 @@ public class GardsSampleAuxSpectrumServiceImpl extends ServiceImpl<GardsSampleAu
int insert = this.baseMapper.insert(sampleAux);
return insert;
}
@Override
public GardsSampleAux getSampleAuxBySampleId(Integer sampleId) {
LambdaQueryWrapper<GardsSampleAux> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(GardsSampleAux::getSampleId, sampleId);
return this.baseMapper.selectOne(queryWrapper);
}
}

View File

@ -13,10 +13,13 @@ import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct;
import org.jeecg.modules.service.IGardsSampleDataSpectrumService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.text.ParseException;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@Service("gardsSampleDataSpectrumService")
@DS("ora")
@ -139,4 +142,16 @@ public class GardsSampleDataSpectrumServiceImpl extends ServiceImpl<GardsSampleD
return insert;
}
@Override
public GardsSampleData getSampleByMId(String measurementId, String dataType, String systemType) {
String detectorId = measurementId.substring(0, 9);
final List<GardsSampleData> sampleDatas = this.baseMapper.getSampleIdAndInputFileName(measurementId, dataType, systemType, detectorId);
if(!CollectionUtils.isEmpty(sampleDatas)){
//如果查询出多条则需要根据inputFileName字段降序排序后返回第一个
final List<GardsSampleData> sortResult = sampleDatas.stream().sorted(Comparator.comparing(GardsSampleData::getInputFileName).reversed()).collect(Collectors.toList());
return sortResult.get(0);
}
return null;
}
}

View File

@ -14,6 +14,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.cache.Cache;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.shiro.SecurityUtils;
@ -32,6 +33,7 @@ import org.jeecg.modules.base.bizVo.BetaRLR;
import org.jeecg.modules.base.dto.*;
import org.jeecg.modules.base.entity.configuration.GardsDetectors;
import org.jeecg.modules.base.entity.configuration.GardsStations;
import org.jeecg.modules.base.entity.original.GardsSampleAux;
import org.jeecg.modules.base.entity.original.GardsSampleData;
import org.jeecg.modules.base.entity.rnman.*;
import org.jeecg.modules.base.enums.*;
@ -68,6 +70,7 @@ import java.util.stream.Collectors;
import static org.jeecg.modules.base.enums.ExportTemplate.*;
@Slf4j
@Service("spectrumAnalysisService")
@DS("ora")
public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements ISpectrumAnalysisService {
@ -287,7 +290,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
}
//声明分页page
Page<GardsSampleDataSpectrum> page = new Page<>(queryRequest.getPageNo(), queryRequest.getPageSize());
Page<GardsSampleDataSpectrum> sampleDataPage = spectrumAnalysisMapper.getDBSpectrumList(page, gardsSampleData, dbName, stationTypes, CollectStopB, AcqStartB, startTime, endTime, userStations, AllUsers, queryRequest.getField(), queryRequest.getOrder());
Page<GardsSampleDataSpectrum> sampleDataPage = spectrumAnalysisMapper.getDBSpectrumListByLeftJoin(page, gardsSampleData, dbName, stationTypes, CollectStopB, AcqStartB, startTime, endTime, userStations, AllUsers, queryRequest.getField(), queryRequest.getOrder());
sampleDataPage.getRecords().stream().forEach(item->{item.setDbName(tempDBName);});
result.setSuccess(true);
result.setResult(sampleDataPage);
@ -415,6 +418,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
File detTmp = null;
File qcTmp = null;
try {
// 如果存在则是分析成功 不存在是分析失败
if (Objects.nonNull(analysisID)) {
//查询数据库文件信息
SpectrumFileRecord dbSpectrumFilePath = spectrumAnalysisMapper.getDBSpectrumFilePath(dbName, sampleId, analysisID);
@ -656,9 +660,121 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
} else {
resultMap.clear();
}
} else {
Map<String, Object> sampleMap = new HashMap<>();
Map<String, Object> gasBgMap = new HashMap<>();
Map<String, Object> detBgMap = new HashMap<>();
Map<String, Object> qcMap = new HashMap<>();
// 获取当前样品谱文件名称
GardsSampleDataSpectrum sampleData = spectrumAnalysisMapper.getSampleData(sampleId);
String sampleFilePath = sampleData.getInputFileName();
String sampleFileName = StrUtil.subAfter(sampleFilePath, StringPool.SLASH, true);
//判断是否有公用变量的缓存
BetaDataFile betaDataFile = cache.getIfPresent(sampleFileName + "-" + userName);
if (Objects.isNull(betaDataFile)) {
betaDataFile = new BetaDataFile();
betaDataFile.setSampleFilePathName(spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() +
StringPool.SLASH + sampleFilePath);
sampleTmp = ftpUtil.downloadFile(betaDataFile.getSampleFilePathName());
//获取smaple文件解析结果
EnergySpectrumStruct struct = EnergySpectrumHandler.getSourceData(sampleTmp.getAbsolutePath());
if (Objects.nonNull(struct)) {
betaDataFile.setSampleStruct(struct);
betaDataFile.setSampleFilePathName(sampleFilePath);
betaDataFile.setSampleFileName(sampleFileName);
sampleMap = phdFileUtil.getSourceData(struct, null, null, "sample", betaDataFile);
sampleMap.put("fileName", betaDataFile.getSampleFileName());
resultMap.put("sample", sampleMap);
}
// 根据当前谱获取GasDetQC谱
GardsSampleAux aux = sampleAuxSpectrumService.getSampleAuxBySampleId(sampleId);
// 查询Det谱
GardsSampleData detSampleData = sampleDataSpectrumService.getSampleByMId(aux.getBkgdMeasurementId(),
DataTypeAbbr.DETBKPHD.getType(), sampleData.getSampleType());
// 查询Gas谱
GardsSampleData gasSampleData = sampleDataSpectrumService.getSampleByMId(aux.getGasBkgdMeasurementId(),
DataTypeAbbr.DETBKPHD.getType(), sampleData.getSampleType());
// 如果找不到sampledetgas谱文件数据则解析失败修改记录状态
if(StringUtils.isEmpty(sampleFilePath) || Objects.isNull(detSampleData)
|| StringUtils.isEmpty(detSampleData.getInputFileName())
|| Objects.isNull(gasSampleData) || StringUtils.isEmpty(gasSampleData.getInputFileName())){
result.error500("gas or det file is no exist or is error..");
return result;
}
String gasFilePath = gasSampleData.getInputFileName();
String gasFileName = StrUtil.subAfter(gasFilePath, StringPool.SLASH, true);
String detFilePath = detSampleData.getInputFileName();
String detFileName = StrUtil.subAfter(detFilePath, StringPool.SLASH, true);
// GAS
betaDataFile.setGasFilePathName(spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath()
+ StringPool.SLASH + gasFilePath);
betaDataFile.setGasFileName(gasFileName);
gasTmp = ftpUtil.downloadFile(betaDataFile.getGasFilePathName());
EnergySpectrumStruct gasStruct = EnergySpectrumHandler.getSourceData(gasTmp.getAbsolutePath());
if (Objects.nonNull(gasStruct)) {
betaDataFile.setGasStruct(gasStruct);
betaDataFile.setGasFilePathName(gasFilePath);
betaDataFile.setGasFileName(gasFileName);
gasBgMap = phdFileUtil.getSourceData(gasStruct, null, null, "gas", betaDataFile);
gasBgMap.put("fileName", betaDataFile.getGasFileName());
resultMap.put("gasBg", gasBgMap);
}
// DET
betaDataFile.setDetFilePathName(spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath()
+ StringPool.SLASH + detFilePath);
detTmp = ftpUtil.downloadFile(betaDataFile.getDetFilePathName());
EnergySpectrumStruct detStruct = EnergySpectrumHandler.getSourceData(detTmp.getAbsolutePath());
if (Objects.nonNull(detStruct)) {
betaDataFile.setDetStruct(detStruct);
betaDataFile.setDetFilePathName(detFilePath);
betaDataFile.setDetFileName(detFileName);
detBgMap = phdFileUtil.getSourceData(detStruct, null, null, "det", betaDataFile);
detBgMap.put("fileName", betaDataFile.getDetFileName());
resultMap.put("detBg", detBgMap);
}
String collectStartStr = DateUtils.formatDate(sampleData.getCollectStart(), "yyyy/MM/dd HH:mm:ss");
// 查询Qc谱
String qcFilePath = spectrumAnalysisMapper.getQCFilePath(sampleData.getSiteDetCode(), collectStartStr);
if (StringUtils.isNotBlank(qcFilePath)) {
GardsSampleData qcSampleData = spectrumAnalysisMapper.findSampleByFilePath(qcFilePath);
String qcFileName = StrUtil.subAfter(qcFilePath, StringPool.SLASH, true);
EnergySpectrumStruct qcStruct = getSourceData(qcFilePath, "qc", betaDataFile);
if (Objects.nonNull(qcStruct)) {
betaDataFile.setQcStruct(qcStruct);
betaDataFile.setQcFilePathName(qcFilePath);
betaDataFile.setQcFileName(qcFileName);
qcMap = phdFileUtil.getSourceData(qcStruct, null, null, "qc", betaDataFile);
qcMap.put("fileName", betaDataFile.getQcFileName());
resultMap.put("qc", qcMap);
}
}
} else {
sampleMap = loadData("sample", betaDataFile);
sampleMap.put("fileName", betaDataFile.getSampleFileName());
resultMap.put("sample",sampleMap);
gasBgMap = loadData("gas", betaDataFile);
gasBgMap.put("fileName", betaDataFile.getGasFileName());
resultMap.put("gasBg",gasBgMap);
detBgMap = loadData("det", betaDataFile);
detBgMap.put("fileName", betaDataFile.getDetFileName());
resultMap.put("detBg",detBgMap);
qcMap = loadData("qc", betaDataFile);
qcMap.put("fileName", betaDataFile.getQcFileName());
resultMap.put("qc",qcMap);
}
}
} catch (Exception e) {
e.printStackTrace();
result.error500("Loading failed, please contact the administrator!");
log.error("", e);
return result;
}
result.setSuccess(true);
result.setResult(resultMap);