From a441eb6ad12fb107b64276166e4f222f10a1f972 Mon Sep 17 00:00:00 2001 From: xiaoguangbin Date: Thu, 29 Aug 2024 11:51:58 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E5=B0=86dll=E7=9A=84h=5Fcounts?= =?UTF-8?q?=E5=8E=BB=E6=8E=89=EF=BC=8Cjava=E9=80=9A=E8=BF=87=E4=BA=8C?= =?UTF-8?q?=E7=BB=B4=E6=95=B0=E7=BB=84=E8=A7=A3=E6=9E=90=E5=B9=B6=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E6=9D=A5=E8=A7=A3=E5=86=B3=E8=87=AA=E5=BB=BA=E5=8F=B0?= =?UTF-8?q?=E7=AB=99beta=20=E5=8A=A0=E8=BD=BD=E6=85=A2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../native_jni/EnergySpectrumHandler.java | 7 + .../struct/EnergySpectrumStruct.java | 2 + .../jeecg/common/util/SelfStationUtil.java | 550 +++++++++++++----- .../service/impl/SelfStationServiceImpl.java | 44 +- 4 files changed, 451 insertions(+), 152 deletions(-) diff --git a/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/modules/native_jni/EnergySpectrumHandler.java b/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/modules/native_jni/EnergySpectrumHandler.java index 009f8129..b3986e9c 100644 --- a/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/modules/native_jni/EnergySpectrumHandler.java +++ b/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/modules/native_jni/EnergySpectrumHandler.java @@ -17,6 +17,13 @@ public class EnergySpectrumHandler { */ public static native EnergySpectrumStruct getSourceData(String path); + /** + * 获取能谱原始数据, 不解析histogram块 + * @param path + * @return + */ + public static native EnergySpectrumStruct getSourceDataNotHis(String path); + /** * 根据不同的拟合方法计算边界值, 默认2次拟合 可以继承书写新的拟合 * @param calcBgBoundaryParam diff --git a/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/modules/native_jni/struct/EnergySpectrumStruct.java b/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/modules/native_jni/struct/EnergySpectrumStruct.java index 59e535c7..223fdfd9 100644 --- a/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/modules/native_jni/struct/EnergySpectrumStruct.java +++ b/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/modules/native_jni/struct/EnergySpectrumStruct.java @@ -390,6 +390,8 @@ public class EnergySpectrumStruct { */ public List h_counts; + public long[][] h_count_arr; + /************************* Certificate_Block ******************/ /** * total source activity (Bq) diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/SelfStationUtil.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/SelfStationUtil.java index b4b0b478..18c58a2a 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/SelfStationUtil.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/SelfStationUtil.java @@ -1,5 +1,7 @@ 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; @@ -15,6 +17,7 @@ import org.jeecg.common.properties.ParameterProperties; import org.jeecg.modules.base.abstracts.AbstractLogOrReport; import org.jeecg.modules.base.enums.CalName; import org.jeecg.modules.base.enums.DataTypeAbbr; +import org.jeecg.modules.base.enums.SampleFileHeader; import org.jeecg.modules.entity.GardsCalibrationSpectrum; import org.jeecg.modules.entity.GardsROIChannelsSpectrum; import org.jeecg.modules.entity.GardsROIResultsSpectrum; @@ -35,10 +38,7 @@ import org.xml.sax.SAXException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.PrintWriter; +import java.io.*; import java.text.DecimalFormat; import java.text.ParseException; import java.util.*; @@ -154,6 +154,207 @@ public class SelfStationUtil extends AbstractLogOrReport { List roiBBoundaryStart = bgBoundary.ROI_B_Boundary_start; List roiBBoundaryStop = bgBoundary.ROI_B_Boundary_stop; + //根据范围1划分 范围1对应的折线图 + Map gammaByROI = this.getGammaByROI(systemType, roiBBoundaryStart, roiBBoundaryStop, selfStationData); + map.putAll(gammaByROI); + //统计散点图 + //横坐标 beta-gamma + long bChannels = struct.b_channels; + //纵坐标 gamma + long gChannels = struct.g_channels; + //值 + long[][] h_count_arr = struct.h_count_arr; + List histogramDataList = new LinkedList<>(); + List histogramDataDList = new LinkedList<>(); + for (int i=0; i 0){ + HistogramData his = new HistogramData(); + his.setG(i); + his.setB(j); + his.setC(count); + histogramDataList.add(his); + histogramDataDList.add(his); + }else { + HistogramData his = new HistogramData(); + his.setG(i); + his.setB(j); + his.setC(count); + histogramDataDList.add(his); + } + } + } + map.put("histogramDataList", histogramDataList); +// map.put("histogramDataDList", histogramDataDList); + //调用算法 传入道值和道值对应的能量 得到计算gamma能量公式的参数 + List gammaParam = EnergySpectrumHandler.GetFileFittingPara(struct.g_centroid_channel, struct.g_energy); + //存储需要计算gamma能量的道值 + List gchannels = new ArrayList<>(); + for (int i=0; i gammaEnergyList = EnergySpectrumHandler.GetFileFittingData(gchannels, gammaParam); + //将gamma能量折线图进行赋值返回 + map.put("gammaEnergyData", gammaEnergyList); + //调用算法 传入道值和道值对应的能量 得到计算beta能量公式的参数 + List betaParam = EnergySpectrumHandler.GetFileFittingPara(struct.b_channel, struct.b_electron_energy); + List bchannels = new ArrayList<>(); + for (int i=0; i betaEnergyList = EnergySpectrumHandler.GetFileFittingData(bchannels, betaParam); + //将beta能量折线图进行赋值返回 + map.put("betaEnergyData", betaEnergyList); + + //g_Energy + if (CollectionUtils.isNotEmpty(struct.g_energy) && CollectionUtils.isNotEmpty(struct.g_centroid_channel) && CollectionUtils.isNotEmpty(struct.g_uncertainty) && Objects.nonNull(struct.g_record_count)) { + if (systemType.equals("sample")) { + GEnergyBlock gEnergyBlock = new GEnergyBlock(); + gEnergyBlock.setG_energy(struct.g_energy); + gEnergyBlock.setCentroid_channel(struct.g_centroid_channel); + gEnergyBlock.setUncertainty(struct.g_uncertainty); + gEnergyBlock.setRecord_count(struct.g_record_count); + sampleVueData.getMapEnerKD().put(CalName.CalPHD.getType(), gEnergyBlock); + //计算得到公式的参数 + List calEnergyParam = CalValuesHandler.calFitPara("Cal_Energy", 2, struct.g_centroid_channel, struct.g_energy, struct.g_uncertainty); + ParameterInfo parameterInfo = new ParameterInfo(); + parameterInfo.setP(calEnergyParam); + sampleVueData.getMapEnerPara().put(CalName.CalPHD.getType(), parameterInfo); + } + } + //g_Resolution + if (CollectionUtils.isNotEmpty(struct.g_r_energy) && CollectionUtils.isNotEmpty(struct.g_r_FWHM) && CollectionUtils.isNotEmpty(struct.g_r_uncertainty) && Objects.nonNull(struct.g_r_record_count)) { + if (systemType.equals("sample")) { + GResolutionBlock gResolutionBlock = new GResolutionBlock(); + gResolutionBlock.setG_energy(struct.g_r_energy); + gResolutionBlock.setFWHM(struct.g_r_FWHM); + gResolutionBlock.setUncertainty(struct.g_r_uncertainty); + gResolutionBlock.setRecord_count(struct.g_r_record_count); + sampleVueData.getMapResoKD().put(CalName.CalPHD.getType(), gResolutionBlock); + //计算得到公式的参数 + List calEnergyParam = CalValuesHandler.calFitPara("Cal_Resolution", 4, struct.g_r_energy, struct.g_r_FWHM, struct.g_r_uncertainty); + ParameterInfo parameterInfo = new ParameterInfo(); + parameterInfo.setP(calEnergyParam); + sampleVueData.getMapResoPara().put(CalName.CalPHD.getType(), parameterInfo); + } + } + //g_Efficiency + if (CollectionUtils.isNotEmpty(struct.g_e_energy) && CollectionUtils.isNotEmpty(struct.g_e_efficiency) && CollectionUtils.isNotEmpty(struct.g_e_uncertainty) && Objects.nonNull(struct.g_e_record_count)) { + if (systemType.equals("sample")) { + GEfficiencyBlock gEfficiencyBlock = new GEfficiencyBlock(); + gEfficiencyBlock.setG_energy(struct.g_e_energy); + gEfficiencyBlock.setEfficiency(struct.g_e_efficiency); + gEfficiencyBlock.setUncertainty(struct.g_e_uncertainty); + gEfficiencyBlock.setRecord_count(struct.g_e_record_count); + sampleVueData.getMapEffiKD().put(CalName.CalPHD.getType(), gEfficiencyBlock); + //计算得到公式的参数 + List calEnergyParam = CalValuesHandler.calFitPara("Cal_Efficiency", 1, struct.g_e_energy, struct.g_e_efficiency, struct.g_e_uncertainty); + ParameterInfo parameterInfo = new ParameterInfo(); + parameterInfo.setP(calEnergyParam); + sampleVueData.getMapEffiPara().put(CalName.CalPHD.getType(), parameterInfo); + } + } + } catch (ParseException e) { + throw new RuntimeException(e); + } + } + public void loadFile(EnergySpectrumStruct struct, SelfStationData selfStationData, Integer sampleId, String status, String systemType, Map map) { + try { + SelfStationVueData sampleVueData = selfStationData.getSampleVueData(); + SelfStationVueData detVueData = selfStationData.getDetVueData(); + + //封装散点图下的基础数据信息 + SpectrumData spectrumData = new SpectrumData(); + //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() - CollectionStart.getTime())/ 1000)); + } + //Acquisition Start + Date AcquisitionStart = null; + if ( StringUtils.isNotBlank(struct.acquisition_start_date) && StringUtils.isNotBlank(struct.acquisition_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(status); + spectrumData.setStationCode(stationCode); + spectrumData.setDetectorCode(detectorCode); + spectrumData.setDataType(dataType); + spectrumData.setCollectionStart(CollectionStart); + spectrumData.setCollectionStop(CollectionStop); + spectrumData.setCollectionTime(CollectionTime); + spectrumData.setAcquisitionStart(AcquisitionStart); + spectrumData.setAcquisitionRealTime(String.format("%.2f", AcquisitionRealTime)); + spectrumData.setAcquisitionLiveTime(String.format("%.2f", AcquisitionLiveTime)); + spectrumData.setAirVolume(String.format("%.5f", airVolume)); + spectrumData.setXeVolume(String.format("%.5f", xeVolume)); + spectrumData.setYield(xeCollectionYield); + spectrumData.setGasBkMeasurementId(gasBkMeasurementId); + spectrumData.setDetectorBkMeasurementId(detectorBkMeasurementId); + spectrumData.setMeasurementId(measurementId); + map.put("spectrumData", spectrumData); + + //gamma能量部分的计算参数 道值对应能量 + List gEnergy = struct.g_energy; + //gamma能量部分的计算参数 道值 + List gCentroidChannel = struct.g_centroid_channel; + //beta能量部分的计算参数 道值对应的能量 + List bElectronEnergy = struct.b_electron_energy; + //beta能量部分的计算参数 道值 + List bChannel = struct.b_channel; + CalcBgBoundaryParam calcBgBoundaryParam = new CalcBgBoundaryParam(); + calcBgBoundaryParam.g_e_cal = EnergySpectrumHandler.GetFileFittingPara(gEnergy, gCentroidChannel); + calcBgBoundaryParam.b_e_cal = EnergySpectrumHandler.GetFileFittingPara(bElectronEnergy, bChannel); + calcBgBoundaryParam.b_energy = struct.b_electron_energy; + calcBgBoundaryParam.b_channel = struct.b_channel; + calcBgBoundaryParam.g_channel = struct.g_centroid_channel; + calcBgBoundaryParam.g_energy = struct.g_energy; + calcBgBoundaryParam.ROI_B_start_x1 = struct.POI_B_x1; + calcBgBoundaryParam.ROI_B_stop_x2 = struct.POI_B_x2; + calcBgBoundaryParam.ROI_G_start_y1 = struct.POI_G_y1; + calcBgBoundaryParam.ROI_G_stop_y2 = struct.POI_G_y2; + BgBoundary bgBoundary = EnergySpectrumHandler.CalcBgBoundary(calcBgBoundaryParam); + // 新beta谱:只取X轴数据从Y轴0的位置开始连成一条线,一直到顶画出矩形框 这个矩形框内的数据就是Gamma谱数据 + List roiBBoundaryStart = bgBoundary.ROI_B_Boundary_start; + List roiBBoundaryStop = bgBoundary.ROI_B_Boundary_stop; + //根据范围1划分 范围1对应的折线图 Map gammaByROI = this.getGammaByROI(systemType, roiBBoundaryStart, roiBBoundaryStop, selfStationData); map.putAll(gammaByROI); @@ -293,6 +494,100 @@ public class SelfStationUtil extends AbstractLogOrReport { return struct; } + /** + * 调用dll解析phd文件,dll不解析histogram块数据 + * @param filePathName 文件地址 + * @param sampleType 谱类型 + * @param selfStationData + * @return + */ + public void getSourceDataNotHis(String filePathName, String sampleType, SelfStationData selfStationData) { + EnergySpectrumStruct struct = null; + File file = null; + try { + //根据完整的文件路径 获取临时文件 + file = ftpUtil.downloadFile(filePathName); + if (Objects.nonNull(file)) { + //解析文件内容 + struct = EnergySpectrumHandler.getSourceDataNotHis(file.getAbsolutePath()); + HashMap hisMap = this.readPHDFile(file.getAbsolutePath()); + 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")); + + if (sampleType.equalsIgnoreCase("sample")) { + selfStationData.setSampleStruct(struct); + selfStationData.setSampleTmpPath(file.getAbsolutePath()); + } else if (sampleType.equalsIgnoreCase("det")) { + selfStationData.setDetStruct(struct); + selfStationData.setDetTmpPath(file.getAbsolutePath()); + } else if (sampleType.equalsIgnoreCase("qc")) { + selfStationData.setQcStruct(struct); + selfStationData.setQcTmpPath(file.getAbsolutePath()); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 解析 #histogram块数据 + * @param phdPath 文件地址 + * @return + */ + public HashMap readPHDFile(String phdPath) { + try { + File file = new File(phdPath); + HashMap result = Maps.newHashMap(); + BufferedReader reader = FileUtil.getReader(file, "utf8"); + List hCounts = Lists.newLinkedList(); + 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]); + hCounts.add(Long.parseLong(split[i])); + } + row++; + } + result.put("h_count", hCountArr); + Console.log("Size:{}",hCounts.size()); + return result; + } catch (IORuntimeException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (NumberFormatException e) { + throw new RuntimeException(e); + } + } /** * 统计道值范围内数量 * @param startChannel 起始道值 @@ -341,11 +636,9 @@ public class SelfStationUtil extends AbstractLogOrReport { SelfStationData selfStationData) { Map map = new HashMap<>(); - - EnergySpectrumStruct struct = selfStationData.getSampleStruct(); long betaChannels = struct.b_channels, gammaChannels = struct.g_channels; - List h_counts = struct.h_counts; + long[][] h_count_arr = struct.h_count_arr; SelfStationVueData sampleVueData = selfStationData.getSampleVueData(); SelfStationVueData detVueData = selfStationData.getDetVueData(); @@ -369,13 +662,7 @@ public class SelfStationUtil extends AbstractLogOrReport { //根据起始道值和结束道值 获取这一列的所有对应道值的数据 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_count_arr[i][j]; } seriseData.setY(sum); sumList.add(sum); @@ -861,20 +1148,129 @@ public class SelfStationUtil extends AbstractLogOrReport { } /** - * 根据DLL解析GammaPHD内容 得到PHDFile实体 - * @param fileName - * @param pathName - * @return + * 根据ROI卡出来的Gamma数据生成新的GammaPHD文件 + * @param pathName 文件存储路径 + * @param fileName GammaPHD名称 + * @param struct BetaPHD内容 + * @param g_counts ROI卡出来的Gamma数据 */ - public PHDFile getGammaPHD(String fileName, String pathName) { + public void createGammaFile(String pathName,String fileName, EnergySpectrumStruct struct, List g_counts) { + File file = new File(pathName + "\\" + fileName); + // 创建PrintWriter对象 + PrintWriter out = null; + DecimalFormat decimalFormat = new DecimalFormat("0.000000"); + try { + out = new PrintWriter(file); + out.println("BEGIN IMS2.0"); + out.println("MSG_TYPE DATA"); + // todo msg_type用的不对,dll没解析出这个字段 + out.println("MSG_ID " + struct.msg_id + " " + struct.msg_type + "\n" + "DATA_TYPE " + struct.data_type); + out.println("#Header 3"); + // 解析出的Gamma谱 系统类型暂时使用G + out.println(struct.site_code + " " + struct.detector_code + " C " + + struct.sample_geometry + " " + struct.spectrum_quantity); + out.println(struct.sample_ref_id); + out.println(struct.measurement_id + " " + struct.detector_bk_measurement_id + " 0"); + out.println(struct.transmit_date + " " + struct.transmit_time); + out.println("#Collection"); + out.println(struct.collection_start_date + " " + struct.collection_start_time + " " + + struct.collection_stop_date + " " + struct.collection_stop_time + " " + + decimalFormat.format(struct.air_volume)); + out.println("#Acquisition"); + out.println(struct.acquisition_start_date + " " + struct.acquisition_start_time + " " + + decimalFormat.format(struct.acquisition_real_time) + " " + + decimalFormat.format(struct.acquisition_live_time)); + out.println("#g_Energy"); + + + format(struct.g_energy, struct.g_centroid_channel, struct.g_uncertainty, out); + out.println("#g_Resolution"); + format(struct.g_r_energy, struct.g_r_FWHM, struct.g_r_uncertainty, out); + out.println("#g_Efficiency"); + format(struct.g_e_energy, struct.g_e_efficiency, struct.g_e_uncertainty, out); + out.println("#g_Spectrum"); + // num_g_channel 根据g_counts数量得来和PHD写的数字没有关系;g_energy_span是PHD写的值 + out.println(struct.num_g_channel + " " + struct.g_energy_span); + // 存储前一个数字 + String beforeStr = ""; + for (int i = 0; i < g_counts.size(); i++) { + String str = g_counts.get(i).toString(); + if(i % 5 == 0) { + if (i == 0) { + out.printf((i+1)+""); + } else { + out.printf("\n" + (i+1) ); + } + beforeStr = i+""; + } + + if(StrUtil.isEmpty(beforeStr)){ + beforeStr = str; + } + // 根据前一个字符长度计算需要的空格 + out.printf("%" + (str.length() + (6 - beforeStr.length()))+ "s" , g_counts.get(i)); + if(i == g_counts.size() - 1) { + out.println(); + } + beforeStr = str; + } + out.print("STOP"); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } finally { + if (null != out) { + out.close(); + } + } + } + /** + * 创建Gamma PHD文件并转换为数据存入SelfStationVueData + * @param path PHD保存地址 + * @param sampleFileName beta样品谱名称 + * @param struct beta谱数据 + * @param sampleVueData 存储数据实体 + */ + public void createGamma(String path, String sampleFileName, EnergySpectrumStruct struct, SelfStationVueData sampleVueData){ + // 根据ROI生成四个Gamma谱文件, 文件命名为Beta名称后面_ROI_x.PHD + String gammaOneName = StrUtil.subBefore(sampleFileName, ".PHD", true) + "_ROI_1.PHD"; + // 创建Gamma文件 + this.createGammaFile(path, gammaOneName, struct, sampleVueData.getROIOneCounts()); + + String gammaTwoName = StrUtil.subBefore(sampleFileName, ".PHD", true) + "_ROI_2.PHD"; + this.createGammaFile(path, gammaTwoName, struct, sampleVueData.getROITwoCounts()); + + String gammaThreeName = StrUtil.subBefore(sampleFileName, ".PHD", true) + "_ROI_3.PHD"; + this.createGammaFile(path, gammaThreeName, struct, sampleVueData.getROIThreeCounts()); + + String gammaFourName = StrUtil.subBefore(sampleFileName, ".PHD", true) + "_ROI_4.PHD"; + this.createGammaFile(path, gammaFourName, struct, sampleVueData.getROIFourCounts()); + + // Gamma文件内容转换为PHD实体 + sampleVueData.setROIOneFileName(gammaOneName); + sampleVueData.setROIOnePHDFile(this.createGammaPHD(struct, gammaOneName, path, sampleVueData.getROIOneCounts())); + sampleVueData.setROITwoFileName(gammaTwoName); + sampleVueData.setROITwoPHDFile(this.createGammaPHD(struct, gammaTwoName, path, sampleVueData.getROITwoCounts())); + sampleVueData.setROIThreeFileName(gammaThreeName); + sampleVueData.setROIThreePHDFile(this.createGammaPHD(struct, gammaThreeName, path, sampleVueData.getROIThreeCounts())); + sampleVueData.setROIFourFileName(gammaFourName); + sampleVueData.setROIFourPHDFile(this.createGammaPHD(struct, gammaFourName, path, sampleVueData.getROIFourCounts())); + } + + /** + * 根据DLL解析GammaPHD内容 得到PHDFile实体 + * @param struct dll解析后的实体 + * @param fileName 文件名称 + * @param pathName 路径 + * @param g_counts beta卡出来的gamma数据 + * @return PHDFile 实体 + */ + public PHDFile createGammaPHD(EnergySpectrumStruct struct, String fileName, String pathName, List g_counts) { PHDFile phd = new PHDFile(); phd.setFilepath(pathName); phd.setFilename(fileName); File file = new File(pathName + StringPool.SLASH + fileName); phd.setTmpFilePath(file.getAbsolutePath()); try { - //读取文件信息 - EnergySpectrumStruct struct = EnergySpectrumHandler.getSourceData(file.getAbsolutePath()); //MsgInfo phd.getMsgInfo().setMsg_id(struct.msg_id); phd.getMsgInfo().setMsg_type(struct.msg_type); @@ -985,7 +1381,8 @@ public class SelfStationUtil extends AbstractLogOrReport { phd.getSpec().setNum_g_channel(struct.g_counts.size()); // todo 原Num_g_channel有误 phd.getSpec().setG_energy_span(struct.g_energy_span); phd.getSpec().setBegin_channel(struct.g_begin_channel); - phd.getSpec().setCounts(struct.g_counts); + // 从 struct.g_counts 换成 beta 卡出来的gamma数据 + phd.getSpec().setCounts(g_counts); int i = 0; for (; i < phd.getSpec().getNum_g_channel(); i++) { if (phd.getSpec().getCounts().get(i) > 0) { @@ -1064,115 +1461,6 @@ public class SelfStationUtil extends AbstractLogOrReport { return phd; } - /** - * 创建Gamma PHD文件并转换为数据存入SelfStationVueData - * @param path PHD保存地址 - * @param sampleFileName beta样品谱名称 - * @param struct beta谱数据 - * @param sampleVueData 存储数据实体 - */ - public void createGamma(String path, String sampleFileName, EnergySpectrumStruct struct, SelfStationVueData sampleVueData){ - // 根据ROI生成四个Gamma谱文件, 文件命名为Beta名称后面_ROI_x.PHD - String gammaOneName = StrUtil.subBefore(sampleFileName, ".PHD", true) + "_ROI_1.PHD"; - // 创建Gamma文件 - this.createGammaFile(path, gammaOneName, struct, sampleVueData.getROIOneCounts()); - - String gammaTwoName = StrUtil.subBefore(sampleFileName, ".PHD", true) + "_ROI_2.PHD"; - this.createGammaFile(path, gammaTwoName, struct, sampleVueData.getROITwoCounts()); - - String gammaThreeName = StrUtil.subBefore(sampleFileName, ".PHD", true) + "_ROI_3.PHD"; - this.createGammaFile(path, gammaThreeName, struct, sampleVueData.getROIThreeCounts()); - - String gammaFourName = StrUtil.subBefore(sampleFileName, ".PHD", true) + "_ROI_4.PHD"; - this.createGammaFile(path, gammaFourName, struct, sampleVueData.getROIFourCounts()); - - // Gamma文件内容转换为PHD实体 - sampleVueData.setROIOneFileName(gammaOneName); - sampleVueData.setROIOnePHDFile(this.getGammaPHD(gammaOneName, path)); - sampleVueData.setROITwoFileName(gammaTwoName); - sampleVueData.setROITwoPHDFile(this.getGammaPHD(gammaTwoName, path)); - sampleVueData.setROIThreeFileName(gammaThreeName); - sampleVueData.setROIThreePHDFile(this.getGammaPHD(gammaThreeName, path)); - sampleVueData.setROIFourFileName(gammaFourName); - sampleVueData.setROIFourPHDFile(this.getGammaPHD(gammaFourName, path)); - } - /** - * 根据ROI卡出来的Gamma数据生成新的GammaPHD文件 - * @param pathName 文件存储路径 - * @param fileName GammaPHD名称 - * @param struct BetaPHD内容 - * @param g_counts ROI卡出来的Gamma数据 - */ - public void createGammaFile(String pathName,String fileName, EnergySpectrumStruct struct, List g_counts) { - File file = new File(pathName + "\\" + fileName); - // 创建PrintWriter对象 - PrintWriter out = null; - DecimalFormat decimalFormat = new DecimalFormat("0.000000"); - try { - out = new PrintWriter(file); - out.println("BEGIN IMS2.0"); - out.println("MSG_TYPE DATA"); - // todo msg_type用的不对,dll没解析出这个字段 - out.println("MSG_ID " + struct.msg_id + " " + struct.msg_type + "\n" + "DATA_TYPE " + struct.data_type); - out.println("#Header 3"); - // 解析出的Gamma谱 系统类型暂时使用G - out.println(struct.site_code + " " + struct.detector_code + " C " + - struct.sample_geometry + " " + struct.spectrum_quantity); - out.println(struct.sample_ref_id); - out.println(struct.measurement_id + " " + struct.detector_bk_measurement_id + " 0"); - out.println(struct.transmit_date + " " + struct.transmit_time); - out.println("#Collection"); - out.println(struct.collection_start_date + " " + struct.collection_start_time + " " + - struct.collection_stop_date + " " + struct.collection_stop_time + " " - + decimalFormat.format(struct.air_volume)); - out.println("#Acquisition"); - out.println(struct.acquisition_start_date + " " + struct.acquisition_start_time + " " + - decimalFormat.format(struct.acquisition_real_time) + " " + - decimalFormat.format(struct.acquisition_live_time)); - out.println("#g_Energy"); - - - format(struct.g_energy, struct.g_centroid_channel, struct.g_uncertainty, out); - out.println("#g_Resolution"); - format(struct.g_r_energy, struct.g_r_FWHM, struct.g_r_uncertainty, out); - out.println("#g_Efficiency"); - format(struct.g_e_energy, struct.g_e_efficiency, struct.g_e_uncertainty, out); - out.println("#g_Spectrum"); - // num_g_channel 根据g_counts数量得来和PHD写的数字没有关系;g_energy_span是PHD写的值 - out.println(struct.num_g_channel + " " + struct.g_energy_span); - // 存储前一个数字 - String beforeStr = ""; - for (int i = 0; i < g_counts.size(); i++) { - String str = g_counts.get(i).toString(); - if(i % 5 == 0) { - if (i == 0) { - out.printf((i+1)+""); - } else { - out.printf("\n" + (i+1) ); - } - beforeStr = i+""; - } - - if(StrUtil.isEmpty(beforeStr)){ - beforeStr = str; - } - // 根据前一个字符长度计算需要的空格 - out.printf("%" + (str.length() + (6 - beforeStr.length()))+ "s" , g_counts.get(i)); - if(i == g_counts.size() - 1) { - out.println(); - } - beforeStr = str; - } - out.print("STOP"); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } finally { - if (null != out) { - out.close(); - } - } - } - /** * 数据格式化 * @param aList 第一列数据 diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SelfStationServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SelfStationServiceImpl.java index 2da5d00b..1854c64a 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SelfStationServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SelfStationServiceImpl.java @@ -281,10 +281,10 @@ public class SelfStationServiceImpl extends AbstractLogOrReport implements ISelf String path = fullPath1.substring(0, fullPath1.lastIndexOf(StrUtil.SLASH)); - PHDFile phd1 = selfStationUtil.getGammaPHD(name1, path); - PHDFile phd2 = selfStationUtil.getGammaPHD(name2, path); - PHDFile phd3 = selfStationUtil.getGammaPHD(name3, path); - PHDFile phd4 = selfStationUtil.getGammaPHD(name4, path); + PHDFile phd1 = selfStationUtil.createGammaPHD(struct, name1, path, sampleVueData.getROIOneCounts()); + PHDFile phd2 = selfStationUtil.createGammaPHD(struct, name2, path, sampleVueData.getROITwoCounts()); + PHDFile phd3 = selfStationUtil.createGammaPHD(struct, name3, path, sampleVueData.getROIThreeCounts()); + PHDFile phd4 = selfStationUtil.createGammaPHD(struct, name4, path, sampleVueData.getROIFourCounts()); // 从数据库加载 ROI信息 List phdFiles = ListUtil.toList(phd1, phd2, phd3, phd4); @@ -462,24 +462,23 @@ public class SelfStationServiceImpl extends AbstractLogOrReport implements ISelf //返回结果map Map map = new HashMap<>(); //获取sample分析后的对象 - EnergySpectrumStruct struct = selfStationUtil.getSourceData(sampleFilePath, "sample", selfStationData); - if (Objects.nonNull(struct)) { - selfStationData.setSampleStruct(struct); + // 获取PHD数据 + selfStationUtil.getSourceDataNotHis(sampleFilePath, "sample", selfStationData); + EnergySpectrumStruct sampleStruct = selfStationData.getSampleStruct(); + if (Objects.nonNull(sampleStruct)) { selfStationData.setSampleFileName(sampleFileName); selfStationData.setSampleFilePathName(sampleFilePath); selfStationUtil.loadFile(selfStationData, null, null, "sample", map); - SelfStationVueData sampleVueData = selfStationData.getSampleVueData(); - selfStationUtil.createGamma(path, sampleFileName, struct, sampleVueData); + selfStationUtil.createGamma(path, sampleFileName, sampleStruct, sampleVueData); resultMap.put("sample", map); // 初始化Configure - initConfigure(struct, selfStationData); - + initConfigure(sampleStruct, selfStationData); // 返回Beta和Gamma的数据 - bGSpectrum(struct, map); + bGSpectrum(sampleStruct, map); } } //判断det文件名是否为空 @@ -489,16 +488,15 @@ public class SelfStationServiceImpl extends AbstractLogOrReport implements ISelf //返回结果map Map map = new HashMap<>(); //获取det分析后的对象 - EnergySpectrumStruct struct = selfStationUtil.getSourceData(detFilePath, "det", selfStationData); - if (Objects.nonNull(struct)) { - selfStationData.setDetStruct(struct); + selfStationUtil.getSourceDataNotHis(detFilePath, "det", selfStationData); + if (Objects.nonNull(selfStationData.getDetStruct())) { selfStationData.setDetFilePathName(detFilePath); selfStationData.setDetFileName(detFileName); selfStationUtil.loadFile(selfStationData, null, null, "det", map); resultMap.put("det", map); // 返回Beta和Gamma的数据 - bGSpectrum(struct, map); + bGSpectrum(selfStationData.getDetStruct(), map); } } //判断qc文件名是否为空 @@ -508,16 +506,15 @@ public class SelfStationServiceImpl extends AbstractLogOrReport implements ISelf //返回结果map Map map = new HashMap<>(); //获取QC分析后的对象 - EnergySpectrumStruct struct = selfStationUtil.getSourceData(qcFilePath, "qc", selfStationData); - if (Objects.nonNull(struct)) { - selfStationData.setQcStruct(struct); + selfStationUtil.getSourceDataNotHis(qcFilePath, "qc", selfStationData); + if (Objects.nonNull(selfStationData.getQcStruct())) { selfStationData.setQcFilePathName(qcFilePath); selfStationData.setQcFileName(qcFileName); selfStationUtil.loadFile(selfStationData, null, null, "qc", map); resultMap.put("qc", map); // 返回Beta和Gamma的数据 - bGSpectrum(struct, map); + bGSpectrum(selfStationData.getQcStruct(), map); } } @@ -543,9 +540,14 @@ public class SelfStationServiceImpl extends AbstractLogOrReport implements ISelf if (StringUtils.isNotBlank(sampleFileName)) { //返回结果map Map map = new HashMap<>(); + //拼接sample文件路径 + String sampleFilePath = path + StringPool.SLASH + sampleFileName; + selfStationData.setSampleFileName(sampleFileName); + selfStationData.setSampleFilePathName(sampleFilePath); + selfStationUtil.loadFile(selfStationData, null, null, "sample", map); resultMap.put("sample", map); - + selfStationUtil.createGamma(path, sampleFileName, selfStationData.getSampleStruct(), selfStationData.getSampleVueData()); // 返回Beta和Gamma的数据 bGSpectrum(selfStationData.getSampleStruct(), map); }