beta,gamma功能saveToDB后返回详细信息内容

This commit is contained in:
qiaoqinzheng 2023-11-03 11:45:22 +08:00
parent 602345508e
commit 79f0a43166
3 changed files with 160 additions and 10 deletions

View File

@ -865,7 +865,7 @@ public class GammaFileUtil extends AbstractLogOrReport {
return true;
}
public List<String> DetailedInfo(Integer sampleId, PHDFile phd) {
public List<String> DetailedInfo(String sampleId, PHDFile phd) {
try {
// Sample_Id, Station_Code, Detector_Code, System_Type, Data_Type, Spectral_Qualifier,
// SRID, Sample_Status, Collect_Start, Sampling_Time, Quantity, Flow_Rate,
@ -876,7 +876,7 @@ public class GammaFileUtil extends AbstractLogOrReport {
detailInfo.add("");
}
//读取phdFile的数据 修改detailInfo的数据
detailInfo.set(0, Objects.nonNull(sampleId)?sampleId.toString():""); // Sample_Id
detailInfo.set(0, StringUtils.isNotBlank(sampleId)?sampleId:""); // Sample_Id
detailInfo.set(1, phd.getHeader().getSite_code()); // Station_Code
detailInfo.set(2, phd.getHeader().getDetector_code()); // Detector_Code
detailInfo.set(3, phd.getHeader().getSystem_type().toUpperCase()); // System_Type

View File

@ -494,7 +494,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
List<String> qcstate = gammaFileUtil.Qcstate(phd);
map.put("QCFlag", qcstate);
// 更新 Detailed Information 信息
List<String> detailedInfo = gammaFileUtil.DetailedInfo(sampleId, phd);
List<String> detailedInfo = gammaFileUtil.DetailedInfo(String.valueOf(sampleId), phd);
map.put("DetailedInformation", detailedInfo);
// 更新 ACQ 模块中各时间信息
map.put("start_time", phd.getAcq().getAcquisition_start_date() + "\n" + phd.getAcq().getAcquisition_start_time());
@ -853,7 +853,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
List<String> qcstate = gammaFileUtil.Qcstate(phd);
map.put("QCFlag", qcstate);
// 更新 Detailed Information 信息
List<String> detailedInfo = gammaFileUtil.DetailedInfo(null, phd);
List<String> detailedInfo = gammaFileUtil.DetailedInfo(phd.getId_sample(), phd);
map.put("DetailedInformation", detailedInfo);
// 更新 ACQ 模块中各时间信息
map.put("start_time", phd.getAcq().getAcquisition_start_date() + "\n" + phd.getAcq().getAcquisition_start_time());
@ -4440,8 +4440,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
if (StringUtils.isBlank(idAnalysis)) {
// RNMAN.GARDS_ANALYSES 表插入数据
analysesSpectrumService.insertEntity(middleData, phd, userName, comments);
// 查询idAnalysis
idAnalysis = spectrumAnalysisMapper.getIdAnalysisByIdAnalyst(phd.getId_sample(), userName);
// 修改sample_data状态
spectrumAnalysisMapper.updateAnalysesStatus(middleData.analyses_save_filePath);
} else {
@ -4488,6 +4486,12 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
result.error500("Save analysis results to DB failed.");
return result;
}
Map<String, Object> map = new HashMap<>();
//更新detial Information
List<String> detailedInfo = gammaFileUtil.DetailedInfo(phd.getId_sample(), phd);
map.put("DetailedInformation", detailedInfo);
result.setSuccess(true);
result.setResult(map);
return result;
}

View File

@ -388,6 +388,26 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService {
phdFileUtil.getLightColor(sampleMap,gasBgMap,detBgMap,qcMap);
String sampleFileName = String.valueOf(sampleMap.get("fileName"));
Cache<String, Map<String, Object>> cache = betaCache.getBetaCache();
Map<String, Object> dataCache = cache.getIfPresent(sampleFileName + "-" + userName + "-data");
if (CollectionUtils.isNotEmpty(dataCache)) {
SpectrumData sample = (SpectrumData) dataCache.get("sample");
if (Objects.nonNull(sample)) {
sampleMap.put("spectrumData", sample);
}
SpectrumData gas = (SpectrumData) dataCache.get("gas");
if (Objects.nonNull(gas)) {
gasBgMap.put("spectrumData", gas);
}
SpectrumData det = (SpectrumData) dataCache.get("det");
if (Objects.nonNull(det)) {
detBgMap.put("spectrumData", det);
}
SpectrumData qc = (SpectrumData) dataCache.get("qc");
if (Objects.nonNull(qc)) {
qcMap.put("spectrumData", qc);
}
}
Map<String, Object> xeDataMap = cache.getIfPresent(sampleFileName + "-" + userName + "-xeData");
if (CollectionUtils.isNotEmpty(xeDataMap)) {
xeResultsSpectrumList = (List<GardsXeResultsSpectrum>) xeDataMap.get("XeData");
@ -485,6 +505,25 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService {
phdFileUtil.getLightColor(sampleMap,gasBgMap,detBgMap,qcMap);
//获取本地缓存信息
Cache<String, Map<String, Object>> cache = betaCache.getBetaCache();
Map<String, Object> dataCache = cache.getIfPresent(sampleFileName + "-" + userName + "-data");
if (CollectionUtils.isNotEmpty(dataCache)) {
SpectrumData sample = (SpectrumData) dataCache.get("sample");
if (Objects.nonNull(sample)) {
sampleMap.put("spectrumData", sample);
}
SpectrumData gas = (SpectrumData) dataCache.get("gas");
if (Objects.nonNull(gas)) {
gasBgMap.put("spectrumData", gas);
}
SpectrumData det = (SpectrumData) dataCache.get("det");
if (Objects.nonNull(det)) {
detBgMap.put("spectrumData", det);
}
SpectrumData qc = (SpectrumData) dataCache.get("qc");
if (Objects.nonNull(qc)) {
qcMap.put("spectrumData", qc);
}
}
//根据key获取缓存数据
Map<String, Object> xeDataMap = cache.getIfPresent(sampleFileName + "-" + userName + "-xeData");
//如果缓存数据存在 则将缓存数据取出使用
@ -597,6 +636,8 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService {
betaCache.deleteBetaCache(analyseKey);
String xeKey = sampleFileName + "-" + userName + "-xeData";
betaCache.deleteBetaCache(xeKey);
String dataKey = sampleFileName + "-" + userName + "-data";
betaCache.deleteBetaCache(dataKey);
}
@Override
@ -4041,8 +4082,13 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService {
@Transactional
public Result saveToDB(BgDataAnlyseResultIn anlyseResultIn, HttpServletRequest request) {
Result result = new Result();
Map<String, Object> map = new HashMap<>();
//根据请求体获取用户名
String userName = JwtUtil.getUserNameByToken(request);
Integer sampleId = null;
Integer gasId = null;
Integer detId = null;
Integer qcId = null;
//判断保存分析结果标识
if (!anlyseResultIn.isSavedAnalysisResult()) {
result.error500("Please first Analyse File!");
@ -4114,7 +4160,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService {
// getROILimit(anlyseResultIn);
//根据sample文件名称模糊查询sampleId
if (StringUtils.isNotBlank(anlyseResultIn.getDbName())) {
Integer sampleId = spectrumAnalysisMapper.getSampleIdLikeFileName(anlyseResultIn.getSampleFileName());
sampleId = spectrumAnalysisMapper.getSampleIdLikeFileName(anlyseResultIn.getSampleFileName());
Integer analysisID = null;
if (anlyseResultIn.getDbName().equals("auto")) {
anlyseResultIn.setDbName("RNAUTO");
@ -4178,15 +4224,16 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService {
result.error500("qcFile save failed");
return result;
}
qcId = spectrumAnalysisMapper.getSampleId(qcFilePathName);
}
if ( !OriginalDataStore(anlyseResultIn.getSampleFilePath(), anlyseResultIn.getSampleFileName(), sampleFilePathName, anlyseResultIn.getUserName()) ){
result.error500("sampleFile save failed");
return result;
}
//根据文件名称查询对应的sampleId--- sampleFile gasFile detFile
Integer sampleId = spectrumAnalysisMapper.getSampleId(sampleFilePathName);
Integer gasId = spectrumAnalysisMapper.getSampleId(gasFilePathName);
Integer detId = spectrumAnalysisMapper.getSampleId(detFilePathName);
sampleId = spectrumAnalysisMapper.getSampleId(sampleFilePathName);
gasId = spectrumAnalysisMapper.getSampleId(gasFilePathName);
detId = spectrumAnalysisMapper.getSampleId(detFilePathName);
//如果分析过就修改原记录--GARDS_ANALYSES
GardsAnalysesSpectrum gardsAnalyses = new GardsAnalysesSpectrum();
gardsAnalyses.setSampleId(sampleId);
@ -4295,13 +4342,16 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService {
File sampleTmp = null;
File gasTmp = null;
File detTmp = null;
File qcTmp = null;
try {
sampleTmp = phdFileUtil.analyzeFile(anlyseResultIn.getSampleFilePath(), anlyseResultIn.getSampleFileName());
gasTmp = phdFileUtil.analyzeFile(anlyseResultIn.getGasFilePath(), anlyseResultIn.getGasFileName());
detTmp = phdFileUtil.analyzeFile(anlyseResultIn.getDetFilePath(), anlyseResultIn.getDetFileName());
qcTmp = phdFileUtil.analyzeFile(anlyseResultIn.getQcFilePath(), anlyseResultIn.getQcFileName());
ftpUtil.saveFile(StringPool.SLASH + ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + sampleFilePathName.substring(0, sampleFilePathName.lastIndexOf(StringPool.SLASH)), anlyseResultIn.getSampleFileName(), new FileInputStream(sampleTmp));
ftpUtil.saveFile(StringPool.SLASH + ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + gasFilePathName.substring(0, gasFilePathName.lastIndexOf(StringPool.SLASH)), anlyseResultIn.getGasFileName(), new FileInputStream(gasTmp));
ftpUtil.saveFile(StringPool.SLASH + ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + detFilePathName.substring(0, detFilePathName.lastIndexOf(StringPool.SLASH)), anlyseResultIn.getDetFileName(), new FileInputStream(detTmp));
ftpUtil.saveFile(StringPool.SLASH + ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + qcFilePathName.substring(0, qcFilePathName.lastIndexOf(StringPool.SLASH)), anlyseResultIn.getQcFileName(), new FileInputStream(qcTmp));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} finally {
@ -4309,7 +4359,26 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService {
gasTmp.delete();
detTmp.delete();
}
if (Objects.nonNull(sampleId)) {
SpectrumData sampleData = getSpectrumData(sampleId);
map.put("sample", sampleData);
}
if (Objects.nonNull(gasId)) {
SpectrumData gasData = getSpectrumData(gasId);
map.put("gas", gasData);
}
if (Objects.nonNull(detId)) {
SpectrumData detData = getSpectrumData(detId);
map.put("det", detData);
}
if (Objects.nonNull(qcId)) {
SpectrumData qcData = getSpectrumData(qcId);
map.put("qc", qcData);
}
cache.put(anlyseResultIn.getSampleFileName()+"-"+userName+"-data", map);
betaCache.setBetaCache(cache);
result.setSuccess(true);
result.setResult(map);
return result;
}
@ -5814,4 +5883,81 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService {
return roiResultsList;
}
public SpectrumData getSpectrumData(Integer sampleId) {
//根据 sampleId获取sampleData的数据内容
GardsSampleDataSpectrum sampleData = spectrumAnalysisMapper.getSampleData(sampleId);
//获取文件存储路径
String inputFileName = sampleData.getInputFileName();
//拼接完整的ftp路径
String filePath = StringPool.SLASH + ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + inputFileName;
File file = ftpUtil.downloadFile(filePath, "betaGamma");
EnergySpectrumStruct struct = EnergySpectrumHandler.getSourceData(file.getAbsolutePath());
SpectrumData spectrumData = new SpectrumData();
try {
//封装散点图下的基础数据信息
//Station Code
String stationCode = struct.site_code;
//Detector Code
String detectorCode = struct.detector_code;
//Data Type
String dataType = struct.data_type;
//Collection Start
Date CollectionStart = null;
if ( StringUtils.isNotBlank(struct.collection_start_date) && StringUtils.isNotBlank(struct.collection_start_time) ){
CollectionStart = DateUtils.parseDate(struct.collection_start_date + StringPool.SPACE + struct.collection_start_time);
}
//Collection Stop
Date CollectionStop = null;
if ( StringUtils.isNotBlank(struct.collection_stop_date) && StringUtils.isNotBlank(struct.collection_stop_time) ){
CollectionStop = DateUtils.parseDate(struct.collection_stop_date + StringPool.SPACE + struct.collection_stop_time);
}
//Collection Time
String CollectionTime = "";
if ( Objects.nonNull(CollectionStart) && Objects.nonNull(CollectionStop) ){
CollectionTime = String.format ("%.2f",Double.valueOf(CollectionStop.getTime()/1000 - CollectionStart.getTime()/ 1000));
}
//Acquisition Start
Date AcquisitionStart = null;
if ( StringUtils.isNotBlank(struct.collection_start_date) && StringUtils.isNotBlank(struct.collection_start_time) ){
AcquisitionStart = DateUtils.parseDate(struct.acquisition_start_date + StringPool.SPACE + struct.acquisition_start_time);
}
//Acq Real Time
double AcquisitionRealTime = struct.acquisition_real_time;
//Acq live Time
double AcquisitionLiveTime = struct.acquisition_live_time;
//Air Volume[m3]
double airVolume = struct.air_volume;
//Xe Volume[m3]
double xeVolume = struct.sample_volume_of_Xe;
//xeCollectionYield
double xeCollectionYield = struct.Xe_collection_yield;
//gasBkMeasurementId
String gasBkMeasurementId = struct.gas_bk_measurement_id;
//detectorBkMeasurementId
String detectorBkMeasurementId = struct.detector_bk_measurement_id;
//measurementId
String measurementId = struct.measurement_id;
spectrumData.setSampleId(sampleId);
spectrumData.setStatus(sampleData.getStatus());
spectrumData.setStationCode(stationCode);
spectrumData.setDetectorCode(detectorCode);
spectrumData.setDataType(dataType);
spectrumData.setCollectionStart(CollectionStart);
spectrumData.setCollectionStop(CollectionStop);
spectrumData.setCollectionTime(CollectionTime);
spectrumData.setAcquisitionStart(AcquisitionStart);
spectrumData.setAcquisitionRealTime(AcquisitionRealTime);
spectrumData.setAcquisitionLiveTime(AcquisitionLiveTime);
spectrumData.setAirVolume(airVolume);
spectrumData.setXeVolume(xeVolume);
spectrumData.setYield(xeCollectionYield);
spectrumData.setGasBkMeasurementId(gasBkMeasurementId);
spectrumData.setDetectorBkMeasurementId(detectorBkMeasurementId);
spectrumData.setMeasurementId(measurementId);
} catch (ParseException e) {
throw new RuntimeException(e);
}
return spectrumData;
}
}