From 6aaffd8fbdefd867b1a2aa324ab00e33898e369a Mon Sep 17 00:00:00 2001 From: panbaolin <123456> Date: Thu, 12 Oct 2023 11:17:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:1.=E4=BF=AE=E6=94=B9=E4=B8=B4=E6=97=B6?= =?UTF-8?q?=E5=AD=98=E6=94=BE=E6=96=87=E4=BB=B6=E7=9B=AE=E5=BD=95=E4=B8=BA?= =?UTF-8?q?=E7=9B=B8=E5=AF=B9=E8=B7=AF=E5=BE=842.=E9=87=8D=E5=90=AFjar?= =?UTF-8?q?=E5=90=8E=E6=B8=85=E7=A9=BA=E4=B8=B4=E6=97=B6=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E7=9B=AE=E5=BD=953.=E4=BF=AE=E6=94=B9=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=8A=A5=E5=91=8A=E5=8A=9F=E8=83=BD=E4=B8=BA=E7=BA=AF=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=94=9F=E6=88=904.=E8=A7=A3=E5=86=B3ftp=E5=B9=B6?= =?UTF-8?q?=E5=8F=91=E5=88=9B=E5=BB=BA=E7=9B=AE=E5=BD=95=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/properties/TaskProperties.java | 2 + .../org/jeecg/modules/AutoProcessManager.java | 10 +- .../jeecg/modules/EmailParsingActuator.java | 7 +- .../modules/FileSourceHandleManager.java | 39 +- .../jeecg/modules/UndealHandleManager.java | 21 +- .../java/org/jeecg/modules/ftp/FTPUtils.java | 313 ++++++----- .../jeecg/modules/service/BlockConstant.java | 5 + ...port.java => AbstractAutoLogOrReport.java} | 5 +- .../jeecg/modules/spectrum/AlertSpectrum.java | 3 +- .../modules/spectrum/DetbkphdSpectrum.java | 1 + .../modules/spectrum/GasbkphdSpectrum.java | 1 + .../spectrum/HealthStatusSpectrum.java | 3 +- .../jeecg/modules/spectrum/MetSpectrum.java | 3 +- .../modules/spectrum/ParsingProcessLog.java | 97 ++-- .../jeecg/modules/spectrum/QcphdSpectrum.java | 1 + .../spectrum/S_D_Q_G_SpectrumHandler.java | 10 +- .../modules/spectrum/Sample_B_Analysis.java | 513 +++++++++--------- .../modules/spectrum/SamplephdSpectrum.java | 1 + .../modules/spectrum/SpectrumHandler.java | 8 +- .../spectrum/SpectrumParsingActuator.java | 10 +- .../spectrum/SpectrumServiceQuotes.java | 3 + .../resources/template/b_report_template.txt | 70 --- .../jeecg/JeecgAutoProcessApplication.java | 31 +- 23 files changed, 609 insertions(+), 548 deletions(-) rename jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/{AbstractLogOrReport.java => AbstractAutoLogOrReport.java} (88%) delete mode 100644 jeecg-module-auto-process/src/main/resources/template/b_report_template.txt diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/TaskProperties.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/TaskProperties.java index 0ad23f77..08670ca5 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/TaskProperties.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/TaskProperties.java @@ -4,6 +4,7 @@ import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.io.File; import java.io.Serializable; /** @@ -64,4 +65,5 @@ public class TaskProperties implements Serializable { * 邮件附件临时存储路径 */ private String temporaryStoragePath; + } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java index dd685337..6fe2c80e 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java @@ -32,7 +32,10 @@ public class AutoProcessManager{ private final SpectrumServiceQuotes spectrumServiceQuotes; private final EmailCounter emailCounter; private Date systemStartupTime; - + /** + * FTP目录操作锁 + */ + private Object ftpOpierationLock; /** * 邮件Map数据锁 */ @@ -50,8 +53,9 @@ public class AutoProcessManager{ /** * 启动自动处理 */ - public void start(Date systemStartupTime) { + public void start(Date systemStartupTime,Object ftpOpierationLock) { this.systemStartupTime = systemStartupTime; + this.ftpOpierationLock = ftpOpierationLock; //邮件数据监测线程 final MailDataMonitor mailDataMonitor = new MailDataMonitor(); mailDataMonitor.setName("mail-data-monitor"); @@ -90,7 +94,7 @@ public class AutoProcessManager{ } if(next.isNewEmailFlag()){ EmailParsingActuator emailParsingActuator = new EmailParsingActuator(); - emailParsingActuator.init(next,spectrumServiceQuotes,emailCounter,systemStartupTime); + emailParsingActuator.init(next,spectrumServiceQuotes,emailCounter,systemStartupTime,ftpOpierationLock); emailParsingActuator.setName(next.getUsername()+"-email-monitor"); emailParsingActuator.start(); //把邮件监测执行线程加入管理队列 diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java index 511a9959..0b927800 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java @@ -24,13 +24,16 @@ public class EmailParsingActuator extends Thread{ private SpectrumServiceQuotes spectrumServiceQuotes; private EmailCounter emailCounter; private Date systemStartupTime; + private Object ftpOpierationLock; - public void init(EmailProperties emailProperties,SpectrumServiceQuotes spectrumServiceQuotes,EmailCounter emailCounter,Date systemStartupTime){ + public void init(EmailProperties emailProperties,SpectrumServiceQuotes spectrumServiceQuotes, + EmailCounter emailCounter,Date systemStartupTime,Object ftpOpierationLock){ this.emailProperties = emailProperties; this.spectrumServiceQuotes = spectrumServiceQuotes; this.taskProperties = spectrumServiceQuotes.getTaskProperties(); this.emailCounter = emailCounter; this.systemStartupTime = systemStartupTime; + this.ftpOpierationLock = ftpOpierationLock; //获取机器可用核心数 int systemCores = Runtime.getRuntime().availableProcessors(); @@ -54,7 +57,7 @@ public class EmailParsingActuator extends Thread{ for(Message message : messages){ SpectrumParsingActuator spectrumParsingActuator = new SpectrumParsingActuator(); spectrumParsingActuator.init(message,emailProperties,emailServiceManager, - taskLatch,spectrumServiceQuotes,emailCounter); + taskLatch,spectrumServiceQuotes,emailCounter,ftpOpierationLock); poolExecutor.execute(spectrumParsingActuator); } taskLatch.await(); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/FileSourceHandleManager.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/FileSourceHandleManager.java index c18cbe1a..6f328887 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/FileSourceHandleManager.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/FileSourceHandleManager.java @@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j; import org.jeecg.common.properties.TaskProperties; import org.jeecg.modules.ftp.FTPProperties; import org.jeecg.modules.ftp.FTPUtils; +import org.jeecg.modules.service.BlockConstant; import org.jeecg.modules.spectrum.SamplephdSpectrum; import org.jeecg.modules.spectrum.SpectrumHandler; import org.jeecg.modules.spectrum.SpectrumServiceQuotes; @@ -38,11 +39,16 @@ public class FileSourceHandleManager { * 相关Spring组件引用 */ private final SpectrumServiceQuotes spectrumServiceQuotes; + /** + * FTP目录操作锁 + */ + private Object ftpOpierationLock; /** * 开始 */ - public void start(){ + public void start(Object ftpOpierationLock){ + this.ftpOpierationLock = ftpOpierationLock; ParseingFileSourceThreadManager fileSourceThreadManager = new ParseingFileSourceThreadManager(); fileSourceThreadManager.init(); fileSourceThreadManager.start(); @@ -79,13 +85,13 @@ public class FileSourceHandleManager { String filePath = spectrumServiceQuotes.getSpectrumPathProperties().getFilesourcePath(); List fileNames = ftpUtil.getFiles(filePath, taskProperties.getFilesourceDirReceiveNum().intValue()); ftpUtil.close(); - //如果获取到的文件数量大于1,则进行排序保障Sample谱最后执行 - if(fileNames.size() > 1){ - fileNames = fileNames.stream().sorted(Comparator.comparing(String::toString)).collect(Collectors.toList()); - } if(!CollectionUtils.isEmpty(fileNames)){ CountDownLatch taskLatch = new CountDownLatch(fileNames.size()); for(String fileName : fileNames){ + //如果是Sample谱则延迟500毫秒后执行 + if(fileName.contains(BlockConstant.sampleFlag)){ + TimeUnit.MILLISECONDS.sleep(200); + } ParseingFileSourceThread parseingFileSourceThread = new ParseingFileSourceThread(); parseingFileSourceThread.init(fileName,filePath,taskLatch); poolExecutor.execute(parseingFileSourceThread); @@ -145,7 +151,7 @@ public class FileSourceHandleManager { //初始化FTP客户端对象 final FTPProperties ftpProperties = spectrumServiceQuotes.getFtpProperties(); this.ftpUtil = new FTPUtils(ftpProperties.getHost(),ftpProperties.getPort(),ftpProperties.getUserName(), - ftpProperties.getPassword(),ftpProperties.getEncoding(),ftpProperties.getFtpRootPath()); + ftpProperties.getPassword(),ftpProperties.getEncoding(),ftpProperties.getFtpRootPath(),ftpOpierationLock); //获取文件内容 fileContent = this.ftpUtil.getFileContent(filePath, fileName); //解析文件 @@ -169,4 +175,25 @@ public class FileSourceHandleManager { } } } + + public static void main(String[] args) { + List list = new ArrayList<>(); + list.add("AUX09_003-20150524_1855_S_FULL_40184.5.PHD"); + list.add("CNX22_001-20150126_0707_S_FULL_40204.PHD"); + list.add("JPX38_001-20150126_1541_S_FULL_40188.8.PHD"); + list.add("AUX09_003-20150527_0425_D_FULL_259450.PHD"); + list.add("AUX09_003-20151224_0655_G_FULL_40182.9.PHD"); + list.add("AUX09_003-20151224_1810_Q_FULL_2393.7.PHD"); + + List newList = new ArrayList<>(); + for(String name : list){ + if(name.contains("_S_")){ + newList.add(name); + }else { + newList.add(0,name); + } + } + list = newList; + System.out.println(list); + } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/UndealHandleManager.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/UndealHandleManager.java index e68feef1..d61b7b3f 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/UndealHandleManager.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/UndealHandleManager.java @@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j; import org.jeecg.common.properties.TaskProperties; import org.jeecg.modules.ftp.FTPProperties; import org.jeecg.modules.ftp.FTPUtils; +import org.jeecg.modules.service.BlockConstant; import org.jeecg.modules.spectrum.SamplephdSpectrum; import org.jeecg.modules.spectrum.SpectrumHandler; import org.jeecg.modules.spectrum.SpectrumServiceQuotes; @@ -12,6 +13,7 @@ import org.springframework.scheduling.concurrent.CustomizableThreadFactory; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; +import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.concurrent.*; @@ -23,7 +25,7 @@ import java.util.stream.Collectors; @Slf4j @Component @RequiredArgsConstructor -public class UndealHandleManager { +public class UndealHandleManager{ /** * 任务属性 @@ -33,11 +35,16 @@ public class UndealHandleManager { * 相关Spring组件引用 */ private final SpectrumServiceQuotes spectrumServiceQuotes; + /** + * FTP目录操作锁 + */ + private Object ftpOpierationLock; /** * 开始 */ - public void start(){ + public void start(Object ftpOpierationLock){ + this.ftpOpierationLock = ftpOpierationLock; ParseingFaliFileThreadManager faliFileThreadManager = new ParseingFaliFileThreadManager(); faliFileThreadManager.init(); faliFileThreadManager.start(); @@ -74,13 +81,13 @@ public class UndealHandleManager { String filePath = spectrumServiceQuotes.getSpectrumPathProperties().getFailPath(); List fileNames = ftpUtil.getFiles(filePath, taskProperties.getUndealDirReceiveNum().intValue()); ftpUtil.close(); - //如果获取到的文件数量大于1,则进行排序保障Sample谱最后执行 - if(fileNames.size() > 1){ - fileNames = fileNames.stream().sorted(Comparator.comparing(String::toString)).collect(Collectors.toList()); - } if(!CollectionUtils.isEmpty(fileNames)){ CountDownLatch taskLatch = new CountDownLatch(fileNames.size()); for(String fileName : fileNames){ + //如果是Sample谱则延迟500毫秒后执行 + if(fileName.contains(BlockConstant.sampleFlag)){ + TimeUnit.MILLISECONDS.sleep(200); + } ParseingFaliFileThread faliFileThread = new ParseingFaliFileThread(); faliFileThread.init(fileName,filePath,taskLatch); poolExecutor.execute(faliFileThread); @@ -137,7 +144,7 @@ public class UndealHandleManager { //初始化FTP客户端对象 final FTPProperties ftpProperties = spectrumServiceQuotes.getFtpProperties(); this.ftpUtil = new FTPUtils(ftpProperties.getHost(),ftpProperties.getPort(),ftpProperties.getUserName(), - ftpProperties.getPassword(),ftpProperties.getEncoding(),ftpProperties.getFtpRootPath()); + ftpProperties.getPassword(),ftpProperties.getEncoding(),ftpProperties.getFtpRootPath(),ftpOpierationLock); //获取文件内容 final String fileContent = this.ftpUtil.getFileContent(filePath, fileName); //解析文件 diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/ftp/FTPUtils.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/ftp/FTPUtils.java index f1aec232..14b92357 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/ftp/FTPUtils.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/ftp/FTPUtils.java @@ -6,44 +6,74 @@ import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.net.ftp.*; import org.apache.logging.log4j.util.Strings; +import org.jeecg.modules.service.BlockConstant; import java.io.*; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.stream.Collectors; -import java.util.stream.Stream; @Slf4j public class FTPUtils { + private String host; + private Integer port; + private String userName; + private String password; private String encoding; - private String ftpRootPath; - private FTPClient client; + /** + * FTP目录操作锁 + */ + private Object ftpOpierationLock; - public FTPUtils(String host, Integer port, String userName, String password, String encoding,String ftpRootPath){ + public FTPUtils(String host, Integer port, String userName, String password, + String encoding,String ftpRootPath,Object ftpOpierationLock){ + this.host = host; + this.port = port; + this.userName = userName; + this.password = password; this.encoding = encoding; this.ftpRootPath = ftpRootPath; + this.ftpOpierationLock = ftpOpierationLock; + + connect(); + } + + public FTPUtils(String host, Integer port, String userName, String password, + String encoding,String ftpRootPath){ + this.host = host; + this.port = port; + this.userName = userName; + this.password = password; + this.encoding = encoding; + this.ftpRootPath = ftpRootPath; + this.ftpOpierationLock = new Object(); + connect(); + } + + /** + * 连接FTP服务 + */ + private void connect(){ try{ //声明FTP客户端 - client = new FTPClient(); + this.client = new FTPClient(); //连接 - client.connect(host, port); + this.client.connect(host, port); //登录 - client.login(userName, password); + this.client.login(userName, password); // 切换为本地被动模式,可以解决FTP上传后文件为空的问题,但需要服务器将FTP服务添加至防火墙白名单 - client.enterLocalPassiveMode(); + this.client.enterLocalPassiveMode(); //设置文件client参数 this.client.setFileType(FTPClient.BINARY_FILE_TYPE); this.client.setControlEncoding(this.encoding); this.client.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); -// this.client.setDataTimeout(60000); -// this.client.setConnectTimeout(); //判断是否连接成功 - int reply = client.getReplyCode(); + int reply = this.client.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { - client.disconnect(); + this.client.disconnect(); } }catch (IOException e){ log.error("FTP服务连接失败,原因:{}",e.getMessage()); @@ -59,30 +89,32 @@ public class FTPUtils { * @throws IOException */ public boolean downloadFTPFile(String ftpFilePath,String fileName,String localPath) throws IOException { - this.checkDirectory(ftpFilePath); - InputStream inputStream = null; - try{ - final String formatFileName = new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1); - final FTPFile[] ftpFiles = this.client.listFiles(formatFileName); - if(ArrayUtils.isNotEmpty(ftpFiles)){ - inputStream = this.client.retrieveFileStream(formatFileName); - if(Objects.nonNull(inputStream)){ - FileUtil.writeFromStream(inputStream,localPath+File.separator+fileName); - return true; + synchronized (ftpOpierationLock){ + this.checkDirectory(ftpFilePath); + InputStream inputStream = null; + try{ + final String formatFileName = new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1); + final FTPFile[] ftpFiles = this.client.listFiles(formatFileName); + if(ArrayUtils.isNotEmpty(ftpFiles)){ + inputStream = this.client.retrieveFileStream(formatFileName); + if(Objects.nonNull(inputStream)){ + FileUtil.writeFromStream(inputStream,localPath+File.separator+fileName); + return true; + } + }else { + log.warn("{}不存在",fileName); + } + }catch (Exception e){ + e.printStackTrace(); + return false; + }finally { + if(Objects.nonNull(inputStream)){ + inputStream.close(); + this.client.completePendingCommand(); } - }else { - log.warn("{}不存在",fileName); } - }catch (Exception e){ - e.printStackTrace(); return false; - }finally { - if(Objects.nonNull(inputStream)){ - inputStream.close(); - this.client.completePendingCommand(); - } } - return false; } /** @@ -92,7 +124,7 @@ public class FTPUtils { */ private boolean checkDirectory(String path){ try{ - final boolean changeFlag = client.changeWorkingDirectory(ftpRootPath); + final boolean changeFlag = this.client.changeWorkingDirectory(ftpRootPath); if(!changeFlag){ log.error("{},根目录切换失败",ftpRootPath); return false; @@ -102,12 +134,12 @@ public class FTPUtils { if(StringUtils.isEmpty(directory)){ continue; } - if(!client.changeWorkingDirectory(directory)){ - if(!client.makeDirectory(directory)){ + if(!this.client.changeWorkingDirectory(directory)){ + if(!this.client.makeDirectory(directory)){ log.error("{},目录创建失败",directory); return false; } - if(!client.changeWorkingDirectory(directory)){ + if(!this.client.changeWorkingDirectory(directory)){ log.error("{},目录切换失败",directory); return false; } @@ -129,28 +161,30 @@ public class FTPUtils { * @return 返回值true/false */ public boolean saveFile(String filePath,String fileName,InputStream inputStream){ - try{ - final boolean flag = this.checkDirectory(filePath); - if(flag){ - final FTPFile[] ftpFiles = this.client.listFiles(fileName); - if(ArrayUtils.isEmpty(ftpFiles)){ - return client.storeFile(fileName, inputStream); + synchronized (ftpOpierationLock){ + try{ + final boolean flag = this.checkDirectory(filePath); + if(flag){ + final FTPFile[] ftpFiles = this.client.listFiles(fileName); + if(ArrayUtils.isEmpty(ftpFiles)){ + return this.client.storeFile(fileName, inputStream); + } + } + }catch (IOException e){ + log.error("{}文件创建失败,原因为:{}",filePath+"/"+fileName,e.getMessage()); + e.printStackTrace(); + return false; + }finally { + if(null != inputStream){ + try { + inputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } } } - }catch (IOException e){ - log.error("{}文件创建失败,原因为:{}",filePath+"/"+fileName,e.getMessage()); - e.printStackTrace(); return false; - }finally { - if(null != inputStream){ - try { - inputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } } - return false; } /** @@ -161,50 +195,62 @@ public class FTPUtils { * @return 返回值true/false */ public boolean saveOrAppendFile(String filePath,String fileName,InputStream inputStream){ - try{ - final boolean flag = this.checkDirectory(filePath); - if(flag){ - final FTPFile[] ftpFiles = this.client.listFiles(fileName); - if(ArrayUtils.isEmpty(ftpFiles)){ - return client.storeFile(fileName, inputStream); - }else{ - return client.appendFile(fileName,inputStream); + synchronized (ftpOpierationLock){ + try{ + final boolean flag = this.checkDirectory(filePath); + if(flag){ + final FTPFile[] ftpFiles = this.client.listFiles(fileName); + if(ArrayUtils.isEmpty(ftpFiles)){ + return this.client.storeFile(fileName, inputStream); + }else{ + return this.client.appendFile(fileName,inputStream); + } + } + }catch (IOException e){ + log.error("{}文件创建失败,原因为:{}",filePath+"/"+fileName,e.getMessage()); + e.printStackTrace(); + return false; + }finally { + if(null != inputStream){ + try { + inputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } } } - }catch (IOException e){ - log.error("{}文件创建失败,原因为:{}",filePath+"/"+fileName,e.getMessage()); - e.printStackTrace(); return false; - }finally { - if(null != inputStream){ - try { - inputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } } - return false; } /** - * 在指定路径下获取指定数量的文件名称列表 + * 在指定路径下获取指定数量的文件名称列表,若有Sample谱则排在最后 * @param filePath * @param getNum * @return */ public List getFiles(String filePath,int getNum) throws IOException { - final boolean flag = this.checkDirectory(filePath); - if(flag){ - final FTPFile[] ftpFiles = this.client.listFiles(); - if(ArrayUtils.isNotEmpty(ftpFiles)){ - //最终实际获取数量 - int num = getNum > ftpFiles.length?ftpFiles.length:getNum; - final List fileNames = Arrays.stream(ftpFiles).sorted(Comparator.comparing(FTPFile::getTimestamp)).map(f->f.getName()).limit(num).collect(Collectors.toList()); - return fileNames; + synchronized (ftpOpierationLock){ + final boolean flag = this.checkDirectory(filePath); + if(flag){ + final FTPFile[] ftpFiles = this.client.listFiles(); + if(ArrayUtils.isNotEmpty(ftpFiles)){ + List sortList = new ArrayList<>(); + for (FTPFile file : ftpFiles){ + if(file.getName().contains(BlockConstant.sampleFlag)){ + sortList.add(file.getName()); + }else { + sortList.add(0,file.getName()); + } + } + //最终实际获取数量 + int num = getNum > sortList.size()?sortList.size():getNum; + + return sortList.stream().limit(num).collect(Collectors.toList()); + } } + return Collections.emptyList(); } - return Collections.emptyList(); } /** @@ -215,37 +261,33 @@ public class FTPUtils { * @throws IOException */ public String getFileContent(String filePath,String fileName) throws IOException { - this.checkDirectory(filePath); - final FTPFile[] ftpFiles = this.client.listFiles(fileName); - if(ArrayUtils.isNotEmpty(ftpFiles)){ - InputStream inputStream = this.client.retrieveFileStream(fileName); - if(Objects.nonNull(inputStream)){ - try(BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream,"UTF-8"))){ - StringBuilder fileContent = new StringBuilder(); - String lineContent; - while ((lineContent = reader.readLine()) != null){ - fileContent.append(lineContent); - fileContent.append(System.lineSeparator()); - } - return fileContent.toString(); - }finally { - if(Objects.nonNull(inputStream)){ - inputStream.close(); - // 完成文件传输命令 - this.client.completePendingCommand(); + synchronized (ftpOpierationLock){ + this.checkDirectory(filePath); + final FTPFile[] ftpFiles = this.client.listFiles(fileName); + if(ArrayUtils.isNotEmpty(ftpFiles)){ + InputStream inputStream = this.client.retrieveFileStream(fileName); + if(Objects.nonNull(inputStream)){ + try(BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream,"UTF-8"))){ + StringBuilder fileContent = new StringBuilder(); + String lineContent; + while ((lineContent = reader.readLine()) != null){ + fileContent.append(lineContent); + fileContent.append(System.lineSeparator()); + } + return fileContent.toString(); + }finally { + if(Objects.nonNull(inputStream)){ + inputStream.close(); + // 完成文件传输命令 + this.client.completePendingCommand(); + } } } } + return Strings.EMPTY; } - return Strings.EMPTY; } -// public static void main(String[] args) throws IOException { -// FTPUtils ftp = new FTPUtils("192.168.17.168",21,"ubuntu","123456","utf-8","/home/ubuntu/ftp"); -// final String fileContent = ftp.getFileContent("/undeal", "CNX22_004-20230731_1436_S_PREL_21593.8.PHD"); -// System.out.println(fileContent); -// } - /** * 删除文件 * @param filePath 文件路径 @@ -253,31 +295,33 @@ public class FTPUtils { * @return 返回值true/false */ public boolean removeFile(String filePath,String fileName){ - try { - final boolean changeFlag = client.changeWorkingDirectory(ftpRootPath); - if(!changeFlag){ - log.error("{},根目录切换失败",ftpRootPath); - return false; - } - String[] directories = filePath.split("/"); - for(String directory : directories){ - if(StringUtils.isEmpty(directory)){ - continue; - } - if(!client.changeWorkingDirectory(directory)){ - log.error("此文件目录不存在:{}",filePath); + synchronized (ftpOpierationLock){ + try { + final boolean changeFlag = this.client.changeWorkingDirectory(ftpRootPath); + if(!changeFlag){ + log.error("{},根目录切换失败",ftpRootPath); return false; } + String[] directories = filePath.split("/"); + for(String directory : directories){ + if(StringUtils.isEmpty(directory)){ + continue; + } + if(!this.client.changeWorkingDirectory(directory)){ + log.error("此文件目录不存在:{}",filePath); + return false; + } + } + boolean result = this.client.deleteFile(new String(fileName.getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1)); + if(!result){ + log.error("此文件不存在:{}",filePath+"/"+fileName); + } + return result; + } catch (IOException e) { + log.error("{}文件删除失败,原因为:{}",filePath,e.getMessage()); + e.printStackTrace(); + return false; } - boolean result = client.deleteFile(new String(fileName.getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1)); - if(!result){ - log.error("此文件不存在:{}",filePath+"/"+fileName); - } - return result; - } catch (IOException e) { - log.error("{}文件删除失败,原因为:{}",filePath,e.getMessage()); - e.printStackTrace(); - return false; } } @@ -287,7 +331,7 @@ public class FTPUtils { */ public String getRootPath(){ try { - final String rootPath = client.printWorkingDirectory(); + final String rootPath = this.client.printWorkingDirectory(); } catch (IOException e) { e.printStackTrace(); } @@ -300,9 +344,8 @@ public class FTPUtils { */ public void close(){ try{ - if (client != null){ -// client.logout(); - client.disconnect(); + if (this.client != null){ + this.client.disconnect(); } }catch (IOException e){ e.printStackTrace(); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/BlockConstant.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/BlockConstant.java index 19528f40..f51230c6 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/BlockConstant.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/BlockConstant.java @@ -24,5 +24,10 @@ public interface BlockConstant { String unit_kev = " keV"; String unit_mbq = " mBq/m3"; + /** + * Sample谱文件名称标记 + */ + String sampleFlag = "_S_"; + } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractLogOrReport.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractAutoLogOrReport.java similarity index 88% rename from jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractLogOrReport.java rename to jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractAutoLogOrReport.java index ced7ce80..4bb3b269 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractLogOrReport.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractAutoLogOrReport.java @@ -1,9 +1,12 @@ package org.jeecg.modules.spectrum; +import org.jeecg.modules.base.abstracts.AbstractLogOrReport; import org.jeecg.modules.base.enums.FittingEquation; +import org.jeecg.modules.service.BlockConstant; + import java.util.List; -public abstract class AbstractLogOrReport { +public abstract class AbstractAutoLogOrReport extends AbstractLogOrReport implements BlockConstant { /** * 获取sample、gas、det谱Beta和Gamma的CH(x)、E(x) diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AlertSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AlertSpectrum.java index 0c664780..a446ea2d 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AlertSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AlertSpectrum.java @@ -13,6 +13,7 @@ import org.jeecg.modules.native_jni.struct.AlertSpectrumStruct; import java.io.ByteArrayInputStream; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.nio.charset.StandardCharsets; import java.time.LocalDate; import java.util.Date; @@ -92,7 +93,7 @@ public class AlertSpectrum extends SpectrumHandler{ * 保存能谱文件到ftp */ @Override - protected void saveFileToFtp() throws Exception { + protected void saveFileToFtp() throws FileNotFoundException { this.updateSpectrumFileName(); //获取文件保存路径 String fileSavePath = this.getFileSavePath(); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/DetbkphdSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/DetbkphdSpectrum.java index ab57d1ba..ed602929 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/DetbkphdSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/DetbkphdSpectrum.java @@ -47,6 +47,7 @@ public class DetbkphdSpectrum extends S_D_Q_G_SpectrumHandler{ super.status = SampleStatus.COMPLETE.getValue(); super.updateStatus(); }catch (Exception e){ + e.printStackTrace(); //修改状态为解析失败 super.status = SampleStatus.FAIL.getValue(); super.updateStatus(); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/GasbkphdSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/GasbkphdSpectrum.java index 7d61b387..dead1cee 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/GasbkphdSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/GasbkphdSpectrum.java @@ -48,6 +48,7 @@ public class GasbkphdSpectrum extends S_D_Q_G_SpectrumHandler{ super.status = SampleStatus.COMPLETE.getValue(); super.updateStatus(); }catch (Exception e){ + e.printStackTrace(); //修改状态为解析失败 super.status = SampleStatus.FAIL.getValue(); super.updateStatus(); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/HealthStatusSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/HealthStatusSpectrum.java index 35b79087..0c9f2360 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/HealthStatusSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/HealthStatusSpectrum.java @@ -15,6 +15,7 @@ import org.springframework.util.CollectionUtils; import java.io.ByteArrayInputStream; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.nio.charset.StandardCharsets; import java.time.LocalDate; import java.util.Date; @@ -94,7 +95,7 @@ public class HealthStatusSpectrum extends SpectrumHandler{ * 保存能谱文件到ftp */ @Override - protected void saveFileToFtp() throws Exception { + protected void saveFileToFtp() throws FileNotFoundException { this.updateSpectrumFileName(); //获取文件保存路径 String fileSavePath = this.getFileSavePath(); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/MetSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/MetSpectrum.java index 814d0b31..a77a1f3a 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/MetSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/MetSpectrum.java @@ -13,6 +13,7 @@ import org.springframework.util.CollectionUtils; import java.io.ByteArrayInputStream; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.nio.charset.StandardCharsets; import java.time.LocalDate; import java.util.Date; @@ -90,7 +91,7 @@ public class MetSpectrum extends SpectrumHandler{ * 保存能谱文件到ftp */ @Override - protected void saveFileToFtp() throws Exception { + protected void saveFileToFtp() throws FileNotFoundException { this.updateSpectrumFileName(); //获取文件保存路径 String fileSavePath = this.getFileSavePath(); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/ParsingProcessLog.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/ParsingProcessLog.java index 627d3381..51c9bfdc 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/ParsingProcessLog.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/ParsingProcessLog.java @@ -18,7 +18,7 @@ import java.util.stream.Collectors; /** * B谱邮件解析流程日志 */ -public class ParsingProcessLog { +public class ParsingProcessLog extends AbstractAutoLogOrReport{ /** * 存储日志内容 @@ -143,7 +143,7 @@ public class ParsingProcessLog { /** * 分析过程日志 */ - private class AnalyseProcessLog extends AbstractLogOrReport implements BlockConstant { + private class AnalyseProcessLog{ /** * 开始处理分析过程日志 @@ -475,14 +475,14 @@ public class ParsingProcessLog { analysisLog.append(System.lineSeparator()).append(System.lineSeparator()).append(System.lineSeparator()); analysisLog.append("Beta:"); analysisLog.append(System.lineSeparator()); - analysisLog.append(rowFormat(ch,super.calibration(analyseResult.s_b_fitting_type,analyseResult.s_b_fitting_e_c))); + analysisLog.append(rowFormat(ch,calibration(analyseResult.s_b_fitting_type,analyseResult.s_b_fitting_e_c))); analysisLog.append(System.lineSeparator()); - analysisLog.append(rowFormat(ex,super.calibration(analyseResult.s_b_fitting_type,analyseResult.s_b_fitting_c_e))); + analysisLog.append(rowFormat(ex,calibration(analyseResult.s_b_fitting_type,analyseResult.s_b_fitting_c_e))); analysisLog.append(System.lineSeparator()).append(System.lineSeparator()); analysisLog.append("Gamma:"); - analysisLog.append(rowFormat(ch,super.calibration(analyseResult.s_g_fitting_type,analyseResult.s_g_fitting_e_c))); + analysisLog.append(rowFormat(ch,calibration(analyseResult.s_g_fitting_type,analyseResult.s_g_fitting_e_c))); analysisLog.append(System.lineSeparator()); - analysisLog.append(rowFormat(ex,super.calibration(analyseResult.s_g_fitting_type,analyseResult.s_g_fitting_c_e))); + analysisLog.append(rowFormat(ex,calibration(analyseResult.s_g_fitting_type,analyseResult.s_g_fitting_c_e))); analysisLog.append(System.lineSeparator()).append(System.lineSeparator()); analysisLog.append(titleFormat(endTitle,22,StringConstant.DOT,StringConstant.DOT)); analysisLog.append(System.lineSeparator()).append(System.lineSeparator()).append(System.lineSeparator()); @@ -530,14 +530,14 @@ public class ParsingProcessLog { analysisLog.append(System.lineSeparator()).append(System.lineSeparator()).append(System.lineSeparator()); analysisLog.append("Beta:"); analysisLog.append(System.lineSeparator()); - analysisLog.append(rowFormat(ch,super.calibration(analyseResult.g_b_fitting_type,analyseResult.g_b_fitting_e_c))); + analysisLog.append(rowFormat(ch,calibration(analyseResult.g_b_fitting_type,analyseResult.g_b_fitting_e_c))); analysisLog.append(System.lineSeparator()); - analysisLog.append(rowFormat(ex,super.calibration(analyseResult.g_b_fitting_type,analyseResult.g_b_fitting_c_e))); + analysisLog.append(rowFormat(ex,calibration(analyseResult.g_b_fitting_type,analyseResult.g_b_fitting_c_e))); analysisLog.append(System.lineSeparator()).append(System.lineSeparator()); analysisLog.append("Gamma:"); - analysisLog.append(rowFormat(ch,super.calibration(analyseResult.g_g_fitting_type,analyseResult.g_g_fitting_e_c))); + analysisLog.append(rowFormat(ch,calibration(analyseResult.g_g_fitting_type,analyseResult.g_g_fitting_e_c))); analysisLog.append(System.lineSeparator()); - analysisLog.append(rowFormat(ex,super.calibration(analyseResult.g_g_fitting_type,analyseResult.g_g_fitting_c_e))); + analysisLog.append(rowFormat(ex,calibration(analyseResult.g_g_fitting_type,analyseResult.g_g_fitting_c_e))); analysisLog.append(System.lineSeparator()).append(System.lineSeparator()); analysisLog.append(titleFormat(endTitle,22,StringConstant.DOT,StringConstant.DOT)); analysisLog.append(System.lineSeparator()).append(System.lineSeparator()).append(System.lineSeparator()); @@ -585,14 +585,14 @@ public class ParsingProcessLog { analysisLog.append(System.lineSeparator()).append(System.lineSeparator()).append(System.lineSeparator()); analysisLog.append("Beta:"); analysisLog.append(System.lineSeparator()); - analysisLog.append(rowFormat(ch,super.calibration(analyseResult.d_b_fitting_type,analyseResult.d_b_fitting_e_c))); + analysisLog.append(rowFormat(ch,calibration(analyseResult.d_b_fitting_type,analyseResult.d_b_fitting_e_c))); analysisLog.append(System.lineSeparator()); - analysisLog.append(rowFormat(ex,super.calibration(analyseResult.d_b_fitting_type,analyseResult.d_b_fitting_c_e))); + analysisLog.append(rowFormat(ex,calibration(analyseResult.d_b_fitting_type,analyseResult.d_b_fitting_c_e))); analysisLog.append(System.lineSeparator()).append(System.lineSeparator()); analysisLog.append("Gamma:"); - analysisLog.append(rowFormat(ch,super.calibration(analyseResult.d_g_fitting_type,analyseResult.d_g_fitting_e_c))); + analysisLog.append(rowFormat(ch,calibration(analyseResult.d_g_fitting_type,analyseResult.d_g_fitting_e_c))); analysisLog.append(System.lineSeparator()); - analysisLog.append(rowFormat(ex,super.calibration(analyseResult.d_g_fitting_type,analyseResult.d_g_fitting_c_e))); + analysisLog.append(rowFormat(ex,calibration(analyseResult.d_g_fitting_type,analyseResult.d_g_fitting_c_e))); analysisLog.append(System.lineSeparator()).append(System.lineSeparator()); analysisLog.append(titleFormat(endTitle,22,StringConstant.DOT,StringConstant.DOT)); analysisLog.append(System.lineSeparator()).append(System.lineSeparator()).append(System.lineSeparator()); @@ -634,9 +634,9 @@ public class ParsingProcessLog { final String format = "ROI : %-6s Sample : %-14s GasBkgnd : %-14s DetBkgnd : %s"; BgAnalyseResult analyseResult = sample_B_Analysis.analyseResult; List roi = analyseResult.ROI.stream().map(Object::toString).collect(Collectors.toList()); - List s_roi_cts = analyseResult.s_roi_cts.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); - List g_roi_cts = analyseResult.g_roi_cts.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); - List d_roi_cts = analyseResult.d_roi_cts.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); + List s_roi_cts = analyseResult.s_roi_cts.stream().map(v->formatToStr5(v)).collect(Collectors.toList()); + List g_roi_cts = analyseResult.g_roi_cts.stream().map(v->formatToStr5(v)).collect(Collectors.toList()); + List d_roi_cts = analyseResult.d_roi_cts.stream().map(v->formatToStr5(v)).collect(Collectors.toList()); analysisLog.append(title); analysisLog.append(System.lineSeparator()).append(System.lineSeparator()).append(System.lineSeparator()); @@ -661,13 +661,13 @@ public class ParsingProcessLog { List roi = analyseResult.ROI.stream().map(String::valueOf).collect(Collectors.toList()); //此参数需第一位补0 analyseResult.LC_CTS.add(0,0D); - List lc = analyseResult.LC_CTS.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); + List lc = analyseResult.LC_CTS.stream().map(v->formatToStr5(v)).collect(Collectors.toList()); analysisLog.append(title); analysisLog.append(System.lineSeparator()).append(System.lineSeparator()).append(System.lineSeparator()); for(int i=0;i con = analyseResult.ROI_con_uncer.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); - List conErr = analyseResult.ROI_con_uncer_err.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); + List con = analyseResult.ROI_con_uncer.stream().map(v->formatToStr5(v)).collect(Collectors.toList()); + List conErr = analyseResult.ROI_con_uncer_err.stream().map(v->formatToStr5(v)).collect(Collectors.toList()); analyseResult.LC.add(0,0.0D); analyseResult.MDC.add(0,0.0D); List roi = analyseResult.ROI.stream().map(Object::toString).collect(Collectors.toList()); - List lc = analyseResult.LC.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); - List mdc = analyseResult.MDC.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); + List lc = analyseResult.LC.stream().map(v->formatToStr5(v)).collect(Collectors.toList()); + List mdc = analyseResult.MDC.stream().map(v->formatToStr5(v)).collect(Collectors.toList()); analysisLog.append(title); analysisLog.append(System.lineSeparator()).append(System.lineSeparator()).append(System.lineSeparator()); @@ -713,14 +713,14 @@ public class ParsingProcessLog { BgAnalyseResult analyseResult = sample_B_Analysis.analyseResult; String[] nuclideName = {XE_135,XE_131m,XE_133m,XE_133}; - String[] conc = {super.formatToStr5(analyseResult.Xe135_con) + arithmetic_flag + super.formatToStr5(analyseResult.Xe135_uncer) + unit_mbq, - super.formatToStr5(analyseResult.Xe131m_con) + arithmetic_flag + super.formatToStr5(analyseResult.Xe131m_uncer) + unit_mbq, - super.formatToStr5(analyseResult.Xe133m_con) + arithmetic_flag + super.formatToStr5(analyseResult.Xe133m_uncer) + unit_mbq, - super.formatToStr5(analyseResult.Xe133_con) + arithmetic_flag + super.formatToStr5(analyseResult.Xe133_uncer) + unit_mbq}; - String[] uncertainty = {super.formatToStr5(analyseResult.LC_Xe135) + unit_mbq,super.formatToStr5(analyseResult.LC_Xe131m) + unit_mbq, - super.formatToStr5(analyseResult.LC_Xe133m) + unit_mbq,super.formatToStr5(analyseResult.LC_Xe133) + unit_mbq}; - String[] mdc = {super.formatToStr5(analyseResult.MDC_Xe135) + unit_mbq,super.formatToStr5(analyseResult.MDC_Xe131m) + unit_mbq, - super.formatToStr5(analyseResult.MDC_Xe133m) + unit_mbq,super.formatToStr5(analyseResult.MDC_Xe133) + unit_mbq}; + String[] conc = {formatToStr5(analyseResult.Xe135_con) + arithmetic_flag + formatToStr5(analyseResult.Xe135_uncer) + unit_mbq, + formatToStr5(analyseResult.Xe131m_con) + arithmetic_flag + formatToStr5(analyseResult.Xe131m_uncer) + unit_mbq, + formatToStr5(analyseResult.Xe133m_con) + arithmetic_flag + formatToStr5(analyseResult.Xe133m_uncer) + unit_mbq, + formatToStr5(analyseResult.Xe133_con) + arithmetic_flag + formatToStr5(analyseResult.Xe133_uncer) + unit_mbq}; + String[] uncertainty = {formatToStr5(analyseResult.LC_Xe135) + unit_mbq,formatToStr5(analyseResult.LC_Xe131m) + unit_mbq, + formatToStr5(analyseResult.LC_Xe133m) + unit_mbq,formatToStr5(analyseResult.LC_Xe133) + unit_mbq}; + String[] mdc = {formatToStr5(analyseResult.MDC_Xe135) + unit_mbq,formatToStr5(analyseResult.MDC_Xe131m) + unit_mbq, + formatToStr5(analyseResult.MDC_Xe133m) + unit_mbq,formatToStr5(analyseResult.MDC_Xe133) + unit_mbq}; String xe_135_nid_flag = analyseResult.Xe135_con>analyseResult.MDC_Xe135?"1":"0"; String xe_131m_nid_flag = analyseResult.Xe131m_con>analyseResult.MDC_Xe131m?"1":"0"; String xe_133m_nid_flag = analyseResult.Xe133m_con>analyseResult.MDC_Xe133m?"1":"0"; @@ -786,39 +786,4 @@ public class ParsingProcessLog { spectrumHandler.ftpUtil.saveOrAppendFile(logFilePath,logFileName,new ByteArrayInputStream(log.getBytes(StandardCharsets.UTF_8))); } - - /** - * 行日志格式化 - * @param source 需要格式化的字符串 - * @param symbolNum 格式化的符号数量 - * @param args 格式化替换参数数组 - * @return - */ - private String titleFormat(String source, Integer symbolNum, String... args){ - StringBuilder firstParam = new StringBuilder(); - for (int i=0;i roi = analyseResult.S_ROI; List b_chan_start = analyseResult.S_ROI_B_Boundary_start; List b_chan_stop = analyseResult.S_ROI_B_Boundary_stop; List g_chan_start = analyseResult.S_ROI_G_Boundary_start; List g_chan_stop = analyseResult.S_ROI_G_Boundary_stop; - List roi = analyseResult.S_ROI.stream().map(Object::toString).collect(Collectors.toList()); - List beta = Lists.newArrayList(); - List gamma = Lists.newArrayList(); - String flag = " to "; + reportContent.append(super.rowFormat(sampleLimitsBlock,sampleData.getSampleId().toString())); + reportContent.append(System.lineSeparator()); + reportContent.append(super.rowFormat(rowTitle,StringConstant.SPACE,StringConstant.SPACE)); + reportContent.append(System.lineSeparator()); for(int i=0;i roi = analyseResult.D_ROI; List b_chan_start = analyseResult.D_ROI_B_Boundary_start; List b_chan_stop = analyseResult.D_ROI_B_Boundary_stop; List g_chan_start = analyseResult.D_ROI_G_Boundary_start; List g_chan_stop = analyseResult.D_ROI_G_Boundary_stop; - List roi = analyseResult.D_ROI.stream().map(Object::toString).collect(Collectors.toList()); - List beta = Lists.newArrayList(); - List gamma = Lists.newArrayList(); - String flag = " to "; + reportContent.append(super.rowFormat(detLimitsBlock,detSampleData.getSampleId().toString())); + reportContent.append(System.lineSeparator()); + reportContent.append(super.rowFormat(rowTitle,StringConstant.SPACE,StringConstant.SPACE)); + reportContent.append(System.lineSeparator()); for(int i=0;i roi = analyseResult.G_ROI; List b_chan_start = analyseResult.G_ROI_B_Boundary_start; List b_chan_stop = analyseResult.G_ROI_B_Boundary_stop; List g_chan_start = analyseResult.G_ROI_G_Boundary_start; List g_chan_stop = analyseResult.G_ROI_G_Boundary_stop; - List roi = analyseResult.G_ROI.stream().map(Object::toString).collect(Collectors.toList()); - List beta = Lists.newArrayList(); - List gamma = Lists.newArrayList(); + reportContent.append(super.rowFormat(gasLimitsBlock,gasSampleData.getSampleId().toString())); + reportContent.append(System.lineSeparator()); + reportContent.append(super.rowFormat(rowTitle,StringConstant.SPACE,StringConstant.SPACE)); + reportContent.append(System.lineSeparator()); for(int i=0;i roi = analyseResult.ROI.stream().map(Object::toString).collect(Collectors.toList()); List s_roi_cts = analyseResult.s_roi_cts.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); List g_roi_cts = analyseResult.g_roi_cts.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); List d_roi_cts = analyseResult.d_roi_cts.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); - this.handleFourParamFormat("#GROSS COUNTS PER ROI",roi,s_roi_cts,g_roi_cts,d_roi_cts); + reportContent.append(grossCountsBlock); + reportContent.append(System.lineSeparator()); + reportContent.append(super.rowFormat(rowTitle,StringConstant.SPACE,StringConstant.SPACE,StringConstant.SPACE)); + reportContent.append(System.lineSeparator()); + for (int i=0;i roi_net_count = analyseResult.ROI_net_coutns; - List roi_net_count_err = analyseResult.ROI_net_coutns_err; + String netCountsBlock = "#NET COUNTS AND LC PER ROI "; + String rowTitle = " Roi %-46s Net count %-41s LC"; + String rowValue = " %-50s %-51s %s"; - List roi = analyseResult.ROI.stream().map(Object::toString).collect(Collectors.toList()); - //此参数需第一位补0 - analyseResult.LC_CTS.add(0,0D); - List lc = analyseResult.LC_CTS.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); - List netCount = Lists.newArrayList(); - for(int i=0;i roi = analyseResult.ROI; + List roi_net_count = analyseResult.ROI_net_coutns; + List roi_net_count_err = analyseResult.ROI_net_coutns_err; + //此参数需第一位补0 + analyseResult.LC_CTS.add(0,0D); + List lc = analyseResult.LC_CTS.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); + + reportContent.append(netCountsBlock); + reportContent.append(System.lineSeparator()); + reportContent.append(super.rowFormat(rowTitle,StringConstant.SPACE,StringConstant.SPACE)); + reportContent.append(System.lineSeparator()); + for (int i=0;i roi = analyseResult.ROI.stream().map(Object::toString).collect(Collectors.toList()); List con = analyseResult.ROI_con_uncer; List conErr = analyseResult.ROI_con_uncer_err; analyseResult.LC.add(0,0.0D); analyseResult.MDC.add(0,0.0D); - List roi = analyseResult.ROI.stream().map(Object::toString).collect(Collectors.toList()); List lc = analyseResult.LC.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); List mdc = analyseResult.MDC.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); - List conc = Lists.newArrayList(); - for(int i=0;ianalyseResult.MDC_Xe135?"1":"0"; String xe_131m_nid_flag = analyseResult.Xe131m_con>analyseResult.MDC_Xe131m?"1":"0"; String xe_133m_nid_flag = analyseResult.Xe133m_con>analyseResult.MDC_Xe133m?"1":"0"; String xe_133_nid_flag = analyseResult.Xe133_con>analyseResult.MDC_Xe133?"1":"0"; - String[] nid_flag = {xe_135_nid_flag,xe_131m_nid_flag,xe_133m_nid_flag,xe_133_nid_flag}; - this.handleFiveParamFormat("#RESULT SUMMARY",nuclideName,conc,uncertainty,mdc,nid_flag); + reportContent.append(resultSummaryBlock); + reportContent.append(System.lineSeparator()); + reportContent.append(super.rowFormat(rowTitle,StringConstant.SPACE,StringConstant.SPACE,StringConstant.SPACE,StringConstant.SPACE)); + reportContent.append(System.lineSeparator()); + reportContent.append(super.rowFormat(rowValue,XE_135,xe_135_conc,xe_135_uncertainty,xe_135_mdc,xe_135_nid_flag)); + reportContent.append(System.lineSeparator()); + reportContent.append(super.rowFormat(rowValue,XE_131m,xe_131m_conc,xe_131m_uncertainty,xe_131m_mdc,xe_131m_nid_flag)); + reportContent.append(System.lineSeparator()); + reportContent.append(super.rowFormat(rowValue,XE_133m,xe_133m_conc,xe_133m_uncertainty,xe_133m_mdc,xe_133m_nid_flag)); + reportContent.append(System.lineSeparator()); + reportContent.append(super.rowFormat(rowValue,XE_133,xe_133_conc,xe_133_uncertainty,xe_133_mdc,xe_133_nid_flag)); + reportContent.append(System.lineSeparator()).append(System.lineSeparator()); } /** * 保存报告到ftp */ private void saveReportToFtp() throws FileNotFoundException { - ftpUtil.saveFile(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath()+StringConstant.SLASH+arrFilePath,arrFileName,new FileInputStream(this.reportTmpFile)); - this.reportTmpFile.delete(); + ftpUtil.saveFile(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath()+StringConstant.SLASH+arrFilePath,arrFileName,new ByteArrayInputStream(reportContent.toString().getBytes(StandardCharsets.UTF_8))); } - - /** - * 处理两个参数的占位符格式化 - * 1.#SAMPLE CALIBRATION 模块 - * 2.#DET CALIBRATION 模块 - * 3.#GAS CALIBRATION 模块 - */ - private void handleTwoParamFormat(String key,String[] param,String[] param1) throws IOException { - final List lines = FileUtils.readLines(this.reportTmpFile, "utf-8"); - for(int i=0;i param,List param1,List param2) throws IOException { - final List lines = FileUtils.readLines(this.reportTmpFile, "utf-8"); - for(int i=0;i param,List param1,List param2,List param3) throws IOException { - final List lines = FileUtils.readLines(this.reportTmpFile, "utf-8"); - for(int i=0;i lines = FileUtils.readLines(this.reportTmpFile, "utf-8"); - for(int i=0;i