From e155d51c79b669e5dc333f1821262418a14655f1 Mon Sep 17 00:00:00 2001 From: xiaoguangbin Date: Mon, 9 Sep 2024 15:44:45 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E8=A7=A3=E5=86=B3=E6=96=B0beta?= =?UTF-8?q?=E8=B0=B1=E8=87=AA=E5=8A=A8=E5=A4=84=E7=90=86=20gamma=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/vo/GStoreMiddleProcessData.java | 10 +- .../AbstractS_D_Q_G_SpectrumHandler.java | 9 +- .../modules/spectrum/Sample_C_Analysis.java | 66 +++++------ .../java/org/jeecg/common/util/SelfUtil.java | 109 +++++++++++++++--- 4 files changed, 140 insertions(+), 54 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/entity/vo/GStoreMiddleProcessData.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/entity/vo/GStoreMiddleProcessData.java index 76faea36..f948afcc 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/entity/vo/GStoreMiddleProcessData.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/entity/vo/GStoreMiddleProcessData.java @@ -231,7 +231,7 @@ public class GStoreMiddleProcessData implements Serializable { //SpecSetup public SpecSetup setting_specSetup; - public GStoreMiddleProcessData(){ + { dbWriteFlag = false; dbWriteStatusFlag = ""; ErrorInfo = ""; @@ -420,5 +420,13 @@ public class GStoreMiddleProcessData implements Serializable { NDC_Analysis_General_Comments = ""; setting_specSetup = new SpecSetup(); } + public GStoreMiddleProcessData(){ + + } + + public GStoreMiddleProcessData(String analyses_save_filePath){ + new GStoreMiddleProcessData(); + this.analyses_save_filePath = analyses_save_filePath; + } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractS_D_Q_G_SpectrumHandler.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractS_D_Q_G_SpectrumHandler.java index 5150537f..6f08c026 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractS_D_Q_G_SpectrumHandler.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractS_D_Q_G_SpectrumHandler.java @@ -9,6 +9,7 @@ import org.apache.logging.log4j.util.Strings; import org.jeecg.common.constant.StringConstant; import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.util.DateUtils; +import org.jeecg.common.util.SelfUtil; import org.jeecg.modules.ErrorLogManager; import org.jeecg.modules.base.entity.original.GardsSampleData; import org.jeecg.modules.base.enums.SampleStatus; @@ -88,7 +89,13 @@ public abstract class AbstractS_D_Q_G_SpectrumHandler extends AbstractSpectrumHa */ @Override protected void parseingEmail() throws Exception { - final EnergySpectrumStruct sourceData = EnergySpectrumHandler.getSourceData(super.spectrumFile.getAbsolutePath()); + // 如果是自建台站能谱,需要单独处理Histogram数据,避免性能问题 + EnergySpectrumStruct sourceData = null; + if (super.spectrumFile.length() > (1024 * 1024 * 4L)) { + sourceData = SelfUtil.getSourceDataNotHis(super.spectrumFile.getAbsolutePath()); + } else { + sourceData = EnergySpectrumHandler.getSourceData(super.spectrumFile.getAbsolutePath()); + } if(Objects.isNull(sourceData) || StringUtils.isBlank(sourceData.data_type)){ //发送格式化错误事件,后续统计报告使用 spectrumServiceQuotes.getApplicationContext().publishEvent(new FormatErrorEvent()); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_C_Analysis.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_C_Analysis.java index d7fa5261..ba1586a7 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_C_Analysis.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_C_Analysis.java @@ -188,38 +188,17 @@ public class Sample_C_Analysis { /* 准备Gamma分析需要的数据 */ Integer sampleId = sampleData.getSampleId(); - // 获取配置文件 - GammaFileUtil gammaFileUtil = ApplicationContextUtil.getContext().getBean(GammaFileUtil.class); - parameterProperties = ApplicationContextUtil.getContext().getBean(ParameterProperties.class); - phdFile1.setXmlFilePath(parameterProperties.getFilePath()); - phdFile2.setXmlFilePath(parameterProperties.getFilePath()); - phdFile3.setXmlFilePath(parameterProperties.getFilePath()); - phdFile4.setXmlFilePath(parameterProperties.getFilePath()); - - // 获取数据库 Gamma 默认参数 - getSettingFromDB(phdFile1, phdFile2, phdFile3, phdFile4); // 文件路径 - GStoreMiddleProcessData middleData1 = new GStoreMiddleProcessData(); - GStoreMiddleProcessData middleData2 = new GStoreMiddleProcessData(); - GStoreMiddleProcessData middleData3 = new GStoreMiddleProcessData(); - GStoreMiddleProcessData middleData4 = new GStoreMiddleProcessData(); - middleData1.setAnalyses_save_filePath(this.sampleInputFilename); - middleData2.setAnalyses_save_filePath(this.sampleInputFilename); - middleData3.setAnalyses_save_filePath(this.sampleInputFilename); - middleData4.setAnalyses_save_filePath(this.sampleInputFilename); + GStoreMiddleProcessData middleData1 = new GStoreMiddleProcessData(this.sampleInputFilename); + GStoreMiddleProcessData middleData2 = new GStoreMiddleProcessData(this.sampleInputFilename); + GStoreMiddleProcessData middleData3 = new GStoreMiddleProcessData(this.sampleInputFilename); + GStoreMiddleProcessData middleData4 = new GStoreMiddleProcessData(this.sampleInputFilename); // 读取文件内容并附值 this.setPHDFile(phdFile1, phdFile2, phdFile3, phdFile4); - - phdFile1.getSetting().setRefTime_act(DateUtils.parseDate(phdFile1.getAcq().getAcquisition_start_date()+" "+phdFile1.getAcq().getAcquisition_start_time())); - phdFile2.getSetting().setRefTime_act(DateUtils.parseDate(phdFile2.getAcq().getAcquisition_start_date()+" "+phdFile2.getAcq().getAcquisition_start_time())); - phdFile3.getSetting().setRefTime_act(DateUtils.parseDate(phdFile3.getAcq().getAcquisition_start_date()+" "+phdFile3.getAcq().getAcquisition_start_time())); - phdFile4.getSetting().setRefTime_act(DateUtils.parseDate(phdFile4.getAcq().getAcquisition_start_date()+" "+phdFile4.getAcq().getAcquisition_start_time())); - phdFile1.getSetting().setRefTime_conc(DateUtils.parseDate(phdFile1.getCollect().getCollection_start_date()+" "+phdFile1.getCollect().getCollection_start_time())); - phdFile2.getSetting().setRefTime_conc(DateUtils.parseDate(phdFile2.getCollect().getCollection_start_date()+" "+phdFile2.getCollect().getCollection_start_time())); - phdFile3.getSetting().setRefTime_conc(DateUtils.parseDate(phdFile3.getCollect().getCollection_start_date()+" "+phdFile3.getCollect().getCollection_start_time())); - phdFile4.getSetting().setRefTime_conc(DateUtils.parseDate(phdFile4.getCollect().getCollection_start_date()+" "+phdFile4.getCollect().getCollection_start_time())); + // 获取数据库 Gamma 默认参数 + getSettingFromDB(phdFile1, phdFile2, phdFile3, phdFile4); // 根据能谱的系统类型传入不同的核素参数 Map nuclideLibs = this.getNuclideLinesG(); @@ -227,7 +206,8 @@ public class Sample_C_Analysis { //读取参数内容 Map mdcInfoMap = readMDCParameter(phdFile1, phdFile2, phdFile3, phdFile4); - // 执行分析业务代码 + // 执行gamma分析业务代码 + GammaFileUtil gammaFileUtil = ApplicationContextUtil.getContext().getBean(GammaFileUtil.class); boolean analyFlag1 = gammaFileUtil.GetMiddleData(phdFile1, CommonConstant.REPORT_PREFIX_AUTO, nuclideLibs, middleData1, MiddleDataType.Auto.getType(), ""); boolean analyFlag2 = gammaFileUtil.GetMiddleData(phdFile2, CommonConstant.REPORT_PREFIX_AUTO, nuclideLibs, middleData2, MiddleDataType.Auto.getType(), ""); boolean analyFlag3 = gammaFileUtil.GetMiddleData(phdFile3, CommonConstant.REPORT_PREFIX_AUTO, nuclideLibs, middleData3, MiddleDataType.Auto.getType(), ""); @@ -279,6 +259,7 @@ public class Sample_C_Analysis { long bChannels = sampleStruct.b_channels; long gChannels = sampleStruct.g_channels; List hCounts = sampleStruct.h_counts; + long[][] hCountArr = sampleStruct.getH_count_arr(); CalcBgBoundaryParam calcBgBoundaryParam = new CalcBgBoundaryParam(); calcBgBoundaryParam.g_e_cal = EnergySpectrumHandler.GetFileFittingPara(gEnergy, gCentroidChannel); calcBgBoundaryParam.b_e_cal = EnergySpectrumHandler.GetFileFittingPara(bElectronEnergy, bChannel); @@ -299,16 +280,16 @@ public class Sample_C_Analysis { // 根据范围1划分 范围1对应的折线图 List roiOneCounts = selfStationUtil.roiList(roiBBoundaryStart.get(0), roiBBoundaryStop.get(0), - bChannels, gChannels, hCounts); + bChannels, gChannels, hCountArr); // 根据范围2划分 范围2对应的折线图 List roiTwoCounts = selfStationUtil.roiList(roiBBoundaryStart.get(1), roiBBoundaryStop.get(1), - bChannels, gChannels, hCounts); + bChannels, gChannels, hCountArr); // 根据范围3划分 范围3对应的折线图 List roiThreeCounts = selfStationUtil.roiList(roiBBoundaryStart.get(2), roiBBoundaryStop.get(2), - bChannels, gChannels, hCounts); + bChannels, gChannels, hCountArr); // 根据范围4划分 范围4对应的折线图 List roiFourCounts = selfStationUtil.roiList(roiBBoundaryStart.get(3), roiBBoundaryStop.get(3), - bChannels, gChannels, hCounts); + bChannels, gChannels, hCountArr); // 根据ROI生成四个Gamma谱文件 文件命名格式为: 样品谱原名_ROI_x.PHD String saveFullPath = this.saveFullPath(); @@ -340,6 +321,13 @@ public class Sample_C_Analysis { gammaThreeName = saveRelativePath + StrUtil.SLASH + gammaThreeName; gammaFourName = saveRelativePath + StrUtil.SLASH + gammaFourName; phdFilePaths = ListUtil.toList(gammaOneName, gammaTwoName, gammaThreeName, gammaFourName); + + // 获取配置文件 + parameterProperties = ApplicationContextUtil.getContext().getBean(ParameterProperties.class); + phdFile1.setXmlFilePath(parameterProperties.getFilePath()); + phdFile2.setXmlFilePath(parameterProperties.getFilePath()); + phdFile3.setXmlFilePath(parameterProperties.getFilePath()); + phdFile4.setXmlFilePath(parameterProperties.getFilePath()); } public String savePath(){ @@ -902,7 +890,7 @@ public class Sample_C_Analysis { PairsEDto pairsEDto = new PairsEDto(); BeanUtil.copyProperties(middleData, pairsEDto); List pairsE = Lists.newArrayList(); - if (pairsEDto.getCalibration_pairs_E_idCalPoint().size() > 0) { + if (!pairsEDto.getCalibration_pairs_E_idCalPoint().isEmpty()) { pairsE = mapFields(pairsEDto, pairs, base_E_Paris, fieldMap); String pairsECaltype = middleData.getCalibration_pairs_E_Caltype(); String pairsEInput = middleData.getCalibration_pairs_E_Input(); @@ -920,7 +908,7 @@ public class Sample_C_Analysis { PairsEFDto pairsEFDto = new PairsEFDto(); BeanUtil.copyProperties(middleData, pairsEFDto); List pairsEF = Lists.newArrayList(); - if (pairsEFDto.getCalibration_pairs_EF_idCalPoint().size() > 0) { + if (!pairsEFDto.getCalibration_pairs_EF_idCalPoint().isEmpty()) { pairsEF = mapFields(pairsEFDto, pairs, base_EF_Paris, fieldMap); String pairsEFCaltype = middleData.getCalibration_pairs_EF_Caltype(); String pairsEFInput = middleData.getCalibration_pairs_EF_Input(); @@ -938,7 +926,7 @@ public class Sample_C_Analysis { PairsRDto pairsRDto = new PairsRDto(); BeanUtil.copyProperties(middleData,pairsRDto); List pairsR = Lists.newArrayList(); - if (pairsRDto.getCalibration_pairs_R_idCalPoint().size() > 0) { + if (!pairsRDto.getCalibration_pairs_R_idCalPoint().isEmpty()) { pairsR = mapFields(pairsRDto, pairs, base_R_Paris, fieldMap); String pairsRCaltype = middleData.getCalibration_pairs_R_Caltype(); String pairsRInput = middleData.getCalibration_pairs_R_Input(); @@ -956,7 +944,7 @@ public class Sample_C_Analysis { PairsTDto pairsTDto = new PairsTDto(); BeanUtil.copyProperties(middleData,pairsTDto); List pairsT = Lists.newArrayList(); - if (pairsTDto.getCalibration_pairs_T_idCalPoint().size() > 0) { + if (!pairsTDto.getCalibration_pairs_T_idCalPoint().isEmpty()) { pairsT = mapFields(pairsTDto, pairs, base_T_Paris, fieldMap); String pairsTCaltype = middleData.getCalibration_pairs_T_Caltype(); String pairsTInput = middleData.getCalibration_pairs_T_Input(); @@ -1348,7 +1336,7 @@ public class Sample_C_Analysis { return fieldMap; } - public void getSettingFromDB(PHDFile... phdFiles){ + public void getSettingFromDB(PHDFile... phdFiles) throws ParseException { Map mapSetting = serviceQuotes.getGammaDefaultParamsService() .mapSetting(); for (PHDFile phdFile : phdFiles) { @@ -1402,6 +1390,10 @@ public class Sample_C_Analysis { String RiskLevelK = mapSetting.get(Setting.RISKLEVELK); if (StrUtil.isNotBlank(RiskLevelK)) setting.setRiskLevelK(Double.parseDouble(RiskLevelK)); + + setting.setRefTime_act(DateUtils.parseDate(phdFile.getAcq().getAcquisition_start_date()+" "+phdFile.getAcq().getAcquisition_start_time())); + setting.setRefTime_conc(DateUtils.parseDate(phdFile.getCollect().getCollection_start_date()+" "+phdFile.getCollect().getCollection_start_time())); + } } diff --git a/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/common/util/SelfUtil.java b/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/common/util/SelfUtil.java index c261c8e5..a192a4fc 100644 --- a/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/common/util/SelfUtil.java +++ b/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/common/util/SelfUtil.java @@ -1,28 +1,32 @@ package org.jeecg.common.util; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.IORuntimeException; +import cn.hutool.core.lang.Console; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.StringPool; +import com.google.common.collect.Maps; import org.jeecg.modules.base.enums.CalName; +import org.jeecg.modules.base.enums.SampleFileHeader; import org.jeecg.modules.entity.vo.*; import org.jeecg.modules.native_jni.EnergySpectrumHandler; import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Component; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.PrintWriter; +import java.io.*; import java.text.DecimalFormat; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; -import java.util.Objects; +import java.util.*; @Component public class SelfUtil { - public List roiList(Integer startChannel, Integer endChannel, long betaChannels, long gammaChannels, List h_counts) { + private static final Logger log = LoggerFactory.getLogger(SelfUtil.class); + + public List roiList(Integer startChannel, Integer endChannel, long betaChannels, long gammaChannels, long[][] h_counts) { // g_counts List counts = new LinkedList<>(); //存储同一列不同行加和后的数量 @@ -33,13 +37,7 @@ public class SelfUtil { //根据起始道值和结束道值 获取这一列的所有对应道值的数据 for (int j=startChannel; j <= endChannel; j++) { //列数 * 总行数 + 当前行下标 获取对应的数据数组下标 - int index = (int) (i * betaChannels + j); - long count = 0; - //判断下标是否在h_counts范围内 - if (index > 0 && index < h_counts.size()) { - count = h_counts.get(index); - } - sum+=count; + sum += h_counts[i][j]; } counts.add(sum); } @@ -345,4 +343,85 @@ public class SelfUtil { } return phd; } + + /** + * 调用dll解析phd文件,dll不解析histogram块数据 + * @param filePathName 文件地址 + * @return + */ + public static EnergySpectrumStruct getSourceDataNotHis(String filePathName) { + EnergySpectrumStruct struct = null; + try { + if (Objects.nonNull(filePathName)) { + //解析文件内容 + long start = System.currentTimeMillis(); + struct = EnergySpectrumHandler.getSourceDataNotHis(filePathName); + Console.log("getsource:{}", (System.currentTimeMillis() - start)); + start = System.currentTimeMillis(); + HashMap hisMap = readPHDFile(filePathName); + Console.log("readPHDFile:{}", (System.currentTimeMillis() - start)); + struct.setH_count_arr((long[][]) hisMap.get("h_count")); + struct.setG_channels((long) hisMap.get("g_channels")); + struct.setB_channels((long) hisMap.get("b_channels")); + struct.setG_energy_span((long) hisMap.get("g_energy_span")); + struct.setB_energy_span((long) hisMap.get("b_energy_span")); + } + } catch (Exception e) { + log.error("getSourceDataNotHis Error:{}", e.getMessage()); + } + return struct; + } + + /** + * 解析 #histogram块数据 + * @param phdPath 文件地址 + * @return + */ + public static HashMap readPHDFile(String phdPath) { + try { + File file = new File(phdPath); + HashMap result = Maps.newHashMap(); + BufferedReader reader = FileUtil.getReader(file, "utf8"); + String currentName = ""; + long [][] hCountArr = null; + int row = 0; + String blockHis = SampleFileHeader.HISTOGRAM.getMessage(); + while (reader.ready()) { + // 当前行 + String line = reader.readLine(); + if (line.equals(blockHis)) { + currentName = line; + // 首行 + String s = reader.readLine(); + String[] split = s.split(" "); + hCountArr = new long[Integer.parseInt(split[0])][Integer.parseInt(split[1])]; + result.put("g_channels", Long.parseLong(split[0])); + result.put("b_channels", Long.parseLong(split[1])); + result.put("g_energy_span", Long.parseLong(split[2])); + result.put("b_energy_span", Long.parseLong(split[3])); + Console.log(s); + continue; + } + if (!line.equals(blockHis) && !currentName.equals(blockHis)) { + continue; + } + if (line.equals("STOP")) { + break; + } + String[] split = line.split(" "); + for (int i = 0; i < split.length; i++) { + hCountArr[row][i] = Long.parseLong(split[i]); + } + row++; + } + result.put("h_count", hCountArr); + return result; + } catch (IORuntimeException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (NumberFormatException e) { + throw new RuntimeException(e); + } + } }