diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/SpectrumPathProperties.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/SpectrumPathProperties.java index 407c4aed..03906ee2 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/SpectrumPathProperties.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/SpectrumPathProperties.java @@ -20,17 +20,20 @@ import java.util.Map; public class SpectrumPathProperties implements Serializable { /** - * eml格式邮件存储路径 - */ - private String emlPath; - - /** - * 能谱文件存储根路径 + * 存储根路径 */ private String rootPath; + /** + * 能谱文件存储路径 + */ private String saveFilePath; + /** + * eml格式邮件存储路径 + */ + private String emlPath; + /** * 日志文件存储路径 */ @@ -44,12 +47,12 @@ public class SpectrumPathProperties implements Serializable { /** * 用户上传文件路径 */ - private String uploadPath;; + private String uploadPath; /** * 能谱解析失败文件存储路径 */ - private String failPath; + private String undealPath; /** * 手动放置能谱文件获取路径 @@ -60,35 +63,4 @@ public class SpectrumPathProperties implements Serializable { * 能谱文件存储路径以能谱系统类型/能谱类型为key,以存储路径为value */ private Map filePathMap; - - public String getSavePath(String fileType, String systemType, String dataType) { - // systemType dataTYpe year month fileName fileType - // Spectrum/Particulates /Samplephd /2023 /06 /RNAUTO_ARP01_001-20230603_1452_S_PREL_57371 .baseline - // Spectrum/Xenon/Spalax /Samplephd /2023 /09 /RNAUTO_CAX05_001-20230910_1528_S_FULL_37564 .baseline - StringBuilder path = new StringBuilder(); - - final int year = LocalDate.now().getYear(); - final int month = LocalDate.now().getMonth().getValue(); - - path.append(this.getRootPath()).append(StringConstant.SLASH); - - // 自动处理报告 - if (fileType.equals(FileTypeEnum.arr.getValue())) { - path.append(this.getArrPath()).append(StringConstant.SLASH); - } - // todo 人工交互分析报告地址 - if (fileType.equals(FileTypeEnum.rrr.getValue())) { - } - - // systemType - path.append(this.getFilePathMap().get(systemType)).append(StringConstant.SLASH); - // dataType - path.append(this.getFilePathMap().get(dataType)).append(StringConstant.SLASH); - // year - path.append(year).append(StringConstant.SLASH); - // month - path.append(month >= 10 ? month : "0" + month).append(StringConstant.SLASH); - - return path.toString(); - } } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/GammaReportUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/GammaReportUtil.java index d18418b8..42890ddf 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/GammaReportUtil.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/GammaReportUtil.java @@ -16,10 +16,8 @@ public class GammaReportUtil { private static FTPUtil ftpUtil = ApplicationContextUtil.getContext().getBean(FTPUtil.class); private static int colLength = 15; public static void writeFile(BaseControls baseCtrl, String path){ - // 获取系统的临时目录 - String tempDir = System.getProperty("java.io.tmpdir"); // 创建文件 - File file = new File(tempDir + System.currentTimeMillis()); + File file = new File(path); // 创建PrintWriter对象 PrintWriter out = null; try { @@ -45,23 +43,17 @@ public class GammaReportUtil { out.println("#StepCounts"); format(baseCtrl.getStepCounts(), out); - String targetPath = StringUtils.substringBeforeLast(path, StringPool.SLASH); - String targetName = StringUtils.substringAfterLast(path, StringPool.SLASH); - ftpUtil.saveFile(targetPath, targetName, new FileInputStream(file)); } catch (FileNotFoundException e) { e.printStackTrace(); } finally { if (null != out) { out.close(); } - file.delete(); } } public static void writeFile(List data, String fileType, String path){ - // 获取系统的临时目录 - String tempDir = System.getProperty("java.io.tmpdir"); // 创建文件 - File file = new File(tempDir + System.currentTimeMillis()); + File file = new File(path); // 创建PrintWriter对象 PrintWriter out = null; try { @@ -70,17 +62,12 @@ public class GammaReportUtil { out.printf("%" + (String.valueOf(data.size()).length() + (colLength - String.valueOf(data.size()).length())) + "s", data.size() + "\n"); format(data, out); - String targetPath = StringUtils.substringBeforeLast(path, StringPool.SLASH); - String targetName = StringUtils.substringAfterLast(path, StringPool.SLASH); - ftpUtil.saveFile(targetPath, targetName, new FileInputStream(file)); - } catch (FileNotFoundException e) { e.printStackTrace(); } finally { if (null != out) { out.close(); } - file.delete(); } } 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 6fe2c80e..71e068ba 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 @@ -7,14 +7,12 @@ import org.jeecg.common.email.EmailServiceManager; import org.jeecg.common.util.RedisUtil; import org.jeecg.modules.base.enums.SysMailEnableType; import org.jeecg.modules.email.EmailProperties; -import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.properties.TaskProperties; import org.jeecg.modules.service.ISysMailService; import org.jeecg.modules.spectrum.EmailCounter; import org.jeecg.modules.spectrum.SpectrumServiceQuotes; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; - import java.util.*; import java.util.concurrent.TimeUnit; @@ -32,10 +30,6 @@ public class AutoProcessManager{ private final SpectrumServiceQuotes spectrumServiceQuotes; private final EmailCounter emailCounter; private Date systemStartupTime; - /** - * FTP目录操作锁 - */ - private Object ftpOpierationLock; /** * 邮件Map数据锁 */ @@ -53,9 +47,8 @@ public class AutoProcessManager{ /** * 启动自动处理 */ - public void start(Date systemStartupTime,Object ftpOpierationLock) { + public void start(Date systemStartupTime) { this.systemStartupTime = systemStartupTime; - this.ftpOpierationLock = ftpOpierationLock; //邮件数据监测线程 final MailDataMonitor mailDataMonitor = new MailDataMonitor(); mailDataMonitor.setName("mail-data-monitor"); @@ -94,7 +87,7 @@ public class AutoProcessManager{ } if(next.isNewEmailFlag()){ EmailParsingActuator emailParsingActuator = new EmailParsingActuator(); - emailParsingActuator.init(next,spectrumServiceQuotes,emailCounter,systemStartupTime,ftpOpierationLock); + emailParsingActuator.init(next,spectrumServiceQuotes,emailCounter,systemStartupTime); 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 0b927800..66c3ba37 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,16 +24,14 @@ 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,Object ftpOpierationLock){ + EmailCounter emailCounter,Date systemStartupTime){ this.emailProperties = emailProperties; this.spectrumServiceQuotes = spectrumServiceQuotes; this.taskProperties = spectrumServiceQuotes.getTaskProperties(); this.emailCounter = emailCounter; this.systemStartupTime = systemStartupTime; - this.ftpOpierationLock = ftpOpierationLock; //获取机器可用核心数 int systemCores = Runtime.getRuntime().availableProcessors(); @@ -57,7 +55,7 @@ public class EmailParsingActuator extends Thread{ for(Message message : messages){ SpectrumParsingActuator spectrumParsingActuator = new SpectrumParsingActuator(); spectrumParsingActuator.init(message,emailProperties,emailServiceManager, - taskLatch,spectrumServiceQuotes,emailCounter,ftpOpierationLock); + taskLatch,spectrumServiceQuotes,emailCounter); 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 6f328887..59d7c887 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 @@ -2,26 +2,19 @@ package org.jeecg.modules; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.FileUtils; 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.file.FileOperation; +import org.jeecg.modules.spectrum.AbstractSpectrumHandler; import org.jeecg.modules.spectrum.SamplephdSpectrum; -import org.jeecg.modules.spectrum.SpectrumHandler; import org.jeecg.modules.spectrum.SpectrumServiceQuotes; import org.springframework.scheduling.concurrent.CustomizableThreadFactory; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; - -import java.io.ByteArrayInputStream; -import java.io.FileInputStream; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; +import java.io.File; import java.util.List; import java.util.concurrent.*; -import java.util.stream.Collectors; /** * 解析手动放置PHD文件程序管理器 @@ -29,7 +22,7 @@ import java.util.stream.Collectors; @Slf4j @Component @RequiredArgsConstructor -public class FileSourceHandleManager { +public class FileSourceHandleManager{ /** * 任务属性 @@ -39,16 +32,11 @@ public class FileSourceHandleManager { * 相关Spring组件引用 */ private final SpectrumServiceQuotes spectrumServiceQuotes; - /** - * FTP目录操作锁 - */ - private Object ftpOpierationLock; /** * 开始 */ - public void start(Object ftpOpierationLock){ - this.ftpOpierationLock = ftpOpierationLock; + public void start(){ ParseingFileSourceThreadManager fileSourceThreadManager = new ParseingFileSourceThreadManager(); fileSourceThreadManager.init(); fileSourceThreadManager.start(); @@ -68,38 +56,32 @@ public class FileSourceHandleManager { //初始化线程池 ThreadFactory threadFactory = new CustomizableThreadFactory("filesource-file-parsing-"); - poolExecutor = new ThreadPoolExecutor(taskProperties.getReceiveNum(),maximumPoolSize,5, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),threadFactory); + poolExecutor = new ThreadPoolExecutor(taskProperties.getFilesourceDirReceiveNum(),maximumPoolSize,5, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),threadFactory); } @Override public void run() { for(;;){ long start = System.currentTimeMillis(); - FTPUtils ftpUtil = null; try { - //初始化FTP客户端对象 - final FTPProperties ftpProperties = spectrumServiceQuotes.getFtpProperties(); - ftpUtil = new FTPUtils(ftpProperties.getHost(),ftpProperties.getPort(),ftpProperties.getUserName(), - ftpProperties.getPassword(),ftpProperties.getEncoding(),ftpProperties.getFtpRootPath()); //手动放置能谱文件获取路径 - String filePath = spectrumServiceQuotes.getSpectrumPathProperties().getFilesourcePath(); - List fileNames = ftpUtil.getFiles(filePath, taskProperties.getFilesourceDirReceiveNum().intValue()); - ftpUtil.close(); - 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); + final String rootPath = spectrumServiceQuotes.getSpectrumPathProperties().getRootPath(); + final String filePath = spectrumServiceQuotes.getSpectrumPathProperties().getFilesourcePath(); + List spectrumFiles = FileOperation.getFiles(rootPath+ File.separator+filePath,taskProperties.getFilesourceDirReceiveNum()); + if(!CollectionUtils.isEmpty(spectrumFiles)){ + CountDownLatch taskLatch = new CountDownLatch(spectrumFiles.size()); + for(File spectrumFile : spectrumFiles){ + //如果是Sample谱则延迟2秒后执行 + if(spectrumFile.getName().contains(BlockConstant.sampleFlag)){ + TimeUnit.SECONDS.sleep(2); } ParseingFileSourceThread parseingFileSourceThread = new ParseingFileSourceThread(); - parseingFileSourceThread.init(fileName,filePath,taskLatch); + parseingFileSourceThread.init(spectrumFile,filePath,taskLatch); poolExecutor.execute(parseingFileSourceThread); } taskLatch.await(); } }catch (Exception e){ - ftpUtil.close(); e.printStackTrace(); } long end = System.currentTimeMillis(); @@ -123,11 +105,7 @@ public class FileSourceHandleManager { /** * 能谱文件名称 */ - private String fileName; - /** - * ftp工具 - */ - private FTPUtils ftpUtil; + private File spectrumFile; /** * 手动放置能谱文件获取路径 */ @@ -139,8 +117,8 @@ public class FileSourceHandleManager { private CountDownLatch taskLatch; - public void init(String fileName,String filePath,CountDownLatch taskLatch){ - this.fileName = fileName; + public void init(File spectrumFile,String filePath,CountDownLatch taskLatch){ + this.spectrumFile = spectrumFile; this.filePath = filePath; this.taskLatch = taskLatch; } @@ -148,52 +126,24 @@ public class FileSourceHandleManager { @Override public void run() { try { - //初始化FTP客户端对象 - final FTPProperties ftpProperties = spectrumServiceQuotes.getFtpProperties(); - this.ftpUtil = new FTPUtils(ftpProperties.getHost(),ftpProperties.getPort(),ftpProperties.getUserName(), - ftpProperties.getPassword(),ftpProperties.getEncoding(),ftpProperties.getFtpRootPath(),ftpOpierationLock); //获取文件内容 - fileContent = this.ftpUtil.getFileContent(filePath, fileName); + fileContent = FileUtils.readFileToString(spectrumFile,"UTF-8"); //解析文件 - SpectrumHandler spectrumHandler = new SamplephdSpectrum(); - spectrumHandler.init(fileContent,spectrumServiceQuotes,this.ftpUtil); + AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum(); + spectrumHandler.init(fileContent,spectrumServiceQuotes); final boolean matchResult = spectrumHandler.saveEmailToLocal(); if(matchResult){ //开始解析 spectrumHandler.handler(); } }catch (Exception e){ - //解析失败会把文件上传到undeal目录 - this.ftpUtil.saveFile(spectrumServiceQuotes.getSpectrumPathProperties().getFailPath(),this.fileName,new ByteArrayInputStream(fileContent.getBytes(StandardCharsets.UTF_8))); - log.error("Parsing the {} file of the filesource directory failed",fileName); + log.error("Parsing the {} file of the filesource directory failed",spectrumFile.getName()); e.printStackTrace(); }finally { - //解析成功或者失败都会删除源文件 - this.ftpUtil.removeFile(this.filePath,this.fileName); - this.ftpUtil.close(); taskLatch.countDown(); + //解析成功或者失败都会删除源文件 + spectrumFile.delete(); } } } - - 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 d61b7b3f..d4634154 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 @@ -2,22 +2,19 @@ package org.jeecg.modules; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.FileUtils; 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.file.FileOperation; +import org.jeecg.modules.spectrum.AbstractSpectrumHandler; import org.jeecg.modules.spectrum.SamplephdSpectrum; -import org.jeecg.modules.spectrum.SpectrumHandler; import org.jeecg.modules.spectrum.SpectrumServiceQuotes; 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.io.File; import java.util.List; import java.util.concurrent.*; -import java.util.stream.Collectors; /** * 解析失败邮件处理程序管理器 @@ -35,16 +32,11 @@ public class UndealHandleManager{ * 相关Spring组件引用 */ private final SpectrumServiceQuotes spectrumServiceQuotes; - /** - * FTP目录操作锁 - */ - private Object ftpOpierationLock; /** * 开始 */ - public void start(Object ftpOpierationLock){ - this.ftpOpierationLock = ftpOpierationLock; + public void start(){ ParseingFaliFileThreadManager faliFileThreadManager = new ParseingFaliFileThreadManager(); faliFileThreadManager.init(); faliFileThreadManager.start(); @@ -71,31 +63,25 @@ public class UndealHandleManager{ public void run() { for(;;){ long start = System.currentTimeMillis(); - FTPUtils ftpUtil = null; try { - //初始化FTP客户端对象 - final FTPProperties ftpProperties = spectrumServiceQuotes.getFtpProperties(); - ftpUtil = new FTPUtils(ftpProperties.getHost(),ftpProperties.getPort(),ftpProperties.getUserName(), - ftpProperties.getPassword(),ftpProperties.getEncoding(),ftpProperties.getFtpRootPath()); //ftp解析失败文件存储路径 - String filePath = spectrumServiceQuotes.getSpectrumPathProperties().getFailPath(); - List fileNames = ftpUtil.getFiles(filePath, taskProperties.getUndealDirReceiveNum().intValue()); - ftpUtil.close(); - 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); + final String rootPath = spectrumServiceQuotes.getSpectrumPathProperties().getRootPath(); + final String filePath = spectrumServiceQuotes.getSpectrumPathProperties().getUndealPath(); + List spectrumFiles = FileOperation.getFiles(rootPath+ File.separator+filePath,taskProperties.getUndealDirReceiveNum()); + if(!CollectionUtils.isEmpty(spectrumFiles)){ + CountDownLatch taskLatch = new CountDownLatch(spectrumFiles.size()); + for(File spectrumFile : spectrumFiles){ + //如果是Sample谱则延迟2秒后执行 + if(spectrumFile.getName().contains(BlockConstant.sampleFlag)){ + TimeUnit.SECONDS.sleep(2); } ParseingFaliFileThread faliFileThread = new ParseingFaliFileThread(); - faliFileThread.init(fileName,filePath,taskLatch); + faliFileThread.init(spectrumFile,filePath,taskLatch); poolExecutor.execute(faliFileThread); } taskLatch.await(); } }catch (Exception e){ - ftpUtil.close(); e.printStackTrace(); } long end = System.currentTimeMillis(); @@ -120,11 +106,7 @@ public class UndealHandleManager{ /** * 能谱文件名称 */ - private String fileName; - /** - * ftp工具 - */ - private FTPUtils ftpUtil; + private File spectrumFile; /** * 失败文件存储路径 */ @@ -132,8 +114,8 @@ public class UndealHandleManager{ private CountDownLatch taskLatch; - public void init(String fileName,String filePath,CountDownLatch taskLatch){ - this.fileName = fileName; + public void init(File spectrumFile,String filePath,CountDownLatch taskLatch){ + this.spectrumFile = spectrumFile; this.filePath = filePath; this.taskLatch = taskLatch; } @@ -141,28 +123,23 @@ public class UndealHandleManager{ @Override public void run() { try { - //初始化FTP客户端对象 - final FTPProperties ftpProperties = spectrumServiceQuotes.getFtpProperties(); - this.ftpUtil = new FTPUtils(ftpProperties.getHost(),ftpProperties.getPort(),ftpProperties.getUserName(), - ftpProperties.getPassword(),ftpProperties.getEncoding(),ftpProperties.getFtpRootPath(),ftpOpierationLock); //获取文件内容 - final String fileContent = this.ftpUtil.getFileContent(filePath, fileName); + final String fileContent = FileUtils.readFileToString(spectrumFile,"UTF-8"); //解析文件 - SpectrumHandler spectrumHandler = new SamplephdSpectrum(); - spectrumHandler.init(fileContent,spectrumServiceQuotes,this.ftpUtil); + AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum(); + spectrumHandler.init(fileContent,spectrumServiceQuotes); final boolean matchResult = spectrumHandler.saveEmailToLocal(); if(matchResult){ //开始解析 spectrumHandler.handler(); } }catch (Exception e){ - log.error("The {} file of the undeal directory fails to be parsed again",fileName); + log.error("The {} file of the undeal directory fails to be parsed again",spectrumFile.getName()); e.printStackTrace(); }finally { - //解析成功或者失败都会删除源文件 - this.ftpUtil.removeFile(this.filePath,this.fileName); - this.ftpUtil.close(); this.taskLatch.countDown(); + //解析成功或者失败都会删除源文件 + spectrumFile.delete(); } } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/file/FileOperation.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/file/FileOperation.java new file mode 100644 index 00000000..04b852f1 --- /dev/null +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/file/FileOperation.java @@ -0,0 +1,161 @@ +package org.jeecg.modules.file; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.io.FileUtil; +import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; +import org.jeecg.common.constant.StringConstant; +import org.jeecg.modules.base.enums.DataType; +import org.jeecg.modules.service.BlockConstant; +import org.springframework.util.CollectionUtils; +import java.io.File; +import java.io.FileFilter; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.*; +import java.util.stream.Collectors; + +public class FileOperation { + + /** + * 存储以能谱后缀为key,default为value,判断filesource或undel目录里的文件是否合法 + */ + private static Map dataTypeMap = Maps.newHashMap(); + + /** + * 获取指定路径下指定数量的文件 + * @param path + * @param receiveNum + * @return + * @throws FileNotFoundException + */ + public static List getFiles(String path, Integer receiveNum) throws FileNotFoundException { + File file = new File(path); + if (!file.exists()){ + throw new FileNotFoundException(path+" directory does not exist"); + } + if (!file.isDirectory()){ + throw new FileNotFoundException(path+" file is not a directory"); + } + if(FileUtil.isDirEmpty(file)){ + return Collections.emptyList(); + } + if(CollectionUtils.isEmpty(dataTypeMap)){ + final DataType[] dataTypes = DataType.values(); + for (DataType dataType : dataTypes){ + dataTypeMap.put(dataType.getSuffix(),"default"); + } + } + File[] spectrumFiles = file.listFiles(new FileFilter() { + @Override + public boolean accept(File file) { + final String suffix = file.getName().substring(file.getName().lastIndexOf(StringConstant.DOT)); + if (dataTypeMap.containsKey(suffix)){ + return true; + } + return false; + } + }); + List sortList = new ArrayList<>(); + for (File spectrumFile : spectrumFiles){ + if(spectrumFile.getName().contains(BlockConstant.sampleFlag)){ + sortList.add(spectrumFile); + }else { + sortList.add(0,spectrumFile); + } + } + //最终实际获取数量 + int num = receiveNum > sortList.size()?sortList.size():receiveNum; + return sortList.stream().limit(num).collect(Collectors.toList()); + } + + /** + * 保存或追加写入文件 + * @param filePath + * @param content + * @throws IOException + */ + public static void saveOrAppendFile(String filePath,String content,boolean appendFlag) throws IOException { + if(appendFlag){ + if(!FileUtil.exist(filePath)){ + FileUtil.writeString(content,filePath,"utf-8"); + }else { + FileUtil.appendString(content,filePath,"utf-8"); + } + }else{ + FileUtil.writeString(content,filePath,"utf-8"); + } + } + + /** + * 保存文件 + * @param filePath + * @param content + * @throws IOException + */ + public static void saveFile(String filePath, List content) throws IOException { + if (CollUtil.isEmpty(content)) return; + FileUtil.writeUtf8Lines(content, filePath); + } + + /** + * 修改文件名称 + * @param file + * @param newFileName + * @param isOverride + * @return + */ + public static File rename(File file,String newFileName,boolean isOverride){ + return FileUtil.rename(file,newFileName,isOverride); + } + + /** + * 移动文件到指定目录 + * @param srcFile + * @param destDir + * @param isOverride + * @throws IOException + */ + public static void moveFile(File srcFile,String destDir,boolean isOverride) throws IOException { + FileUtil.move(srcFile,new File(destDir),true); + } + + /** + * 复制文件到指定目录 + * @param srcFile + * @param destDir + * @param isOverride + * @throws IOException + */ + public static void copyFile(File srcFile,String destDir,boolean isOverride) throws IOException { + FileUtil.copy(srcFile,new File(destDir),true); + } + + /** + * 把路径中系统分隔符进行转换 + * 若系统为windows,则转换为linux分隔符,否则不进行操作 + * @param filePath + * @return + */ + public static String separatorConvert(String filePath){ + String os = System.getProperty("os.name").toLowerCase(); + if (os.contains("win")) { + return StringUtils.replace(filePath,"\\","/"); + } + return filePath; + } + + /** + * 把路径中系统分隔符进行转换 + * 若系统为windows,则把linux分隔符转换为windows分隔符,否则不进行操作 + * @param filePath + * @return + */ + public static String separatorConvertReversal(String filePath){ + String os = System.getProperty("os.name").toLowerCase(); + if (os.contains("win")) { + return StringUtils.replace(filePath,"/","\\"); + } + return filePath; + } +} diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/ftp/FTPProperties.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/ftp/FTPProperties.java deleted file mode 100644 index 258b1833..00000000 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/ftp/FTPProperties.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.jeecg.modules.ftp; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; - -@Data -@Component -@ConfigurationProperties(prefix = "ftp") -public class FTPProperties { - - private String host; - - private Integer port; - - private String userName; - - private String password; - - private String encoding; - - private String ftpRootPath; - - -} 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 deleted file mode 100644 index 14b92357..00000000 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/ftp/FTPUtils.java +++ /dev/null @@ -1,354 +0,0 @@ -package org.jeecg.modules.ftp; - -import cn.hutool.core.io.FileUtil; -import lombok.extern.slf4j.Slf4j; -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; - -@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,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客户端 - this.client = new FTPClient(); - //连接 - this.client.connect(host, port); - //登录 - this.client.login(userName, password); - // 切换为本地被动模式,可以解决FTP上传后文件为空的问题,但需要服务器将FTP服务添加至防火墙白名单 - this.client.enterLocalPassiveMode(); - //设置文件client参数 - this.client.setFileType(FTPClient.BINARY_FILE_TYPE); - this.client.setControlEncoding(this.encoding); - this.client.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); - //判断是否连接成功 - int reply = this.client.getReplyCode(); - if (!FTPReply.isPositiveCompletion(reply)) { - this.client.disconnect(); - } - }catch (IOException e){ - log.error("FTP服务连接失败,原因:{}",e.getMessage()); - e.printStackTrace(); - } - } - - /** - * 下载ftp服务文件 - * @param ftpFilePath - * @param fileName - * @param localPath - * @throws IOException - */ - public boolean downloadFTPFile(String ftpFilePath,String fileName,String localPath) throws IOException { - 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(); - } - } - return false; - } - } - - /** - * 检查目录是否存在,不存在则创建,支持递归创建 - * @param path 目录路径 - * @return 返回值true/false - */ - private boolean checkDirectory(String path){ - try{ - final boolean changeFlag = this.client.changeWorkingDirectory(ftpRootPath); - if(!changeFlag){ - log.error("{},根目录切换失败",ftpRootPath); - return false; - } - String[] directories = path.split("/"); - for(String directory : directories){ - if(StringUtils.isEmpty(directory)){ - continue; - } - if(!this.client.changeWorkingDirectory(directory)){ - if(!this.client.makeDirectory(directory)){ - log.error("{},目录创建失败",directory); - return false; - } - if(!this.client.changeWorkingDirectory(directory)){ - log.error("{},目录切换失败",directory); - return false; - } - } - } - return true; - }catch (IOException e){ - log.error("检查目录失败,原因:{}",e.getMessage()); - e.printStackTrace(); - } - return true; - } - - /** - * 写入文件,若文件或文件目录不存在则自行创建,存在无操作 - * @param filePath 文件路径 - * @param fileName 文件名称 - * @param inputStream 文件输入流 - * @return 返回值true/false - */ - public boolean saveFile(String filePath,String fileName,InputStream 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(); - } - } - } - return false; - } - } - - /** - * 写入文件,若文件或文件目录不存在则自行创建,存在则追加内容 - * @param filePath 文件路径 - * @param fileName 文件名称 - * @param inputStream 文件输入流 - * @return 返回值true/false - */ - public boolean saveOrAppendFile(String filePath,String fileName,InputStream 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(); - } - } - } - return false; - } - } - - /** - * 在指定路径下获取指定数量的文件名称列表,若有Sample谱则排在最后 - * @param filePath - * @param getNum - * @return - */ - public List getFiles(String filePath,int getNum) throws IOException { - 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(); - } - } - - /** - * 获取文件内容 - * @param filePath 文件路径 - * @param fileName 文件名称 - * @return 返回值,文件内容 - * @throws IOException - */ - public String getFileContent(String filePath,String fileName) throws IOException { - 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; - } - } - - /** - * 删除文件 - * @param filePath 文件路径 - * @param fileName 文件名称 - * @return 返回值true/false - */ - public boolean removeFile(String filePath,String fileName){ - 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; - } - } - } - - /** - * 获取FTP服务根目录(绝对路径) - * @return - */ - public String getRootPath(){ - try { - final String rootPath = this.client.printWorkingDirectory(); - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } - - /** - * 关闭ftp客户端连接 - * @throws IOException - */ - public void close(){ - try{ - 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/impl/GardsAnalysesServiceImpl.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsAnalysesServiceImpl.java index ef4ef3ab..4f695572 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsAnalysesServiceImpl.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsAnalysesServiceImpl.java @@ -9,6 +9,7 @@ import org.jeecg.common.properties.SoftwareProperties; import org.jeecg.modules.base.entity.original.GardsSampleData; import org.jeecg.modules.base.entity.rnauto.GardsAnalyses; import org.jeecg.modules.base.enums.AnalysesType; +import org.jeecg.modules.file.FileOperation; import org.jeecg.modules.mapper.GardsAnalysesMapper; import org.jeecg.modules.service.GardsAnalysesService; import org.springframework.stereotype.Service; @@ -52,8 +53,8 @@ public class GardsAnalysesServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(GardsSampleData::getInputFileName,inputFileName); - return this.getOne(queryWrapper); + if (StrUtil.isNotBlank(inputFileName)){ + inputFileName = FileOperation.separatorConvert(inputFileName); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(GardsSampleData::getInputFileName,inputFileName); + return this.getOne(queryWrapper); + } + return null; } /** diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/SpectrumBaseBlockServiceImpl.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/SpectrumBaseBlockServiceImpl.java index 467e7ee0..25ad8787 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/SpectrumBaseBlockServiceImpl.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/SpectrumBaseBlockServiceImpl.java @@ -9,6 +9,7 @@ import org.jeecg.modules.base.entity.configuration.GardsDetectors; import org.jeecg.modules.base.entity.configuration.GardsStations; import org.jeecg.modules.base.entity.original.GardsSampleAux; import org.jeecg.modules.base.entity.original.GardsSampleData; +import org.jeecg.modules.file.FileOperation; import org.jeecg.modules.mapper.GardsDetectorsMapper; import org.jeecg.modules.mapper.GardsSampleAuxMapper; import org.jeecg.modules.mapper.GardsSampleDataMapper; @@ -43,6 +44,7 @@ public class SpectrumBaseBlockServiceImpl implements ISpectrumBaseBlockService { */ @Override public GardsSampleData create(EnergySpectrumStruct struct,String fileName,String status) throws Exception { + fileName = FileOperation.separatorConvert(fileName); final GardsSampleData sampleData = this.saveSampleData(struct,fileName,status); this.saveSampleAux(struct,sampleData); return sampleData; diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Chain.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractChain.java similarity index 81% rename from jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Chain.java rename to jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractChain.java index 628227ee..2a549107 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Chain.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractChain.java @@ -6,19 +6,19 @@ import lombok.Setter; /** * 能谱执行链路 */ -public abstract class Chain { +public abstract class AbstractChain { /** * 上一任处理链 */ @Setter - protected SpectrumHandler previous; + protected AbstractSpectrumHandler previous; /** * 下一任处理链 */ @Setter - protected SpectrumHandler next; + protected AbstractSpectrumHandler next; /** * 是否匹配成功 diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/S_D_Q_G_SpectrumHandler.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractS_D_Q_G_SpectrumHandler.java similarity index 83% rename from jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/S_D_Q_G_SpectrumHandler.java rename to jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractS_D_Q_G_SpectrumHandler.java index 4c0aa9a3..d9c55f63 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/S_D_Q_G_SpectrumHandler.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractS_D_Q_G_SpectrumHandler.java @@ -2,7 +2,6 @@ package org.jeecg.modules.spectrum; import cn.hutool.core.io.FileUtil; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.util.Strings; @@ -35,7 +34,7 @@ import java.util.Objects; * 样品谱(Samplephd)、探测器本地谱(Detbkphd)、QC谱(Qcphd)、气体谱(Gasbkphd) */ @Slf4j -public abstract class S_D_Q_G_SpectrumHandler extends SpectrumHandler{ +public abstract class AbstractS_D_Q_G_SpectrumHandler extends AbstractSpectrumHandler{ /** * 解析后的数据 @@ -93,48 +92,33 @@ public abstract class S_D_Q_G_SpectrumHandler extends SpectrumHandler{ */ @Override protected void parseingEmail() throws Exception { - final EnergySpectrumStruct sourceData = EnergySpectrumHandler.getSourceData(mailFile.getAbsolutePath()); + final EnergySpectrumStruct sourceData = EnergySpectrumHandler.getSourceData(super.spectrumFile.getAbsolutePath()); if(Objects.isNull(sourceData)){ - throw new PHD_ReadException("THE PHDFile has some blocks can't be read:"+this.mailFile.getAbsolutePath()); + throw new PHD_ReadException("THE PHDFile has some blocks can't be read:"+super.spectrumFile.getAbsolutePath()); } this.sourceData = sourceData; } /** - * 保存能谱文件到ftp - */ - @Override - protected void saveFileToFtp() throws FileNotFoundException { - //修改能谱文件名称 - this.updateSpectrumFileName(); - //获取文件保存路径 - String fileSavePath = this.getFileSavePath(); - final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); - super.ftpUtil.saveFile(properties.getRootPath()+StringConstant.SLASH+fileSavePath,this.mailFile.getName(),new FileInputStream(this.mailFile)); - //设置FTP文件保存路径 - super.ftpSavePath = fileSavePath+StringConstant.SLASH+this.mailFile.getName(); - } - - /** - * 获取文件保存路径 + * 获取文件保存相对路径 * @return */ - protected String getFileSavePath(){ - //处理此文件需要保存到ftp服务的路径 + @Override + protected String getFileSaveRelativePath(){ //measurement_id切割后的字符数组 String[] arr = this.sourceData.measurement_id.split(StringConstant.DASH); //切割后第一个,元素是年,第二个是月 final String[] yearMonth = arr[1].split(StringConstant.SLASH); final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); - StringBuilder ftpPath = new StringBuilder(); - ftpPath.append(properties.getFilePathMap().get(this.sourceData.system_type)); - ftpPath.append(StringConstant.SLASH); - ftpPath.append(properties.getFilePathMap().get(this.sourceData.data_type)); - ftpPath.append(StringConstant.SLASH); - ftpPath.append(yearMonth[0]); - ftpPath.append(StringConstant.SLASH); - ftpPath.append(yearMonth[1]); - return ftpPath.toString(); + StringBuilder relativePath = new StringBuilder(); + relativePath.append(properties.getFilePathMap().get(this.sourceData.system_type)); + relativePath.append(File.separator); + relativePath.append(properties.getFilePathMap().get(this.sourceData.data_type)); + relativePath.append(File.separator); + relativePath.append(yearMonth[0]); + relativePath.append(File.separator); + relativePath.append(yearMonth[1]); + return relativePath.toString(); } /** @@ -155,10 +139,10 @@ public abstract class S_D_Q_G_SpectrumHandler extends SpectrumHandler{ newFileName.append(StringConstant.UNDER_LINE); newFileName.append(handleLiveTime()); newFileName.append(super.currDataType.getSuffix()); - if(!mailFile.exists()){ - throw new FileNotFoundException(mailFile.getAbsolutePath()+"文件不存在"); + if(!super.spectrumFile.exists()){ + throw new FileNotFoundException(super.spectrumFile.getAbsolutePath()+" does not exist"); } - mailFile = FileUtil.rename(mailFile, newFileName.toString(), true); + super.spectrumFile = FileUtil.rename(super.spectrumFile, newFileName.toString(), true); } /** @@ -192,7 +176,7 @@ public abstract class S_D_Q_G_SpectrumHandler extends SpectrumHandler{ * @throws Exception */ protected void readFileLabel() throws Exception{ - Path path = Paths.get(mailFile.getAbsolutePath()); + Path path = Paths.get(super.spectrumFile.getAbsolutePath()); final List lines = Files.readAllLines(path); for(String line : lines){ if(line.indexOf("#") != -1){ @@ -208,7 +192,7 @@ public abstract class S_D_Q_G_SpectrumHandler extends SpectrumHandler{ protected void handlerOriginalData() throws Exception { this.startIntoDatabaseTime = new Date(); //如果数据已经存储,不在重复存储 - final GardsSampleData query = spectrumServiceQuotes.getSampleDataService().findByInputFileName(super.ftpSavePath); + final GardsSampleData query = spectrumServiceQuotes.getSampleDataService().findByInputFileName(super.spectrumFileRelativePath); if(Objects.nonNull(query)){ this.sampleData = query; this.endIntoDatabaseTime = new Date(); @@ -220,7 +204,7 @@ public abstract class S_D_Q_G_SpectrumHandler extends SpectrumHandler{ final TransactionStatus transactionStatus = spectrumServiceQuotes.getTransactionManager().getTransaction(spectrumServiceQuotes.getTransactionDefinition()); try{ //存储基础数据 - this.sampleData = spectrumServiceQuotes.getSpectrumBaseBlockService().create(this.sourceData,super.ftpSavePath,status); + this.sampleData = spectrumServiceQuotes.getSpectrumBaseBlockService().create(this.sourceData,super.spectrumFileRelativePath,status); //存储其他块数据 for(String labels : spectrumFileLabels){ final ISpectrumBlockService spectrumBlockService = spectrumServiceQuotes.getSpectrumBlockService().get(labels); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumHandler.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractSpectrumHandler.java similarity index 60% rename from jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumHandler.java rename to jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractSpectrumHandler.java index d50f70c7..10c379e9 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumHandler.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractSpectrumHandler.java @@ -5,11 +5,12 @@ import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.RandomUtils; import org.jeecg.common.constant.StringConstant; +import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.modules.base.enums.DataType; -import org.jeecg.modules.ftp.FTPUtils; +import org.jeecg.modules.file.FileOperation; import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOException; import java.util.List; import java.util.Objects; @@ -17,7 +18,7 @@ import java.util.Objects; * 能谱处理模版 */ @Slf4j -public abstract class SpectrumHandler extends Chain{ +public abstract class AbstractSpectrumHandler extends AbstractChain { private final static String DATA_TYPE_PREFIX = "DATA_TYPE "; @@ -26,10 +27,6 @@ public abstract class SpectrumHandler extends Chain{ * 处理能谱数据相关Service引用 */ protected SpectrumServiceQuotes spectrumServiceQuotes; - /** - * ftp工具 - */ - protected FTPUtils ftpUtil; /** * 当前解析的邮件内容文本 */ @@ -41,11 +38,11 @@ public abstract class SpectrumHandler extends Chain{ /** * 当前解析的能谱文件路径 */ - protected File mailFile = null; + protected File spectrumFile = null; /** - * 能谱文件FTP保存路径 + * 能谱文件保存相对路径 */ - protected String ftpSavePath; + protected String spectrumFileRelativePath; /** * 保存当前能谱文件有哪些#开头的标签 @@ -55,21 +52,19 @@ public abstract class SpectrumHandler extends Chain{ /** * 初始化参数 */ - public void init(String mailContent,SpectrumServiceQuotes spectrumServiceQuotes,FTPUtils ftpUtil) throws Exception{ + public void init(String mailContent,SpectrumServiceQuotes spectrumServiceQuotes) throws Exception{ this.mailContent = mailContent; this.spectrumServiceQuotes = spectrumServiceQuotes; - this.ftpUtil = ftpUtil; } /** * 初始化参数 */ - protected void initNext(SpectrumServiceQuotes spectrumServiceQuotes,File mailFile,DataType currDataType, - FTPUtils ftpUtil,String mailContent){ + protected void initNext(SpectrumServiceQuotes spectrumServiceQuotes,File spectrumFile,DataType currDataType, + String mailContent){ this.spectrumServiceQuotes = spectrumServiceQuotes; - this.mailFile = mailFile; + this.spectrumFile = spectrumFile; this.currDataType = currDataType; - this.ftpUtil = ftpUtil; this.mailContent = mailContent; this.setChina(); } @@ -85,9 +80,32 @@ public abstract class SpectrumHandler extends Chain{ protected abstract void parseingEmail() throws Exception; /** - * 保存能谱文件到ftp + * 保存能谱文件到savefile */ - protected abstract void saveFileToFtp() throws Exception; + protected void saveFileToSavefile() throws Exception{ + //修改能谱文件名称 + this.updateSpectrumFileName(); + //获取文件保存路径 + String fileSavePath = this.getFileSaveRelativePath(); + final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); + StringBuilder finalPath = new StringBuilder(); + finalPath.append(properties.getRootPath()); + finalPath.append(File.separator); + finalPath.append(properties.getSaveFilePath()); + finalPath.append(File.separator); + finalPath.append(fileSavePath); + finalPath.append(File.separator); + finalPath.append(this.spectrumFile.getName()); + FileOperation.copyFile(this.spectrumFile,finalPath.toString(),true); + //设置能谱文件保存相对路径(包含文件名称) + this.spectrumFileRelativePath = fileSavePath+File.separator+this.spectrumFile.getName(); + } + + /** + * 获取文件保存相对路径 + * @return + */ + protected abstract String getFileSaveRelativePath(); /** * 对本地能谱临时文件进行改名 @@ -100,9 +118,9 @@ public abstract class SpectrumHandler extends Chain{ protected abstract void handlerOriginalData() throws Exception; /** - * 把流程日志写入ftp日志文件 + * 把流程日志保存到日志目录 */ - protected void saveLogToFtp() {}; + protected void saveLogToLogDir() throws IOException {}; /** * 打印当前能谱类型 @@ -127,7 +145,7 @@ public abstract class SpectrumHandler extends Chain{ localPath.append(File.separator); localPath.append(System.currentTimeMillis()+StringConstant.UNDER_LINE+RandomUtils.nextInt()); localPath.append(value.getSuffix()); - this.mailFile = FileUtil.writeString(this.mailContent, localPath.toString(), "UTF-8"); + this.spectrumFile = FileUtil.writeString(this.mailContent, localPath.toString(), "UTF-8"); // 能谱数据类型如果是 SPHDP 或者 SPHDF 统一改为 SAMPLEPHD if (value.equals(DataType.SPHDP) || value.equals(DataType.SPHDF)) { this.currDataType = DataType.SAMPLEPHD; @@ -146,19 +164,27 @@ public abstract class SpectrumHandler extends Chain{ } /** - * 处理解析失败的文件,上传到ftp->undeal目录 + * 处理解析失败的文件,上传到undeal目录 * @throws FileNotFoundException */ protected void handleParseingFailFile() throws FileNotFoundException { - this.ftpUtil.saveFile(spectrumServiceQuotes.getSpectrumPathProperties().getFailPath(),this.mailFile.getName(),new FileInputStream(this.mailFile)); + try { + //解析失败会把文件移动到undeal目录 + final String rootPath = spectrumServiceQuotes.getSpectrumPathProperties().getRootPath(); + final String undealPath = spectrumServiceQuotes.getSpectrumPathProperties().getUndealPath(); + final String finalPath = rootPath+File.separator+undealPath; + FileOperation.copyFile(spectrumFile,finalPath,true); + } catch (IOException ex) { + ex.printStackTrace(); + } } /** * 删除本地临时文件 */ protected void deleteLocalTemporaryFile(){ - if(Objects.nonNull(mailFile) && mailFile.isFile()){ - mailFile.delete(); + if(Objects.nonNull(spectrumFile) && spectrumFile.isFile() && spectrumFile.exists()){ + spectrumFile.delete(); } } } 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 a446ea2d..ca4f9f9d 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 @@ -1,6 +1,5 @@ package org.jeecg.modules.spectrum; -import cn.hutool.core.io.FileUtil; import org.apache.commons.lang3.StringUtils; import org.jeecg.common.constant.StringConstant; import org.jeecg.common.properties.SpectrumPathProperties; @@ -8,13 +7,10 @@ import org.jeecg.common.util.DateUtils; import org.jeecg.modules.base.entity.original.GardsAlertData; import org.jeecg.modules.base.enums.DataType; import org.jeecg.modules.exception.PHD_ReadException; +import org.jeecg.modules.file.FileOperation; import org.jeecg.modules.native_jni.EnergySpectrumHandler; 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.io.*; import java.time.LocalDate; import java.util.Date; import java.util.Objects; @@ -22,7 +18,7 @@ import java.util.Objects; /** * 警告谱处理 */ -public class AlertSpectrum extends SpectrumHandler{ +public class AlertSpectrum extends AbstractSpectrumHandler{ /** * 解析后的数据 @@ -44,9 +40,9 @@ public class AlertSpectrum extends SpectrumHandler{ */ @Override protected void setChina() { - SpectrumHandler spectrumHandler = new HealthStatusSpectrum(); - spectrumHandler.initNext(super.spectrumServiceQuotes,super.mailFile, - super.currDataType,super.ftpUtil,super.mailContent); + AbstractSpectrumHandler spectrumHandler = new HealthStatusSpectrum(); + spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile, + super.currDataType,super.mailContent); spectrumHandler.setPrevious(this); super.setNext(spectrumHandler); } @@ -64,14 +60,14 @@ public class AlertSpectrum extends SpectrumHandler{ super.printCurrDataType(); //解析邮件内容 this.parseingEmail(); - //保存PHD文件到ftp - this.saveFileToFtp(); + //保存PHD文件到savefile + super.saveFileToSavefile(); //结构体数据入库 this.handlerOriginalData(); //删除本地临时文件 super.deleteLocalTemporaryFile(); - //把流程日志写入ftp日志文件 - this.saveLogToFtp(); + //把流程日志保存到日志目录 + this.saveLogToLogDir(); }else{ super.next.handler(); } @@ -82,50 +78,36 @@ public class AlertSpectrum extends SpectrumHandler{ */ @Override protected void parseingEmail() throws Exception { - final AlertSpectrumStruct sourceData = EnergySpectrumHandler.getAlertSourceData(mailFile.getAbsolutePath()); + final AlertSpectrumStruct sourceData = EnergySpectrumHandler.getAlertSourceData(super.spectrumFile.getAbsolutePath()); if(Objects.isNull(sourceData)){ - throw new PHD_ReadException("THE PHDFile has some blocks can't be read:"+this.mailFile.getAbsolutePath()); + throw new PHD_ReadException("THE PHDFile has some blocks can't be read:"+super.spectrumFile.getAbsolutePath()); } this.sourceData = sourceData; } /** - * 保存能谱文件到ftp - */ - @Override - protected void saveFileToFtp() throws FileNotFoundException { - this.updateSpectrumFileName(); - //获取文件保存路径 - String fileSavePath = this.getFileSavePath(); - final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); - super.ftpUtil.saveFile(properties.getRootPath()+StringConstant.SLASH+fileSavePath,this.mailFile.getName(),new FileInputStream(this.mailFile)); - //设置FTP文件保存路径 - super.ftpSavePath = fileSavePath+StringConstant.SLASH+this.mailFile.getName(); - } - - /** - * 获取文件保存路径 + * 获取文件保存相对路径 * @return */ - private String getFileSavePath(){ - //处理此文件需要保存到ftp服务的路径 + @Override + protected String getFileSaveRelativePath(){ final int year = LocalDate.now().getYear(); final int month = LocalDate.now().getMonth().getValue(); - final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); - StringBuilder ftpPath = new StringBuilder(); - ftpPath.append(properties.getFilePathMap().get(super.currDataType.getType())); - ftpPath.append(StringConstant.SLASH); - ftpPath.append(year); - ftpPath.append(StringConstant.SLASH); - ftpPath.append(month>=10?month:"0"+month); - return ftpPath.toString(); + final SpectrumPathProperties properties = super.spectrumServiceQuotes.getSpectrumPathProperties(); + StringBuilder relativePath = new StringBuilder(); + relativePath.append(properties.getFilePathMap().get(super.currDataType.getType())); + relativePath.append(File.separator); + relativePath.append(year); + relativePath.append(File.separator); + relativePath.append(month>=10?month:"0"+month); + return relativePath.toString(); } /** * 对本地能谱临时文件进行改名 */ @Override - protected void updateSpectrumFileName() { + protected void updateSpectrumFileName() throws FileNotFoundException { StringBuilder newFileName = new StringBuilder(); newFileName.append(this.sourceData.station_code); newFileName.append(StringConstant.UNDER_LINE); @@ -135,7 +117,10 @@ public class AlertSpectrum extends SpectrumHandler{ newFileName.append(StringConstant.UNDER_LINE); newFileName.append(StringUtils.replace(this.sourceData.time,":","")); newFileName.append(super.currDataType.getSuffix()); - mailFile = FileUtil.rename(mailFile,newFileName.toString(),true); + if(!super.spectrumFile.exists()){ + throw new FileNotFoundException(super.spectrumFile.getAbsolutePath()+" does not exist"); + } + super.spectrumFile = FileOperation.rename(super.spectrumFile,newFileName.toString(),true); } /** @@ -144,26 +129,27 @@ public class AlertSpectrum extends SpectrumHandler{ @Override protected void handlerOriginalData() throws Exception { this.startIntoDatabaseTime = new Date(); - this.alertData = spectrumServiceQuotes.getAlertSpectrumService().create(this.sourceData, super.ftpSavePath); + this.alertData = super.spectrumServiceQuotes.getAlertSpectrumService().create(this.sourceData, super.spectrumFileRelativePath); this.endIntoDatabaseTime = new Date(); } /** - * 把流程日志写入ftp日志文件 + * 把流程日志保存到日志目录 */ @Override - protected void saveLogToFtp() { + protected void saveLogToLogDir() throws IOException { //组装日志文件内容 StringBuilder logContent = new StringBuilder(); logContent.append("-------------------------- Write Data into Database at ").append(DateUtils.formatDate(this.startIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" ---------------------------"); logContent.append(System.lineSeparator()).append(System.lineSeparator()); - logContent.append("ALERT ID: ").append(this.alertData.getAlertId()).append(" StandardFile:").append(spectrumServiceQuotes.getFtpProperties().getFtpRootPath()).append(StringConstant.SLASH).append(super.ftpSavePath); + logContent.append("ALERT ID: ").append(this.alertData.getAlertId()).append(" StandardFile:").append(super.spectrumServiceQuotes.getSpectrumPathProperties().getRootPath()).append(StringConstant.SLASH).append(super.spectrumFileRelativePath); logContent.append(System.lineSeparator()).append(System.lineSeparator()); logContent.append("------------------- ").append("Write Data into Database Successfully at ").append(DateUtils.formatDate(this.endIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" --------------------"); - //保存日志文件到ftp - final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); - final String ftpPath = properties.getLogPath()+StringConstant.SLASH+this.getFileSavePath(); - final String fileName = super.mailFile.getName().replace(this.currDataType.getSuffix(),LOG_FILE_SUFFIX); - super.ftpUtil.saveFile(ftpPath,fileName,new ByteArrayInputStream(logContent.toString().getBytes(StandardCharsets.UTF_8))); + + final SpectrumPathProperties properties = super.spectrumServiceQuotes.getSpectrumPathProperties(); + final String dirPath = properties.getLogPath()+File.separator+this.getFileSaveRelativePath(); + final String fileName = super.spectrumFile.getName().replace(this.currDataType.getSuffix(),LOG_FILE_SUFFIX); + final String finalPath = dirPath+File.separator+fileName; + FileOperation.saveOrAppendFile(finalPath,logContent.toString(),true); } } 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 ed602929..e0309048 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 @@ -1,6 +1,5 @@ package org.jeecg.modules.spectrum; - import org.jeecg.modules.base.enums.DataType; import org.jeecg.modules.base.enums.SampleStatus; import java.util.Objects; @@ -8,16 +7,16 @@ import java.util.Objects; /** * 探测器本地谱处理 */ -public class DetbkphdSpectrum extends S_D_Q_G_SpectrumHandler{ +public class DetbkphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler { /** * 设置过滤链路 */ @Override protected void setChina() { - SpectrumHandler spectrumHandler = new QcphdSpectrum(); - spectrumHandler.initNext(super.spectrumServiceQuotes,super.mailFile, - super.currDataType,super.ftpUtil,super.mailContent); + AbstractSpectrumHandler spectrumHandler = new QcphdSpectrum(); + spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile, + super.currDataType,super.mailContent); spectrumHandler.setPrevious(this); super.setNext(spectrumHandler); } @@ -39,20 +38,19 @@ public class DetbkphdSpectrum extends S_D_Q_G_SpectrumHandler{ super.parseingEmail(); //读取邮件内容标签 super.readFileLabel(); - //保存PHD文件到ftp - super.saveFileToFtp(); + //保存PHD文件到savefile + super.saveFileToSavefile(); //结构体数据入库 super.handlerOriginalData(); //修改状态为解析完成 super.status = SampleStatus.COMPLETE.getValue(); super.updateStatus(); }catch (Exception e){ - e.printStackTrace(); //修改状态为解析失败 super.status = SampleStatus.FAIL.getValue(); super.updateStatus(); - //处理解析失败的文件,上传到ftp->undeal目录 + //处理解析失败的文件,上传到undeal目录 super.handleParseingFailFile(); throw e; }finally { 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 dead1cee..fa8f2d51 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 @@ -9,16 +9,16 @@ import java.util.Objects; * 气体谱处理 */ @Slf4j -public class GasbkphdSpectrum extends S_D_Q_G_SpectrumHandler{ +public class GasbkphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler { /** * 设置过滤链路 */ @Override protected void setChina() { - SpectrumHandler spectrumHandler = new MetSpectrum(); - spectrumHandler.initNext(super.spectrumServiceQuotes,super.mailFile, - super.currDataType,super.ftpUtil,super.mailContent); + AbstractSpectrumHandler spectrumHandler = new MetSpectrum(); + spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile, + super.currDataType,super.mailContent); spectrumHandler.setPrevious(this); super.setNext(spectrumHandler); } @@ -40,20 +40,19 @@ public class GasbkphdSpectrum extends S_D_Q_G_SpectrumHandler{ super.parseingEmail(); //读取邮件内容标签 super.readFileLabel(); - //保存PHD文件到ftp - super.saveFileToFtp(); + //保存PHD文件到savefile + super.saveFileToSavefile(); //结构体数据入库 super.handlerOriginalData(); //修改状态为解析完成 super.status = SampleStatus.COMPLETE.getValue(); super.updateStatus(); }catch (Exception e){ - e.printStackTrace(); //修改状态为解析失败 super.status = SampleStatus.FAIL.getValue(); super.updateStatus(); - //处理解析失败的文件,上传到ftp->undeal目录 + //处理解析失败的文件,上传到undeal目录 super.handleParseingFailFile(); throw e; }finally { 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 0c9f2360..6fd91c7f 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 @@ -9,13 +9,12 @@ import org.jeecg.modules.base.entity.original.GardsSohData; import org.jeecg.modules.base.enums.DataType; import org.jeecg.modules.exception.AirSamplerFlowException; import org.jeecg.modules.exception.PHD_ReadException; +import org.jeecg.modules.file.FileOperation; import org.jeecg.modules.native_jni.EnergySpectrumHandler; import org.jeecg.modules.native_jni.struct.SOHSpectrumStruct; import org.springframework.util.CollectionUtils; -import java.io.ByteArrayInputStream; -import java.io.FileInputStream; -import java.io.FileNotFoundException; +import java.io.*; import java.nio.charset.StandardCharsets; import java.time.LocalDate; import java.util.Date; @@ -25,7 +24,7 @@ import java.util.Objects; /** * 健康状态谱处理 */ -public class HealthStatusSpectrum extends SpectrumHandler{ +public class HealthStatusSpectrum extends AbstractSpectrumHandler{ /** * 解析后的数据 @@ -50,7 +49,7 @@ public class HealthStatusSpectrum extends SpectrumHandler{ } protected void checkAirSamplerFlowBlock(){ - if(this.mailContent.indexOf("#AirSamplerFlow") == -1){ + if(super.mailContent.indexOf("#AirSamplerFlow") == -1){ throw new AirSamplerFlowException("this is no ariSamplerFlow data"); } } @@ -65,14 +64,14 @@ public class HealthStatusSpectrum extends SpectrumHandler{ super.printCurrDataType(); //解析邮件内容 this.parseingEmail(); - //保存PHD文件到ftp - this.saveFileToFtp(); + //保存PHD文件到savefile + super.saveFileToSavefile(); //结构体数据入库 this.handlerOriginalData(); //删除本地临时文件 super.deleteLocalTemporaryFile(); - //把流程日志写入ftp日志文件 - this.saveLogToFtp(); + //把流程日志保存到日志目录 + this.saveLogToLogDir(); } } @@ -81,9 +80,9 @@ public class HealthStatusSpectrum extends SpectrumHandler{ */ @Override protected void parseingEmail() throws Exception { - final SOHSpectrumStruct sourceData = EnergySpectrumHandler.getSOHSourceData(mailFile.getAbsolutePath()); + final SOHSpectrumStruct sourceData = EnergySpectrumHandler.getSOHSourceData(super.spectrumFile.getAbsolutePath()); if(Objects.isNull(sourceData)){ - throw new PHD_ReadException("THE PHDFile has some blocks can't be read:"+this.mailFile.getAbsolutePath()); + throw new PHD_ReadException("THE PHDFile has some blocks can't be read:"+super.spectrumFile.getAbsolutePath()); } if(sourceData.af_record_count <= 0 || sourceData.af_start_date.size() < 0 || sourceData.af_start_time.size() < 0){ throw new AirSamplerFlowException("ariSamplerFlow data error"); @@ -92,42 +91,28 @@ public class HealthStatusSpectrum extends SpectrumHandler{ } /** - * 保存能谱文件到ftp - */ - @Override - protected void saveFileToFtp() throws FileNotFoundException { - this.updateSpectrumFileName(); - //获取文件保存路径 - String fileSavePath = this.getFileSavePath(); - final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); - super.ftpUtil.saveFile(properties.getRootPath()+StringConstant.SLASH+fileSavePath,this.mailFile.getName(),new FileInputStream(this.mailFile)); - //设置FTP文件保存路径 - super.ftpSavePath = fileSavePath+StringConstant.SLASH+this.mailFile.getName(); - } - - /** - * 获取文件保存路径 + * 获取文件保存相对路径 * @return */ - private String getFileSavePath(){ - //处理此文件需要保存到ftp服务的路径 + @Override + protected String getFileSaveRelativePath(){ final int year = LocalDate.now().getYear(); final int month = LocalDate.now().getMonth().getValue(); - final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); - StringBuilder ftpPath = new StringBuilder(); - ftpPath.append(properties.getFilePathMap().get(super.currDataType.getType())); - ftpPath.append(StringConstant.SLASH); - ftpPath.append(year); - ftpPath.append(StringConstant.SLASH); - ftpPath.append(month>=10?month:"0"+month); - return ftpPath.toString(); + final SpectrumPathProperties properties = super.spectrumServiceQuotes.getSpectrumPathProperties(); + StringBuilder relativePath = new StringBuilder(); + relativePath.append(properties.getFilePathMap().get(super.currDataType.getType())); + relativePath.append(File.separator); + relativePath.append(year); + relativePath.append(File.separator); + relativePath.append(month>=10?month:"0"+month); + return relativePath.toString(); } /** * 对本地能谱临时文件进行改名 */ @Override - protected void updateSpectrumFileName() { + protected void updateSpectrumFileName() throws FileNotFoundException { StringBuilder newFileName = new StringBuilder(); newFileName.append(this.sourceData.station_code); newFileName.append(StringConstant.UNDER_LINE); @@ -137,7 +122,10 @@ public class HealthStatusSpectrum extends SpectrumHandler{ newFileName.append(StringConstant.UNDER_LINE); newFileName.append(StringUtils.replace(this.sourceData.start_time,":","")); newFileName.append(super.currDataType.getSuffix()); - mailFile = FileUtil.rename(mailFile,newFileName.toString(),true); + if(!super.spectrumFile.exists()){ + throw new FileNotFoundException(super.spectrumFile.getAbsolutePath()+" does not exist"); + } + super.spectrumFile = FileOperation.rename(super.spectrumFile,newFileName.toString(),true); } /** @@ -146,15 +134,15 @@ public class HealthStatusSpectrum extends SpectrumHandler{ @Override protected void handlerOriginalData() throws Exception { this.startIntoDatabaseTime = new Date(); - this.sohDatas = spectrumServiceQuotes.getSohSpectrumService().create(this.sourceData, super.ftpSavePath); + this.sohDatas = spectrumServiceQuotes.getSohSpectrumService().create(this.sourceData, super.spectrumFileRelativePath); this.endIntoDatabaseTime = new Date(); } /** - * 把流程日志写入ftp日志文件 + * 把流程日志保存到日志目录 */ @Override - protected void saveLogToFtp() { + protected void saveLogToLogDir() throws IOException { //获取健康谱记录ID范围 String sohIdRange = ""; if(!CollectionUtils.isEmpty(this.sohDatas)){ @@ -164,13 +152,14 @@ public class HealthStatusSpectrum extends SpectrumHandler{ StringBuilder logContent = new StringBuilder(); logContent.append("-------------------------- Write Data into Database at ").append(DateUtils.formatDate(this.startIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" ---------------------------"); logContent.append(System.lineSeparator()).append(System.lineSeparator()); - logContent.append("SOH ID: ").append(sohIdRange).append(" StandardFile:").append(spectrumServiceQuotes.getFtpProperties().getFtpRootPath()).append(StringConstant.SLASH).append(super.ftpSavePath); + logContent.append("SOH ID: ").append(sohIdRange).append(" StandardFile:").append(super.spectrumServiceQuotes.getSpectrumPathProperties().getRootPath()).append(StringConstant.SLASH).append(super.spectrumFileRelativePath); logContent.append(System.lineSeparator()).append(System.lineSeparator()); logContent.append("------------------- ").append("Write Data into Database Successfully at ").append(DateUtils.formatDate(this.endIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" --------------------"); - //保存日志文件到ftp + final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); - final String ftpPath = properties.getLogPath()+StringConstant.SLASH+this.getFileSavePath(); - final String fileName = super.mailFile.getName().replace(this.currDataType.getSuffix(),LOG_FILE_SUFFIX); - super.ftpUtil.saveFile(ftpPath,fileName,new ByteArrayInputStream(logContent.toString().getBytes(StandardCharsets.UTF_8))); + final String dirPath = properties.getLogPath()+File.separator+this.getFileSaveRelativePath(); + final String fileName = super.spectrumFile.getName().replace(this.currDataType.getSuffix(),LOG_FILE_SUFFIX); + final String finalPath = dirPath+ File.separator+fileName; + FileOperation.saveOrAppendFile(finalPath,logContent.toString(),true); } } 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 a77a1f3a..fe038c89 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 @@ -1,20 +1,16 @@ package org.jeecg.modules.spectrum; -import cn.hutool.core.io.FileUtil; import org.apache.commons.lang3.StringUtils; import org.jeecg.common.constant.StringConstant; import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.util.DateUtils; import org.jeecg.modules.base.entity.original.GardsMetData; import org.jeecg.modules.base.enums.DataType; +import org.jeecg.modules.file.FileOperation; import org.jeecg.modules.native_jni.EnergySpectrumHandler; import org.jeecg.modules.native_jni.struct.MetSpectrumStruct; import org.springframework.util.CollectionUtils; - -import java.io.ByteArrayInputStream; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.nio.charset.StandardCharsets; +import java.io.*; import java.time.LocalDate; import java.util.Date; import java.util.List; @@ -23,7 +19,7 @@ import java.util.Objects; /** * 气象谱处理 */ -public class MetSpectrum extends SpectrumHandler{ +public class MetSpectrum extends AbstractSpectrumHandler{ /** * 解析后的数据 @@ -45,9 +41,9 @@ public class MetSpectrum extends SpectrumHandler{ */ @Override protected void setChina() { - SpectrumHandler spectrumHandler = new AlertSpectrum(); - spectrumHandler.initNext(super.spectrumServiceQuotes,super.mailFile, - super.currDataType,super.ftpUtil,super.mailContent); + AbstractSpectrumHandler spectrumHandler = new AlertSpectrum(); + spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile, + super.currDataType,super.mailContent); spectrumHandler.setPrevious(this); super.setNext(spectrumHandler); } @@ -62,14 +58,14 @@ public class MetSpectrum extends SpectrumHandler{ super.printCurrDataType(); //解析邮件内容 this.parseingEmail(); - //保存PHD文件到ftp - this.saveFileToFtp(); + //保存PHD文件到savefile + super.saveFileToSavefile(); //结构体数据入库 this.handlerOriginalData(); //删除本地临时文件 super.deleteLocalTemporaryFile(); - //把流程日志写入ftp日志文件 - this.saveLogToFtp(); + //把流程日志保存到日志目录 + this.saveLogToLogDir(); }else{ super.next.handler(); } @@ -80,50 +76,36 @@ public class MetSpectrum extends SpectrumHandler{ */ @Override protected void parseingEmail() throws Exception{ - final MetSpectrumStruct sourceData = EnergySpectrumHandler.getMetSourceData(mailFile.getAbsolutePath()); + final MetSpectrumStruct sourceData = EnergySpectrumHandler.getMetSourceData(super.spectrumFile.getAbsolutePath()); if(Objects.isNull(sourceData)){ - throw new RuntimeException("THE PHDFile has some blocks can't be read:"+this.mailFile.getAbsolutePath()); + throw new RuntimeException("THE PHDFile has some blocks can't be read:"+super.spectrumFile.getAbsolutePath()); } this.sourceData = sourceData; } /** - * 保存能谱文件到ftp - */ - @Override - protected void saveFileToFtp() throws FileNotFoundException { - this.updateSpectrumFileName(); - //获取文件保存路径 - String fileSavePath = this.getFileSavePath(); - final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); - super.ftpUtil.saveFile(properties.getRootPath()+StringConstant.SLASH+fileSavePath,this.mailFile.getName(),new FileInputStream(this.mailFile)); - //设置FTP文件保存路径 - super.ftpSavePath = fileSavePath+StringConstant.SLASH+this.mailFile.getName(); - } - - /** - * 获取文件保存路径 + * 获取文件保存相对路径 * @return */ - private String getFileSavePath(){ - //处理此文件需要保存到ftp服务的路径 + @Override + protected String getFileSaveRelativePath(){ final int year = LocalDate.now().getYear(); final int month = LocalDate.now().getMonth().getValue(); - final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); - StringBuilder ftpPath = new StringBuilder(); - ftpPath.append(properties.getFilePathMap().get(super.currDataType.getType())); - ftpPath.append(StringConstant.SLASH); - ftpPath.append(year); - ftpPath.append(StringConstant.SLASH); - ftpPath.append(month>=10?month:"0"+month); - return ftpPath.toString(); + final SpectrumPathProperties properties = super.spectrumServiceQuotes.getSpectrumPathProperties(); + StringBuilder relativePath = new StringBuilder(); + relativePath.append(properties.getFilePathMap().get(super.currDataType.getType())); + relativePath.append(File.separator); + relativePath.append(year); + relativePath.append(File.separator); + relativePath.append(month>=10?month:"0"+month); + return relativePath.toString(); } /** * 对本地能谱临时文件进行改名 */ @Override - protected void updateSpectrumFileName() { + protected void updateSpectrumFileName() throws FileNotFoundException { StringBuilder newFileName = new StringBuilder(); newFileName.append(this.sourceData.station_code); newFileName.append(StringConstant.UNDER_LINE); @@ -133,7 +115,10 @@ public class MetSpectrum extends SpectrumHandler{ newFileName.append(StringConstant.UNDER_LINE); newFileName.append(StringUtils.replace(this.sourceData.met_start_time.get(0),":","")); newFileName.append(super.currDataType.getSuffix()); - mailFile = FileUtil.rename(mailFile,newFileName.toString(),true); + if(!super.spectrumFile.exists()){ + throw new FileNotFoundException(super.spectrumFile.getAbsolutePath()+" does not exist"); + } + super.spectrumFile = FileOperation.rename(super.spectrumFile,newFileName.toString(),true); } /** @@ -142,15 +127,15 @@ public class MetSpectrum extends SpectrumHandler{ @Override protected void handlerOriginalData() throws Exception { this.startIntoDatabaseTime = new Date(); - spectrumServiceQuotes.getMetSpectrumService().create(this.sourceData,super.ftpSavePath); + spectrumServiceQuotes.getMetSpectrumService().create(this.sourceData,super.spectrumFileRelativePath); this.endIntoDatabaseTime = new Date(); } /** - * 把流程日志写入ftp日志文件 + * 把流程日志保存到日志目录 */ @Override - protected void saveLogToFtp() { + protected void saveLogToLogDir() throws IOException { //获取气象记录ID范围 String metIdRange = ""; if(!CollectionUtils.isEmpty(this.metDatas)){ @@ -160,13 +145,14 @@ public class MetSpectrum extends SpectrumHandler{ StringBuilder logContent = new StringBuilder(); logContent.append("-------------------------- Write Data into Database at ").append(DateUtils.formatDate(this.startIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" ---------------------------"); logContent.append(System.lineSeparator()).append(System.lineSeparator()); - logContent.append("Met ID: ").append(metIdRange).append(" StandardFile:").append(spectrumServiceQuotes.getFtpProperties().getFtpRootPath()).append(StringConstant.SLASH).append(super.ftpSavePath); + logContent.append("Met ID: ").append(metIdRange).append(" StandardFile:").append(super.spectrumServiceQuotes.getSpectrumPathProperties().getRootPath()).append(StringConstant.SLASH).append(super.spectrumFileRelativePath); logContent.append(System.lineSeparator()).append(System.lineSeparator()); logContent.append("------------------- ").append("Write Data into Database Successfully at ").append(DateUtils.formatDate(this.endIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" --------------------"); - //保存日志文件到ftp + final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); - final String ftpPath = properties.getLogPath()+StringConstant.SLASH+this.getFileSavePath(); - final String fileName = super.mailFile.getName().replace(this.currDataType.getSuffix(),LOG_FILE_SUFFIX); - super.ftpUtil.saveFile(ftpPath,fileName,new ByteArrayInputStream(logContent.toString().getBytes(StandardCharsets.UTF_8))); + final String dirPath = properties.getLogPath()+File.separator+this.getFileSaveRelativePath(); + final String fileName = super.spectrumFile.getName().replace(this.currDataType.getSuffix(),LOG_FILE_SUFFIX); + final String finalPath = dirPath+File.separator+fileName; + FileOperation.saveOrAppendFile(finalPath,logContent.toString(),true); } } 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 51c9bfdc..15d06b7c 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 @@ -6,11 +6,12 @@ import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.util.DateUtils; import org.jeecg.modules.base.enums.DataType; import org.jeecg.modules.base.enums.SystemType; +import org.jeecg.modules.file.FileOperation; import org.jeecg.modules.native_jni.struct.BgAnalyseResult; import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct; -import org.jeecg.modules.service.BlockConstant; -import java.io.ByteArrayInputStream; -import java.nio.charset.StandardCharsets; + +import java.io.File; +import java.io.IOException; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -52,7 +53,7 @@ public class ParsingProcessLog extends AbstractAutoLogOrReport{ * 能谱处理父类 */ @Setter - private S_D_Q_G_SpectrumHandler spectrumHandler; + private AbstractS_D_Q_G_SpectrumHandler spectrumHandler; /** * 能谱分析类 */ @@ -93,14 +94,14 @@ public class ParsingProcessLog extends AbstractAutoLogOrReport{ final String oraUsername = spectrumHandler.spectrumServiceQuotes.getOraDataSourceProperties().getUsername(); final String oraUrl = spectrumHandler.spectrumServiceQuotes.getOraDataSourceProperties().getUrl(); final String startIntoDatabaseTime = DateUtils.formatDate(spectrumHandler.startIntoDatabaseTime, "yyyy-MM-dd HH:mm:ss"); - final String standardFile = spectrumHandler.spectrumServiceQuotes.getFtpProperties().getFtpRootPath() + StringConstant.SLASH + spectrumHandler.ftpSavePath; + final String standardFile = spectrumHandler.spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + StringConstant.SLASH + spectrumHandler.spectrumFileRelativePath; storageLog.append(titleFormat(WRITE_INTO_START,26, StringConstant.DASH,startIntoDatabaseTime,StringConstant.DASH)); storageLog.append(System.lineSeparator()).append(System.lineSeparator()); storageLog.append(rowFormat(APPLICATION_PATH,spectrumHandler.getProjectAbsolutePath(),spectrumHandler.getProjectName(),startIntoDatabaseTime)); storageLog.append(System.lineSeparator()).append(System.lineSeparator()); storageLog.append(rowFormat(DATABASE_CONNECTED,oraUrl.substring(oraUrl.lastIndexOf(":")+1),oraUsername)); storageLog.append(System.lineSeparator()).append(System.lineSeparator()); - storageLog.append(rowFormat(SOURCE_FILE,spectrumHandler.mailFile.getAbsolutePath())); + storageLog.append(rowFormat(SOURCE_FILE,spectrumHandler.spectrumFile.getAbsolutePath())); storageLog.append(System.lineSeparator()); storageLog.append(rowFormat(STANDARD_FILE,standardFile)); storageLog.append(System.lineSeparator()).append(System.lineSeparator()); @@ -116,7 +117,7 @@ public class ParsingProcessLog extends AbstractAutoLogOrReport{ */ private void endOfFileRepeat(){ final String endIntoDatabaseTime = DateUtils.formatDate(spectrumHandler.endIntoDatabaseTime, "yyyy-MM-dd HH:mm:ss"); - storageLog.append(rowFormat(FILE_REPEAT,spectrumHandler.ftpSavePath)); + storageLog.append(rowFormat(FILE_REPEAT,spectrumHandler.spectrumFileRelativePath)); storageLog.append(System.lineSeparator()).append(System.lineSeparator()); storageLog.append(titleFormat(WRITE_INTO_ERROR,19,StringConstant.DASH,endIntoDatabaseTime,StringConstant.DASH)); storageLog.append(System.lineSeparator()).append(System.lineSeparator()).append(System.lineSeparator()); @@ -761,7 +762,7 @@ public class ParsingProcessLog extends AbstractAutoLogOrReport{ /** * 处理所有日志 */ - protected void handleLog(){ + protected void handleLog() throws IOException { this.handleStorageProcessLog(); if(DataType.SAMPLEPHD.getType().equals(this.spectrumHandler.currDataType.getType()) && this.spectrumHandler.sourceData.system_type.equals(SystemType.BETA.getType()) && @@ -772,18 +773,24 @@ public class ParsingProcessLog extends AbstractAutoLogOrReport{ if(Objects.nonNull(this.analysisLog)){ this.storageLog.append(this.analysisLog); } - this.saveLogToFTP(this.storageLog.toString()); + this.saveLog(this.storageLog.toString()); } /** - * 保存日志到ftp + * 保存日志到log目录 */ - private void saveLogToFTP(String log){ - //保存日志文件到ftp + private void saveLog(String log) throws IOException { + //保存日志到指定目录文件 final SpectrumPathProperties properties = spectrumHandler.spectrumServiceQuotes.getSpectrumPathProperties(); - String logFilePath = properties.getLogPath()+StringConstant.SLASH+spectrumHandler.getFileSavePath(); - String logFileName = spectrumHandler.mailFile.getName().replace(DataType.SAMPLEPHD.getSuffix(),SpectrumHandler.LOG_FILE_SUFFIX); - - spectrumHandler.ftpUtil.saveOrAppendFile(logFilePath,logFileName,new ByteArrayInputStream(log.getBytes(StandardCharsets.UTF_8))); + final String logFileName = spectrumHandler.spectrumFile.getName().replace(DataType.SAMPLEPHD.getSuffix(),AbstractSpectrumHandler.LOG_FILE_SUFFIX); + StringBuilder finalLogPath = new StringBuilder(); + finalLogPath.append(properties.getRootPath()); + finalLogPath.append(File.separator); + finalLogPath.append(properties.getLogPath()); + finalLogPath.append(File.separator); + finalLogPath.append(spectrumHandler.getFileSaveRelativePath()); + finalLogPath.append(File.separator); + finalLogPath.append(logFileName); + FileOperation.saveOrAppendFile(finalLogPath.toString(),log,true); } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/QcphdSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/QcphdSpectrum.java index 4afdfae8..85b826d0 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/QcphdSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/QcphdSpectrum.java @@ -7,16 +7,16 @@ import java.util.Objects; /** * QC谱处理 */ -public class QcphdSpectrum extends S_D_Q_G_SpectrumHandler{ +public class QcphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler { /** * 设置过滤链路 */ @Override protected void setChina() { - SpectrumHandler spectrumHandler = new GasbkphdSpectrum(); - spectrumHandler.initNext(super.spectrumServiceQuotes,super.mailFile, - super.currDataType,super.ftpUtil,super.mailContent); + AbstractSpectrumHandler spectrumHandler = new GasbkphdSpectrum(); + spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile, + super.currDataType,super.mailContent); spectrumHandler.setPrevious(this); super.setNext(spectrumHandler); } @@ -39,20 +39,19 @@ public class QcphdSpectrum extends S_D_Q_G_SpectrumHandler{ super.parseingEmail(); //读取邮件内容标签 super.readFileLabel(); - //保存PHD文件到ftp - super.saveFileToFtp(); + //保存PHD文件到savefile + super.saveFileToSavefile(); //结构体数据入库 super.handlerOriginalData(); //修改状态为解析完成 super.status = SampleStatus.COMPLETE.getValue(); super.updateStatus(); }catch (Exception e){ - e.printStackTrace(); //修改状态为解析失败 super.status = SampleStatus.FAIL.getValue(); super.updateStatus(); - //处理解析失败的文件,上传到ftp->undeal目录 + //处理解析失败的文件,上传到undeal目录 super.handleParseingFailFile(); throw e; }finally { diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_B_Analysis.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_B_Analysis.java index 6705e742..43c72571 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_B_Analysis.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_B_Analysis.java @@ -13,14 +13,13 @@ import org.jeecg.modules.base.enums.*; import org.jeecg.modules.config.datasource.DataSourceSwitcher; import org.jeecg.modules.exception.BAnalyseException; import org.jeecg.modules.exception.FileNotExistException; -import org.jeecg.modules.ftp.FTPUtils; +import org.jeecg.modules.file.FileOperation; import org.jeecg.modules.native_jni.EnergySpectrumHandler; import org.jeecg.modules.native_jni.struct.BgAnalyseResult; import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct; import org.jeecg.modules.service.BlockConstant; import org.springframework.transaction.TransactionStatus; import java.io.*; -import java.nio.charset.StandardCharsets; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; @@ -69,16 +68,16 @@ public class Sample_B_Analysis implements BlockConstant { /** * det谱PHD文件临时路径 */ - private String detTempFilePath; + private String detFileFinalPath; /** * gas谱PHD文件临时路径 */ - private String gasTempFilePath; + private String gasFileFinalPath; /** - * SamplephdSpectrum类->saveFileToFtp()构造的能谱文件ftp保存路径 + * SamplephdSpectrum类->saveFileToSavefile()构造的能谱文件保存路径 * 可根据此路径构造log和arr保存路径 */ - protected String ftpSavePath; + protected String spectrumFileRelativePath; /** * SamplephdSpectrum类->updateSpectrumFileName()构造的能谱文件名称 可根据此路径构造log和arr文件名称 */ @@ -103,10 +102,6 @@ public class Sample_B_Analysis implements BlockConstant { * spring bean引用 */ private SpectrumServiceQuotes spectrumServiceQuotes; - /** - * ftp工具 - */ - private FTPUtils ftpUtil; /** * 分析结果 */ @@ -132,15 +127,14 @@ public class Sample_B_Analysis implements BlockConstant { public Sample_B_Analysis() { } - public Sample_B_Analysis(S_D_Q_G_SpectrumHandler spectrumHandler){ + public Sample_B_Analysis(AbstractS_D_Q_G_SpectrumHandler spectrumHandler){ this.sampleData = spectrumHandler.sampleData; - this.sampleTempFilePath = spectrumHandler.mailFile.getAbsolutePath(); + this.sampleTempFilePath = spectrumHandler.spectrumFile.getAbsolutePath(); this.spectrumServiceQuotes = spectrumHandler.spectrumServiceQuotes; this.sampleStruct = spectrumHandler.sourceData; - this.ftpUtil = spectrumHandler.ftpUtil; this.parsingProcessLog = spectrumHandler.parsingProcessLog; - this.ftpSavePath = spectrumHandler.getFileSavePath(); - this.phdFileName = spectrumHandler.mailFile.getName(); + this.spectrumFileRelativePath = spectrumHandler.getFileSaveRelativePath(); + this.phdFileName = spectrumHandler.spectrumFile.getName(); } @@ -158,8 +152,8 @@ public class Sample_B_Analysis implements BlockConstant { this.queryPHDFile(); //构造报告文件存储路径及文件名称、日志文件存储路径及文件名称 this.structureLogAndArrFilePath(); - //下载det和gas谱PHD文件,sample谱PHD文件位置在构造函数已经传过来 - this.downloadPHDFile(); + //查找det和gas谱PHD文件,sample谱PHD文件位置在构造函数已经传过来 + this.getPHDFile(); //传入sample、det和gas谱PHD文件调用dll进行分析 this.autoAnalyse(); //存储数据 @@ -179,8 +173,6 @@ public class Sample_B_Analysis implements BlockConstant { if(!analyseFail && Objects.nonNull(this.analyses)){ spectrumServiceQuotes.getAnalysesService().updateAnalysesEndTime(this.analyses.getIdAnalysis(),this.endAnalysisTime); } - //删除下载的det和gas临时文件 - this.deleteLocalTemporaryFile(); } } @@ -208,58 +200,48 @@ public class Sample_B_Analysis implements BlockConstant { private void structureLogAndArrFilePath(){ final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); //构造报告文件路径 - StringBuilder ftpPath = new StringBuilder(); - ftpPath.append(properties.getArrPath()); - ftpPath.append(StringConstant.SLASH); - ftpPath.append(this.ftpSavePath); - this.arrFilePath = ftpPath.toString(); + StringBuilder relativePath = new StringBuilder(); + relativePath.append(properties.getSaveFilePath()); + relativePath.append(File.separator); + relativePath.append(properties.getArrPath()); + relativePath.append(File.separator); + relativePath.append(this.spectrumFileRelativePath); + this.arrFilePath = relativePath.toString(); String arrFileTail = ARR_FILE_NAME_TAIL+ARR_FILE_SUFFIX; this.arrFileName = this.phdFileName.replace(DataType.SAMPLEPHD.getSuffix(),arrFileTail); //构造日志文件路径,不包括log前缀 - this.logFilePath = this.ftpSavePath; - this.logFileName = this.phdFileName.replace(DataType.SAMPLEPHD.getSuffix(),SpectrumHandler.LOG_FILE_SUFFIX); + this.logFilePath = this.spectrumFileRelativePath; + this.logFileName = this.phdFileName.replace(DataType.SAMPLEPHD.getSuffix(),AbstractSpectrumHandler.LOG_FILE_SUFFIX); } /** * 调用dll库的分析B谱结果 */ private void autoAnalyse() throws BAnalyseException, FileNotExistException { - BgAnalyseResult analyseResult = EnergySpectrumHandler.bgAnalyse(this.sampleTempFilePath,this.gasTempFilePath,this.detTempFilePath); + BgAnalyseResult analyseResult = EnergySpectrumHandler.bgAnalyse(this.sampleTempFilePath,this.gasFileFinalPath,this.detFileFinalPath); System.out.println(analyseResult); if(Objects.isNull(analyseResult) || !analyseResult.analyse_flag){ - throw new BAnalyseException("THE PHD file cannot be parsed:"+this.sampleTempFilePath+","+this.gasTempFilePath+","+this.detTempFilePath); + throw new BAnalyseException("THE PHD file cannot be parsed:"+this.sampleTempFilePath+","+this.gasFileFinalPath+","+this.detFileFinalPath); } this.analyseResult = analyseResult; } /** - * 下载det和gas谱PHD文件,sample谱PHD文件位置在构造函数已经传过来 + * 获取det和gas谱PHD文件,sample谱PHD文件位置在构造函数已经传过来 * @throws IOException */ - private void downloadPHDFile() throws IOException, FileNotExistException { + private void getPHDFile() throws IOException, FileNotExistException { boolean flag = false; - //下载gas谱PHD文件到本地临时路径 - String gasFileName = gasSampleData.getInputFileName().substring(gasSampleData.getInputFileName().lastIndexOf(StringConstant.SLASH) + 1); - String gasFileFTPPath = this.spectrumServiceQuotes.getSpectrumPathProperties().getRootPath()+StringConstant.SLASH+gasSampleData.getInputFileName().substring(0, gasSampleData.getInputFileName().lastIndexOf(StringConstant.SLASH)); - boolean gasFlag = ftpUtil.downloadFTPFile(gasFileFTPPath,gasFileName,this.spectrumServiceQuotes.getTaskProperties().getTemporaryStoragePath()); - if(!gasFlag){ - flag = true; - } - gasTempFilePath = this.spectrumServiceQuotes.getTaskProperties().getTemporaryStoragePath()+File.separator+gasFileName; - File gasFile = new File(gasTempFilePath); + //gas谱PHD文件本地路径 + this.gasFileFinalPath = this.spectrumServiceQuotes.getSpectrumPathProperties().getRootPath()+File.separator+this.spectrumServiceQuotes.getSpectrumPathProperties().getSaveFilePath()+File.separator+gasSampleData.getInputFileName(); + File gasFile = new File(this.gasFileFinalPath); if(!gasFile.exists()){ flag = true; } - //下载det谱PHD文件到本地临时路径 - final String detFileName = detSampleData.getInputFileName().substring(detSampleData.getInputFileName().lastIndexOf(StringConstant.SLASH) + 1); - String detFileFTPPath = this.spectrumServiceQuotes.getSpectrumPathProperties().getRootPath()+StringConstant.SLASH+detSampleData.getInputFileName().substring(0, detSampleData.getInputFileName().lastIndexOf(StringConstant.SLASH)); - boolean detFlag = ftpUtil.downloadFTPFile(detFileFTPPath,detFileName,this.spectrumServiceQuotes.getTaskProperties().getTemporaryStoragePath()); - if(!detFlag){ - flag = true; - } - detTempFilePath = this.spectrumServiceQuotes.getTaskProperties().getTemporaryStoragePath()+ File.separator+detFileName; - File detFile = new File(detTempFilePath); + //det谱PHD文件本地路径 + this.detFileFinalPath = this.spectrumServiceQuotes.getSpectrumPathProperties().getRootPath()+File.separator+this.spectrumServiceQuotes.getSpectrumPathProperties().getSaveFilePath()+File.separator+detSampleData.getInputFileName(); + File detFile = new File(this.detFileFinalPath); if(!detFile.exists()){ flag = true; } @@ -268,8 +250,8 @@ public class Sample_B_Analysis implements BlockConstant { parsingProcessLog.setFileNotExist(true); throw new FileNotExistException("gas or det file is no exist or is error.."); } - this.detStruct = EnergySpectrumHandler.getSourceData(detTempFilePath); - this.gasStruct = EnergySpectrumHandler.getSourceData(gasTempFilePath); + this.detStruct = EnergySpectrumHandler.getSourceData(this.detFileFinalPath); + this.gasStruct = EnergySpectrumHandler.getSourceData(this.gasFileFinalPath); } /** @@ -323,24 +305,6 @@ public class Sample_B_Analysis implements BlockConstant { } } - /** - * 删除下载的det和gas临时文件 - */ - private void deleteLocalTemporaryFile(){ - if(StringUtils.isNotBlank(this.detTempFilePath)){ - File detFile = new File(this.detTempFilePath); - if(detFile.exists() && detFile.isFile()){ - detFile.delete(); - } - } - if(StringUtils.isNotBlank(this.gasTempFilePath)){ - File gasFile = new File(this.gasTempFilePath); - if(gasFile.exists() && gasFile.isFile()){ - gasFile.delete(); - } - } - } - /** * 分析成功数据发送到Redis */ @@ -412,8 +376,8 @@ public class Sample_B_Analysis implements BlockConstant { this.handleConcentrationAndLC(); //处理#RESULT SUMMARY 模块 this.handleResultSummary(); - //把报告存储到ftp - this.saveReportToFtp(); + //把报告存储到savefile->arr目录 + this.saveReportToSavefileArr(); } /** @@ -813,8 +777,14 @@ public class Sample_B_Analysis implements BlockConstant { /** * 保存报告到ftp */ - private void saveReportToFtp() throws FileNotFoundException { - ftpUtil.saveFile(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath()+StringConstant.SLASH+arrFilePath,arrFileName,new ByteArrayInputStream(reportContent.toString().getBytes(StandardCharsets.UTF_8))); + private void saveReportToSavefileArr() throws IOException { + StringBuilder finalReportPath = new StringBuilder(); + finalReportPath.append(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath()); + finalReportPath.append(File.separator); + finalReportPath.append(arrFilePath); + finalReportPath.append(File.separator); + finalReportPath.append(arrFileName); + FileOperation.saveOrAppendFile(finalReportPath.toString(),reportContent.toString(),false); } } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_G_Analysis.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_G_Analysis.java index 4f0c752d..ffbcab53 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_G_Analysis.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_G_Analysis.java @@ -18,6 +18,7 @@ import org.jeecg.common.constant.*; import org.jeecg.common.constant.enums.SpectrumSystemType; import org.jeecg.common.properties.ParameterProperties; import org.jeecg.common.properties.SpectrumPathProperties; +import org.jeecg.common.util.DateUtils; import org.jeecg.common.util.GammaFileUtil; import org.jeecg.common.util.RedisUtil; import org.jeecg.modules.base.bizVo.AttributeItemVo; @@ -28,15 +29,14 @@ import org.jeecg.modules.base.entity.rnauto.*; import org.jeecg.modules.base.enums.MiddleDataType; import org.jeecg.modules.config.datasource.DataSourceSwitcher; import org.jeecg.modules.entity.vo.*; -import org.jeecg.modules.ftp.FTPUtils; +import org.jeecg.modules.file.FileOperation; import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct; import org.jeecgframework.core.util.ApplicationContextUtil; -import org.springframework.beans.factory.annotation.Value; import org.springframework.transaction.TransactionStatus; - import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOException; import java.lang.reflect.Field; import java.util.*; @@ -44,980 +44,968 @@ import java.util.*; @Slf4j public class Sample_G_Analysis { - private final Map fieldMap = fieldMap(); + private final Map fieldMap = fieldMap(); - // Sample谱原始数据 - private GardsSampleData sampleData; + // Sample谱原始数据 + private GardsSampleData sampleData; - // 分析所需Service - private SpectrumServiceQuotes serviceQuotes; + // 分析所需Service + private SpectrumServiceQuotes serviceQuotes; - // Sample谱结构体数据 - private EnergySpectrumStruct energySpectrumStruct; + // Sample谱结构体数据 + private EnergySpectrumStruct energySpectrumStruct; - // 能谱文件存储路径属性 - private SpectrumPathProperties spectrumPathProperties; + // 能谱文件存储路径属性 + private SpectrumPathProperties spectrumPathProperties; - private ParameterProperties parameterProperties; + private ParameterProperties parameterProperties; - private RedisUtil redisUtil; + private RedisUtil redisUtil; - /** - * 系统类型 - */ - private String systemType; + /** + * 系统类型 + */ + private String systemType; - /** - * 数据类型 - */ - private String dataType; + /** + * 数据类型 + */ + private String dataType; - /** - * 样品谱地址 - */ - private String sampleInputFilename; + /** + * 样品谱地址 + */ + private String sampleInputFilename; - /** - * 样品谱名称 - */ - private String sampleFilename; + /** + * 样品谱名称 + */ + private String sampleFilename; - /** - * 日志文件路径 - */ - private String logFilePath; - /** - * 日志文件名称 - */ - private String logFileName; - /** - * 报告文件路径 - */ - private String arrFilePath; - /** - * 报告文件名称 - */ - private String arrFileName; + /** + * 日志文件路径 + */ + private String logFilePath; + /** + * 日志文件名称 + */ + private String logFileName; + /** + * 报告文件路径 + */ + private String arrFilePath; + /** + * 报告文件名称 + */ + private String arrFileName; - private FTPUtils ftpUtil; + public Sample_G_Analysis(EnergySpectrumStruct energySpectrumStruct,SpectrumServiceQuotes serviceQuotes, + GardsSampleData sampleData) { + this.sampleData = sampleData; + this.serviceQuotes = serviceQuotes; + this.energySpectrumStruct = energySpectrumStruct; + this.systemType = energySpectrumStruct.system_type; + this.dataType = energySpectrumStruct.data_type; + this.sampleInputFilename = sampleData.getInputFileName(); + this.sampleFilename = StringUtils.substring(sampleData.getInputFileName(), + sampleData.getInputFileName().lastIndexOf((StringConstant.SLASH)+1)); + } - public Sample_G_Analysis(EnergySpectrumStruct energySpectrumStruct,SpectrumServiceQuotes serviceQuotes, - GardsSampleData sampleData, FTPUtils ftpUtil) { - this.sampleData = sampleData; - this.serviceQuotes = serviceQuotes; - this.energySpectrumStruct = energySpectrumStruct; - this.systemType = energySpectrumStruct.system_type; - this.dataType = energySpectrumStruct.data_type; - this.sampleInputFilename = sampleData.getInputFileName(); - this.sampleFilename = StringUtils.substring(sampleData.getInputFileName(), - sampleData.getInputFileName().lastIndexOf((StringConstant.SLASH)+1)); - this.ftpUtil = ftpUtil; - } + public void analysis(){ + try { + /* 准备Gamma分析需要的数据 */ + GStoreMiddleProcessData middleData = new GStoreMiddleProcessData(); + Integer sampleId = sampleData.getSampleId(); - public void analysis(){ - try { - /* 准备Gamma分析需要的数据 */ - GStoreMiddleProcessData middleData = new GStoreMiddleProcessData(); - Integer sampleId = sampleData.getSampleId(); + GammaFileUtil gammaFileUtil = ApplicationContextUtil.getContext().getBean(GammaFileUtil.class); + parameterProperties = ApplicationContextUtil.getContext().getBean(ParameterProperties.class); + PHDFile phdFile = new PHDFile(); + phdFile.setXmlFilePath(parameterProperties.getFilePath()); + // 解析PHD文件 + spectrumPathProperties = ApplicationContextUtil.getContext().getBean(SpectrumPathProperties.class); + String sampleFilePath = sampleData.getInputFileName(); + String pathName = File.separator + spectrumPathProperties.getSaveFilePath() + File.separator + + sampleFilePath.substring(0, sampleFilePath.lastIndexOf(StringPool.SLASH)); + String fileName = sampleFilePath.substring(sampleFilePath.lastIndexOf(StringPool.SLASH)+1); + boolean flag = gammaFileUtil.loadFile(pathName, fileName, phdFile, new Result()); + // todo 测试阶段暂时注释掉,获取数据库 Gamma 默认参数 + getSettingFromDB(phdFile); + // 文件路径 + middleData.setAnalyses_save_filePath(this.sampleInputFilename); + // 读取文件内容并附值 + this.setPHDFile(phdFile, this.energySpectrumStruct); + phdFile.getSetting().setRefTime_act(DateUtils.parseDate(phdFile.getAcq().getAcquisition_start_date()+" "+phdFile.getAcq().getAcquisition_start_time())); + phdFile.getSetting().setRefTime_conc(DateUtils.parseDate(phdFile.getCollect().getCollection_start_date()+" "+phdFile.getCollect().getCollection_start_time())); + // todo 根据系统类型传入不同的核素参数 + Map nuclideLibs = new HashMap<>(); + if (this.systemType.equals(SpectrumSystemType.P.name())) { + nuclideLibs = this.getNuclideLinesP(); + } + if (this.systemType.equals(SpectrumSystemType.G.name())) { + nuclideLibs = this.getNuclideLinesG(); + } + gammaFileUtil.GetMiddleData(phdFile, CommonConstant.REPORT_PREFIX_AUTO, nuclideLibs, middleData, MiddleDataType.Auto.getType()); - GammaFileUtil gammaFileUtil = ApplicationContextUtil.getContext().getBean(GammaFileUtil.class); - parameterProperties = ApplicationContextUtil.getContext().getBean(ParameterProperties.class); - PHDFile phdFile = new PHDFile(); - phdFile.setXmlFilePath(parameterProperties.getFilePath()); - // 解析PHD文件 - spectrumPathProperties = ApplicationContextUtil.getContext().getBean(SpectrumPathProperties.class); - String sampleFilePath = sampleData.getInputFileName(); - String pathName = StringPool.SLASH + spectrumPathProperties.getRootPath() + StringPool.SLASH + sampleFilePath.substring(0, sampleFilePath.lastIndexOf(StringPool.SLASH)); - String fileName = sampleFilePath.substring(sampleFilePath.lastIndexOf(StringPool.SLASH)+1); - boolean flag = gammaFileUtil.loadFile(pathName, fileName, phdFile, new Result()); - // todo 测试阶段暂时注释掉,获取数据库 Gamma 默认参数 - getSettingFromDB(phdFile); - // 文件路径 - middleData.setAnalyses_save_filePath(this.sampleInputFilename); - // 读取文件内容并附值 - this.setPHDFile(phdFile, this.energySpectrumStruct); - // todo 根据系统类型传入不同的核素参数 - Map nuclideLibs = new HashMap<>(); - if (this.systemType.equals(SpectrumSystemType.P.name())) { - nuclideLibs = this.getNuclideLinesP(); - } - if (this.systemType.equals(SpectrumSystemType.G.name())) { - nuclideLibs = this.getNuclideLinesG(); - } - gammaFileUtil.GetMiddleData(phdFile, CommonConstant.REPORT_PREFIX_AUTO, nuclideLibs, middleData, MiddleDataType.Auto.getType()); + // 数据插入数据库 + this.storageDataToDatabase(middleData, phdFile.getQcItems()); - // 数据插入数据库 - this.storageDataToDatabase(middleData, phdFile.getQcItems()); + // 生成日志文件 + writeLog(middleData.getAnalyses_LogPath(), middleData); + // todo 报告文件 + String reportContent = gammaFileUtil.GetReportContent(middleData); + String reportPath = StringUtils.substringBeforeLast(middleData.getAnalyses_ReportPath(), StringPool.SLASH); + String reportName = StringUtils.substringAfterLast(middleData.getAnalyses_ReportPath(), StringPool.SLASH) + ".txt"; + String savePath = spectrumPathProperties.getRootPath() + File.separator + + spectrumPathProperties.getSaveFilePath() + File.separator + reportPath + + File.separator + reportName; + // 保存文件 + try { + FileOperation.saveOrAppendFile(savePath, reportContent, false); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + }catch (Exception e){ + e.printStackTrace(); - // 生成日志文件 - writeLog(middleData.getAnalyses_LogPath(), middleData); - // todo 报告文件 - String reportContent = gammaFileUtil.GetReportContent(phdFile, false); - String reportPath = StringUtils.substringBeforeLast(middleData.getAnalyses_ReportPath(), StringPool.SLASH); - String reportName = StringUtils.substringAfterLast(middleData.getAnalyses_ReportPath(), StringPool.SLASH) + ".txt"; - String savePath = StringPool.SLASH + spectrumPathProperties.getRootPath() + StringPool.SLASH + reportPath; - String tempDir = System.getProperty("java.io.tmpdir"); - // 创建文件 - File reportFile = FileUtil.writeString(reportContent, tempDir + System.currentTimeMillis(), "utf8"); - try { - ftpUtil.saveFile(savePath, reportName, new FileInputStream(reportFile)); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } finally { - if (null != reportFile) { - reportFile.delete(); - } - } - }catch (Exception e){ - e.printStackTrace(); + }finally { - }finally { + } + } - } - } - - private void storageDataToDatabase(GStoreMiddleProcessData middleData, Map qcItems){ - //如果数据已经存储,不在重复存储 - final Integer idAnalysis = serviceQuotes.getAnalysesService().getIdAnalysis(this.sampleData.getSampleId()); - if(Objects.nonNull(idAnalysis)){ + private void storageDataToDatabase(GStoreMiddleProcessData middleData, Map qcItems){ + //如果数据已经存储,不在重复存储 + final Integer idAnalysis = serviceQuotes.getAnalysesService().getIdAnalysis(this.sampleData.getSampleId()); + if(Objects.nonNull(idAnalysis)){ // log.warn("{} file analysis data has been stored",new File(this.sampleTempFilePath).getName()); - return; - } - DataSourceSwitcher.switchToOracle(); - final TransactionStatus transactionStatus = serviceQuotes.getTransactionManager().getTransaction(serviceQuotes.getTransactionDefinition()); - try { - Integer sampleId = this.sampleData.getSampleId(); - // 保存分析结果 ==> INSERT INTO RNAUTO.GARDS_ANALYSES - saveAnalysis(middleData, sampleId); - // 获取分析结果ID ==> SELECT IDANALYSIS - Integer IdAnalysis = getIdAnalysis(sampleId); - // 修改保存结果状态 ==> UPDATE ORIGINAL.GARDS_SAMPLE_DATA + return; + } + DataSourceSwitcher.switchToOracle(); + final TransactionStatus transactionStatus = serviceQuotes.getTransactionManager().getTransaction(serviceQuotes.getTransactionDefinition()); + try { + Integer sampleId = this.sampleData.getSampleId(); + // 保存分析结果 ==> INSERT INTO RNAUTO.GARDS_ANALYSES + saveAnalysis(middleData, sampleId); + // 获取分析结果ID ==> SELECT IDANALYSIS + Integer IdAnalysis = getIdAnalysis(sampleId); + // 修改保存结果状态 ==> UPDATE ORIGINAL.GARDS_SAMPLE_DATA // serviceQuotes.getSampleDataService().updateStatus(null,null); - /* GARDS_CALIBRATION_PAIRS 数据表保存 */ - saveCalibrationPairs(middleData, sampleId, IdAnalysis); - /* GARDS_CALIBRATION 数据表保存 */ - saveCalibration(middleData, sampleId, IdAnalysis); - /* Gards_Peaks 数据表保存 */ - savePeaks(middleData, sampleId, IdAnalysis); - /* Gards_Nucl_Lines_Ided 数据表保存 */ - saveNuclLinesIded(middleData, sampleId, IdAnalysis); - /* Gards_Nucl_Ided 数据表保存 */ - saveNuclIded(middleData, sampleId, IdAnalysis); - /* Gards_Qc_Check 数据表保存 */ - saveQcCheck(middleData, sampleId, IdAnalysis, qcItems); - //提交事务 - serviceQuotes.getTransactionManager().commit(transactionStatus); - } catch (Exception e) { - //设置分析数据存储失败标记 + /* GARDS_CALIBRATION_PAIRS 数据表保存 */ + saveCalibrationPairs(middleData, sampleId, IdAnalysis); + /* GARDS_CALIBRATION 数据表保存 */ + saveCalibration(middleData, sampleId, IdAnalysis); + /* Gards_Peaks 数据表保存 */ + savePeaks(middleData, sampleId, IdAnalysis); + /* Gards_Nucl_Lines_Ided 数据表保存 */ + saveNuclLinesIded(middleData, sampleId, IdAnalysis); + /* Gards_Nucl_Ided 数据表保存 */ + saveNuclIded(middleData, sampleId, IdAnalysis); + /* Gards_Qc_Check 数据表保存 */ + saveQcCheck(middleData, sampleId, IdAnalysis, qcItems); + //提交事务 + serviceQuotes.getTransactionManager().commit(transactionStatus); + } catch (Exception e) { + //设置分析数据存储失败标记 // this.parsingProcessLog.setAnalysisDataStoreFlag(false); - //回滚事务 - serviceQuotes.getTransactionManager().rollback(transactionStatus); - throw e; - } finally { - DataSourceSwitcher.clearDataSource(); - } - } - /** - * 生成日志文件 - * @param logFilePath - * @param middleData - */ - private void writeLog(String logFilePath, GStoreMiddleProcessData middleData) { - logFilePath = StringPool.SLASH + spectrumPathProperties.getLogPath() + StringPool.SLASH + logFilePath; - String sampleId = middleData.getSample_id(); - MyLogFormatUtil myLogFormatUtil = new MyLogFormatUtil(); - List writes = new LinkedList<>(); + //回滚事务 + serviceQuotes.getTransactionManager().rollback(transactionStatus); + throw e; + } finally { + DataSourceSwitcher.clearDataSource(); + } + } + /** + * 生成日志文件 + * @param logFilePath + * @param middleData + */ + private void writeLog(String logFilePath, GStoreMiddleProcessData middleData) { + logFilePath = spectrumPathProperties.getRootPath() + File.separator + + spectrumPathProperties.getLogPath() + File.separator + logFilePath; + String sampleId = middleData.getSample_id(); + MyLogFormatUtil myLogFormatUtil = new MyLogFormatUtil(); + List writes = new LinkedList<>(); - // 自动处理分析开始 - String analyseBegin = MyLogFormatUtil.analyseResultsBegin.replace("%1", "date"); - writes.add(MyLogFormatUtil.getTitleFormat(analyseBegin, MyLogFormatUtil.FILE_TITLE_FLAG)); + // 自动处理分析开始 + String analyseBegin = MyLogFormatUtil.analyseResultsBegin.replace("%1", "date"); + writes.add(MyLogFormatUtil.getTitleFormat(analyseBegin, MyLogFormatUtil.FILE_TITLE_FLAG)); - /* Read calibration data */ - writes.add(MyLogFormatUtil.getTitleFormat(MyLogFormatUtil.titleCalibration)); + /* Read calibration data */ + writes.add(MyLogFormatUtil.getTitleFormat(MyLogFormatUtil.titleCalibration)); - List data = new ArrayList<>(); - writes.add(MyLogFormatUtil.getHeaderFormat(MyLogFormatUtil.SetSampleGEnergyChannel.replace("%1", sampleId))); + List data = new ArrayList<>(); + writes.add(MyLogFormatUtil.getHeaderFormat(MyLogFormatUtil.SetSampleGEnergyChannel.replace("%1", sampleId))); - AttributeItemVo item = null; - item = new AttributeItemVo("Channel", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_E_xValue(), 3)); - data.add(item); - item = new AttributeItemVo("Energy", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_E_yValue(),3)); - data.add(item); - item = new AttributeItemVo("Error", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_E_uncYValue(), 3)); - data.add(item); - writes.addAll(MyLogFormatUtil.getBlockContext(data)); + AttributeItemVo item = null; + item = new AttributeItemVo("Channel", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_E_xValue(), 3)); + data.add(item); + item = new AttributeItemVo("Energy", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_E_yValue(),3)); + data.add(item); + item = new AttributeItemVo("Error", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_E_uncYValue(), 3)); + data.add(item); + writes.addAll(MyLogFormatUtil.getBlockContext(data)); - // Reading gamma Efficiency pairs(sampleID: %1) - writes.add(MyLogFormatUtil.getHeaderFormat(MyLogFormatUtil.GSetSampleEfficiencyChannel.replace("%1", sampleId))); + // Reading gamma Efficiency pairs(sampleID: %1) + writes.add(MyLogFormatUtil.getHeaderFormat(MyLogFormatUtil.GSetSampleEfficiencyChannel.replace("%1", sampleId))); - item = new AttributeItemVo("Channel", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_EF_xValue(), 3)); - data.add(item); - item = new AttributeItemVo("Energy", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_EF_xValue(), 3)); - data.add(item); - item = new AttributeItemVo("Error", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_EF_xValue(), 3)); - data.add(item); - writes.addAll(MyLogFormatUtil.getBlockContext(data)); + item = new AttributeItemVo("Channel", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_EF_xValue(), 3)); + data.add(item); + item = new AttributeItemVo("Energy", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_EF_xValue(), 3)); + data.add(item); + item = new AttributeItemVo("Error", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_EF_xValue(), 3)); + data.add(item); + writes.addAll(MyLogFormatUtil.getBlockContext(data)); - // Reading gamma Resolution pairs(sampleID: %1) - writes.add(MyLogFormatUtil.getHeaderFormat(MyLogFormatUtil.GSetSampleResolutionChannel.replace("%1", sampleId))); + // Reading gamma Resolution pairs(sampleID: %1) + writes.add(MyLogFormatUtil.getHeaderFormat(MyLogFormatUtil.GSetSampleResolutionChannel.replace("%1", sampleId))); - item = new AttributeItemVo("Channel", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_EF_xValue(), 3)); - data.add(item); - item = new AttributeItemVo("Energy", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_R_yValue(),3)); - data.add(item); - item = new AttributeItemVo("Error", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_R_uncYValue(),3)); - data.add(item); - writes.addAll(MyLogFormatUtil.getBlockContext(data)); + item = new AttributeItemVo("Channel", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_EF_xValue(), 3)); + data.add(item); + item = new AttributeItemVo("Energy", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_R_yValue(),3)); + data.add(item); + item = new AttributeItemVo("Error", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_R_uncYValue(),3)); + data.add(item); + writes.addAll(MyLogFormatUtil.getBlockContext(data)); - // Reading gamma TotalEfficiency pairs(sampleID: %1) - writes.add(MyLogFormatUtil.getHeaderFormat(MyLogFormatUtil.GSetSampleTotalEfficiencyChannel.replace("%1", sampleId))); - item = new AttributeItemVo("Channel", middleData.getCalibration_pairs_S_T_xValue()); - data.add(item); - item = new AttributeItemVo("Energy", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_T_yValue(), 3)); - data.add(item); - item = new AttributeItemVo("Error", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_T_uncYValue(), 3)); - data.add(item); - writes.addAll(MyLogFormatUtil.getBlockContext(data)); + // Reading gamma TotalEfficiency pairs(sampleID: %1) + writes.add(MyLogFormatUtil.getHeaderFormat(MyLogFormatUtil.GSetSampleTotalEfficiencyChannel.replace("%1", sampleId))); + item = new AttributeItemVo("Channel", middleData.getCalibration_pairs_S_T_xValue()); + data.add(item); + item = new AttributeItemVo("Energy", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_T_yValue(), 3)); + data.add(item); + item = new AttributeItemVo("Error", MyLogFormatUtil.getValuePoint(middleData.getCalibration_pairs_S_T_uncYValue(), 3)); + data.add(item); + writes.addAll(MyLogFormatUtil.getBlockContext(data)); - // Reading sample information - writes.add(MyLogFormatUtil.getHeaderFormat(MyLogFormatUtil.sampleInfo)); - Map infoMap = new LinkedHashMap<>(); - infoMap.put("Collection Start", middleData.sample_collection_start); - infoMap.put("Collection Stop", middleData.sample_collection_stop); - infoMap.put("Sampling Time[h]", middleData.sample_time); - infoMap.put("Sample Quantity[m3]", middleData.sample_quantity); - infoMap.put("Decay Time[h]", middleData.sample_decay_time); - infoMap.put("Acquisition Start", middleData.sample_acquisiton_start); - infoMap.put("Acquisition Stop", middleData.sample_acquistion_stop); - infoMap.put("Acquisition Time[s]", middleData.sample_acquistion_time); - writes.addAll(MyLogFormatUtil.getBlockContext(infoMap)); + // Reading sample information + writes.add(MyLogFormatUtil.getHeaderFormat(MyLogFormatUtil.sampleInfo)); + Map infoMap = new LinkedHashMap<>(); + infoMap.put("Collection Start", middleData.sample_collection_start); + infoMap.put("Collection Stop", middleData.sample_collection_stop); + infoMap.put("Sampling Time[h]", middleData.sample_time); + infoMap.put("Sample Quantity[m3]", middleData.sample_quantity); + infoMap.put("Decay Time[h]", middleData.sample_decay_time); + infoMap.put("Acquisition Start", middleData.sample_acquisiton_start); + infoMap.put("Acquisition Stop", middleData.sample_acquistion_stop); + infoMap.put("Acquisition Time[s]", middleData.sample_acquistion_time); + writes.addAll(MyLogFormatUtil.getBlockContext(infoMap)); - // Read calibration finished - writes.add(MyLogFormatUtil.getTitleFormat(MyLogFormatUtil.titleCalibrationIdEnd)); + // Read calibration finished + writes.add(MyLogFormatUtil.getTitleFormat(MyLogFormatUtil.titleCalibrationIdEnd)); - /* Starting Calibration */ - writes.add(MyLogFormatUtil.getTitleFormat(MyLogFormatUtil.GTitleCalibration)); + /* Starting Calibration */ + writes.add(MyLogFormatUtil.getTitleFormat(MyLogFormatUtil.GTitleCalibration)); - // Energy Calibration [%1 ] - if(middleData.calibration_pairs_E_idCalPoint.size()>0) { - infoMap = new LinkedHashMap<>(); - infoMap.put("Energy Calibration [%1 ]".replace("%1", middleData.calibration_pairs_R_Input), ""); - infoMap.put("Function", middleData.calibration_E_functionTypeDef); - infoMap.put("E", middleData.calibration_E_functionDef); - infoMap.put("P", middleData.calibration_E_coeff_string); - infoMap.put("Err", middleData.calibration_E_uncoeff_string); - infoMap.put("Data", middleData.calibration_pairs_E_Input); - writes.addAll(MyLogFormatUtil.getBlockContext(infoMap)); - } + // Energy Calibration [%1 ] + if(middleData.calibration_pairs_E_idCalPoint.size()>0) { + infoMap = new LinkedHashMap<>(); + infoMap.put("Energy Calibration [%1 ]".replace("%1", middleData.calibration_pairs_R_Input), ""); + infoMap.put("Function", middleData.calibration_E_functionTypeDef); + infoMap.put("E", middleData.calibration_E_functionDef); + infoMap.put("P", middleData.calibration_E_coeff_string); + infoMap.put("Err", middleData.calibration_E_uncoeff_string); + infoMap.put("Data", middleData.calibration_pairs_E_Input); + writes.addAll(MyLogFormatUtil.getBlockContext(infoMap)); + } - // Resolution Calibration [%1 ] - if(middleData.calibration_pairs_R_idCalPoint.size()>0) { - infoMap = new LinkedHashMap<>(); - infoMap.put("Resolution Calibration [%1 ]".replace("%1", middleData.calibration_pairs_R_Input) , ""); - infoMap.put("Function", middleData.calibration_R_functionTypeDef); - infoMap.put("E", middleData.calibration_R_functionDef); - infoMap.put("P", middleData.calibration_R_coeff_string); - infoMap.put("Err", middleData.calibration_R_uncoeff_string); - infoMap.put("Data", middleData.calibration_pairs_R_Input); - writes.addAll(MyLogFormatUtil.getBlockContext(infoMap)); - } + // Resolution Calibration [%1 ] + if(middleData.calibration_pairs_R_idCalPoint.size()>0) { + infoMap = new LinkedHashMap<>(); + infoMap.put("Resolution Calibration [%1 ]".replace("%1", middleData.calibration_pairs_R_Input) , ""); + infoMap.put("Function", middleData.calibration_R_functionTypeDef); + infoMap.put("E", middleData.calibration_R_functionDef); + infoMap.put("P", middleData.calibration_R_coeff_string); + infoMap.put("Err", middleData.calibration_R_uncoeff_string); + infoMap.put("Data", middleData.calibration_pairs_R_Input); + writes.addAll(MyLogFormatUtil.getBlockContext(infoMap)); + } - // Efficiency Calibration [PHD ] - if(middleData.calibration_pairs_EF_idCalPoint.size()>0) { - infoMap = new LinkedHashMap<>(); - infoMap.put("Efficiency Calibration [%1 ]".replace("%1", middleData.calibration_pairs_EF_Input), ""); - infoMap.put("Function", middleData.calibration_pairs_EF_Input); - infoMap.put("E", middleData.calibration_EF_functionTypeDef); - infoMap.put("P", middleData.calibration_EF_functionDef); - infoMap.put("Err", middleData.calibration_EF_coeff_string); - infoMap.put("Data", middleData.calibration_EF_uncoeff_string); - writes.addAll(MyLogFormatUtil.getBlockContext(infoMap)); - } + // Efficiency Calibration [PHD ] + if(middleData.calibration_pairs_EF_idCalPoint.size()>0) { + infoMap = new LinkedHashMap<>(); + infoMap.put("Efficiency Calibration [%1 ]".replace("%1", middleData.calibration_pairs_EF_Input), ""); + infoMap.put("Function", middleData.calibration_pairs_EF_Input); + infoMap.put("E", middleData.calibration_EF_functionTypeDef); + infoMap.put("P", middleData.calibration_EF_functionDef); + infoMap.put("Err", middleData.calibration_EF_coeff_string); + infoMap.put("Data", middleData.calibration_EF_uncoeff_string); + writes.addAll(MyLogFormatUtil.getBlockContext(infoMap)); + } - if(middleData.calibration_pairs_T_idCalPoint.size()>0) { - infoMap = new LinkedHashMap<>(); - infoMap.put("Tot_efficiency Calibration [%1 ]".replace("%1", middleData.calibration_pairs_T_Input), ""); - infoMap.put("Function", middleData.calibration_pairs_T_Input); - infoMap.put("E", middleData.calibration_T_functionTypeDef); - infoMap.put("P", middleData.calibration_T_functionDef); - infoMap.put("Err", middleData.calibration_T_coeff_string); - infoMap.put("Data", middleData.calibration_T_uncoeff_string); - writes.addAll(MyLogFormatUtil.getBlockContext(infoMap)); + if(middleData.calibration_pairs_T_idCalPoint.size()>0) { + infoMap = new LinkedHashMap<>(); + infoMap.put("Tot_efficiency Calibration [%1 ]".replace("%1", middleData.calibration_pairs_T_Input), ""); + infoMap.put("Function", middleData.calibration_pairs_T_Input); + infoMap.put("E", middleData.calibration_T_functionTypeDef); + infoMap.put("P", middleData.calibration_T_functionDef); + infoMap.put("Err", middleData.calibration_T_coeff_string); + infoMap.put("Data", middleData.calibration_T_uncoeff_string); + writes.addAll(MyLogFormatUtil.getBlockContext(infoMap)); - } - // Calibration Finished - writes.add(MyLogFormatUtil.getTitleFormat(MyLogFormatUtil.GTitleCalibrationEnd)); + } + // Calibration Finished + writes.add(MyLogFormatUtil.getTitleFormat(MyLogFormatUtil.GTitleCalibrationEnd)); - /* Starting Spectrum Analysis */ - writes.add(MyLogFormatUtil.getTitleFormat(MyLogFormatUtil.GTitleSpectrum)); + /* Starting Spectrum Analysis */ + writes.add(MyLogFormatUtil.getTitleFormat(MyLogFormatUtil.GTitleSpectrum)); - // PROCESSING PARAMETERS..... - writes.add(MyLogFormatUtil.getHeaderFormat(MyLogFormatUtil.GGetPROCESSING)); + // PROCESSING PARAMETERS..... + writes.add(MyLogFormatUtil.getHeaderFormat(MyLogFormatUtil.GGetPROCESSING)); - infoMap = new LinkedHashMap<>(); - infoMap.put("ECutAnalysis_Low", middleData.setting_specSetup.getECutAnalysis_Low()); - infoMap.put("ECutAnalysis_High", middleData.setting_specSetup.getECutAnalysis_High()); - infoMap.put("EnergyTolerance", middleData.setting_specSetup.getEnergyTolerance()); - infoMap.put("BaseImprovePSS", middleData.setting_specSetup.getBaseImprovePSS()); - infoMap.put("PSS_low", middleData.setting_specSetup.getPss_low()); - infoMap.put("k_back", middleData.setting_specSetup.getK_back()); - infoMap.put("k_alpha", middleData.setting_specSetup.getK_alpha()); - infoMap.put("k_beta", middleData.setting_specSetup.getK_beta()); - infoMap.put("RiskLevelK", middleData.setting_specSetup.getRiskLevelK()); - infoMap.put("refTime_act", middleData.setting_specSetup.getRefTime_act()); - infoMap.put("refTime_conc", middleData.setting_specSetup.getRefTime_conc()); - writes.addAll(MyLogFormatUtil.getBlockContext(infoMap)); + infoMap = new LinkedHashMap<>(); + infoMap.put("ECutAnalysis_Low", middleData.setting_specSetup.getECutAnalysis_Low()); + infoMap.put("ECutAnalysis_High", middleData.setting_specSetup.getECutAnalysis_High()); + infoMap.put("EnergyTolerance", middleData.setting_specSetup.getEnergyTolerance()); + infoMap.put("BaseImprovePSS", middleData.setting_specSetup.getBaseImprovePSS()); + infoMap.put("PSS_low", middleData.setting_specSetup.getPss_low()); + infoMap.put("k_back", middleData.setting_specSetup.getK_back()); + infoMap.put("k_alpha", middleData.setting_specSetup.getK_alpha()); + infoMap.put("k_beta", middleData.setting_specSetup.getK_beta()); + infoMap.put("RiskLevelK", middleData.setting_specSetup.getRiskLevelK()); + infoMap.put("refTime_act", middleData.setting_specSetup.getRefTime_act()); + infoMap.put("refTime_conc", middleData.setting_specSetup.getRefTime_conc()); + writes.addAll(MyLogFormatUtil.getBlockContext(infoMap)); - // CALIBRATION PARAMETERS..... - writes.add(MyLogFormatUtil.getHeaderFormat(MyLogFormatUtil.GGetCALIBRATION)); - infoMap = new LinkedHashMap<>(); - infoMap.put("CalibrationPSS_low", middleData.setting_specSetup.getCalibrationPSS_low()); - infoMap.put("CalibrationPSS_high", middleData.setting_specSetup.getCalibrationPSS_high()); - infoMap.put("bUpdateCal", middleData.setting_specSetup.isBUpdateCal()); - infoMap.put("KeepCalPeakSearchPeaks", middleData.setting_specSetup.isKeepCalPeakSearchPeaks()); - writes.addAll(MyLogFormatUtil.getBlockContext(infoMap)); + // CALIBRATION PARAMETERS..... + writes.add(MyLogFormatUtil.getHeaderFormat(MyLogFormatUtil.GGetCALIBRATION)); + infoMap = new LinkedHashMap<>(); + infoMap.put("CalibrationPSS_low", middleData.setting_specSetup.getCalibrationPSS_low()); + infoMap.put("CalibrationPSS_high", middleData.setting_specSetup.getCalibrationPSS_high()); + infoMap.put("bUpdateCal", middleData.setting_specSetup.isBUpdateCal()); + infoMap.put("KeepCalPeakSearchPeaks", middleData.setting_specSetup.isKeepCalPeakSearchPeaks()); + writes.addAll(MyLogFormatUtil.getBlockContext(infoMap)); - // Nuclide Identified..... - writes.add(MyLogFormatUtil.getHeaderFormat(MyLogFormatUtil.GGetPeakSearchResult)); - infoMap = new LinkedHashMap<>(); - int idPeakSize = middleData.peaks_idPeak.size(); - double peaksUsed = 0; - for(int m=0;m(); + int idPeakSize = middleData.peaks_idPeak.size(); + double peaksUsed = 0; + for(int m=0;m(); - item = new AttributeItemVo("PeakID", middleData.getPeaks_idPeak()); - data.add(item); - item = new AttributeItemVo("Energy", MyLogFormatUtil.getValuePoint(middleData.getPeaks_Energy(), 3)); - data.add(item); - item = new AttributeItemVo("Centroid", MyLogFormatUtil.getValuePoint(middleData.getPeaks_peakCentroid(), 3)); - data.add(item); - item = new AttributeItemVo("FWHM", MyLogFormatUtil.getValuePoint(middleData.getPeaks_Fwhm(), 3)); - data.add(item); - item = new AttributeItemVo("NetArea", MyLogFormatUtil.getValuePoint(middleData.getPeaks_Area(), 3)); - data.add(item); - List percentData = MyLogFormatUtil.getPercent(middleData.getPeaks_areaErr(), middleData.getPeaks_Area()); - item = new AttributeItemVo("NAErr%", MyLogFormatUtil.getValuePoint(percentData, 3)); - data.add(item); - item = new AttributeItemVo("Signif", MyLogFormatUtil.getValuePoint(middleData.getPeaks_Significance(), 3)); - data.add(item); - item = new AttributeItemVo("Sensit", MyLogFormatUtil.getValuePoint(middleData.getPeaks_Sensitivity(), 3)); - data.add(item); - item = new AttributeItemVo("Nuclide", middleData.getPeaks_Nuclide_name()); - data.add(item); - writes.addAll(MyLogFormatUtil.getBlock(MyLogFormatUtil.GSetSampleEfficiencyChannel, sampleId, data)); + data = new ArrayList<>(); + item = new AttributeItemVo("PeakID", middleData.getPeaks_idPeak()); + data.add(item); + item = new AttributeItemVo("Energy", MyLogFormatUtil.getValuePoint(middleData.getPeaks_Energy(), 3)); + data.add(item); + item = new AttributeItemVo("Centroid", MyLogFormatUtil.getValuePoint(middleData.getPeaks_peakCentroid(), 3)); + data.add(item); + item = new AttributeItemVo("FWHM", MyLogFormatUtil.getValuePoint(middleData.getPeaks_Fwhm(), 3)); + data.add(item); + item = new AttributeItemVo("NetArea", MyLogFormatUtil.getValuePoint(middleData.getPeaks_Area(), 3)); + data.add(item); + List percentData = MyLogFormatUtil.getPercent(middleData.getPeaks_areaErr(), middleData.getPeaks_Area()); + item = new AttributeItemVo("NAErr%", MyLogFormatUtil.getValuePoint(percentData, 3)); + data.add(item); + item = new AttributeItemVo("Signif", MyLogFormatUtil.getValuePoint(middleData.getPeaks_Significance(), 3)); + data.add(item); + item = new AttributeItemVo("Sensit", MyLogFormatUtil.getValuePoint(middleData.getPeaks_Sensitivity(), 3)); + data.add(item); + item = new AttributeItemVo("Nuclide", middleData.getPeaks_Nuclide_name()); + data.add(item); + writes.addAll(MyLogFormatUtil.getBlock(MyLogFormatUtil.GSetSampleEfficiencyChannel, sampleId, data)); - // Nuclide Identified..... - writes.add(MyLogFormatUtil.getHeaderFormat(MyLogFormatUtil.GGetPeakSearchResult)); - StringBuilder qsNuclidesName = new StringBuilder(); - for(int m = 0; m < middleData.nucl_ided_Nuclidename.size() -1; m++) - { - qsNuclidesName.append(middleData.nucl_ided_Nuclidename.get(m)).append(","); - } - if(middleData.nucl_ided_Nuclidename.size() > 1) - { - qsNuclidesName.append(middleData.nucl_ided_Nuclidename.get(middleData.nucl_ided_Nuclidename.size() - 1)); - } - infoMap = new LinkedHashMap<>(); - infoMap.put("Nuclides Identified", qsNuclidesName.toString()); - infoMap.put("Keyline Activities for Nuclides with defined Reference Line", ""); - infoMap.put("Activity Reference Time", middleData.getSample_acquisiton_start()); - infoMap.put("Concentration Reference Time", middleData.getSample_collection_start()); - writes.addAll(MyLogFormatUtil.getBlockContext(infoMap)); + // Nuclide Identified..... + writes.add(MyLogFormatUtil.getHeaderFormat(MyLogFormatUtil.GGetPeakSearchResult)); + StringBuilder qsNuclidesName = new StringBuilder(); + for(int m = 0; m < middleData.nucl_ided_Nuclidename.size() -1; m++) + { + qsNuclidesName.append(middleData.nucl_ided_Nuclidename.get(m)).append(","); + } + if(middleData.nucl_ided_Nuclidename.size() > 1) + { + qsNuclidesName.append(middleData.nucl_ided_Nuclidename.get(middleData.nucl_ided_Nuclidename.size() - 1)); + } + infoMap = new LinkedHashMap<>(); + infoMap.put("Nuclides Identified", qsNuclidesName.toString()); + infoMap.put("Keyline Activities for Nuclides with defined Reference Line", ""); + infoMap.put("Activity Reference Time", middleData.getSample_acquisiton_start()); + infoMap.put("Concentration Reference Time", middleData.getSample_collection_start()); + writes.addAll(MyLogFormatUtil.getBlockContext(infoMap)); - data = new ArrayList<>(); - item = new AttributeItemVo("Nuclide", middleData.getNucl_ided_Nuclidename()); - data.add(item); - item = new AttributeItemVo("Halflife", middleData.getNucl_ided_Halflife()); - data.add(item); - item = new AttributeItemVo("Activity", - MyLogFormatUtil.getValuePoint(middleData.getNucl_ided_activ_key(), 3), "bq"); - data.add(item); - List ideaPercent = MyLogFormatUtil.getPercent(middleData.getNucl_ided_activ_key_err(), middleData.getNucl_ided_activ_key()); - item = new AttributeItemVo("RelErr", ideaPercent, "%"); - data.add(item); - item = new AttributeItemVo("Conc", middleData.getNucl_ided_Concentration(), "uBq/m^3"); - data.add(item); - item = new AttributeItemVo("MDC", middleData.getNucl_ided_MDC(), "uBq/m^3"); - data.add(item); - writes.addAll(MyLogFormatUtil.getBlockContext(infoMap)); + data = new ArrayList<>(); + item = new AttributeItemVo("Nuclide", middleData.getNucl_ided_Nuclidename()); + data.add(item); + item = new AttributeItemVo("Halflife", middleData.getNucl_ided_Halflife()); + data.add(item); + item = new AttributeItemVo("Activity", + MyLogFormatUtil.getValuePoint(middleData.getNucl_ided_activ_key(), 3), "bq"); + data.add(item); + List ideaPercent = MyLogFormatUtil.getPercent(middleData.getNucl_ided_activ_key_err(), middleData.getNucl_ided_activ_key()); + item = new AttributeItemVo("RelErr", ideaPercent, "%"); + data.add(item); + item = new AttributeItemVo("Conc", middleData.getNucl_ided_Concentration(), "uBq/m^3"); + data.add(item); + item = new AttributeItemVo("MDC", middleData.getNucl_ided_MDC(), "uBq/m^3"); + data.add(item); + writes.addAll(MyLogFormatUtil.getBlockContext(infoMap)); - // Starting Data Quality..... - writes.add(MyLogFormatUtil.getHeaderFormat(MyLogFormatUtil.GGetDataQuality)); - data = new ArrayList<>(); - item = new AttributeItemVo("Name", middleData.getQC_CHECK_QC_NAME()); - data.add(item); - item = new AttributeItemVo("Pass/Fail", MyLogFormatUtil.getPass(middleData.getQC_CHECK_QC_RESULT())); - data.add(item); - item = new AttributeItemVo("Value", MyLogFormatUtil.getValuePoint(middleData.getQC_CHECK_QC_VALUE(), 3)); - data.add(item); - item = new AttributeItemVo("Test", middleData.getQC_CHECK_QC_STANDARD()); - data.add(item); - writes.addAll(MyLogFormatUtil.getBlockContext(infoMap)); + // Starting Data Quality..... + writes.add(MyLogFormatUtil.getHeaderFormat(MyLogFormatUtil.GGetDataQuality)); + data = new ArrayList<>(); + item = new AttributeItemVo("Name", middleData.getQC_CHECK_QC_NAME()); + data.add(item); + item = new AttributeItemVo("Pass/Fail", MyLogFormatUtil.getPass(middleData.getQC_CHECK_QC_RESULT())); + data.add(item); + item = new AttributeItemVo("Value", MyLogFormatUtil.getValuePoint(middleData.getQC_CHECK_QC_VALUE(), 3)); + data.add(item); + item = new AttributeItemVo("Test", middleData.getQC_CHECK_QC_STANDARD()); + data.add(item); + writes.addAll(MyLogFormatUtil.getBlockContext(infoMap)); - // Spectrum Analysis Finished - writes.add(MyLogFormatUtil.getTitleFormat(MyLogFormatUtil.GTitleSpectrumEnd)); - // todo Data store successfully ..... - // todo Instance status successfully set to: P..... - // todo Error info: data has NULL INF..... + // Spectrum Analysis Finished + writes.add(MyLogFormatUtil.getTitleFormat(MyLogFormatUtil.GTitleSpectrumEnd)); + // todo Data store successfully ..... + // todo Instance status successfully set to: P..... + // todo Error info: data has NULL INF..... - // Sample Analyse Successfully at %1 - String analyseEnd = MyLogFormatUtil.analyseResultsEnd.replace("%1", "date"); - writes.add(MyLogFormatUtil.getTitleFormat(analyseEnd)); + // Sample Analyse Successfully at %1 + String analyseEnd = MyLogFormatUtil.analyseResultsEnd.replace("%1", "date"); + writes.add(MyLogFormatUtil.getTitleFormat(analyseEnd)); - // 保存文件 - // 获取系统的临时目录 - String tempDir = System.getProperty("java.io.tmpdir"); - // 创建文件 - File file = FileUtil.writeLines(writes, tempDir + System.currentTimeMillis(), "utf8"); - String targetPath = StringUtils.substringBeforeLast(logFilePath, StringPool.SLASH); - String targetName = StringUtils.substringAfterLast(logFilePath, StringPool.SLASH); - try { - ftpUtil.saveFile(targetPath, targetName, new FileInputStream(file)); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } finally { - // 删除临时文件 - if(null != file) file.delete(); - } - } + // 保存文件 + try { + FileOperation.saveFile(logFilePath, writes); + } catch (IOException e) { + e.printStackTrace(); + } + } - public void saveAnalysis(GStoreMiddleProcessData middleData,Integer sampleId){ - GardsAnalyses analysis = toAnalysis(middleData); - analysis.setSampleId(sampleId); - serviceQuotes.getAnalysesService().save(analysis); - } + public void saveAnalysis(GStoreMiddleProcessData middleData,Integer sampleId){ + GardsAnalyses analysis = toAnalysis(middleData); + analysis.setSampleId(sampleId); + serviceQuotes.getAnalysesService().save(analysis); + } - public Integer getIdAnalysis(Integer sampleId){ - return serviceQuotes.getAnalysesService().getIdAnalysis(sampleId); - } + public Integer getIdAnalysis(Integer sampleId){ + return serviceQuotes.getAnalysesService().getIdAnalysis(sampleId); + } - public void saveCalibrationPairs(GStoreMiddleProcessData middleData, - Integer sampleId, Integer IdAnalysis){ - String pairsSampleType = middleData.getCalibration_pairs_sample_type(); - GardsCalibrationPairs pairs = new GardsCalibrationPairs(); - // GARDS_CALIBRATION_PAIRS (Energy) ==> INSERT INTO RNAUTO.GARDS_CALIBRATION_PAIRS - String base_E_Paris = "calibration_pairs_E_idCalPoint"; - PairsEDto pairsEDto = new PairsEDto(); - BeanUtil.copyProperties(middleData,pairsEDto); - List pairsE = Lists.newArrayList(); - if (pairsEDto.getCalibration_pairs_E_idCalPoint().size() > 0) { - pairsE = mapFields(pairsEDto, pairs, base_E_Paris, fieldMap); - String pairsECaltype = middleData.getCalibration_pairs_E_Caltype(); - String pairsEInput = middleData.getCalibration_pairs_E_Input(); - for (GardsCalibrationPairs onePairs : pairsE) { - onePairs.setSampleId(sampleId); - onePairs.setIdAnalysis(IdAnalysis); - onePairs.setSampleType(pairsSampleType); - onePairs.setCaltype(pairsECaltype); - onePairs.setInput(pairsEInput); - } - } - // GARDS_CALIBRATION_PAIRS (Efficiency) ==> INSERT INTO RNAUTO.GARDS_CALIBRATION_PAIRS - String base_EF_Paris = "calibration_pairs_EF_idCalPoint"; - PairsEFDto pairsEFDto = new PairsEFDto(); - BeanUtil.copyProperties(middleData,pairsEFDto); - List pairsEF = Lists.newArrayList(); - if (pairsEFDto.getCalibration_pairs_EF_idCalPoint().size() > 0) { - pairsEF = mapFields(pairsEFDto, pairs, base_EF_Paris, fieldMap); - String pairsEFCaltype = middleData.getCalibration_pairs_EF_Caltype(); - String pairsEFInput = middleData.getCalibration_pairs_EF_Input(); - for (GardsCalibrationPairs onePairs : pairsEF) { - onePairs.setSampleId(sampleId); - onePairs.setIdAnalysis(IdAnalysis); - onePairs.setSampleType(pairsSampleType); - onePairs.setCaltype(pairsEFCaltype); - onePairs.setInput(pairsEFInput); - } - } - // GARDS_CALIBRATION_PAIRS (Resolution) ==> INSERT INTO RNAUTO.GARDS_CALIBRATION_PAIRS - String base_R_Paris = "calibration_pairs_R_idCalPoint"; - PairsRDto pairsRDto = new PairsRDto(); - BeanUtil.copyProperties(middleData,pairsRDto); - List pairsR = Lists.newArrayList(); - if (pairsRDto.getCalibration_pairs_R_idCalPoint().size() > 0) { - pairsR = mapFields(pairsRDto, pairs, base_R_Paris, fieldMap); - String pairsRCaltype = middleData.getCalibration_pairs_R_Caltype(); - String pairsRInput = middleData.getCalibration_pairs_R_Input(); - for (GardsCalibrationPairs onePairs : pairsR) { - onePairs.setSampleId(sampleId); - onePairs.setIdAnalysis(IdAnalysis); - onePairs.setSampleType(pairsSampleType); - onePairs.setCaltype(pairsRCaltype); - onePairs.setInput(pairsRInput); - } - } - // GARDS_CALIBRATION_PAIRS (TotalEfficiency) ==> INSERT INTO RNAUTO.GARDS_CALIBRATION_PAIRS - String base_T_Paris = "calibration_pairs_T_idCalPoint"; - PairsTDto pairsTDto = new PairsTDto(); - BeanUtil.copyProperties(middleData,pairsTDto); - List pairsT = Lists.newArrayList(); - if (pairsTDto.getCalibration_pairs_T_idCalPoint().size() > 0) { - pairsT = mapFields(pairsTDto, pairs, base_T_Paris, fieldMap); - String pairsTCaltype = middleData.getCalibration_pairs_T_Caltype(); - String pairsTInput = middleData.getCalibration_pairs_T_Input(); - for (GardsCalibrationPairs onePairs : pairsT) { - onePairs.setSampleId(sampleId); - onePairs.setIdAnalysis(IdAnalysis); - onePairs.setSampleType(pairsSampleType); - onePairs.setCaltype(pairsTCaltype); - onePairs.setInput(pairsTInput); - } - } - // GARDS_CALIBRATION_PAIRS 汇总保存 - List allPairs = new ArrayList<>(); - allPairs.addAll(pairsE);allPairs.addAll(pairsEF); - allPairs.addAll(pairsR);allPairs.addAll(pairsT); - serviceQuotes.getGardsCalibrationPairsService().saveBatch(allPairs); - } - public void saveCalibration(GStoreMiddleProcessData middleData, - Integer sampleId, Integer IdAnalysis){ - String calibrationSampleType = middleData.getCalibration_sample_type(); - List pairsEIdCalPoint = middleData.getCalibration_pairs_E_idCalPoint(); - List pairsEFIdCalPoint = middleData.getCalibration_pairs_EF_idCalPoint(); - List pairsRIdCalPoint = middleData.getCalibration_pairs_R_idCalPoint(); - List pairsTIdCalPoint = middleData.getCalibration_pairs_T_idCalPoint(); - List calibrations = new ArrayList<>(); - // GARDS_CALIBRATION (E) ==> INSERT INTO RNAUTO.GARDS_CALIBRATION - if (CollUtil.isNotEmpty(pairsEIdCalPoint)){ - GardsCalibration calibration = new GardsCalibration(); - calibration.setSampleId(sampleId); - calibration.setIdAnalysis(IdAnalysis); - calibration.setSampleType(calibrationSampleType); - calibration.setCalType(middleData.getCalibration_E_Caltype()); - calibration.setFunction((int)middleData.getCalibration_E_function()); - calibration.setFunctionDef(middleData.getCalibration_E_functionDef()); - calibration.setStartOfRange((int)middleData.getCalibration_E_startOfRange()); - calibration.setEndOfRange((int)middleData.getCalibration_E_endOfRange()); - calibration.setCoeffString(middleData.getCalibration_E_coeff_string()); - calibration.setModdate(new Date()); - calibrations.add(calibration); - } - // GARDS_CALIBRATION (EF) ==> INSERT INTO RNAUTO.GARDS_CALIBRATION - if (CollUtil.isNotEmpty(pairsEFIdCalPoint)){ - GardsCalibration calibration = new GardsCalibration(); - calibration.setSampleId(sampleId); - calibration.setIdAnalysis(IdAnalysis); - calibration.setSampleType(calibrationSampleType); - String efCaltype = middleData.getCalibration_EF_Caltype(); - double efFunction = middleData.getCalibration_EF_function(); - String efFunctionDef = middleData.getCalibration_EF_functionDef(); - double efStartOfRange = middleData.getCalibration_EF_startOfRange(); - double efEndOfRange = middleData.getCalibration_EF_endOfRange(); - String efCoeffString = middleData.getCalibration_EF_coeff_string(); - calibration.setCalType(efCaltype); - calibration.setFunction((int)efFunction); - calibration.setFunctionDef(efFunctionDef); - calibration.setStartOfRange((int)efStartOfRange); - calibration.setEndOfRange((int)efEndOfRange); - calibration.setCoeffString(efCoeffString); - calibration.setModdate(new Date()); - calibrations.add(calibration); - } - // GARDS_CALIBRATION (R) ==> INSERT INTO RNAUTO.GARDS_CALIBRATION - if (CollUtil.isNotEmpty(pairsRIdCalPoint)){ - GardsCalibration calibration = new GardsCalibration(); - calibration.setSampleId(sampleId); - calibration.setIdAnalysis(IdAnalysis); - calibration.setSampleType(calibrationSampleType); - String rCaltype = middleData.getCalibration_R_Caltype(); - double rFunction = middleData.getCalibration_R_function(); - String rFunctionDef = middleData.getCalibration_R_functionDef(); - double rStartOfRange = middleData.getCalibration_R_startOfRange(); - double rEndOfRange = middleData.getCalibration_R_endOfRange(); - String rCoeffString = middleData.getCalibration_R_coeff_string(); - calibration.setCalType(rCaltype); - calibration.setFunction((int)rFunction); - calibration.setFunctionDef(rFunctionDef); - calibration.setStartOfRange((int)rStartOfRange); - calibration.setEndOfRange((int)rEndOfRange); - calibration.setCoeffString(rCoeffString); - calibration.setModdate(new Date()); - calibrations.add(calibration); - } - // GARDS_CALIBRATION (T) ==> INSERT INTO RNAUTO.GARDS_CALIBRATION - if (CollUtil.isNotEmpty(pairsTIdCalPoint)){ - GardsCalibration calibration = new GardsCalibration(); - calibration.setSampleId(sampleId); - calibration.setIdAnalysis(IdAnalysis); - calibration.setSampleType(calibrationSampleType); - String tCaltype = middleData.getCalibration_T_Caltype(); - double tFunction = middleData.getCalibration_T_function(); - String tFunctionDef = middleData.getCalibration_T_functionDef(); - double tStartOfRange = middleData.getCalibration_T_startOfRange(); - double tEndOfRange = middleData.getCalibration_T_endOfRange(); - String tCoeffString = middleData.getCalibration_T_coeff_string(); - calibration.setCalType(tCaltype); - calibration.setFunction((int)middleData.getCalibration_T_function()); - calibration.setFunctionDef(tFunctionDef); - calibration.setStartOfRange((int)tStartOfRange); - calibration.setEndOfRange((int)tEndOfRange); - calibration.setCoeffString(tCoeffString); - calibration.setModdate(new Date()); - calibrations.add(calibration); - } - serviceQuotes.getGardsCalibrationService().createBatch(calibrations); - } + public void saveCalibrationPairs(GStoreMiddleProcessData middleData, + Integer sampleId, Integer IdAnalysis){ + String pairsSampleType = middleData.getCalibration_pairs_sample_type(); + GardsCalibrationPairs pairs = new GardsCalibrationPairs(); + // GARDS_CALIBRATION_PAIRS (Energy) ==> INSERT INTO RNAUTO.GARDS_CALIBRATION_PAIRS + String base_E_Paris = "calibration_pairs_E_idCalPoint"; + PairsEDto pairsEDto = new PairsEDto(); + BeanUtil.copyProperties(middleData,pairsEDto); + List pairsE = Lists.newArrayList(); + if (pairsEDto.getCalibration_pairs_E_idCalPoint().size() > 0) { + pairsE = mapFields(pairsEDto, pairs, base_E_Paris, fieldMap); + String pairsECaltype = middleData.getCalibration_pairs_E_Caltype(); + String pairsEInput = middleData.getCalibration_pairs_E_Input(); + for (GardsCalibrationPairs onePairs : pairsE) { + onePairs.setSampleId(sampleId); + onePairs.setIdAnalysis(IdAnalysis); + onePairs.setSampleType(pairsSampleType); + onePairs.setCaltype(pairsECaltype); + onePairs.setInput(pairsEInput); + } + } + // GARDS_CALIBRATION_PAIRS (Efficiency) ==> INSERT INTO RNAUTO.GARDS_CALIBRATION_PAIRS + String base_EF_Paris = "calibration_pairs_EF_idCalPoint"; + PairsEFDto pairsEFDto = new PairsEFDto(); + BeanUtil.copyProperties(middleData,pairsEFDto); + List pairsEF = Lists.newArrayList(); + if (pairsEFDto.getCalibration_pairs_EF_idCalPoint().size() > 0) { + pairsEF = mapFields(pairsEFDto, pairs, base_EF_Paris, fieldMap); + String pairsEFCaltype = middleData.getCalibration_pairs_EF_Caltype(); + String pairsEFInput = middleData.getCalibration_pairs_EF_Input(); + for (GardsCalibrationPairs onePairs : pairsEF) { + onePairs.setSampleId(sampleId); + onePairs.setIdAnalysis(IdAnalysis); + onePairs.setSampleType(pairsSampleType); + onePairs.setCaltype(pairsEFCaltype); + onePairs.setInput(pairsEFInput); + } + } + // GARDS_CALIBRATION_PAIRS (Resolution) ==> INSERT INTO RNAUTO.GARDS_CALIBRATION_PAIRS + String base_R_Paris = "calibration_pairs_R_idCalPoint"; + PairsRDto pairsRDto = new PairsRDto(); + BeanUtil.copyProperties(middleData,pairsRDto); + List pairsR = Lists.newArrayList(); + if (pairsRDto.getCalibration_pairs_R_idCalPoint().size() > 0) { + pairsR = mapFields(pairsRDto, pairs, base_R_Paris, fieldMap); + String pairsRCaltype = middleData.getCalibration_pairs_R_Caltype(); + String pairsRInput = middleData.getCalibration_pairs_R_Input(); + for (GardsCalibrationPairs onePairs : pairsR) { + onePairs.setSampleId(sampleId); + onePairs.setIdAnalysis(IdAnalysis); + onePairs.setSampleType(pairsSampleType); + onePairs.setCaltype(pairsRCaltype); + onePairs.setInput(pairsRInput); + } + } + // GARDS_CALIBRATION_PAIRS (TotalEfficiency) ==> INSERT INTO RNAUTO.GARDS_CALIBRATION_PAIRS + String base_T_Paris = "calibration_pairs_T_idCalPoint"; + PairsTDto pairsTDto = new PairsTDto(); + BeanUtil.copyProperties(middleData,pairsTDto); + List pairsT = Lists.newArrayList(); + if (pairsTDto.getCalibration_pairs_T_idCalPoint().size() > 0) { + pairsT = mapFields(pairsTDto, pairs, base_T_Paris, fieldMap); + String pairsTCaltype = middleData.getCalibration_pairs_T_Caltype(); + String pairsTInput = middleData.getCalibration_pairs_T_Input(); + for (GardsCalibrationPairs onePairs : pairsT) { + onePairs.setSampleId(sampleId); + onePairs.setIdAnalysis(IdAnalysis); + onePairs.setSampleType(pairsSampleType); + onePairs.setCaltype(pairsTCaltype); + onePairs.setInput(pairsTInput); + } + } + // GARDS_CALIBRATION_PAIRS 汇总保存 + List allPairs = new ArrayList<>(); + allPairs.addAll(pairsE);allPairs.addAll(pairsEF); + allPairs.addAll(pairsR);allPairs.addAll(pairsT); + serviceQuotes.getGardsCalibrationPairsService().saveBatch(allPairs); + } + public void saveCalibration(GStoreMiddleProcessData middleData, + Integer sampleId, Integer IdAnalysis){ + String calibrationSampleType = middleData.getCalibration_sample_type(); + List pairsEIdCalPoint = middleData.getCalibration_pairs_E_idCalPoint(); + List pairsEFIdCalPoint = middleData.getCalibration_pairs_EF_idCalPoint(); + List pairsRIdCalPoint = middleData.getCalibration_pairs_R_idCalPoint(); + List pairsTIdCalPoint = middleData.getCalibration_pairs_T_idCalPoint(); + List calibrations = new ArrayList<>(); + // GARDS_CALIBRATION (E) ==> INSERT INTO RNAUTO.GARDS_CALIBRATION + if (CollUtil.isNotEmpty(pairsEIdCalPoint)){ + GardsCalibration calibration = new GardsCalibration(); + calibration.setSampleId(sampleId); + calibration.setIdAnalysis(IdAnalysis); + calibration.setSampleType(calibrationSampleType); + calibration.setCalType(middleData.getCalibration_E_Caltype()); + calibration.setFunction((int)middleData.getCalibration_E_function()); + calibration.setFunctionDef(middleData.getCalibration_E_functionDef()); + calibration.setStartOfRange((int)middleData.getCalibration_E_startOfRange()); + calibration.setEndOfRange((int)middleData.getCalibration_E_endOfRange()); + calibration.setCoeffString(middleData.getCalibration_E_coeff_string()); + calibration.setModdate(new Date()); + calibrations.add(calibration); + } + // GARDS_CALIBRATION (EF) ==> INSERT INTO RNAUTO.GARDS_CALIBRATION + if (CollUtil.isNotEmpty(pairsEFIdCalPoint)){ + GardsCalibration calibration = new GardsCalibration(); + calibration.setSampleId(sampleId); + calibration.setIdAnalysis(IdAnalysis); + calibration.setSampleType(calibrationSampleType); + String efCaltype = middleData.getCalibration_EF_Caltype(); + double efFunction = middleData.getCalibration_EF_function(); + String efFunctionDef = middleData.getCalibration_EF_functionDef(); + double efStartOfRange = middleData.getCalibration_EF_startOfRange(); + double efEndOfRange = middleData.getCalibration_EF_endOfRange(); + String efCoeffString = middleData.getCalibration_EF_coeff_string(); + calibration.setCalType(efCaltype); + calibration.setFunction((int)efFunction); + calibration.setFunctionDef(efFunctionDef); + calibration.setStartOfRange((int)efStartOfRange); + calibration.setEndOfRange((int)efEndOfRange); + calibration.setCoeffString(efCoeffString); + calibration.setModdate(new Date()); + calibrations.add(calibration); + } + // GARDS_CALIBRATION (R) ==> INSERT INTO RNAUTO.GARDS_CALIBRATION + if (CollUtil.isNotEmpty(pairsRIdCalPoint)){ + GardsCalibration calibration = new GardsCalibration(); + calibration.setSampleId(sampleId); + calibration.setIdAnalysis(IdAnalysis); + calibration.setSampleType(calibrationSampleType); + String rCaltype = middleData.getCalibration_R_Caltype(); + double rFunction = middleData.getCalibration_R_function(); + String rFunctionDef = middleData.getCalibration_R_functionDef(); + double rStartOfRange = middleData.getCalibration_R_startOfRange(); + double rEndOfRange = middleData.getCalibration_R_endOfRange(); + String rCoeffString = middleData.getCalibration_R_coeff_string(); + calibration.setCalType(rCaltype); + calibration.setFunction((int)rFunction); + calibration.setFunctionDef(rFunctionDef); + calibration.setStartOfRange((int)rStartOfRange); + calibration.setEndOfRange((int)rEndOfRange); + calibration.setCoeffString(rCoeffString); + calibration.setModdate(new Date()); + calibrations.add(calibration); + } + // GARDS_CALIBRATION (T) ==> INSERT INTO RNAUTO.GARDS_CALIBRATION + if (CollUtil.isNotEmpty(pairsTIdCalPoint)){ + GardsCalibration calibration = new GardsCalibration(); + calibration.setSampleId(sampleId); + calibration.setIdAnalysis(IdAnalysis); + calibration.setSampleType(calibrationSampleType); + String tCaltype = middleData.getCalibration_T_Caltype(); + double tFunction = middleData.getCalibration_T_function(); + String tFunctionDef = middleData.getCalibration_T_functionDef(); + double tStartOfRange = middleData.getCalibration_T_startOfRange(); + double tEndOfRange = middleData.getCalibration_T_endOfRange(); + String tCoeffString = middleData.getCalibration_T_coeff_string(); + calibration.setCalType(tCaltype); + calibration.setFunction((int)middleData.getCalibration_T_function()); + calibration.setFunctionDef(tFunctionDef); + calibration.setStartOfRange((int)tStartOfRange); + calibration.setEndOfRange((int)tEndOfRange); + calibration.setCoeffString(tCoeffString); + calibration.setModdate(new Date()); + calibrations.add(calibration); + } + serviceQuotes.getGardsCalibrationService().createBatch(calibrations); + } - public void savePeaks(GStoreMiddleProcessData middleData,Integer sampleId, Integer IdAnalysis){ - // Gards_Peaks数据表 ==> INSERT INTO RNAUTO.GARDS_PEAKS - String base_P_IdPeak = "peaks_idPeak"; - GardsPeaksDto gardsPeaksDto = new GardsPeaksDto(); - BeanUtil.copyProperties(middleData,gardsPeaksDto); - GardsPeaks gardsPeaks = new GardsPeaks(); - if (gardsPeaksDto.getPeaks_idPeak().size() > 0) { - List peaks = mapFields(gardsPeaksDto, gardsPeaks, base_P_IdPeak, fieldMap); - peaks.forEach(ided -> { - ided.setSampleId(sampleId); - ided.setIdAnalysis(IdAnalysis); - }); - serviceQuotes.getGardsPeaksAutoService().saveBatch(peaks); - } - } + public void savePeaks(GStoreMiddleProcessData middleData,Integer sampleId, Integer IdAnalysis){ + // Gards_Peaks数据表 ==> INSERT INTO RNAUTO.GARDS_PEAKS + String base_P_IdPeak = "peaks_idPeak"; + GardsPeaksDto gardsPeaksDto = new GardsPeaksDto(); + BeanUtil.copyProperties(middleData,gardsPeaksDto); + GardsPeaks gardsPeaks = new GardsPeaks(); + if (gardsPeaksDto.getPeaks_idPeak().size() > 0) { + List peaks = mapFields(gardsPeaksDto, gardsPeaks, base_P_IdPeak, fieldMap); + peaks.forEach(ided -> { + ided.setSampleId(sampleId); + ided.setIdAnalysis(IdAnalysis); + }); + serviceQuotes.getGardsPeaksAutoService().saveBatch(peaks); + } + } - public void saveNuclLinesIded(GStoreMiddleProcessData middleData, - Integer sampleId, Integer IdAnalysis){ - // Gards_Nucl_Lines_Ided数据表 ==> INSERT INTO RNAUTO.GARDS_NUCL_LINES_IDED - Map nuclLinesIdedData = middleData.getNucl_lines_ided_data(); - String base_IdPeak = "idPeak"; - List allNuclLinesIdeds = new ArrayList<>(); - for (Map.Entry entry : nuclLinesIdedData.entrySet()) { - String nuclideName = entry.getKey(); - GStoreMiddleProcessDataNuclLinesIded nuclLinesIded = entry.getValue(); - GardsNuclLinesIded gardsNuclLinesIded = new GardsNuclLinesIded(); - List gardsNuclLinesIdeds = - mapFields(nuclLinesIded, gardsNuclLinesIded, base_IdPeak, fieldMap); - if (CollUtil.isNotEmpty(gardsNuclLinesIdeds)){ - for (GardsNuclLinesIded ided : gardsNuclLinesIdeds) { - ided.setSampleId(sampleId); - ided.setIdAnalysis(IdAnalysis); - ided.setNuclideName(nuclideName); - } - allNuclLinesIdeds.addAll(gardsNuclLinesIdeds); - } - } - serviceQuotes.getGardsNuclLinesIdedAutoService().saveBatch(allNuclLinesIdeds); - } + public void saveNuclLinesIded(GStoreMiddleProcessData middleData, + Integer sampleId, Integer IdAnalysis){ + // Gards_Nucl_Lines_Ided数据表 ==> INSERT INTO RNAUTO.GARDS_NUCL_LINES_IDED + Map nuclLinesIdedData = middleData.getNucl_lines_ided_data(); + String base_IdPeak = "idPeak"; + List allNuclLinesIdeds = new ArrayList<>(); + for (Map.Entry entry : nuclLinesIdedData.entrySet()) { + String nuclideName = entry.getKey(); + GStoreMiddleProcessDataNuclLinesIded nuclLinesIded = entry.getValue(); + GardsNuclLinesIded gardsNuclLinesIded = new GardsNuclLinesIded(); + List gardsNuclLinesIdeds = + mapFields(nuclLinesIded, gardsNuclLinesIded, base_IdPeak, fieldMap); + if (CollUtil.isNotEmpty(gardsNuclLinesIdeds)){ + for (GardsNuclLinesIded ided : gardsNuclLinesIdeds) { + ided.setSampleId(sampleId); + ided.setIdAnalysis(IdAnalysis); + ided.setNuclideName(nuclideName); + } + allNuclLinesIdeds.addAll(gardsNuclLinesIdeds); + } + } + serviceQuotes.getGardsNuclLinesIdedAutoService().saveBatch(allNuclLinesIdeds); + } - public void saveNuclIded(GStoreMiddleProcessData middleData, - Integer sampleId, Integer IdAnalysis){ - // Gards_Nucl_Ided数据表 ==> INSERT INTO RNAUTO.GARDS_NUCL_IDED - GardsNuclIdedDto gardsNuclIdedDto = new GardsNuclIdedDto(); - GardsNuclIded gardsNuclIded = new GardsNuclIded(); - BeanUtil.copyProperties(middleData,gardsNuclIdedDto); - if (gardsNuclIdedDto.getNucl_ided_Nuclidename().size() > 0) { - String base_NuclideName = "nucl_ided_Nuclidename"; - List gardsNuclIdeds = - mapFields(gardsNuclIdedDto, gardsNuclIded, base_NuclideName, fieldMap); - for (GardsNuclIded ided : gardsNuclIdeds) { - ided.setSampleId(sampleId); - ided.setIdAnalysis(IdAnalysis); - } - serviceQuotes.getGardsNuclIdedAutoService().saveBatch(gardsNuclIdeds); - } - // serviceQuotes.get - } + public void saveNuclIded(GStoreMiddleProcessData middleData, + Integer sampleId, Integer IdAnalysis){ + // Gards_Nucl_Ided数据表 ==> INSERT INTO RNAUTO.GARDS_NUCL_IDED + GardsNuclIdedDto gardsNuclIdedDto = new GardsNuclIdedDto(); + GardsNuclIded gardsNuclIded = new GardsNuclIded(); + BeanUtil.copyProperties(middleData,gardsNuclIdedDto); + if (gardsNuclIdedDto.getNucl_ided_Nuclidename().size() > 0) { + String base_NuclideName = "nucl_ided_Nuclidename"; + List gardsNuclIdeds = + mapFields(gardsNuclIdedDto, gardsNuclIded, base_NuclideName, fieldMap); + for (GardsNuclIded ided : gardsNuclIdeds) { + ided.setSampleId(sampleId); + ided.setIdAnalysis(IdAnalysis); + } + serviceQuotes.getGardsNuclIdedAutoService().saveBatch(gardsNuclIdeds); + } + // serviceQuotes.get + } - public void saveQcCheck(GStoreMiddleProcessData middleData, - Integer sampleId, Integer IdAnalysis,Map qcItems){ - // Gards_Qc_Check数据表 ==> INSERT INTO RNAUTO.GARDS_QC_CHECK - if (MapUtil.isNotEmpty(qcItems)){ - String base_QC = String.valueOf(qcItems.size()); - QcCheckDto qcCheckDto = new QcCheckDto(); - BeanUtil.copyProperties(middleData,qcCheckDto); - if (qcItems.size() > 0) { - GardsQcCheck gardsQcCheck = new GardsQcCheck(); - List gardsQcChecks = mapFields(qcCheckDto, gardsQcCheck,base_QC,fieldMap); - for (GardsQcCheck qcCheck : gardsQcChecks) { - qcCheck.setSampleId(sampleId); - qcCheck.setIdanalysis(IdAnalysis); - } - serviceQuotes.getGardsQcCheckAutoService().saveBatch(gardsQcChecks); - } - } - } + public void saveQcCheck(GStoreMiddleProcessData middleData, + Integer sampleId, Integer IdAnalysis,Map qcItems){ + // Gards_Qc_Check数据表 ==> INSERT INTO RNAUTO.GARDS_QC_CHECK + if (MapUtil.isNotEmpty(qcItems)){ + String base_QC = String.valueOf(qcItems.size()); + QcCheckDto qcCheckDto = new QcCheckDto(); + BeanUtil.copyProperties(middleData,qcCheckDto); + if (qcItems.size() > 0) { + GardsQcCheck gardsQcCheck = new GardsQcCheck(); + List gardsQcChecks = mapFields(qcCheckDto, gardsQcCheck,base_QC,fieldMap); + for (GardsQcCheck qcCheck : gardsQcChecks) { + qcCheck.setSampleId(sampleId); + qcCheck.setIdanalysis(IdAnalysis); + } + serviceQuotes.getGardsQcCheckAutoService().saveBatch(gardsQcChecks); + } + } + } - public Map getNuclideLinesG() { - redisUtil = ApplicationContextUtil.getContext().getBean(RedisUtil.class); - Object nuclideLibs = redisUtil.get(RedisConstant.NUCLIDE_LINES_LIB + "G"); - return Objects.isNull(nuclideLibs) ? Maps.newHashMap() : (Map) nuclideLibs; - } + public Map getNuclideLinesG() { + redisUtil = ApplicationContextUtil.getContext().getBean(RedisUtil.class); + Object nuclideLibs = redisUtil.get(RedisConstant.NUCLIDE_LINES_LIB + "G"); + return Objects.isNull(nuclideLibs) ? Maps.newHashMap() : (Map) nuclideLibs; + } - public Map getNuclideLinesP(){ - redisUtil = ApplicationContextUtil.getContext().getBean(RedisUtil.class); - Object nuclideLibs = redisUtil.get(RedisConstant.NUCLIDE_LINES_LIB + "P"); - return Objects.isNull(nuclideLibs) ? Maps.newHashMap() : (Map) nuclideLibs; - } + public Map getNuclideLinesP(){ + redisUtil = ApplicationContextUtil.getContext().getBean(RedisUtil.class); + Object nuclideLibs = redisUtil.get(RedisConstant.NUCLIDE_LINES_LIB + "P"); + return Objects.isNull(nuclideLibs) ? Maps.newHashMap() : (Map) nuclideLibs; + } - public Map fieldMap(){ - Map fieldMap = new HashMap<>(); - // Gards_Nucl_Lines_Ided - fieldMap.put("nuclideFullname","nuclidefullname");fieldMap.put("Energy","energy"); - fieldMap.put("Abundance","abundance");fieldMap.put("Activity","activity"); - fieldMap.put("Effic","effic");fieldMap.put("uncEffic","unEffic"); - fieldMap.put("Mda","mda");fieldMap.put("key_flag","keyFlag"); - fieldMap.put("csc_ratio","cscRatio");fieldMap.put("csc_ratio_err","cscRatioErr"); - fieldMap.put("csc_mod_flag","cscModFlag");fieldMap.put("MDC","mdc"); - fieldMap.put("Concentration","concentration"); - // Gards_Nucl_Ided - fieldMap.put("nucl_ided_Nucidename","nuclideName");fieldMap.put("nucl_ided_Type","type"); - fieldMap.put("nucl_ided_Halflife","halflife");fieldMap.put("nucl_ided_ave_activ","aveActiv"); - fieldMap.put("nucl_ided_ave_activ_err","aveActivErr");fieldMap.put("nucl_ided_activ_key","activKey"); - fieldMap.put("nucl_ided_activ_key_err","activKeyErr");fieldMap.put("nucl_ided_mda","mda"); - fieldMap.put("nucl_ided_mda_err","mdaErr");fieldMap.put("nucl_ided_nid_flag","nidFlag"); - fieldMap.put("nucl_ided_csc_ratio","cscRatio");fieldMap.put("nucl_ided_csc_ratio_err","cscRatioErr"); - fieldMap.put("nucl_ided_csc_mod_flag","cscModFlag");fieldMap.put("nucl_ided_MDC","mdc"); - fieldMap.put("nucl_ided_Concentration","concentration");fieldMap.put("nucl_ided_Key_Energy","keyEnergy"); - fieldMap.put("nucl_ided_Key_Yield","keyYield"); - // Gards_Qc_Check - fieldMap.put("QC_CHECK_QC_NAME","qcName"); - fieldMap.put("QC_CHECK_QC_VALUE","qcValue"); - fieldMap.put("QC_CHECK_QC_STANDARD","qcStandard"); - fieldMap.put("QC_CHECK_QC_RESULT","qcResult"); - // Gards_Peaks - fieldMap.put("peaks_idPeak", "idPeak"); - fieldMap.put("peaks_peakCentroid", "centroidChannel"); - fieldMap.put("peaks_uncpeakCentroid", "uncCentroidChannel"); - fieldMap.put("peaks_Energy", "energy"); - fieldMap.put("peaks_uncEnergy", "uncEnergy"); - fieldMap.put("peaks_Area", "area"); - fieldMap.put("peaks_areaErr", "uncArea"); - fieldMap.put("peaks_netCountRate", "netCountRate"); - fieldMap.put("peaks_uncNetCountRate", "uncNetCountRate"); - fieldMap.put("peaks_Efficiency", "efficiency"); - fieldMap.put("peaks_Uncefficiency", "uncefficiency"); - fieldMap.put("peaks_Fwhm", "fwhm"); - fieldMap.put("peaks_Fwhmc", "fwtm"); - fieldMap.put("peaks_Significance", "significance"); - fieldMap.put("peaks_Sensitivity", "sensitivity"); - fieldMap.put("peaks_multiIndex", "mulitiIndex"); - fieldMap.put("peaks_ROIstart", "roiStart"); - fieldMap.put("peaks_ROIend", "roiEnd"); - fieldMap.put("peaks_tail", "tail"); - fieldMap.put("peaks_tailAlpha", "tailAlpha"); - fieldMap.put("peaks_upperTail", "upperTail"); - fieldMap.put("peaks_upperTailAlpha", "upperTailAlpha"); - fieldMap.put("peaks_BWWidthChan", "bwwidthchan"); - fieldMap.put("peaks_recoilDeltaChan", "recoildeltachan"); - fieldMap.put("peaks_stepRatio", "stepraio"); - fieldMap.put("peaks_backgroundArea", "backgroundarea"); - fieldMap.put("peaks_meanBackCount", "meanbackcount"); - fieldMap.put("peaks_Lc", "lc"); - fieldMap.put("peaks_Ld", "ld"); - // GARDS_CALIBRATION_PAIRS - fieldMap.put("calibration_pairs_E_idCalPoint","idCalPoint"); - fieldMap.put("calibration_pairs_E_xValue","xValue"); - fieldMap.put("calibration_pairs_E_yValue","yValue"); - fieldMap.put("calibration_pairs_E_uncYValue","uncYValue"); - fieldMap.put("calibration_pairs_EF_idCalPoint","idCalPoint"); - fieldMap.put("calibration_pairs_EF_xValue","xValue"); - fieldMap.put("calibration_pairs_EF_yValue","yValue"); - fieldMap.put("calibration_pairs_EF_uncYValue","uncYValue"); - fieldMap.put("calibration_pairs_R_idCalPoint","idCalPoint"); - fieldMap.put("calibration_pairs_R_xValue","xValue"); - fieldMap.put("calibration_pairs_R_yValue","yValue"); - fieldMap.put("calibration_pairs_R_uncYValue","uncYValue"); - fieldMap.put("calibration_pairs_T_idCalPoint","idCalPoint"); - fieldMap.put("calibration_pairs_T_xValue","xValue"); - fieldMap.put("calibration_pairs_T_yValue","yValue"); - fieldMap.put("calibration_pairs_T_uncYValue","uncYValue"); - return fieldMap; - } + public Map fieldMap(){ + Map fieldMap = new HashMap<>(); + // Gards_Nucl_Lines_Ided + fieldMap.put("nuclideFullname","nuclidefullname");fieldMap.put("Energy","energy"); + fieldMap.put("Abundance","abundance");fieldMap.put("Activity","activity"); + fieldMap.put("Effic","effic");fieldMap.put("uncEffic","unEffic"); + fieldMap.put("Mda","mda");fieldMap.put("key_flag","keyFlag"); + fieldMap.put("csc_ratio","cscRatio");fieldMap.put("csc_ratio_err","cscRatioErr"); + fieldMap.put("csc_mod_flag","cscModFlag");fieldMap.put("MDC","mdc"); + fieldMap.put("Concentration","concentration"); + // Gards_Nucl_Ided + fieldMap.put("nucl_ided_Nucidename","nuclideName");fieldMap.put("nucl_ided_Type","type"); + fieldMap.put("nucl_ided_Halflife","halflife");fieldMap.put("nucl_ided_ave_activ","aveActiv"); + fieldMap.put("nucl_ided_ave_activ_err","aveActivErr");fieldMap.put("nucl_ided_activ_key","activKey"); + fieldMap.put("nucl_ided_activ_key_err","activKeyErr");fieldMap.put("nucl_ided_mda","mda"); + fieldMap.put("nucl_ided_mda_err","mdaErr");fieldMap.put("nucl_ided_nid_flag","nidFlag"); + fieldMap.put("nucl_ided_csc_ratio","cscRatio");fieldMap.put("nucl_ided_csc_ratio_err","cscRatioErr"); + fieldMap.put("nucl_ided_csc_mod_flag","cscModFlag");fieldMap.put("nucl_ided_MDC","mdc"); + fieldMap.put("nucl_ided_Concentration","concentration");fieldMap.put("nucl_ided_Key_Energy","keyEnergy"); + fieldMap.put("nucl_ided_Key_Yield","keyYield"); + // Gards_Qc_Check + fieldMap.put("QC_CHECK_QC_NAME","qcName"); + fieldMap.put("QC_CHECK_QC_VALUE","qcValue"); + fieldMap.put("QC_CHECK_QC_STANDARD","qcStandard"); + fieldMap.put("QC_CHECK_QC_RESULT","qcResult"); + // Gards_Peaks + fieldMap.put("peaks_idPeak", "idPeak"); + fieldMap.put("peaks_peakCentroid", "centroidChannel"); + fieldMap.put("peaks_uncpeakCentroid", "uncCentroidChannel"); + fieldMap.put("peaks_Energy", "energy"); + fieldMap.put("peaks_uncEnergy", "uncEnergy"); + fieldMap.put("peaks_Area", "area"); + fieldMap.put("peaks_areaErr", "uncArea"); + fieldMap.put("peaks_netCountRate", "netCountRate"); + fieldMap.put("peaks_uncNetCountRate", "uncNetCountRate"); + fieldMap.put("peaks_Efficiency", "efficiency"); + fieldMap.put("peaks_Uncefficiency", "uncefficiency"); + fieldMap.put("peaks_Fwhm", "fwhm"); + fieldMap.put("peaks_Fwhmc", "fwtm"); + fieldMap.put("peaks_Significance", "significance"); + fieldMap.put("peaks_Sensitivity", "sensitivity"); + fieldMap.put("peaks_multiIndex", "mulitiIndex"); + fieldMap.put("peaks_ROIstart", "roiStart"); + fieldMap.put("peaks_ROIend", "roiEnd"); + fieldMap.put("peaks_tail", "tail"); + fieldMap.put("peaks_tailAlpha", "tailAlpha"); + fieldMap.put("peaks_upperTail", "upperTail"); + fieldMap.put("peaks_upperTailAlpha", "upperTailAlpha"); + fieldMap.put("peaks_BWWidthChan", "bwwidthchan"); + fieldMap.put("peaks_recoilDeltaChan", "recoildeltachan"); + fieldMap.put("peaks_stepRatio", "stepraio"); + fieldMap.put("peaks_backgroundArea", "backgroundarea"); + fieldMap.put("peaks_meanBackCount", "meanbackcount"); + fieldMap.put("peaks_Lc", "lc"); + fieldMap.put("peaks_Ld", "ld"); + // GARDS_CALIBRATION_PAIRS + fieldMap.put("calibration_pairs_E_idCalPoint","idCalPoint"); + fieldMap.put("calibration_pairs_E_xValue","xValue"); + fieldMap.put("calibration_pairs_E_yValue","yValue"); + fieldMap.put("calibration_pairs_E_uncYValue","uncYValue"); + fieldMap.put("calibration_pairs_EF_idCalPoint","idCalPoint"); + fieldMap.put("calibration_pairs_EF_xValue","xValue"); + fieldMap.put("calibration_pairs_EF_yValue","yValue"); + fieldMap.put("calibration_pairs_EF_uncYValue","uncYValue"); + fieldMap.put("calibration_pairs_R_idCalPoint","idCalPoint"); + fieldMap.put("calibration_pairs_R_xValue","xValue"); + fieldMap.put("calibration_pairs_R_yValue","yValue"); + fieldMap.put("calibration_pairs_R_uncYValue","uncYValue"); + fieldMap.put("calibration_pairs_T_idCalPoint","idCalPoint"); + fieldMap.put("calibration_pairs_T_xValue","xValue"); + fieldMap.put("calibration_pairs_T_yValue","yValue"); + fieldMap.put("calibration_pairs_T_uncYValue","uncYValue"); + return fieldMap; + } - public PHDFile getSettingFromDB(PHDFile phdFile){ - Map mapSetting = serviceQuotes.getGammaDefaultParamsService() - .mapSetting(); - SpecSetup setting = phdFile.getSetting(); - String BaseImprovePSS = mapSetting.get(Setting.BASEIMPROVEPSS); - if (StrUtil.isNotBlank(BaseImprovePSS)) - setting.setBaseImprovePSS(Double.parseDouble(BaseImprovePSS)); - String CalibrationPSS_low = mapSetting.get(Setting.CALIBRATIONPSS_LOW); - if (StrUtil.isNotBlank(CalibrationPSS_low)) - setting.setCalibrationPSS_low(Double.parseDouble(CalibrationPSS_low)); - String CalibrationPSS_high = mapSetting.get(Setting.CALIBRATIONPSS_HIGH); - if (StrUtil.isNotBlank(CalibrationPSS_high)) - setting.setCalibrationPSS_high(Double.parseDouble(CalibrationPSS_high)); - String ECutAnalysis_High = mapSetting.get(Setting.ECUTANALYSIS_HIGH); - if (StrUtil.isNotBlank(ECutAnalysis_High)){ - setting.setECutAnalysis_High(Double.parseDouble(ECutAnalysis_High)); - }else { - setting.setECutAnalysis_High(Double.POSITIVE_INFINITY); - } - String systemType = energySpectrumStruct.system_type; - if (StrUtil.equals(systemType, SpectrumSystemType.P.name())){ - String ECutAnalysis_Low = mapSetting.get(Setting.ECUTANALYSIS_LOW_P); - if (StrUtil.isNotBlank(ECutAnalysis_Low)) - setting.setECutAnalysis_Low(Double.parseDouble(ECutAnalysis_Low)); - String bUpdateCal_P = mapSetting.get(Setting.BUPDATECAL_P); - setting.setBUpdateCal(StrUtil.equals(bUpdateCal_P, "1")); - }else { - String ECutAnalysis_Low = mapSetting.get(Setting.ECUTANALYSIS_LOW_G); - if (StrUtil.isNotBlank(ECutAnalysis_Low)) - setting.setECutAnalysis_Low(Double.parseDouble(ECutAnalysis_Low)); - String bUpdateCal_G = mapSetting.get(Setting.BUPDATECAL_G); - setting.setBUpdateCal(StrUtil.equals(bUpdateCal_G, "1")); - } - String EnergyTolerance = mapSetting.get(Setting.ENERGYTOLERANCE); - if (StrUtil.isNotBlank(EnergyTolerance)) - setting.setEnergyTolerance(Double.parseDouble(EnergyTolerance)); - String KeepCalPeakSearchPeaks = mapSetting.get(Setting.KEEPCALPEAKSERCHPEAKS); - setting.setKeepCalPeakSearchPeaks(StrUtil.equals(KeepCalPeakSearchPeaks,"1")); - String k_alpha = mapSetting.get(Setting.K_ALPHA); - if (StrUtil.isNotBlank(k_alpha)) - setting.setK_alpha(Double.parseDouble(k_alpha)); - String k_back = mapSetting.get(Setting.K_BACK); - if (StrUtil.isNotBlank(k_back)) - setting.setK_back(Double.parseDouble(k_back)); - String k_beta = mapSetting.get(Setting.K_BETA); - if (StrUtil.isNotBlank(k_beta)) - setting.setK_beta(Double.parseDouble(k_beta)); - String PSS_low = mapSetting.get(Setting.PSS_LOW); - if (StrUtil.isNotBlank(PSS_low)) - setting.setPss_low(Double.parseDouble(PSS_low)); - String RiskLevelK = mapSetting.get(Setting.RISKLEVELK); - if (StrUtil.isNotBlank(RiskLevelK)) - setting.setRiskLevelK(Double.parseDouble(RiskLevelK)); - return phdFile; - } + public PHDFile getSettingFromDB(PHDFile phdFile){ + Map mapSetting = serviceQuotes.getGammaDefaultParamsService() + .mapSetting(); + SpecSetup setting = phdFile.getSetting(); + String BaseImprovePSS = mapSetting.get(Setting.BASEIMPROVEPSS); + if (StrUtil.isNotBlank(BaseImprovePSS)) + setting.setBaseImprovePSS(Double.parseDouble(BaseImprovePSS)); + String CalibrationPSS_low = mapSetting.get(Setting.CALIBRATIONPSS_LOW); + if (StrUtil.isNotBlank(CalibrationPSS_low)) + setting.setCalibrationPSS_low(Double.parseDouble(CalibrationPSS_low)); + String CalibrationPSS_high = mapSetting.get(Setting.CALIBRATIONPSS_HIGH); + if (StrUtil.isNotBlank(CalibrationPSS_high)) + setting.setCalibrationPSS_high(Double.parseDouble(CalibrationPSS_high)); + String ECutAnalysis_High = mapSetting.get(Setting.ECUTANALYSIS_HIGH); + if (StrUtil.isNotBlank(ECutAnalysis_High)){ + setting.setECutAnalysis_High(Double.parseDouble(ECutAnalysis_High)); + }else { + setting.setECutAnalysis_High(Double.POSITIVE_INFINITY); + } + String systemType = energySpectrumStruct.system_type; + if (StrUtil.equals(systemType, SpectrumSystemType.P.name())){ + String ECutAnalysis_Low = mapSetting.get(Setting.ECUTANALYSIS_LOW_P); + if (StrUtil.isNotBlank(ECutAnalysis_Low)) + setting.setECutAnalysis_Low(Double.parseDouble(ECutAnalysis_Low)); + String bUpdateCal_P = mapSetting.get(Setting.BUPDATECAL_P); + setting.setBUpdateCal(StrUtil.equals(bUpdateCal_P, "1")); + }else { + String ECutAnalysis_Low = mapSetting.get(Setting.ECUTANALYSIS_LOW_G); + if (StrUtil.isNotBlank(ECutAnalysis_Low)) + setting.setECutAnalysis_Low(Double.parseDouble(ECutAnalysis_Low)); + String bUpdateCal_G = mapSetting.get(Setting.BUPDATECAL_G); + setting.setBUpdateCal(StrUtil.equals(bUpdateCal_G, "1")); + } + String EnergyTolerance = mapSetting.get(Setting.ENERGYTOLERANCE); + if (StrUtil.isNotBlank(EnergyTolerance)) + setting.setEnergyTolerance(Double.parseDouble(EnergyTolerance)); + String KeepCalPeakSearchPeaks = mapSetting.get(Setting.KEEPCALPEAKSERCHPEAKS); + setting.setKeepCalPeakSearchPeaks(StrUtil.equals(KeepCalPeakSearchPeaks,"1")); + String k_alpha = mapSetting.get(Setting.K_ALPHA); + if (StrUtil.isNotBlank(k_alpha)) + setting.setK_alpha(Double.parseDouble(k_alpha)); + String k_back = mapSetting.get(Setting.K_BACK); + if (StrUtil.isNotBlank(k_back)) + setting.setK_back(Double.parseDouble(k_back)); + String k_beta = mapSetting.get(Setting.K_BETA); + if (StrUtil.isNotBlank(k_beta)) + setting.setK_beta(Double.parseDouble(k_beta)); + String PSS_low = mapSetting.get(Setting.PSS_LOW); + if (StrUtil.isNotBlank(PSS_low)) + setting.setPss_low(Double.parseDouble(PSS_low)); + String RiskLevelK = mapSetting.get(Setting.RISKLEVELK); + if (StrUtil.isNotBlank(RiskLevelK)) + setting.setRiskLevelK(Double.parseDouble(RiskLevelK)); + return phdFile; + } - private GardsAnalyses toAnalysis(GStoreMiddleProcessData middleData){ - GardsAnalyses gardsAnalyses = new GardsAnalyses(); - String dateTime = DateConstant.DATE_BIAS_TIME; - String analysisBegin = middleData.getAnalyses_analysisBegin(); - Date analysis_Begin = DateUtil.parse(analysisBegin, dateTime) - .toJdkDate(); - gardsAnalyses.setAnalysisBegin(analysis_Begin); - String analysisEnd = middleData.getAnalyses_analysisEnd(); - Date analysis_End = DateUtil.parse(analysisEnd, dateTime) - .toJdkDate(); - gardsAnalyses.setAnalysisEnd(analysis_End); - gardsAnalyses.setType(middleData.getAnalyses_type()); - gardsAnalyses.setSoftware(middleData.getAnalyses_software()); - gardsAnalyses.setSwVersion(middleData.getAnalyses_swVersion()); - gardsAnalyses.setAnalyst(middleData.getAnalyses_analyst()); - gardsAnalyses.setComments(middleData.getAnalyses_comments()); - gardsAnalyses.setSearchStartChannel((int)middleData.getAnalyses_searchStartChannel()); - gardsAnalyses.setSearchEndChannel((int)middleData.getAnalyses_searchEndChannel()); - gardsAnalyses.setSearchThreshold(middleData.getAnalyses_searchThreshold()); - gardsAnalyses.setNumberOfPeaks((int) middleData.getAnalyses_numberOfPeaks()); - gardsAnalyses.setTotalCounts((float) middleData.getAnalyses_totalCounts()); - gardsAnalyses.setBaselinePath(middleData.getAnalyses_baseline_filePath()); - gardsAnalyses.setLcPath(middleData.getAnalyses_lc_filePath()); - gardsAnalyses.setScacPath(middleData.getAnalyses_scac_filePath()); - gardsAnalyses.setLogPath(middleData.getAnalyses_LogPath()); - gardsAnalyses.setReportPath(middleData.getAnalyses_ReportPath()); - return gardsAnalyses; - } + private GardsAnalyses toAnalysis(GStoreMiddleProcessData middleData){ + GardsAnalyses gardsAnalyses = new GardsAnalyses(); + String dateTime = DateConstant.DATE_BIAS_TIME; + String analysisBegin = middleData.getAnalyses_analysisBegin(); + Date analysis_Begin = DateUtil.parse(analysisBegin, dateTime) + .toJdkDate(); + gardsAnalyses.setAnalysisBegin(analysis_Begin); + String analysisEnd = middleData.getAnalyses_analysisEnd(); + Date analysis_End = DateUtil.parse(analysisEnd, dateTime) + .toJdkDate(); + gardsAnalyses.setAnalysisEnd(analysis_End); + gardsAnalyses.setType(middleData.getAnalyses_type()); + gardsAnalyses.setSoftware(middleData.getAnalyses_software()); + gardsAnalyses.setSwVersion(middleData.getAnalyses_swVersion()); + gardsAnalyses.setAnalyst(middleData.getAnalyses_analyst()); + gardsAnalyses.setComments(middleData.getAnalyses_comments()); + gardsAnalyses.setSearchStartChannel((int)middleData.getAnalyses_searchStartChannel()); + gardsAnalyses.setSearchEndChannel((int)middleData.getAnalyses_searchEndChannel()); + gardsAnalyses.setSearchThreshold(middleData.getAnalyses_searchThreshold()); + gardsAnalyses.setNumberOfPeaks((int) middleData.getAnalyses_numberOfPeaks()); + gardsAnalyses.setTotalCounts((float) middleData.getAnalyses_totalCounts()); + gardsAnalyses.setBaselinePath(middleData.getAnalyses_baseline_filePath()); + gardsAnalyses.setLcPath(middleData.getAnalyses_lc_filePath()); + gardsAnalyses.setScacPath(middleData.getAnalyses_scac_filePath()); + gardsAnalyses.setLogPath(middleData.getAnalyses_LogPath()); + gardsAnalyses.setReportPath(middleData.getAnalyses_ReportPath()); + return gardsAnalyses; + } - public List mapFields(T1 source, T2 tartget, String baseLine, Map fieldMap) { - try { - List result = new ArrayList<>(); - Class sourceClass = source.getClass(); - boolean isNumber = NumberUtil.isNumber(baseLine); - int total; - if (isNumber){ - total = Integer.parseInt(baseLine); - }else { - Field declaredField = sourceClass.getDeclaredField(baseLine); - declaredField.setAccessible(true); - List baseList = (List) declaredField.get(source); - if (CollUtil.isEmpty(baseList)) - return result; - total = baseList.size(); - } - Class tartgetClass = (Class) tartget.getClass(); - Field[] sourceFields = sourceClass.getDeclaredFields(); - for (int i = 0; i < total; i++) { - tartget = tartgetClass.newInstance(); - for (Field sourceField : sourceFields) { - sourceField.setAccessible(true); - List sourceList = (List) sourceField.get(source); - if (CollUtil.isEmpty(sourceList)) - continue; - if (sourceList.size() <= i) - continue; - String value = sourceList.get(i); - if (StrUtil.isNotBlank(value)){ - String sourceFieldName = sourceField.getName(); - String targetFieldName = fieldMap.get(sourceFieldName); - targetFieldName = StrUtil.isBlank(targetFieldName) ? sourceFieldName : targetFieldName; - Field tartgetField = tartgetClass.getDeclaredField(targetFieldName); - tartgetField.setAccessible(true); - Class type = tartgetField.getType(); - if (type == String.class) { - tartgetField.set(tartget, value); - } else if (type == Integer.class || type == int.class) { - tartgetField.set(tartget,Integer.valueOf(value)); - } else if (type == Double.class || type == double.class) { - tartgetField.set(tartget,Double.valueOf(value)); - } else if (type == Boolean.class || type == boolean.class) { - tartgetField.set(tartget, Boolean.valueOf(value)); - } - } - } - result.add(tartget); - } - return result; - } catch (Exception e) { - e.printStackTrace(); - return new ArrayList<>(); - } - } + public List mapFields(T1 source, T2 tartget, String baseLine, Map fieldMap) { + try { + List result = new ArrayList<>(); + Class sourceClass = source.getClass(); + boolean isNumber = NumberUtil.isNumber(baseLine); + int total; + if (isNumber){ + total = Integer.parseInt(baseLine); + }else { + Field declaredField = sourceClass.getDeclaredField(baseLine); + declaredField.setAccessible(true); + List baseList = (List) declaredField.get(source); + if (CollUtil.isEmpty(baseList)) + return result; + total = baseList.size(); + } + Class tartgetClass = (Class) tartget.getClass(); + Field[] sourceFields = sourceClass.getDeclaredFields(); + for (int i = 0; i < total; i++) { + tartget = tartgetClass.newInstance(); + for (Field sourceField : sourceFields) { + sourceField.setAccessible(true); + List sourceList = (List) sourceField.get(source); + if (CollUtil.isEmpty(sourceList)) + continue; + if (sourceList.size() <= i) + continue; + String value = sourceList.get(i); + if (StrUtil.isNotBlank(value)){ + String sourceFieldName = sourceField.getName(); + String targetFieldName = fieldMap.get(sourceFieldName); + targetFieldName = StrUtil.isBlank(targetFieldName) ? sourceFieldName : targetFieldName; + Field tartgetField = tartgetClass.getDeclaredField(targetFieldName); + tartgetField.setAccessible(true); + Class type = tartgetField.getType(); + if (type == String.class) { + tartgetField.set(tartget, value); + } else if (type == Integer.class || type == int.class) { + tartgetField.set(tartget,Integer.valueOf(value)); + } else if (type == Double.class || type == double.class) { + tartgetField.set(tartget,Double.valueOf(value)); + } else if (type == Boolean.class || type == boolean.class) { + tartgetField.set(tartget, Boolean.valueOf(value)); + } + } + } + result.add(tartget); + } + return result; + } catch (Exception e) { + e.printStackTrace(); + return new ArrayList<>(); + } + } - private void setPHDFile(PHDFile phdFile, EnergySpectrumStruct spectrumStruct) { - HeaderBlock headerBlock = new HeaderBlock(); - BeanUtil.copyProperties(spectrumStruct, headerBlock); - phdFile.setHeader(headerBlock); + private void setPHDFile(PHDFile phdFile, EnergySpectrumStruct spectrumStruct) { + HeaderBlock headerBlock = new HeaderBlock(); + BeanUtil.copyProperties(spectrumStruct, headerBlock); + phdFile.setHeader(headerBlock); - CollectionBlock collectionBlock = new CollectionBlock(); - BeanUtil.copyProperties(spectrumStruct, collectionBlock); - phdFile.setCollect(collectionBlock); + CollectionBlock collectionBlock = new CollectionBlock(); + BeanUtil.copyProperties(spectrumStruct, collectionBlock); + phdFile.setCollect(collectionBlock); - // MessageInfo - MessageInfo messageInfo = new MessageInfo(); - BeanUtil.copyProperties(spectrumStruct, messageInfo); - phdFile.setMsgInfo(messageInfo); - // AcquisitionBlock - AcquisitionBlock acquisitionBlock = new AcquisitionBlock(); - BeanUtil.copyProperties(spectrumStruct, acquisitionBlock); - phdFile.setAcq(acquisitionBlock); - // GSpectrumBlock - GSpectrumBlock gSpectrumBlock = new GSpectrumBlock(); - BeanUtil.copyProperties(spectrumStruct, gSpectrumBlock); - phdFile.setSpec(gSpectrumBlock); - // ProcessingBlock - ProcessingBlock processingBlock = new ProcessingBlock(); - BeanUtil.copyProperties(spectrumStruct, processingBlock); - phdFile.setProcess(processingBlock); - // CalibrationBlock - CalibrationBlock calibrationBlock = new CalibrationBlock(); - BeanUtil.copyProperties(spectrumStruct, calibrationBlock); - phdFile.setCalibration(calibrationBlock); - // SampleBlock - SampleBlock sampleBlock = new SampleBlock(); - BeanUtil.copyProperties(spectrumStruct, sampleBlock); - phdFile.setSampleBlock(sampleBlock); - // CertificateBlock - CertificateBlock certificateBlock = new CertificateBlock(); - BeanUtil.copyProperties(spectrumStruct, certificateBlock); - phdFile.setCertificate(certificateBlock); - } + // MessageInfo + MessageInfo messageInfo = new MessageInfo(); + BeanUtil.copyProperties(spectrumStruct, messageInfo); + phdFile.setMsgInfo(messageInfo); + // AcquisitionBlock + AcquisitionBlock acquisitionBlock = new AcquisitionBlock(); + BeanUtil.copyProperties(spectrumStruct, acquisitionBlock); + phdFile.setAcq(acquisitionBlock); + // GSpectrumBlock + GSpectrumBlock gSpectrumBlock = new GSpectrumBlock(); + BeanUtil.copyProperties(spectrumStruct, gSpectrumBlock); + phdFile.setSpec(gSpectrumBlock); + // ProcessingBlock + ProcessingBlock processingBlock = new ProcessingBlock(); + BeanUtil.copyProperties(spectrumStruct, processingBlock); + phdFile.setProcess(processingBlock); + // CalibrationBlock + CalibrationBlock calibrationBlock = new CalibrationBlock(); + BeanUtil.copyProperties(spectrumStruct, calibrationBlock); + phdFile.setCalibration(calibrationBlock); + // SampleBlock + SampleBlock sampleBlock = new SampleBlock(); + BeanUtil.copyProperties(spectrumStruct, sampleBlock); + phdFile.setSampleBlock(sampleBlock); + // CertificateBlock + CertificateBlock certificateBlock = new CertificateBlock(); + BeanUtil.copyProperties(spectrumStruct, certificateBlock); + phdFile.setCertificate(certificateBlock); + } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SamplephdSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SamplephdSpectrum.java index 3ccf009b..1d518d60 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SamplephdSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SamplephdSpectrum.java @@ -8,16 +8,16 @@ import java.util.Objects; /** * 样品谱处理 */ -public class SamplephdSpectrum extends S_D_Q_G_SpectrumHandler{ +public class SamplephdSpectrum extends AbstractS_D_Q_G_SpectrumHandler { /** * 设置过滤链路 */ @Override protected void setChina() { - SpectrumHandler spectrumHandler = new DetbkphdSpectrum(); - spectrumHandler.initNext(super.spectrumServiceQuotes,super.mailFile, - super.currDataType,super.ftpUtil,super.mailContent); + AbstractSpectrumHandler spectrumHandler = new DetbkphdSpectrum(); + spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile, + super.currDataType,super.mailContent); spectrumHandler.setPrevious(this); super.setNext(spectrumHandler); } @@ -39,8 +39,8 @@ public class SamplephdSpectrum extends S_D_Q_G_SpectrumHandler{ super.parseingEmail(); //读取邮件内容标签 super.readFileLabel(); - //保存PHD文件到ftp - super.saveFileToFtp(); + //保存PHD文件到savefile + super.saveFileToSavefile(); //结构体数据入库 super.handlerOriginalData(); //进行B、G(P)谱分析 @@ -55,7 +55,7 @@ public class SamplephdSpectrum extends S_D_Q_G_SpectrumHandler{ super.status = SampleStatus.FAIL.getValue(); super.updateStatus(); - //处理解析失败的文件,上传到ftp->undeal目录 + //处理解析失败的文件,上传到undeal目录 super.handleParseingFailFile(); throw e; }finally { @@ -79,9 +79,9 @@ public class SamplephdSpectrum extends S_D_Q_G_SpectrumHandler{ Sample_B_Analysis bAnalysis = new Sample_B_Analysis(this); bAnalysis.analysis(); } - if (this.sourceData.system_type.equals(SystemType.PARTICULATE.getType()) || this.sourceData.system_type.equals(SystemType.GAMMA.getType())) { - Sample_G_Analysis sample_g_analysis = new Sample_G_Analysis(super.sourceData, super.spectrumServiceQuotes, super.sampleData,super.ftpUtil); - sample_g_analysis.analysis(); - } + if (this.sourceData.system_type.equals(SystemType.PARTICULATE.getType()) || this.sourceData.system_type.equals(SystemType.GAMMA.getType())) { + Sample_G_Analysis sample_g_analysis = new Sample_G_Analysis(super.sourceData, super.spectrumServiceQuotes, super.sampleData); + sample_g_analysis.analysis(); + } } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java index 7f3cd0f5..55cfc8b7 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java @@ -7,12 +7,13 @@ import org.jeecg.common.email.EmailServiceManager; import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.util.DateUtils; import org.jeecg.modules.email.EmailProperties; -import org.jeecg.modules.ftp.FTPProperties; -import org.jeecg.modules.ftp.FTPUtils; + import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeUtility; +import java.io.File; +import java.io.FileOutputStream; import java.util.Date; import java.util.concurrent.CountDownLatch; @@ -28,7 +29,7 @@ public class SpectrumParsingActuator implements Runnable{ private final static String MSG_TYPE = "MSG_TYPE DATA"; private final static String EMAIL_STOP = "STOP"; /** - * 存储到ftp的Email文件后缀 + * 存储到eml目录的Email文件后缀 */ private final static String SAVE_EML_SUFFIX = ".eml"; @@ -60,18 +61,10 @@ public class SpectrumParsingActuator implements Runnable{ * 邮件计数器 */ private EmailCounter emailCounter; - /** - * ftp工具 - */ - private FTPUtils ftpUtil; - /** - * FTP目录操作锁 - */ - private Object ftpOpierationLock; public void init(Message message, EmailProperties emailProperties,EmailServiceManager emailServiceManager, CountDownLatch taskLatch, SpectrumServiceQuotes spectrumServiceQuotes, - EmailCounter emailCounter,Object ftpOpierationLock){ + EmailCounter emailCounter){ this.message = message; this.emailProperties = emailProperties; this.emailServiceManager = emailServiceManager; @@ -79,11 +72,6 @@ public class SpectrumParsingActuator implements Runnable{ this.spectrumServiceQuotes = spectrumServiceQuotes; this.spectrumPathProperties = spectrumServiceQuotes.getSpectrumPathProperties(); this.emailCounter = emailCounter; - this.ftpOpierationLock = ftpOpierationLock; - //初始化FTP客户端对象 - final FTPProperties ftpProperties = spectrumServiceQuotes.getFtpProperties(); - ftpUtil = new FTPUtils(ftpProperties.getHost(),ftpProperties.getPort(),ftpProperties.getUserName(), - ftpProperties.getPassword(),ftpProperties.getEncoding(),ftpProperties.getFtpRootPath(),ftpOpierationLock); } @Override @@ -99,12 +87,12 @@ public class SpectrumParsingActuator implements Runnable{ System.out.println(subject); mailContent = new StringBuilder(); emailServiceManager.getMailContent(message,mailContent); - //所有邮件都需以.eml格式存储到ftp eml文件夹中 - downloadEmailToFtp(); + //所有邮件都需以.eml格式存储到eml文件夹中 + downloadEmailToEmlDir(); //判断是否是IMS2.0协议文件 if(checkMailContent(mailContent,subject)){ - SpectrumHandler spectrumHandler = new SamplephdSpectrum(); - spectrumHandler.init(mailContent.toString(),spectrumServiceQuotes,ftpUtil); + AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum(); + spectrumHandler.init(mailContent.toString(),spectrumServiceQuotes); final boolean matchResult = spectrumHandler.saveEmailToLocal(); if(matchResult){ //保存邮件解析日志到PG数据库 @@ -127,7 +115,6 @@ public class SpectrumParsingActuator implements Runnable{ e.printStackTrace(); } this.taskLatch.countDown(); - this.ftpUtil.close(); } } @@ -162,11 +149,11 @@ public class SpectrumParsingActuator implements Runnable{ } /** - * 把邮件下载到ftp指定文件夹(eml) + * 把邮件下载到eml目录 * 格式为:发件人_主题_年月日_时分秒毫秒_计数(0-10000) * 当计数大于10000后从0开始,服务重启后也从0开始 */ - private void downloadEmailToFtp() throws Exception{ + private void downloadEmailToEmlDir() throws Exception{ //获取发件人 final String address = ((InternetAddress) message.getFrom()[0]).getAddress(); final String from = address.substring(0,address.indexOf(StringConstant.AT)); @@ -190,6 +177,14 @@ public class SpectrumParsingActuator implements Runnable{ fileName.append(StringConstant.UNDER_LINE); fileName.append(emailCounter.getCurrValue()); fileName.append(SAVE_EML_SUFFIX); - ftpUtil.saveFile(spectrumPathProperties.getEmlPath(),fileName.toString(),message.getInputStream()); + final String rootPath = spectrumPathProperties.getRootPath(); + final String emlPath = spectrumPathProperties.getEmlPath(); + final File file = new File(rootPath+File.separator+emlPath+File.separator+fileName); + if(!file.exists()){ + file.setWritable(true); + file.setReadable(true); + file.createNewFile(); + } + message.writeTo(new FileOutputStream(file)); } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumServiceQuotes.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumServiceQuotes.java index 88018064..e4b5f0f8 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumServiceQuotes.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumServiceQuotes.java @@ -8,7 +8,6 @@ import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.properties.TaskProperties; import org.jeecg.common.util.RedisStreamUtil; import org.jeecg.modules.datasource.OraDataSourceProperties; -import org.jeecg.modules.ftp.FTPProperties; import org.jeecg.modules.service.*; import org.springframework.core.io.ResourceLoader; import org.springframework.jdbc.datasource.DataSourceTransactionManager; @@ -34,8 +33,6 @@ public class SpectrumServiceQuotes { private final TaskProperties taskProperties; - private final FTPProperties ftpProperties; - private final SpectrumPathProperties spectrumPathProperties; private final ParameterProperties parameterProperties; diff --git a/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/common/util/GammaFileUtil.java b/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/common/util/GammaFileUtil.java index 736fb321..412b83b4 100644 --- a/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/common/util/GammaFileUtil.java +++ b/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/common/util/GammaFileUtil.java @@ -1367,7 +1367,7 @@ public class GammaFileUtil extends AbstractLogOrReport { try { String phdStr = mapper.writeValueAsString(phd); String nuclideLinesMap = mapper.writeValueAsString(mapLines); - String strValue = CalValuesHandler.analyseSpectrum(phdStr, nuclideLinesMap, tmpFile.getAbsolutePath(), analysisProcess); + String strValue = CalValuesHandler.analyseSpectrum(phdStr, nuclideLinesMap, tmpFile.getAbsolutePath(), null); Map parseMap = JSON.parseObject(strValue, Map.class); for (Map.Entry entry:parseMap.entrySet()) { if (entry.getKey().equalsIgnoreCase("bAnalyed")) { @@ -2809,7 +2809,8 @@ public class GammaFileUtil extends AbstractLogOrReport { strBuffer.append(String.format("%s:%-30s%s", " RiskLevelK", StringPool.SPACE, String.valueOf(middleData.setting_specSetup.getRiskLevelK()))); //换行 strBuffer.append(System.lineSeparator()); - strBuffer.append(String.format("%s:%-30s%s", " refTime_act", StringPool.SPACE, DateUtils.formatDate(middleData.setting_specSetup.getRefTime_act()), "yyyy-MM-dd HH:mm:ss")); + Date refTimeAct = middleData.setting_specSetup.getRefTime_act(); + strBuffer.append(String.format("%s:%-30s%s", " refTime_act", StringPool.SPACE, DateUtils.formatDate(refTimeAct), "yyyy-MM-dd HH:mm:ss")); //换行 strBuffer.append(System.lineSeparator()); strBuffer.append(String.format("%s:%-30s%s", " refTime_conc", StringPool.SPACE, DateUtils.formatDate(middleData.setting_specSetup.getRefTime_conc(), "yyyy-MM-dd HH:mm:ss"))); @@ -3107,9 +3108,10 @@ public class GammaFileUtil extends AbstractLogOrReport { String qsSaveBaseLine = StringPool.SLASH+spectrumPathProperties.getSaveFilePath()+StringPool.SLASH+qsBaseLinePath; String qsSaveLc = StringPool.SLASH+spectrumPathProperties.getSaveFilePath()+StringPool.SLASH+qsLcPath; String qsSaveScac = StringPool.SLASH+spectrumPathProperties.getSaveFilePath()+StringPool.SLASH+qsScacPath; - GammaReportUtil.writeFile(fileAnlyse.getBaseCtrls(), qsSaveBaseLine); - GammaReportUtil.writeFile(fileAnlyse.getVLc(), "LC", qsSaveLc); - GammaReportUtil.writeFile(fileAnlyse.getVScac(), "SCSC", qsSaveScac); + String rootPath = spectrumPathProperties.getRootPath(); + GammaReportUtil.writeFile(fileAnlyse.getBaseCtrls(), rootPath + qsSaveBaseLine); + GammaReportUtil.writeFile(fileAnlyse.getVLc(), "LC", rootPath + qsSaveLc); + GammaReportUtil.writeFile(fileAnlyse.getVScac(), "SCSC", rootPath + qsSaveScac); // WriteBaseInfo(fileAnlyse.getBaseCtrls(),qsSaveBaseLine); // WriteLcScac(fileAnlyse.getVLc(),"Lc",qsSaveLc); // WriteLcScac(fileAnlyse.getVScac(),"Scac",qsSaveScac); @@ -4183,6 +4185,7 @@ public class GammaFileUtil extends AbstractLogOrReport { } public File analyzeFile(String path, String fileName) { + path = path.replace("\\","/"); //连接ftp FTPClient ftpClient = ftpUtil.LoginFTP(); InputStream inputStream = null; diff --git a/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java b/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java index 6e8c27b1..bf671ea6 100644 --- a/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java +++ b/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java @@ -1,8 +1,10 @@ package org.jeecg; +import cn.hutool.core.io.FileUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.FileUtils; +import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.properties.TaskProperties; import org.jeecg.common.util.DateUtils; import org.jeecg.common.util.oConvertUtils; @@ -37,6 +39,7 @@ import java.util.Date; @RequiredArgsConstructor public class JeecgAutoProcessApplication extends SpringBootServletInitializer implements CommandLineRunner { + private final SpectrumPathProperties spectrumPathProperties; private final TaskProperties taskProperties; private final AutoProcessManager autoProcessManager; private final UndealHandleManager undealHandleManager; @@ -72,17 +75,19 @@ public class JeecgAutoProcessApplication extends SpringBootServletInitializer im if(EmailReceivePolicy.CURR_DATE_ORDER_RECEIVE.getPolicy().equals(taskProperties.getReceivePolicy())){ systemStartupTime = new Date(); } - //校验临时存储目录是否存在 - checkTemporaryStorageDirectory(); - // autoProcessManager.start(systemStartupTime,ftpOpierationLock); - // undealHandleManager.start(ftpOpierationLock); - fileSourceHandleManager.start(ftpOpierationLock); + //校验临时存储目录是否存在,不存在则创建 + checkTempStorageDirectory(); + //校验存储目录是否存在,不存在则创建,存在无操作 + checkStorageDirectory(); + // autoProcessManager.start(systemStartupTime); + undealHandleManager.start(); + fileSourceHandleManager.start(); } /** * 校验临时存储目录是否存在,不存在则创建 */ - private void checkTemporaryStorageDirectory() throws IOException { + private void checkTempStorageDirectory() throws IOException { ApplicationHome home = new ApplicationHome(getClass()); File tempStorageDirectory = new File(home.getSource().getParentFile().getAbsolutePath()+File.separator+taskProperties.getTemporaryStoragePath()); if(!tempStorageDirectory.exists() || !tempStorageDirectory.isDirectory()){ @@ -92,7 +97,18 @@ public class JeecgAutoProcessApplication extends SpringBootServletInitializer im taskProperties.setTemporaryStoragePath(tempStorageDirectory.getAbsolutePath()); }else{ FileUtils.deleteDirectory(tempStorageDirectory); - checkTemporaryStorageDirectory(); + checkTempStorageDirectory(); } } + + /** + * 校验存储目录是否存在,不存在则创建,存在无操作 + */ + private void checkStorageDirectory() { + FileUtil.mkdir(spectrumPathProperties.getRootPath()+File.separator+spectrumPathProperties.getSaveFilePath()); + FileUtil.mkdir(spectrumPathProperties.getRootPath()+File.separator+spectrumPathProperties.getLogPath()); + FileUtil.mkdir(spectrumPathProperties.getRootPath()+File.separator+spectrumPathProperties.getUndealPath()); + FileUtil.mkdir(spectrumPathProperties.getRootPath()+File.separator+spectrumPathProperties.getFilesourcePath()); + FileUtil.mkdir(spectrumPathProperties.getRootPath()+File.separator+spectrumPathProperties.getEmlPath()); + } } \ No newline at end of file