fix:1.修改ftp文件管理改为本地文件管理
This commit is contained in:
parent
0e4d702b96
commit
b3f5f0d276
|
@ -127,7 +127,7 @@ public class EmailServiceManager {
|
|||
final int messageCount = folder.getMessageCount();
|
||||
if(messageCount > 0){
|
||||
SearchTerm searchTerm = new ReceivedDateTerm(ComparisonTerm.GE,this.systemStartupTime);
|
||||
Message[] messages = folder.search(searchTerm);
|
||||
Message[] messages = folder.getMessages(1,4);//folder.search(searchTerm);
|
||||
Arrays.sort(messages, (o1, o2) -> {
|
||||
try {
|
||||
return o1.getReceivedDate().compareTo(o2.getReceivedDate());
|
||||
|
|
|
@ -19,16 +19,21 @@ import java.util.Map;
|
|||
@ConfigurationProperties(prefix = "filesystem")
|
||||
public class SpectrumPathProperties implements Serializable {
|
||||
|
||||
/**
|
||||
* 存储根路径
|
||||
*/
|
||||
private String rootPath;
|
||||
|
||||
/**
|
||||
* 能谱文件存储路径
|
||||
*/
|
||||
private String saveFilePath;
|
||||
|
||||
/**
|
||||
* eml格式邮件存储路径
|
||||
*/
|
||||
private String emlPath;
|
||||
|
||||
/**
|
||||
* 能谱文件存储根路径
|
||||
*/
|
||||
private String rootPath;
|
||||
|
||||
/**
|
||||
* 日志文件存储路径
|
||||
*/
|
||||
|
@ -42,12 +47,12 @@ public class SpectrumPathProperties implements Serializable {
|
|||
/**
|
||||
* 用户上传文件路径
|
||||
*/
|
||||
private String uploadPath;;
|
||||
private String uploadPath;
|
||||
|
||||
/**
|
||||
* 能谱解析失败文件存储路径
|
||||
*/
|
||||
private String failPath;
|
||||
private String undealPath;
|
||||
|
||||
/**
|
||||
* 手动放置能谱文件获取路径
|
||||
|
@ -58,35 +63,4 @@ public class SpectrumPathProperties implements Serializable {
|
|||
* 能谱文件存储路径以能谱系统类型/能谱类型为key,以存储路径为value
|
||||
*/
|
||||
private Map<String,String> 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
//把邮件监测执行线程加入管理队列
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
@ -75,31 +63,25 @@ public class FileSourceHandleManager {
|
|||
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<String> fileNames = ftpUtil.getFiles(filePath, taskProperties.getFilesourceDirReceiveNum().intValue());
|
||||
ftpUtil.close();
|
||||
if(!CollectionUtils.isEmpty(fileNames)){
|
||||
CountDownLatch taskLatch = new CountDownLatch(fileNames.size());
|
||||
for(String fileName : fileNames){
|
||||
final String rootPath = spectrumServiceQuotes.getSpectrumPathProperties().getRootPath();
|
||||
final String filePath = spectrumServiceQuotes.getSpectrumPathProperties().getFilesourcePath();
|
||||
List<File> spectrumFiles = FileOperation.getFiles(rootPath+ File.separator+filePath,taskProperties.getFilesourceDirReceiveNum());
|
||||
if(!CollectionUtils.isEmpty(spectrumFiles)){
|
||||
CountDownLatch taskLatch = new CountDownLatch(spectrumFiles.size());
|
||||
for(File spectrumFile : spectrumFiles){
|
||||
//如果是Sample谱则延迟500毫秒后执行
|
||||
if(fileName.contains(BlockConstant.sampleFlag)){
|
||||
TimeUnit.MILLISECONDS.sleep(200);
|
||||
if(spectrumFile.getName().contains(BlockConstant.sampleFlag)){
|
||||
TimeUnit.MILLISECONDS.sleep(500);
|
||||
}
|
||||
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<String> 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<String> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String> fileNames = ftpUtil.getFiles(filePath, taskProperties.getUndealDirReceiveNum().intValue());
|
||||
ftpUtil.close();
|
||||
if(!CollectionUtils.isEmpty(fileNames)){
|
||||
CountDownLatch taskLatch = new CountDownLatch(fileNames.size());
|
||||
for(String fileName : fileNames){
|
||||
final String rootPath = spectrumServiceQuotes.getSpectrumPathProperties().getRootPath();
|
||||
final String filePath = spectrumServiceQuotes.getSpectrumPathProperties().getUndealPath();
|
||||
List<File> spectrumFiles = FileOperation.getFiles(rootPath+ File.separator+filePath,taskProperties.getFilesourceDirReceiveNum());
|
||||
if(!CollectionUtils.isEmpty(spectrumFiles)){
|
||||
CountDownLatch taskLatch = new CountDownLatch(spectrumFiles.size());
|
||||
for(File spectrumFile : spectrumFiles){
|
||||
//如果是Sample谱则延迟500毫秒后执行
|
||||
if(fileName.contains(BlockConstant.sampleFlag)){
|
||||
TimeUnit.MILLISECONDS.sleep(200);
|
||||
if(spectrumFile.getName().contains(BlockConstant.sampleFlag)){
|
||||
TimeUnit.MILLISECONDS.sleep(500);
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,149 @@
|
|||
package org.jeecg.modules.file;
|
||||
|
||||
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<String,String> dataTypeMap = Maps.newHashMap();
|
||||
|
||||
/**
|
||||
* 获取指定路径下指定数量的文件
|
||||
* @param path
|
||||
* @param receiveNum
|
||||
* @return
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
public static List<File> 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<File> 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 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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
|
||||
}
|
|
@ -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<String> 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<String> 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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* 是否匹配成功
|
|
@ -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<String> 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);
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user