From 0b7a03f283d01190c55797115194a9fbc4cc66a9 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Mon, 14 Aug 2023 14:34:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=A5=E5=B3=B0=E5=A4=84=E7=9A=84=E6=8E=A2?= =?UTF-8?q?=E6=B5=8B=E6=95=88=E7=8E=87=E4=B8=8D=E7=A1=AE=E5=AE=9A=E5=BA=A6?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=90=8D=E7=A7=B0=E4=BF=AE=E6=94=B9=20?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E6=B5=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/rnauto/GardsNuclLinesIded.java | 2 +- .../base/entity/rnauto/GardsRoiChannels.java | 1 + .../base/entity/rnauto/GardsRoiResults.java | 1 + .../base/entity/rnman/GardsNuclLinesIded.java | 2 +- .../org/jeecg/common/util/PHDFileUtil.java | 13 +- .../SpectrumAnalysesController.java | 9 +- .../entity/GardsROIChannelsSpectrum.java | 54 ++ .../entity/GardsROIResultsSpectrum.java | 93 ++++ .../mapper/SpectrumAnalysisMapper.java | 11 + .../mapper/xml/SpectrumAnalysisMapper.xml | 96 +++- .../service/ISpectrumAnalysisService.java | 3 +- .../impl/SpectrumAnalysisServiceImpl.java | 493 ++++++++++++++---- .../org/jeecg/common/util/ReadLineUtil.java | 10 +- 13 files changed, 677 insertions(+), 111 deletions(-) create mode 100644 jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/entity/GardsROIChannelsSpectrum.java create mode 100644 jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/entity/GardsROIResultsSpectrum.java diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/rnauto/GardsNuclLinesIded.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/rnauto/GardsNuclLinesIded.java index eb5e0b30..d82f967a 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/rnauto/GardsNuclLinesIded.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/rnauto/GardsNuclLinesIded.java @@ -83,7 +83,7 @@ public class GardsNuclLinesIded implements Serializable { * 该峰处的探测效率不确定度 */ @TableField(value = "UNEFFIC") - private Double uncEffic; + private Double unEffic; /** * 利用该峰计算得到的最小可探测活度 */ diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/rnauto/GardsRoiChannels.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/rnauto/GardsRoiChannels.java index dae04fa9..f18cf5f5 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/rnauto/GardsRoiChannels.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/rnauto/GardsRoiChannels.java @@ -56,4 +56,5 @@ public class GardsRoiChannels implements Serializable { @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date moddate; + } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/rnauto/GardsRoiResults.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/rnauto/GardsRoiResults.java index d3b0de5b..0f1ce183 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/rnauto/GardsRoiResults.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/rnauto/GardsRoiResults.java @@ -96,4 +96,5 @@ public class GardsRoiResults implements Serializable { @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date moddate; + } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/rnman/GardsNuclLinesIded.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/rnman/GardsNuclLinesIded.java index d497525e..036063cb 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/rnman/GardsNuclLinesIded.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/rnman/GardsNuclLinesIded.java @@ -82,7 +82,7 @@ public class GardsNuclLinesIded implements Serializable { * 该峰处的探测效率不确定度 */ @TableField(value = "UNEFFIC") - private Double uncEffic; + private Double unEffic; /** * 利用该峰计算得到的最小可探测活度 */ diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/PHDFileUtil.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/PHDFileUtil.java index 508247e9..32fa14c6 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/PHDFileUtil.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/PHDFileUtil.java @@ -265,6 +265,7 @@ public class PHDFileUtil { if (Objects.isNull(ftpClient)){ throw new RuntimeException("ftp连接失败!"); } + InputStream iStream= null; try { ftpClient.enterLocalPassiveMode(); String fileName = filePath.substring(filePath.lastIndexOf(StringPool.SLASH) + 1); @@ -282,15 +283,12 @@ public class PHDFileUtil { for (FTPFile ftpFile:ftpFiles) { if (ftpFile.getName().equals(fileName)){ //读取ftp文件的输入流 - InputStream iStream=ftpClient.retrieveFileStream(ftpFile.getName()); + iStream=ftpClient.retrieveFileStream(ftpFile.getName()); //声明一个临时文件 File file = File.createTempFile("tmp", null); //将ftp文件的输入流复制给临时文件 FileUtils.copyInputStreamToFile(iStream, file); List allLines = FileUtils.readLines(file, ftpUtil.getEncoding()); - if (Objects.nonNull(iStream)){ - iStream.close(); - } return allLines; } } @@ -300,7 +298,12 @@ public class PHDFileUtil { throw new RuntimeException(e); } finally { try { - ftpClient.disconnect(); + if (Objects.nonNull(ftpClient)){ + ftpClient.disconnect(); + } + if (Objects.nonNull(iStream)){ + iStream.close(); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/SpectrumAnalysesController.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/SpectrumAnalysesController.java index 54eebf47..60010ed7 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/SpectrumAnalysesController.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/SpectrumAnalysesController.java @@ -5,10 +5,7 @@ import io.swagger.annotations.ApiOperation; import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.vo.Result; import org.jeecg.modules.entity.GardsSampleDataSpectrum; -import org.jeecg.modules.entity.vo.AnalyseData; -import org.jeecg.modules.entity.vo.FittingBody; -import org.jeecg.modules.entity.vo.SeriseData; -import org.jeecg.modules.entity.vo.StatisticsQueryData; +import org.jeecg.modules.entity.vo.*; import org.jeecg.modules.service.ISpectrumAnalysisService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.annotation.DateTimeFormat; @@ -66,8 +63,8 @@ public class SpectrumAnalysesController { @GetMapping("viewRRR") @ApiOperation(value = "查看RRR报告", notes = "查看RRR报告") - public void viewRRR(Integer sampleId, HttpServletResponse response){ - spectrumAnalysisService.viewRRR(sampleId, response); + public Result viewRRR(String dbName, Integer sampleId, boolean sampleData, boolean GasBgData, boolean DetBgData, boolean QCData, boolean bGammaEnergyValid, boolean bBetaEnergyValid){ + return spectrumAnalysisService.viewRRR(dbName, sampleId, sampleData, GasBgData, DetBgData, QCData, bGammaEnergyValid, bBetaEnergyValid); } @GetMapping("viewSpectrum") diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/entity/GardsROIChannelsSpectrum.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/entity/GardsROIChannelsSpectrum.java new file mode 100644 index 00000000..5f04e0ff --- /dev/null +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/entity/GardsROIChannelsSpectrum.java @@ -0,0 +1,54 @@ +package org.jeecg.modules.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.util.Date; + +@Data +public class GardsROIChannelsSpectrum implements Serializable { + + + /** + * 样品id + */ + private Integer sampleId; + + /** + * 感兴趣区ID号 + */ + private Integer roi; + + /** + * 分析ID号 + */ + private Integer idAnalysis; + + /** + * 感兴趣区的β能量起始值 + */ + private Integer bChanStart; + + /** + * 感兴趣区的β能量结束值 + */ + private Integer bChanStop; + + /** + * 感兴趣区的γ能量起始值 + */ + private Integer gChanStart; + + /** + * 感兴趣区的γ能量结束值 + */ + private Integer gChanStop; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date moddate; + +} diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/entity/GardsROIResultsSpectrum.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/entity/GardsROIResultsSpectrum.java new file mode 100644 index 00000000..99f2cb84 --- /dev/null +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/entity/GardsROIResultsSpectrum.java @@ -0,0 +1,93 @@ +package org.jeecg.modules.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.util.Date; + +@Data +public class GardsROIResultsSpectrum implements Serializable { + + /** + * 样品id + */ + private Integer sampleId; + + /** + * 感兴趣区ID号 + */ + private Integer roi; + + /** + * 分析ID号 + */ + private Integer idAnalysis; + + /** + * 样品谱感兴趣区总计数 + */ + private Double sGross; + + /** + * 气体本底谱感兴趣区总计数 + */ + private Double gGross; + + /** + * 探测器本底谱感兴趣区总计数 + */ + private Double bGross; + + /** + * 样品谱感兴趣区净计数 + */ + private Double sNet; + + /** + * 气体本底谱感兴趣区净计数 + */ + private Double gNet; + + /** + * 感兴趣区净计数 + */ + private Double net; + + /** + * 感兴趣区净计数不确定度 + */ + private Double netErr; + + /** + * 感兴趣区活度浓度 + */ + private Double conc; + + /** + * 感兴趣区活度浓度不确定度 + */ + private Double concErr; + + /** + * 感兴趣区LC + */ + private Double lc; + + /** + * 感兴趣区MDC + */ + private Double mdc; + + /** + * 感兴趣区识别标示;1:识别到,0,未识别到 + */ + private Integer nidFlag; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date moddate; + +} diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/mapper/SpectrumAnalysisMapper.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/mapper/SpectrumAnalysisMapper.java index 08f0cbe2..ccfb1425 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/mapper/SpectrumAnalysisMapper.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/mapper/SpectrumAnalysisMapper.java @@ -71,4 +71,15 @@ public interface SpectrumAnalysisMapper { List UserNuclide(@Param(value = "systemType") String systemType, @Param(value = "userName") String userName); + Integer getAnalysisID(@Param(value = "dbName") String dbName, @Param(value = "sampleId") Integer sampleId); + + GardsCalibrationSpectrum ReadGammaCalibrationParam(@Param(value = "dbName") String dbName, @Param(value = "idAnalysis") Integer idAnalysis, @Param(value = "sampleId") Integer sampleId); + + GardsCalibrationSpectrum ReadBetaCalibrationParam(@Param(value = "dbName") String dbName, @Param(value = "idAnalysis") Integer idAnalysis, @Param(value = "sampleId") Integer sampleId); + + List ReadROIChannels(@Param(value = "dbName") String dbName, @Param(value = "idAnalysis") Integer idAnalysis, @Param(value = "sampleId") Integer sampleId); + + List ReadROIResults(@Param(value = "dbName") String dbName, @Param(value = "idAnalysis") Integer idAnalysis, @Param(value = "sampleId") Integer sampleId); + + List ReadXeResults(@Param(value = "dbName") String dbName, @Param(value = "idAnalysis") Integer idAnalysis, @Param(value = "sampleId") Integer sampleId); } diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/mapper/xml/SpectrumAnalysisMapper.xml b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/mapper/xml/SpectrumAnalysisMapper.xml index 62c95a45..bd0e3323 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/mapper/xml/SpectrumAnalysisMapper.xml +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/mapper/xml/SpectrumAnalysisMapper.xml @@ -433,7 +433,7 @@ ACTIVITY, UNCACTIVITY, EFFIC, - UNEFFIC, + UNEFFIC , MDA, KEY_FLAG, MDC, @@ -491,4 +491,98 @@ SELECT nuclide_name FROM sys_default_nuclide where use_type = 3 and nuclide_type = #{systemType} and create_by = #{userName} + + + + + + + + + + + + \ No newline at end of file diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/ISpectrumAnalysisService.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/ISpectrumAnalysisService.java index ca06aa98..93258700 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/ISpectrumAnalysisService.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/ISpectrumAnalysisService.java @@ -6,6 +6,7 @@ import org.jeecg.modules.entity.GardsSampleDataSpectrum; import org.jeecg.modules.entity.vo.AnalyseData; import org.jeecg.modules.entity.vo.SeriseData; import org.jeecg.modules.entity.vo.StatisticsQueryData; +import org.jeecg.modules.entity.vo.TableWidget; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -26,7 +27,7 @@ public interface ISpectrumAnalysisService { void viewARR(Integer sampleId, HttpServletResponse response); - void viewRRR(Integer sampleId, HttpServletResponse response); + Result viewRRR(String dbName, Integer sampleId, boolean sampleData, boolean GasBgData, boolean DetBgData, boolean QCData, boolean bGammaEnergyValid, boolean bBetaEnergyValid); Result viewSpectrum(Integer sampleId); diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumAnalysisServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumAnalysisServiceImpl.java index ef81a18a..cd297dfe 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumAnalysisServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumAnalysisServiceImpl.java @@ -15,8 +15,7 @@ import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.system.util.JwtUtil; import org.jeecg.common.util.*; import org.jeecg.modules.base.entity.original.GardsSampleData; -import org.jeecg.modules.entity.GardsSampleDataSpectrum; -import org.jeecg.modules.entity.GardsXeResultsSpectrum; +import org.jeecg.modules.entity.*; import org.jeecg.modules.entity.vo.*; import org.jeecg.modules.mapper.SpectrumAnalysisMapper; import org.jeecg.modules.native_jni.EnergySpectrumHandler; @@ -234,6 +233,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { if (Objects.isNull(ftpClient)){ throw new RuntimeException("ftp连接失败"); } + InputStream inputStream = null; try { //切换被动模式 ftpClient.enterLocalPassiveMode(); @@ -250,15 +250,12 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { } FTPFile ftpFile = ftpFiles.get(0); if (Objects.nonNull(ftpFile)){ - InputStream inputStream = ftpClient.retrieveFileStream(ftpFile.getName()); + inputStream = ftpClient.retrieveFileStream(ftpFile.getName()); //声明一个临时文件 File file = File.createTempFile("tmp", null); //将ftp文件的输入流复制给临时文件 FileUtils.copyInputStreamToFile(inputStream, file); map = phdFileUtil.getSourceData(file.getAbsolutePath(), fileName, xeDataList, sampleId, status); - if (Objects.nonNull(inputStream)){ - inputStream.close(); - } } } catch (IOException e) { throw new RuntimeException(e); @@ -267,6 +264,9 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { if (Objects.nonNull(ftpClient)){ ftpClient.disconnect(); } + if (Objects.nonNull(inputStream)){ + inputStream.close(); + } } catch (IOException e) { throw new RuntimeException(e); } @@ -298,6 +298,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { result.error500("ftp连接失败"); return result; } + InputStream inputStream = null; try { //切换被动模式 ftpClient.enterLocalPassiveMode(); @@ -315,7 +316,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { } FTPFile ftpFile = ftpFiles.get(0); if (Objects.nonNull(ftpFile)){ - InputStream inputStream = ftpClient.retrieveFileStream(ftpFile.getName()); + inputStream = ftpClient.retrieveFileStream(ftpFile.getName()); //声明一个临时文件 File file = File.createTempFile("tmp", null); //将ftp文件的输入流复制给临时文件 @@ -332,6 +333,9 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { if (Objects.nonNull(ftpClient)){ ftpClient.disconnect(); } + if (Objects.nonNull(inputStream)){ + inputStream.close(); + } } catch (IOException e) { throw new RuntimeException(e); } @@ -367,6 +371,8 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { if (Objects.isNull(ftpClient)){ throw new RuntimeException("ftp连接失败"); } + InputStream inputStream = null; + ServletOutputStream outputStream = null; try { //切换被动模式 ftpClient.enterLocalPassiveMode(); @@ -383,20 +389,14 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { } FTPFile ftpFile = ftpFiles.get(0); if (Objects.nonNull(ftpFile)){ - InputStream inputStream = ftpClient.retrieveFileStream(ftpFile.getName()); - ServletOutputStream outputStream = response.getOutputStream(); + inputStream = ftpClient.retrieveFileStream(ftpFile.getName()); + outputStream = response.getOutputStream(); byte[] buffer = new byte[1024]; int bytesRead; // 将文件输出流写入到输出流中 while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } - if (ObjectUtil.isNotNull(inputStream)){ - inputStream.close(); - } - if (ObjectUtil.isNotNull(outputStream)){ - outputStream.close(); - } } } catch (IOException e) { throw new RuntimeException(e); @@ -405,6 +405,12 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { if (Objects.nonNull(ftpClient)){ ftpClient.disconnect(); } + if (ObjectUtil.isNotNull(inputStream)){ + inputStream.close(); + } + if (ObjectUtil.isNotNull(outputStream)){ + outputStream.close(); + } } catch (IOException e) { throw new RuntimeException(e); } @@ -412,61 +418,346 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { } @Override - public void viewRRR(Integer sampleId, HttpServletResponse response) { - //获取自动处理生成的报告地址 - String reportPath = spectrumAnalysisMapper.viewRRR(sampleId); - if (StringUtils.isBlank(reportPath)){ - throw new RuntimeException("人工交互分析生成报告不存在!"); + public Result viewRRR(String dbName, Integer sampleId, + boolean sampleData, boolean GasBgData, + boolean DetBgData, boolean QCData, + boolean bGammaEnergyValid, boolean bBetaEnergyValid) { + Result result = new Result(); + //GetAnalysisID sample_id + if (dbName.equalsIgnoreCase("auto")){ + dbName = "RNAUTO"; + }else if (dbName.equalsIgnoreCase("man")){ + dbName = "RNMAN"; } - String pathName = reportPath.substring(0, reportPath.lastIndexOf(StringPool.SLASH)); - String fileName = reportPath.substring(reportPath.lastIndexOf(StringPool.SLASH)+1)+".txt"; - //连接ftp - FTPClient ftpClient = ftpUtil.LoginFTP(); - if (Objects.isNull(ftpClient)){ - throw new RuntimeException("ftp连接失败"); - } - try { - //切换被动模式 - ftpClient.enterLocalPassiveMode(); - ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); - // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项 - ftpClient.setControlEncoding("UTF-8"); - ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); - pathName=StringPool.SLASH + spectrumPathProperties.getRootPath() + StringPool.SLASH + pathName; - ftpClient.changeWorkingDirectory(pathName); - List ftpFiles = Arrays.asList(ftpClient.listFiles()); - ftpFiles=ftpFiles.stream().filter(item -> item.getName().equals(fileName)).collect(Collectors.toList()); - if (CollectionUtils.isEmpty(ftpFiles)){ - throw new RuntimeException("ftp下对应的报告文件不存在"); - } - FTPFile ftpFile = ftpFiles.get(0); - if (Objects.nonNull(ftpFile)){ - InputStream inputStream = ftpClient.retrieveFileStream(ftpFile.getName()); - ServletOutputStream outputStream = response.getOutputStream(); - byte[] buffer = new byte[1024]; - int bytesRead; - // 将文件输出流写入到输出流中 - while ((bytesRead = inputStream.read(buffer)) != -1) { - outputStream.write(buffer, 0, bytesRead); + Integer analysisID = spectrumAnalysisMapper.getAnalysisID(dbName, sampleId); + SpectrumFileRecord dbSpectrumFilePath = spectrumAnalysisMapper.getDBSpectrumFilePath("RNAUTO.GARDS_ANALYSES", sampleId); + Information information = new Information(); + //sampleFile 相关数据 + if (Objects.nonNull(dbSpectrumFilePath)){ + if (StringUtils.isNotBlank(dbSpectrumFilePath.getSampleFilePath())){ + String filePath = dbSpectrumFilePath.getSampleFilePath(); + String pathName = filePath.substring(0, filePath.lastIndexOf(StringPool.SLASH)); + String fileName = filePath.substring(filePath.lastIndexOf(StringPool.SLASH)+1); + FTPClient ftpClient = ftpUtil.LoginFTP(); + if (Objects.isNull(ftpClient)){ + result.error500("ftp连接失败"); + return result; } - if (ObjectUtil.isNotNull(inputStream)){ - inputStream.close(); - } - if (ObjectUtil.isNotNull(outputStream)){ - outputStream.close(); + InputStream inputStream = null; + try { + //切换被动模式 + ftpClient.enterLocalPassiveMode(); + ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); + // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项 + ftpClient.setControlEncoding("UTF-8"); + ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); + pathName=StringPool.SLASH + spectrumPathProperties.getRootPath() + StringPool.SLASH + pathName; + ftpClient.changeWorkingDirectory(pathName); + List ftpFiles = Arrays.asList(ftpClient.listFiles()); + ftpFiles=ftpFiles.stream().filter(item -> item.getName().equals(fileName)).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(ftpFiles)){ + result.error500("ftp下对应文件不存在"); + return result; + } + FTPFile ftpFile = ftpFiles.get(0); + if (Objects.nonNull(ftpFile)){ + inputStream = ftpClient.retrieveFileStream(ftpFile.getName()); + //声明一个临时文件 + File file = File.createTempFile("tmp", null); + //将ftp文件的输入流复制给临时文件 + FileUtils.copyInputStreamToFile(inputStream, file); + //加载dll工具库 + System.loadLibrary("ReadPHDFile"); + EnergySpectrumStruct struct = EnergySpectrumHandler.getSourceData(file.getAbsolutePath()); + + information.setSample_measid_name(struct.measurement_id); + information.setSample_det_measid_name(struct.detector_bk_measurement_id); + information.setSample_gas_measid_name(struct.gas_bk_measurement_id); + information.setSit_det_code(struct.site_code); + information.setSample_type(struct.system_type); + information.setGeometry(struct.sample_geometry); + information.setSpectral_qualifie(struct.spectrum_quantity); + String transmit_dtg_str=struct.transmit_date+" "+struct.transmit_time; + Date transmit_dtg = DateUtils.parseDate(transmit_dtg_str.substring(0, transmit_dtg_str.indexOf(StringPool.DOT)), "yyyy/MM/dd HH:mm:ss"); + information.setTransmit_dtg(transmit_dtg); + information.setDetect_code(struct.detector_code); + information.setMeasurementID(struct.measurement_id.replace("\\","/")); + information.setBkgdMeasurementID(struct.detector_bk_measurement_id.replace("\\","/")); + information.setGasBkgdMeasurementID(struct.gas_bk_measurement_id.replace("\\","/")); + information.setSampleRefId(struct.sample_ref_id); + String collect_start_str = struct.collection_start_date+" "+struct.collection_start_time; + Date collect_start = DateUtils.parseDate(collect_start_str.substring(0, collect_start_str.indexOf(StringPool.DOT)), "yyyy/MM/dd HH:mm:ss"); + information.setCollect_start(collect_start); + String collect_stop_str = struct.collection_stop_date+" "+struct.collection_stop_time; + Date collect_stop = DateUtils.parseDate(collect_stop_str.substring(0, collect_stop_str.indexOf(StringPool.DOT)), "yyyy/MM/dd HH:mm:ss"); + information.setCollect_stop(collect_stop); + information.setS_xe_stable_volume(struct.air_volume); + String acquisition_start_str = struct.acquisition_start_date+" "+struct.acquisition_start_time; + Date acquisition_start = DateUtils.parseDate(acquisition_start_str.substring(0, acquisition_start_str.indexOf(StringPool.DOT)), "yyyy/MM/dd HH:mm:ss"); + information.setAcquisition_start(acquisition_start); + double dataTime = acquisition_start.getTime()/1000; + dataTime = dataTime + struct.acquisition_live_time; + String acquisition_stop_str = DateUtils.formatDate(new Date((long) (dataTime * 1000)), "yyyy-MM-dd HH:mm:ss"); + Date acquisition_stop = DateUtils.parseDate(acquisition_stop_str, "yyyy-MM-dd HH:mm:ss"); + information.setAcquisition_stop(acquisition_stop); + information.setAcquisition_real_sec(struct.acquisition_real_time); + information.setAcquisition_live_sec(struct.acquisition_live_time); + information.setS_volume_of_Xe(struct.sample_volume_of_Xe); + } + } catch (IOException e) { + throw new RuntimeException(e); + } catch (ParseException e) { + throw new RuntimeException(e); + } finally { + try { + if (Objects.nonNull(ftpClient)){ + ftpClient.disconnect(); + } + if (ObjectUtil.isNotNull(inputStream)){ + inputStream.close(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } } } - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - try { - if (Objects.nonNull(ftpClient)){ - ftpClient.disconnect(); + if (StringUtils.isNotBlank(dbSpectrumFilePath.getGasBgFilePath())){ + String filePath = dbSpectrumFilePath.getGasBgFilePath(); + String pathName = filePath.substring(0, filePath.lastIndexOf(StringPool.SLASH)); + String fileName = filePath.substring(filePath.lastIndexOf(StringPool.SLASH)+1); + FTPClient ftpClient = ftpUtil.LoginFTP(); + if (Objects.isNull(ftpClient)){ + result.error500("ftp连接失败"); + return result; + } + InputStream inputStream = null; + try { + //切换被动模式 + ftpClient.enterLocalPassiveMode(); + ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); + // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项 + ftpClient.setControlEncoding("UTF-8"); + ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); + pathName=StringPool.SLASH + spectrumPathProperties.getRootPath() + StringPool.SLASH + pathName; + ftpClient.changeWorkingDirectory(pathName); + List ftpFiles = Arrays.asList(ftpClient.listFiles()); + ftpFiles=ftpFiles.stream().filter(item -> item.getName().equals(fileName)).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(ftpFiles)){ + result.error500("ftp下对应文件不存在"); + return result; + } + FTPFile ftpFile = ftpFiles.get(0); + if (Objects.nonNull(ftpFile)){ + inputStream = ftpClient.retrieveFileStream(ftpFile.getName()); + //声明一个临时文件 + File file = File.createTempFile("tmp", null); + //将ftp文件的输入流复制给临时文件 + FileUtils.copyInputStreamToFile(inputStream, file); + //加载dll工具库 + System.loadLibrary("ReadPHDFile"); + EnergySpectrumStruct struct = EnergySpectrumHandler.getSourceData(file.getAbsolutePath()); + + information.setGas_measid_name(struct.measurement_id); + } + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + try { + if (Objects.nonNull(ftpClient)){ + ftpClient.disconnect(); + } + if (ObjectUtil.isNotNull(inputStream)){ + inputStream.close(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + if (StringUtils.isNotBlank(dbSpectrumFilePath.getDetBgFilePath())){ + String filePath = dbSpectrumFilePath.getDetBgFilePath(); + String pathName = filePath.substring(0, filePath.lastIndexOf(StringPool.SLASH)); + String fileName = filePath.substring(filePath.lastIndexOf(StringPool.SLASH)+1); + FTPClient ftpClient = ftpUtil.LoginFTP(); + if (Objects.isNull(ftpClient)){ + result.error500("ftp连接失败"); + return result; + } + InputStream inputStream = null; + try { + //切换被动模式 + ftpClient.enterLocalPassiveMode(); + ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); + // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项 + ftpClient.setControlEncoding("UTF-8"); + ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); + pathName=StringPool.SLASH + spectrumPathProperties.getRootPath() + StringPool.SLASH + pathName; + ftpClient.changeWorkingDirectory(pathName); + List ftpFiles = Arrays.asList(ftpClient.listFiles()); + ftpFiles=ftpFiles.stream().filter(item -> item.getName().equals(fileName)).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(ftpFiles)){ + result.error500("ftp下对应文件不存在"); + return result; + } + FTPFile ftpFile = ftpFiles.get(0); + if (Objects.nonNull(ftpFile)){ + inputStream = ftpClient.retrieveFileStream(ftpFile.getName()); + //声明一个临时文件 + File file = File.createTempFile("tmp", null); + //将ftp文件的输入流复制给临时文件 + FileUtils.copyInputStreamToFile(inputStream, file); + //加载dll工具库 + System.loadLibrary("ReadPHDFile"); + EnergySpectrumStruct struct = EnergySpectrumHandler.getSourceData(file.getAbsolutePath()); + + information.setDet_measid_name(struct.measurement_id); + } + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + try { + if (Objects.nonNull(ftpClient)){ + ftpClient.disconnect(); + } + if (ObjectUtil.isNotNull(inputStream)){ + inputStream.close(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } } - } catch (IOException e) { - throw new RuntimeException(e); } } + //#SAMPLE: LIMITS PER ROI GAMMA + GardsCalibrationSpectrum gammaCalibrationParam = spectrumAnalysisMapper.ReadGammaCalibrationParam(dbName, analysisID, sampleId); + //#SAMPLE: LIMITS PER ROI BETA + GardsCalibrationSpectrum betaCalibrationParam = spectrumAnalysisMapper.ReadBetaCalibrationParam(dbName, analysisID, sampleId); + //#SAMPLE: LIMITS PER ROI + List channelsSpectrums = spectrumAnalysisMapper.ReadROIChannels(dbName, analysisID, sampleId); + //#GROSS COUNTS PER ROI + List resultsSpectrums = spectrumAnalysisMapper.ReadROIResults(dbName, analysisID, sampleId); + //#RESULT SUMMARY + List xeResultsSpectrums = spectrumAnalysisMapper.ReadXeResults(dbName, analysisID, sampleId); + StringBuffer strBuffer = new StringBuffer(); + strBuffer.append("CNL06 GENERATED REPORT").append("\n"); + strBuffer.append("REVIEWED RADIONUCLIDE REPORT").append("\n"); + strBuffer.append("(Noble Gas Version)").append("\n"); + strBuffer.append("Creation Date "+DateUtils.formatDate(new Date(), "yyyy/MM/dd-HH:mm:ss")).append("\n"); + strBuffer.append("\n"); + strBuffer.append("#FILE INFORMATION").append("\n"); + strBuffer.append(" SampleMeasID: ").append(information.getMeasurementID()).append("\n"); + strBuffer.append(" GASBKMeasID: ").append(information.getGasBkgdMeasurementID()).append("\n"); + strBuffer.append(" SRID: ").append(information.getSampleRefId()).append("\n"); + strBuffer.append(" Detector Type: ").append("3D b-g").append("\n"); + strBuffer.append("\n"); + strBuffer.append("#COLLECTION INFORMATION").append("\n"); + strBuffer.append(" Station CODE: ").append(information.getSit_det_code()).append("\n"); + strBuffer.append(" Detector CODE: ").append(information.getDetect_code()).append("\n"); + strBuffer.append(" Collection Start: ").append(information.getCollect_start()).append("\n"); + strBuffer.append(" Collection Stop: ").append(information.getCollect_stop()).append("\n"); + strBuffer.append(" Collection TIME(h): ").append((information.getCollect_stop().getTime()/1000-information.getCollect_start().getTime()/1000)/3600).append("\n"); + strBuffer.append(" Air Volume[cm3]: ").append(information.getS_xe_stable_volume()).append("\n"); + strBuffer.append(" Xe Volume[cm3]: ").append(information.getS_volume_of_Xe()).append("\n"); + strBuffer.append("\n"); + strBuffer.append("#ACQUISITION INFORMATION").append("\n"); + strBuffer.append(" Acquisition Start: ").append(information.getAcquisition_start()).append("\n"); + strBuffer.append(" Acq Real Time(s): ").append(information.getAcquisition_real_sec()).append("\n"); + strBuffer.append(" Acq Live Time: ").append(information.getAcquisition_live_sec()).append("\n"); + strBuffer.append("\n"); + strBuffer.append("#SOFTWARE").append("\n"); + strBuffer.append(" version: ").append("1.0.1").append("\n"); + strBuffer.append("\n"); + strBuffer.append("#SAMPLE Old CALIBRATION").append("\n"); + strBuffer.append(" Old Beta Old Gamma ").append("\n"); + if (sampleData){ + strBuffer.append(" CH(x) = (?1)+(?2)*x+(?3)x*x ").append(" CH(x) = (?1)+(?2)*x+(?3)x*x").append("\n"); + strBuffer.append(" E(x) = (?1)+(?2)*x+(?3)x*x ").append(" E(x) = (?1)+(?2)*x+(?3)x*x").append("\n"); + }else { + strBuffer.append(" CH(x) = (?1)+(?2)*x+(?3)x*x ").append(" CH(x) = (?1)+(?2)*x+(?3)x*x").append("\n"); + strBuffer.append(" E(x) = (?1)+(?2)*x+(?3)x*x ").append(" E(x) = (?1)+(?2)*x+(?3)x*x").append("\n"); + } + strBuffer.append("\n"); + strBuffer.append("#SAMPLE New CALIBRATION").append("\n"); + strBuffer.append(" New Beta New Gamma ").append("\n"); + strBuffer.append(" CH(x) = (?1)+(?2)*x+(?3)x*x ").append(" CH(x) = (?1)+(?2)*x+(?3)x*x").append("\n"); + strBuffer.append(" E(x) = ("+betaCalibrationParam.getCoeff1()+")+("+betaCalibrationParam.getCoeff2()+")*x+("+betaCalibrationParam.getCoeff3()+")x*x ").append(" E(x) = ("+gammaCalibrationParam.getCoeff1()+")+("+gammaCalibrationParam.getCoeff2()+")*x+("+gammaCalibrationParam.getCoeff3()+")x*x").append("\n"); + strBuffer.append("\n"); + strBuffer.append("#SAMPLE: LIMITS PER ROI").append("\n"); + strBuffer.append(" Roi Beta Gamma ").append("\n"); + for (GardsROIChannelsSpectrum channelsSpectrum:channelsSpectrums) { + strBuffer.append(" "+channelsSpectrum.getRoi()+" "+channelsSpectrum.getBChanStart()+"to"+channelsSpectrum.getBChanStop()+" "+channelsSpectrum.getGChanStart()+"to"+channelsSpectrum.getGChanStop()).append("\n"); + } + strBuffer.append("\n"); + strBuffer.append("#DET Old CALIBRATION").append("\n"); + strBuffer.append(" Old Beta Old Gamma ").append("\n"); + if (DetBgData){ + strBuffer.append(" CH(x) = (?1)+(?2)*x+(?3)x*x ").append(" CH(x) = (?1)+(?2)*x+(?3)x*x").append("\n"); + strBuffer.append(" E(x) = (?1)+(?2)*x+(?3)x*x ").append(" E(x) = (?1)+(?2)*x+(?3)x*x").append("\n"); + }else { + strBuffer.append(" CH(x) = (?1)+(?2)*x+(?3)x*x ").append(" CH(x) = (?1)+(?2)*x+(?3)x*x").append("\n"); + strBuffer.append(" E(x) = (?1)+(?2)*x+(?3)x*x ").append(" E(x) = (?1)+(?2)*x+(?3)x*x").append("\n"); + } + strBuffer.append("\n"); + strBuffer.append("#DET New CALIBRATION").append("\n"); + strBuffer.append(" New Beta New Gamma ").append("\n"); + strBuffer.append(" CH(x) = (?1)+(?2)*x+(?3)x*x ").append(" CH(x) = (?1)+(?2)*x+(?3)x*x").append("\n"); + strBuffer.append(" E(x) = ("+gammaCalibrationParam.getCoeff1()+")+("+gammaCalibrationParam.getCoeff2()+")*x+("+gammaCalibrationParam.getCoeff3()+")x*x ").append(" E(x) = ("+gammaCalibrationParam.getCoeff1()+")+("+gammaCalibrationParam.getCoeff2()+")*x+("+gammaCalibrationParam.getCoeff3()+")x*x").append("\n"); + strBuffer.append("\n"); + strBuffer.append("#DET: LIMITS PER ROI").append("\n"); + strBuffer.append(" Roi Beta Gamma ").append("\n"); + for (GardsROIChannelsSpectrum channelsSpectrum:channelsSpectrums) { + strBuffer.append(" "+channelsSpectrum.getRoi()+" "+channelsSpectrum.getBChanStart()+"to"+channelsSpectrum.getBChanStop()+" "+channelsSpectrum.getGChanStart()+"to"+channelsSpectrum.getGChanStop()).append("\n"); + } + strBuffer.append("\n"); + strBuffer.append("#GAS Old CALIBRATION").append("\n"); + strBuffer.append(" Old Beta Old Gamma ").append("\n"); + if (GasBgData){ + strBuffer.append(" CH(x) = (?1)+(?2)*x+(?3)x*x ").append(" CH(x) = (?1)+(?2)*x+(?3)x*x").append("\n"); + strBuffer.append(" E(x) = (?1)+(?2)*x+(?3)x*x ").append(" E(x) = (?1)+(?2)*x+(?3)x*x").append("\n"); + }else { + strBuffer.append(" CH(x) = (?1)+(?2)*x+(?3)x*x ").append(" CH(x) = (?1)+(?2)*x+(?3)x*x").append("\n"); + strBuffer.append(" E(x) = (?1)+(?2)*x+(?3)x*x ").append(" E(x) = (?1)+(?2)*x+(?3)x*x").append("\n"); + } + strBuffer.append("\n"); + strBuffer.append("#GAS New CALIBRATION").append("\n"); + strBuffer.append(" New Beta New Gamma ").append("\n"); + strBuffer.append(" CH(x) = (?1)+(?2)*x+(?3)x*x ").append(" CH(x) = (?1)+(?2)*x+(?3)x*x").append("\n"); + strBuffer.append(" E(x) = ("+betaCalibrationParam.getCoeff1()+")+("+betaCalibrationParam.getCoeff2()+")*x+("+betaCalibrationParam.getCoeff3()+")x*x ").append(" E(x) = ("+gammaCalibrationParam.getCoeff1()+")+("+gammaCalibrationParam.getCoeff2()+")*x+("+gammaCalibrationParam.getCoeff3()+")x*x").append("\n"); + strBuffer.append("\n"); + strBuffer.append("#GAS: LIMITS PER ROI").append("\n"); + strBuffer.append(" Roi Beta Gamma ").append("\n"); + for (GardsROIChannelsSpectrum channelsSpectrum:channelsSpectrums) { + strBuffer.append(" "+channelsSpectrum.getRoi()+" "+channelsSpectrum.getBChanStart()+"to"+channelsSpectrum.getBChanStop()+" "+channelsSpectrum.getGChanStart()+"to"+channelsSpectrum.getGChanStop()).append("\n"); + } + strBuffer.append("\n"); + strBuffer.append("#GROSS COUNTS PER ROI").append("\n"); + strBuffer.append(" Roi Sample GasBkgnd DetBkgnd ").append("\n"); + for (GardsROIResultsSpectrum resultsSpectrum:resultsSpectrums) { + strBuffer.append(" "+resultsSpectrum.getRoi()+" "+resultsSpectrum.getSGross()+" "+resultsSpectrum.getGGross()+" "+resultsSpectrum.getBGross()+"").append("\n"); + } + strBuffer.append("\n"); + strBuffer.append("#NET COUNTS AND LC PER ROI").append("\n"); + strBuffer.append(" Roi Net count ").append("\n"); + for (GardsROIResultsSpectrum resultsSpectrum:resultsSpectrums){ + strBuffer.append(" "+resultsSpectrum.getRoi()+" "+resultsSpectrum.getNet()+" +/- "+Math.sqrt(resultsSpectrum.getNetErr())).append("\n"); + } + strBuffer.append("\n"); + strBuffer.append("#CONCENTRATION AND LC PER ROI").append("\n"); + strBuffer.append(" Roi Conc(mBq/m3) LC(mBq/m3) MDC(mBq/m3): "); + for (GardsROIResultsSpectrum resultsSpectrum:resultsSpectrums){ + strBuffer.append(" "+resultsSpectrum.getRoi()+" "+resultsSpectrum.getConcErr()+" +/- "+resultsSpectrum.getConcErr()+" "+resultsSpectrum.getLc()+" "+resultsSpectrum.getMdc()).append("\n"); + } + strBuffer.append("\n"); + strBuffer.append("#RESULT SUMMARY").append("\n"); + strBuffer.append(" Nuclide Name Conc LC MDC NID Flag ").append("\n"); + for (GardsXeResultsSpectrum xeResultsSpectrum:xeResultsSpectrums) { + strBuffer.append(" "+xeResultsSpectrum.getNuclideName()+" "+xeResultsSpectrum.getConc()+" +/- "+xeResultsSpectrum.getConcErr()+" "+xeResultsSpectrum.getLc()+" "+xeResultsSpectrum.getMdc()+" "+xeResultsSpectrum.getNidFlag()).append("\n"); + } + strBuffer.append("\n"); + + result.setSuccess(true); + result.setResult(strBuffer); + return result; } @Override @@ -515,6 +806,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { result.error500("ftp连接失败"); return result; } + InputStream inputStream = null; try { //切换被动模式 ftpClient.enterLocalPassiveMode(); @@ -532,7 +824,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { } FTPFile ftpFile = ftpFiles.get(0); if (Objects.nonNull(ftpFile)){ - InputStream inputStream = ftpClient.retrieveFileStream(ftpFile.getName()); + inputStream = ftpClient.retrieveFileStream(ftpFile.getName()); //声明一个临时文件 File file = File.createTempFile("tmp", null); //将ftp文件的输入流复制给临时文件 @@ -596,6 +888,9 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { if (Objects.nonNull(ftpClient)){ ftpClient.disconnect(); } + if (Objects.nonNull(inputStream)){ + inputStream.close(); + } } catch (IOException e) { throw new RuntimeException(e); } @@ -635,7 +930,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { result.error500("ftp连接失败"); return result; } - + InputStream inputStream = null; try { //切换被动模式 ftpClient.enterLocalPassiveMode(); @@ -656,7 +951,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { } FTPFile sampleFtpFile = sampleFtpFiles.get(0); if (Objects.nonNull(sampleFtpFile)){ - InputStream inputStream = ftpClient.retrieveFileStream(sampleFtpFile.getName()); + inputStream = ftpClient.retrieveFileStream(sampleFtpFile.getName()); //声明一个临时文件 File file = File.createTempFile("tmp", null); //将ftp文件的输入流复制给临时文件 @@ -688,9 +983,6 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { }else { qcResult.setXenonVolumeStatus("Failed"); } - if (Objects.nonNull(inputStream)){ - inputStream.close(); - } } } catch (IOException e) { throw new RuntimeException(e); @@ -701,6 +993,9 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { if (Objects.nonNull(ftpClient)){ ftpClient.disconnect(); } + if (Objects.nonNull(inputStream)){ + inputStream.close(); + } } catch (IOException e) { throw new RuntimeException(e); } @@ -712,6 +1007,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { result.error500("ftp连接失败"); return result; } + InputStream inputStream = null; try { //切换被动模式 ftpClient.enterLocalPassiveMode(); @@ -732,7 +1028,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { } FTPFile gasBgFtpFile = gasBgFtpFiles.get(0); if (Objects.nonNull(gasBgFtpFile)){ - InputStream inputStream = ftpClient.retrieveFileStream(gasBgFtpFile.getName()); + inputStream = ftpClient.retrieveFileStream(gasBgFtpFile.getName()); //声明一个临时文件 File file = File.createTempFile("tmp", null); //将ftp文件的输入流复制给临时文件 @@ -744,9 +1040,6 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { }else { qcResult.setGasBgValueAndStatus(false); } - if (Objects.nonNull(inputStream)){ - inputStream.close(); - } } } catch (IOException e) { throw new RuntimeException(e); @@ -755,6 +1048,9 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { if (Objects.nonNull(ftpClient)){ ftpClient.disconnect(); } + if (Objects.nonNull(inputStream)){ + inputStream.close(); + } } catch (IOException e) { throw new RuntimeException(e); } @@ -766,6 +1062,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { result.error500("ftp连接失败"); return result; } + InputStream inputStream = null; try { //切换被动模式 ftpClient.enterLocalPassiveMode(); @@ -786,7 +1083,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { } FTPFile detBgFtpFile = detBgFtpFiles.get(0); if (Objects.nonNull(detBgFtpFile)){ - InputStream inputStream = ftpClient.retrieveFileStream(detBgFtpFile.getName()); + inputStream = ftpClient.retrieveFileStream(detBgFtpFile.getName()); //声明一个临时文件 File file = File.createTempFile("tmp", null); //将ftp文件的输入流复制给临时文件 @@ -798,9 +1095,6 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { }else { qcResult.setDetBgValueAndStatus(false); } - if (Objects.nonNull(inputStream)){ - inputStream.close(); - } } } catch (IOException e) { throw new RuntimeException(e); @@ -809,6 +1103,9 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { if (Objects.nonNull(ftpClient)){ ftpClient.disconnect(); } + if (Objects.nonNull(inputStream)){ + inputStream.close(); + } } catch (IOException e) { throw new RuntimeException(e); } @@ -840,6 +1137,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { result.error500("ftp连接失败"); return result; } + InputStream inputStream = null; //查询数据库中结果的Xe数据 List xeDataList = spectrumAnalysisMapper.getXeDataList(sampleId); try { @@ -862,7 +1160,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { } FTPFile sampleFtpFile = sampleFtpFiles.get(0); if (Objects.nonNull(sampleFtpFile)){ - InputStream inputStream = ftpClient.retrieveFileStream(sampleFtpFile.getName()); + inputStream = ftpClient.retrieveFileStream(sampleFtpFile.getName()); //声明一个临时文件 File file = File.createTempFile("tmp", null); //将ftp文件的输入流复制给临时文件 @@ -910,9 +1208,6 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { rlrDataValues.setXe135_MDC(String.valueOf(xe135.getMdc())); rlrDataValues.setXe135_LC(String.valueOf(xe135.getLc())); } - if (Objects.nonNull(inputStream)){ - inputStream.close(); - } } } } catch (IOException e) { @@ -922,6 +1217,9 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { if (Objects.nonNull(ftpClient)){ ftpClient.disconnect(); } + if (Objects.nonNull(inputStream)){ + inputStream.close(); + } } catch (IOException e) { throw new RuntimeException(e); } @@ -943,6 +1241,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { result.error500("ftp连接失败"); return result; } + InputStream inputStream = null; try { if (StringUtils.isNotBlank(dbQcFilePath)){ String qcPathName = dbQcFilePath.substring(0, dbQcFilePath.lastIndexOf(StringPool.SLASH)); @@ -957,7 +1256,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { } FTPFile qcFtpFile = qcFtpFiles.get(0); if (Objects.nonNull(qcFtpFile)){ - InputStream inputStream = ftpClient.retrieveFileStream(qcFtpFile.getName()); + inputStream = ftpClient.retrieveFileStream(qcFtpFile.getName()); //声明一个临时文件 File file = File.createTempFile("tmp", null); //将ftp文件的输入流复制给临时文件 @@ -1042,9 +1341,6 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { map.put("min", min); map.put("max", max); map.put("gammaSpectrum", seriseDataList); - if (Objects.nonNull(inputStream)){ - inputStream.close(); - } } } } catch (IOException e) { @@ -1054,6 +1350,9 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { if (Objects.nonNull(ftpClient)){ ftpClient.disconnect(); } + if (Objects.nonNull(inputStream)){ + inputStream.close(); + } } catch (IOException e) { throw new RuntimeException(e); } @@ -1075,6 +1374,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { result.error500("ftp连接失败"); return result; } + InputStream inputStream = null; try { //切换被动模式 ftpClient.enterLocalPassiveMode(); @@ -1095,7 +1395,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { } FTPFile qcFtpFile = qcFtpFiles.get(0); if (Objects.nonNull(qcFtpFile)){ - InputStream inputStream = ftpClient.retrieveFileStream(qcFtpFile.getName()); + inputStream = ftpClient.retrieveFileStream(qcFtpFile.getName()); //声明一个临时文件 File file = File.createTempFile("tmp", null); //将ftp文件的输入流复制给临时文件 @@ -1183,9 +1483,6 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { fittingParaToUiStr.add(String.valueOf(para)); } map.put("EToC", fittingParaToUiStr); - if (Objects.nonNull(inputStream)){ - inputStream.close(); - } } } } catch (IOException e) { @@ -1195,6 +1492,9 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { if (Objects.nonNull(ftpClient)){ ftpClient.disconnect(); } + if (Objects.nonNull(inputStream)){ + inputStream.close(); + } } catch (IOException e) { throw new RuntimeException(e); } @@ -1216,6 +1516,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { result.error500("ftp连接失败"); return result; } + InputStream inputStream = null; if (StringUtils.isNotBlank(sampleFilePath)){ String samplePathName = sampleFilePath.substring(0, sampleFilePath.lastIndexOf(StringPool.SLASH)); String sampleFileName = sampleFilePath.substring(sampleFilePath.lastIndexOf(StringPool.SLASH)+1); @@ -1237,7 +1538,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { FTPFile sampleFtpFile = sampleFtpFiles.get(0); if (Objects.nonNull(sampleFtpFile)){ //获取ftp文件的输入流 - InputStream inputStream = ftpClient.retrieveFileStream(sampleFtpFile.getName()); + inputStream = ftpClient.retrieveFileStream(sampleFtpFile.getName()); //声明一个临时文件 File file = File.createTempFile("tmp", null); //ftp文件输入流复制给临时文件 @@ -1309,9 +1610,6 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { betaProjectedSeriseData.add(temp); } map.put("betaProjectedSeriseData", betaProjectedSeriseData); - if (Objects.nonNull(inputStream)){ - inputStream.close(); - } } } catch (IOException e) { throw new RuntimeException(e); @@ -1320,6 +1618,9 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { if (Objects.nonNull(ftpClient)){ ftpClient.disconnect(); } + if (Objects.nonNull(inputStream)){ + inputStream.close(); + } } catch (IOException e) { throw new RuntimeException(e); } @@ -1814,6 +2115,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { result.error500("ftp连接失败"); return result; } + InputStream inputStream = null; try { //切换被动模式 ftpClient.enterLocalPassiveMode(); @@ -1834,7 +2136,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { } FTPFile qcFtpFile = qcFtpFiles.get(0); if (Objects.nonNull(qcFtpFile)){ - InputStream inputStream = ftpClient.retrieveFileStream(qcFtpFile.getName()); + inputStream = ftpClient.retrieveFileStream(qcFtpFile.getName()); //声明一个临时文件 File file = File.createTempFile("tmp", null); //将ftp文件的输入流复制给临时文件 @@ -1867,6 +2169,9 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { if (Objects.nonNull(ftpClient)){ ftpClient.disconnect(); } + if (Objects.nonNull(inputStream)){ + inputStream.close(); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/jeecg-module-web-statistics/src/main/java/org/jeecg/common/util/ReadLineUtil.java b/jeecg-module-web-statistics/src/main/java/org/jeecg/common/util/ReadLineUtil.java index 2cc8de34..18fb26c2 100644 --- a/jeecg-module-web-statistics/src/main/java/org/jeecg/common/util/ReadLineUtil.java +++ b/jeecg-module-web-statistics/src/main/java/org/jeecg/common/util/ReadLineUtil.java @@ -45,6 +45,7 @@ public class ReadLineUtil { if (Objects.isNull(ftpClient)){ throw new RuntimeException("ftp连接失败!"); } + InputStream iStream = null; try { ftpClient.enterLocalPassiveMode(); String fileName = filePath.substring(filePath.lastIndexOf(StringPool.SLASH) + 1); @@ -62,7 +63,7 @@ public class ReadLineUtil { for (FTPFile ftpFile:ftpFiles) { if (ftpFile.getName().equals(fileName)){ //读取ftp文件的输入流 - InputStream iStream=ftpClient.retrieveFileStream(ftpFile.getName()); + iStream=ftpClient.retrieveFileStream(ftpFile.getName()); //声明一个临时文件 File file = File.createTempFile("tmp", null); //将ftp文件的输入流复制给临时文件 @@ -88,7 +89,12 @@ public class ReadLineUtil { throw new RuntimeException(e); } finally { try { - ftpClient.disconnect(); + if (Objects.nonNull(ftpClient)){ + ftpClient.disconnect(); + } + if (Objects.nonNull(iStream)){ + iStream.close(); + } } catch (IOException e) { throw new RuntimeException(e); }