From 02083f93f50ec8cba2491773b5ad2e7b34ad8870 Mon Sep 17 00:00:00 2001 From: nieziyan Date: Thu, 8 Aug 2024 09:41:12 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat=EF=BC=9A=E8=87=AA=E5=BB=BA=E5=8F=B0?= =?UTF-8?q?=E7=AB=99=E8=87=AA=E5=8A=A8=E5=A4=84=E7=90=86=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/spectrum/Sample_C_Analysis.java | 119 +++++++++++++----- 1 file changed, 90 insertions(+), 29 deletions(-) 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 d11006b4..6d67f07b 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 @@ -27,14 +27,14 @@ import org.jeecg.modules.base.bizVo.AttributeItemVo; import org.jeecg.modules.base.dto.*; import org.jeecg.modules.base.entity.original.GardsSampleData; import org.jeecg.modules.base.entity.rnauto.*; -import org.jeecg.modules.base.enums.DSType; -import org.jeecg.modules.base.enums.MiddleDataType; -import org.jeecg.modules.base.enums.SpectrumType; +import org.jeecg.modules.base.enums.*; import org.jeecg.modules.config.datasource.DataSourceSwitcher; import org.jeecg.modules.eneity.event.SpectrumErrorEvent; import org.jeecg.modules.entity.vo.*; +import org.jeecg.modules.enums.ErrorType; import org.jeecg.modules.exception.AnalySpectrumException; import org.jeecg.modules.exception.CAnalyseException; +import org.jeecg.modules.exception.FileNotExistException; import org.jeecg.modules.file.FileOperation; import org.jeecg.modules.native_jni.EnergySpectrumHandler; import org.jeecg.modules.native_jni.struct.BgBoundary; @@ -124,9 +124,9 @@ public class Sample_C_Analysis { */ private String arrFileName; - /* - * 自建台站谱解析所需的四个Gamms谱对象 - * */ + /* + * 自建台站谱解析所需的四个Gamms谱对象 + */ private PHDFile phdFile1; private PHDFile phdFile2; private PHDFile phdFile3; @@ -136,6 +136,18 @@ public class Sample_C_Analysis { private Map middleDataMap; + protected Date startAnalysisTime; + + protected Date endAnalysisTime; + + protected GardsSampleData detSampleData = null; + + protected EnergySpectrumStruct detStruct = null; + + private String detFileFinalPath; + + protected ParsingProcessLog parsingProcessLog; + public Sample_C_Analysis(AbstractS_D_Q_G_SpectrumHandler spectrumHandler, EnergySpectrumStruct sampleStruct, SpectrumServiceQuotes serviceQuotes, GardsSampleData sampleData) { this.spectrumHandler = spectrumHandler; @@ -144,6 +156,7 @@ public class Sample_C_Analysis { this.sampleStruct = sampleStruct; this.systemType = sampleStruct.system_type; this.dataType = sampleStruct.data_type; + this.parsingProcessLog = spectrumHandler.parsingProcessLog; this.sampleInputFilename = sampleData.getInputFileName(); this.sampleFilename = StringUtils.substring(sampleData.getInputFileName(), sampleData.getInputFileName().lastIndexOf((StringConstant.SLASH))+1); @@ -152,6 +165,20 @@ public class Sample_C_Analysis { public void analysis() throws CAnalyseException, AnalySpectrumException{ log.info("SelfStaion自动处理分析--Start"); try { + this.startAnalysisTime = new Date(); + + //声明分析日志对象 + // parsingProcessLog.setSample_C_Analysis(this); + + //查询det数据(sampleId,inputFileName) sample数据在构造函数已经传过来 + this.queryPHDFile(); + + //查找det谱PHD文件 sample谱PHD文件位置在构造函数已经传过来 + this.getPHDFile(); + + // Beta谱进行分析 TODO Analysis + + //获取PHD文件的路径以及文件名称信息 String sampleFilePathName = spectrumHandler.spectrumFile.getAbsolutePath().replace("\\", StringPool.SLASH); this.sampleFilePath = sampleFilePathName.substring(0, sampleFilePathName.lastIndexOf(StringPool.SLASH)); @@ -235,6 +262,8 @@ public class Sample_C_Analysis { } else { throw new CAnalyseException("Sample Analyse Error at "+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss")); } + }finally { + this.endAnalysisTime = new Date(); } log.info("SelfStaion自动处理分析--End"); } @@ -342,6 +371,43 @@ public class Sample_C_Analysis { return rootPath + saveFilePath + StrUtil.SLASH + saveRelativePath; } + private void queryPHDFile() throws FileNotExistException { + //查询det和gas能谱文 + this.detSampleData = serviceQuotes.getSampleDataService().getSampleIdAndInputFileName(this.sampleStruct.detector_bk_measurement_id, DataTypeAbbr.DETBKPHD.getType(), this.sampleStruct.system_type); + + //如果找不到sample、det、gas谱文件数据则解析失败修改记录状态 + if(StringUtils.isEmpty(this.sampleData.getInputFileName()) || Objects.isNull(this.detSampleData) || StringUtils.isEmpty(this.detSampleData.getInputFileName())){ + parsingProcessLog.setFileNotExist(true); + + this.serviceQuotes.getSampleDataService().updateStatus(SampleStatus.FAIL.getValue(),this.sampleData.getInputFileName()); + ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(), ErrorType.GAS_OR_DET_ERROR,this.sampleFilename)); + throw new FileNotExistException("gas or det file is no exist or is error.."); + } + } + + private void getPHDFile() throws FileNotExistException { + boolean flag = false; + + //det谱PHD文件本地路径 + StringBuilder detFileFinalPath = new StringBuilder(); + detFileFinalPath.append(this.serviceQuotes.getSpectrumPathProperties().getRootPath()); + detFileFinalPath.append(this.serviceQuotes.getSpectrumPathProperties().getSaveFilePath()); + detFileFinalPath.append(StrUtil.SLASH); + detFileFinalPath.append(detSampleData.getInputFileName()); + this.detFileFinalPath = detFileFinalPath.toString(); + File detFile = new File(this.detFileFinalPath); + if(!detFile.exists()){ + flag = true; + } + + if(flag){ + parsingProcessLog.setFileNotExist(true); + ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(), ErrorType.GAS_OR_DET_ERROR,this.sampleFilename)); + throw new FileNotExistException("gas or det file is no exist or is error.."); + } + this.detStruct = EnergySpectrumHandler.getSourceData(this.detFileFinalPath); + } + /** * 读取计算MDC参数文件方法 */ @@ -451,8 +517,9 @@ public class Sample_C_Analysis { final TransactionStatus transactionStatus = serviceQuotes.getTransactionManager().getTransaction(serviceQuotes.getTransactionDefinition()); try { Integer sampleId = this.sampleData.getSampleId(); - // 保存分析结果 ==> INSERT INTO RNAUTO.GARDS_ANALYSES - saveAnalysis(middleDatas[0], sampleId); + // 保存分析结果 ==> INSERT INTO RNAUTO.GARDS_ANALYSES TODO 填充Beta分析产生的报告和日志地址 + saveAnalysis(sampleId, this.detSampleData, this.startAnalysisTime, + this.endAnalysisTime, null, null); // 获取分析结果ID ==> SELECT IDANALYSIS idAnalysis = serviceQuotes.getAnalysesService().getIdAnalysis(sampleId); // 保存分析结果 ==> INSERT INTO RNAUTO.GARDS_ANALYSES @@ -1334,31 +1401,25 @@ public class Sample_C_Analysis { } } - public void saveAnalysis(GStoreMiddleProcessData middleData, Integer sampleId){ - GardsAnalyses analysis = toAnalysis(middleData); + public void saveAnalysis(Integer sampleId, GardsSampleData detSampleData, Date analysisBegin, + Date analysisEnd, String logPath, String reportPath){ + GardsAnalyses analysis = new GardsAnalyses(); analysis.setSampleId(sampleId); + analysis.setCategory(1);//按C++代码写死的1,该字段是分级结果张博士还没有想好数据要不要分级1,2,3,4 + analysis.setAnalysisBegin(analysisBegin); + analysis.setAnalysisEnd(analysisEnd); + analysis.setType(AnalysesType.AUTO.getValue()); + analysis.setSoftware(serviceQuotes.getSoftwareProperties().getSwName()); + analysis.setSwVersion(serviceQuotes.getSoftwareProperties().getSwVersion()); + analysis.setAnalyst(serviceQuotes.getSoftwareProperties().getAnalyst()); + analysis.setComments("test");//按C++代码写死的test + analysis.setUseddetphd(detSampleData.getInputFileName()); + analysis.setUseddetphdId(detSampleData.getSampleId()); + analysis.setLogPath(FileOperation.separatorConvert(logPath)); + analysis.setReportPath(FileOperation.separatorConvert(reportPath)); serviceQuotes.getAnalysesService().save(analysis); } - private GardsAnalyses toAnalysis(GStoreMiddleProcessData middleData){ - GardsAnalyses gardsAnalyses = new GardsAnalyses(); - String dateTime = DateConstant.DATE_BIAS_TIME; - String analysisBegin = middleData.getAnalyses_analysisBegin(); - Date analysis_Begin = DateUtil.parse(analysisBegin, dateTime) - .toJdkDate(); - gardsAnalyses.setAnalysisBegin(analysis_Begin); - String analysisEnd = middleData.getAnalyses_analysisEnd(); - Date analysis_End = DateUtil.parse(analysisEnd, dateTime) - .toJdkDate(); - gardsAnalyses.setAnalysisEnd(analysis_End); - gardsAnalyses.setType(middleData.getAnalyses_type()); - gardsAnalyses.setSoftware(middleData.getAnalyses_software()); - gardsAnalyses.setSwVersion(middleData.getAnalyses_swVersion()); - gardsAnalyses.setAnalyst(middleData.getAnalyses_analyst()); - gardsAnalyses.setComments(middleData.getAnalyses_comments()); - return gardsAnalyses; - } - /* public List mapFields(T1 source, T2 tartget, String baseLine, Map fieldMap) { try { List result = new ArrayList<>(); From 8aeebe304741d3a205e27fe3857cfbfc0378c598 Mon Sep 17 00:00:00 2001 From: nieziyan Date: Fri, 9 Aug 2024 09:17:55 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat=EF=BC=9A=E8=87=AA=E5=BB=BA=E5=8F=B0?= =?UTF-8?q?=E7=AB=99pekaInfomation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/common/util/ExportUtil.java | 24 ++++++ .../controller/SelfStationController.java | 12 +++ .../modules/service/ISelfStationService.java | 4 + .../service/impl/SelfStationServiceImpl.java | 85 +++++++++++++++++++ 4 files changed, 125 insertions(+) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/ExportUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/ExportUtil.java index 1dbe6319..678bc2c8 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/ExportUtil.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/ExportUtil.java @@ -13,6 +13,7 @@ import org.apache.poi.ss.usermodel.Workbook; import org.jeecgframework.poi.excel.ExcelExportUtil; import org.jeecgframework.poi.excel.entity.ExportParams; import org.jeecgframework.poi.excel.entity.TemplateExportParams; +import org.jeecgframework.poi.excel.entity.enmus.ExcelType; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; @@ -104,6 +105,29 @@ public class ExportUtil { } } + public static void exportXls(HttpServletResponse response, List> dataList, String fileName){ + Workbook workbook = null; + OutputStream outputStream = null; + try { + // 设置文件名、Excel类型(xls|xlsx) + outputStream = ExportUtil.xls(response,fileName); + workbook = ExcelExportUtil. + exportExcel(dataList, ExcelType.HSSF); + workbook.write(outputStream); + } catch (IOException e) { + e.printStackTrace(); + }finally { + try { + if (ObjectUtil.isNotNull(outputStream)) + outputStream.close(); + if (ObjectUtil.isNotNull(workbook)) + workbook.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + public static void exportXls(HttpServletResponse response, Class target, List data){ exportXls(response, target, data, "file.xls"); } diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/SelfStationController.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/SelfStationController.java index 32bda5d5..ec16ec2b 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/SelfStationController.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/SelfStationController.java @@ -427,4 +427,16 @@ public class SelfStationController { public Result viewBGLogViewer(String sampleFileName, HttpServletRequest request) { return selfStationService.viewBGLogViewer(sampleFileName, request); } + + @GetMapping("peakInformation") + @ApiOperation(value = "查看Peak Information页面数据", notes = "查看Peak Information页面数据") + public Result peakInformation(String sampleFileName, HttpServletRequest request){ + return selfStationService.peakInformation(sampleFileName, request); + } + + @GetMapping("exportPeakInformation") + @ApiOperation(value = "导出Peak Information页面数据", notes = "导出Peak Information页面数据") + public void exportPeakInformation(String sampleFileName, HttpServletRequest request, HttpServletResponse response){ + selfStationService.exportPeakInformation(sampleFileName, request, response); + } } diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/ISelfStationService.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/ISelfStationService.java index 496b7b70..f1d954b7 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/ISelfStationService.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/ISelfStationService.java @@ -138,4 +138,8 @@ public interface ISelfStationService { Result viewAutomaticAnalysisLog(Integer sampleId); Result viewBGLogViewer(String sampleFileName, HttpServletRequest request); + + Result peakInformation(String sampleFileName, HttpServletRequest request); + + void exportPeakInformation(String sampleFileName, HttpServletRequest request, HttpServletResponse response); } 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 0290db0f..196fc622 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 @@ -1,5 +1,6 @@ package org.jeecg.modules.service.impl; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.ObjectUtil; @@ -42,6 +43,8 @@ import org.jeecg.modules.native_jni.CalValuesHandler; import org.jeecg.modules.native_jni.EnergySpectrumHandler; import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct; import org.jeecg.modules.service.*; +import org.jeecgframework.poi.excel.entity.ExportParams; +import org.jeecgframework.poi.excel.entity.enmus.ExcelType; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -5412,6 +5415,88 @@ public class SelfStationServiceImpl implements ISelfStationService { return Result.OK(result); } + @Override + public Result peakInformation(String sampleFileName, HttpServletRequest request) { + String userName = JwtUtil.getUserNameByToken(request); + Cache selfCache = selfStationCache.getSelfCache(); + SelfStationData selfStationData = selfCache.getIfPresent(sampleFileName + StringPool.DASH + userName); + if (ObjectUtil.isNull(selfStationData)) + return Result.error("Please select the parse file first!"); + Map> result = new HashMap<>(); + SelfStationVueData sampleVueData = selfStationData.getSampleVueData(); + PHDFile phd1 = sampleVueData.getROIOnePHDFile(); + PHDFile phd2 = sampleVueData.getROITwoPHDFile(); + PHDFile phd3 = sampleVueData.getROIThreePHDFile(); + PHDFile phd4 = sampleVueData.getROIFourPHDFile(); + List phdFiles = ListUtil.toList(phd1, phd2, phd3, phd4); + for (int i = 0; i < phdFiles.size(); i++) { + PHDFile phdFile = phdFiles.get(i); + List vPeak = phdFile.getVPeak(); + if (CollUtil.isEmpty(vPeak)) continue; + List tablePeaks = new LinkedList<>(); + for (PeakInfo peak : vPeak) { + TablePeak tablePeak = new TablePeak(); + tablePeak.setEnergy(String.format("%.3f", peak.energy)); + tablePeak.setCentroid(String.format("%.3f", peak.peakCentroid)); + tablePeak.setMultiplet(String.valueOf(peak.multiIndex)); + tablePeak.setFwhm(String.format("%.3f", peak.fwhm)); + tablePeak.setNetArea(String.format("%.3f", peak.area)); + tablePeak.setAreaErr(peak.area > 0 ? String.format("%.3f", (peak.areaErr / peak.area) * 100) : "0"); + tablePeak.setSignificant(String.format("%.3f", peak.significance)); + tablePeak.setSensitivity(String.format("%.3f", peak.sensitivity)); + tablePeak.setIndentify(org.apache.commons.lang3.StringUtils.join(peak.nuclides, ";")); + tablePeaks.add(tablePeak); + } + result.put("Gamma_ROI_" + (i + 1), tablePeaks); + } + return Result.OK(result); + } + + @Override + public void exportPeakInformation(String sampleFileName, HttpServletRequest request, HttpServletResponse response) { + String userName = JwtUtil.getUserNameByToken(request); + Cache selfCache = selfStationCache.getSelfCache(); + SelfStationData selfStationData = selfCache.getIfPresent(sampleFileName + StringPool.DASH + userName); + if (ObjectUtil.isNull(selfStationData)) return; + SelfStationVueData sampleVueData = selfStationData.getSampleVueData(); + PHDFile phd1 = sampleVueData.getROIOnePHDFile(); + PHDFile phd2 = sampleVueData.getROITwoPHDFile(); + PHDFile phd3 = sampleVueData.getROIThreePHDFile(); + PHDFile phd4 = sampleVueData.getROIFourPHDFile(); + List phdFiles = ListUtil.toList(phd1, phd2, phd3, phd4); + List> dataList = new ArrayList<>(); + for (int i = 0; i < phdFiles.size(); i++) { + PHDFile phdFile = phdFiles.get(i); + List vPeak = phdFile.getVPeak(); + if (CollUtil.isEmpty(vPeak)) continue; + Map data = new HashMap<>(); + ExportParams exportParam = new ExportParams(); + exportParam.setSheetName("ROI_" + (i + 1)); + data.put("title", exportParam); + data.put("entity", TablePeak.class); + List tablePeaks = new LinkedList<>(); + for (int j = 0; j < vPeak.size(); j++) { + PeakInfo peak = vPeak.get(j); + TablePeak tablePeak = new TablePeak(); + tablePeak.setNo(j + 1); + tablePeak.setEnergy(String.format("%.3f", peak.energy)); + tablePeak.setCentroid(String.format("%.3f", peak.peakCentroid)); + tablePeak.setMultiplet(String.valueOf(peak.multiIndex)); + tablePeak.setFwhm(String.format("%.3f", peak.fwhm)); + tablePeak.setNetArea(String.format("%.3f", peak.area)); + tablePeak.setAreaErr(peak.area > 0 ? String.format("%.3f", (peak.areaErr / peak.area) * 100) : "0"); + tablePeak.setSignificant(String.format("%.3f", peak.significance)); + tablePeak.setSensitivity(String.format("%.3f", peak.sensitivity)); + tablePeak.setIndentify(org.apache.commons.lang3.StringUtils.join(peak.nuclides, ";")); + tablePeaks.add(tablePeak); + } + data.put("data", tablePeaks); + dataList.add(data); + } + if (CollUtil.isNotEmpty(dataList)) + ExportUtil.exportXls(response, dataList, "PeakInformation.xls"); + } + @Transactional public boolean SaveSampleToDB(PHDFile phd, String input_file_name) { boolean bRet = false;