Merge branch 'sleepDownload' into mdc
# Conflicts: # jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java # jeecg-boot-base-core/src/main/java/org/jeecg/common/util/TemplateUtil.java # jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/redisStream/AnalysisConsumer.java # jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java # jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java # jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/jobs/DatabaseJob.java # jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/jobs/ServerJob.java
This commit is contained in:
commit
d940f1d6e4
|
@ -1,16 +1,13 @@
|
|||
package org.jeecg.common.email;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sun.mail.imap.IMAPStore;
|
||||
import com.sun.mail.smtp.SMTPAddressFailedException;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.Charsets;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jeecg.common.api.dto.message.MessageDTO;
|
||||
import org.jeecg.common.constant.RedisConstant;
|
||||
|
@ -21,7 +18,6 @@ import org.jeecg.common.exception.DownloadEmailException;
|
|||
import org.jeecg.common.properties.SpectrumPathProperties;
|
||||
import org.jeecg.common.properties.TaskProperties;
|
||||
import org.jeecg.common.util.DateUtils;
|
||||
import org.jeecg.common.util.Md5Util;
|
||||
import org.jeecg.common.util.RedisUtil;
|
||||
import org.jeecg.modules.base.entity.postgre.SysEmail;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -36,6 +32,9 @@ import java.io.*;
|
|||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -70,6 +69,8 @@ public class EmailServiceManager {
|
|||
|
||||
private Object downloadEmlLocal = new Object();
|
||||
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
@NotNull
|
||||
public static EmailServiceManager getInstance(){
|
||||
return new EmailServiceManager();
|
||||
|
@ -609,6 +610,105 @@ public class EmailServiceManager {
|
|||
}
|
||||
}
|
||||
|
||||
/*public File downloadEmailToEmlDir(@NotNull Message message, Integer emailCounter, Integer batchesCounter) throws MessagingException, IOException {
|
||||
AtomicReference<FileOutputStream> outputStream = new AtomicReference<>();
|
||||
CompletableFuture<File> future = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
lock.lock(); // 获取锁
|
||||
// 执行需要获取锁才能进行的操作
|
||||
// return executeWithLock(message, emailCounter, batchesCounter);
|
||||
File file = executeWithLock(message, emailCounter, batchesCounter);
|
||||
outputStream.set(new FileOutputStream(file));
|
||||
a(outputStream,message);
|
||||
return null;
|
||||
} catch (MessagingException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
// 如果成功拿到锁 释放锁
|
||||
lock.unlock();
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
return future.get(5, TimeUnit.SECONDS);
|
||||
// return future.get(5, TimeUnit.SECONDS);// 等待任务执行,超过5秒则抛出TimeoutException
|
||||
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
||||
future.cancel(true); // 取消任务执行
|
||||
if (ObjectUtil.isNotNull(outputStream) && ObjectUtil.isNotNull(outputStream.get()))
|
||||
outputStream.get().close();
|
||||
log.error("下载 eml 执行超时", e);
|
||||
throw new RuntimeException("下载 eml 执行超时");
|
||||
}
|
||||
}*/
|
||||
public File executeWithLock(Message message,Integer emailCounter,Integer batchesCounter) throws MessagingException {
|
||||
|
||||
String subject = "";
|
||||
File emlFile = null;
|
||||
String status = EmailLogManager.STATUS_SUCCESS;
|
||||
Date receivedDate = null;
|
||||
try {
|
||||
// 获取锁 设置超时
|
||||
//获取发件人
|
||||
final String address = ((InternetAddress) message.getFrom()[0]).getAddress();
|
||||
final String from = address.substring(0,address.indexOf(StringConstant.AT));
|
||||
//获取主题
|
||||
subject = MimeUtility.decodeText(message.getSubject());
|
||||
if(subject.contains(StringConstant.SLASH)){
|
||||
subject = StringUtils.replace(subject,StringConstant.SLASH,"");
|
||||
}
|
||||
if(subject.contains(StringConstant.COLON)){
|
||||
subject = StringUtils.replace(subject,StringConstant.COLON,"");
|
||||
}
|
||||
receivedDate = message.getReceivedDate();
|
||||
StringBuilder fileName = new StringBuilder();
|
||||
fileName.append(from);
|
||||
fileName.append(StringConstant.UNDER_LINE);
|
||||
fileName.append(subject);
|
||||
fileName.append(StringConstant.UNDER_LINE);
|
||||
fileName.append(DateUtils.formatDate(new Date(),"YYMMdd"));
|
||||
fileName.append(StringConstant.UNDER_LINE);
|
||||
fileName.append(DateUtils.formatDate(new Date(),"HHmmssSSS"));
|
||||
fileName.append(StringConstant.UNDER_LINE);
|
||||
fileName.append("receive");
|
||||
fileName.append(StringConstant.UNDER_LINE);
|
||||
fileName.append(DateUtils.formatDate(receivedDate,"YYMMdd"));
|
||||
fileName.append(StringConstant.UNDER_LINE);
|
||||
fileName.append(DateUtils.formatDate(receivedDate,"HHmmssSSS"));
|
||||
fileName.append(StringConstant.UNDER_LINE);
|
||||
fileName.append(emailCounter);
|
||||
fileName.append(SAVE_EML_SUFFIX);
|
||||
final String rootPath = spectrumPathProperties.getRootPath();
|
||||
final String emlPath = spectrumPathProperties.getEmlPath();
|
||||
emlFile = new File(rootPath+emlPath+File.separator+fileName);
|
||||
// Thread.sleep(6000l);
|
||||
// try(FileOutputStream outputStream = new FileOutputStream(emlFile)) {
|
||||
// message.writeTo(outputStream);
|
||||
// } catch (IOException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
} catch (MessagingException | IOException e) {
|
||||
// 下载邮件失败 抛出自定义邮件下载异常
|
||||
status = EmailLogManager.STATUS_ERROR;
|
||||
String errorMsg = StrUtil.format("The email download failed, the subject of the email is {}, the reason is {}.", subject, e.getMessage());
|
||||
log.error(errorMsg);
|
||||
throw new DownloadEmailException(errorMsg);
|
||||
} catch (Exception e) {
|
||||
log.error("",e);
|
||||
} finally {
|
||||
EmailLogEvent event = new EmailLogEvent(batchesCounter,Thread.currentThread().getId(),EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETIDEML,subject,DateUtils.formatDate(receivedDate,"yyyy-MM-dd HH:mm:ss:SSS"),
|
||||
(Objects.isNull(emlFile)?" ":emlFile.getAbsolutePath()));
|
||||
EmailLogManager.getInstance().offer(Thread.currentThread().getId(),event);
|
||||
}
|
||||
return emlFile;
|
||||
}
|
||||
|
||||
public void a(AtomicReference<FileOutputStream> outputStream, Message message) throws MessagingException, IOException {
|
||||
message.writeTo(outputStream.get());
|
||||
}
|
||||
/**
|
||||
* 删除邮件
|
||||
* @param message
|
||||
|
@ -622,7 +722,7 @@ public class EmailServiceManager {
|
|||
subject = MimeUtility.decodeText(message.getSubject());
|
||||
receivedDate = message.getReceivedDate();
|
||||
message.setFlag(Flags.Flag.DELETED,true);
|
||||
// log.info("EmailServiceManager: Remove Email:{},receiveTime:{}",message.getSubject(), DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss"));
|
||||
// log.info("EmailServiceManager: Remove Email:{},receiveTime:{}",message.getSubject(), DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss"));
|
||||
} catch (MessagingException | UnsupportedEncodingException e) {
|
||||
status = EmailLogManager.STATUS_ERROR;
|
||||
log.error("Email deletion failed, the subject of the email is :{}, the reason is :{}.",subject,e.getMessage());
|
||||
|
@ -648,6 +748,7 @@ public class EmailServiceManager {
|
|||
if(null != store){
|
||||
store.close();
|
||||
}
|
||||
log.info("EmailServiceManage资源关闭完成.");
|
||||
// for(String messageId : messageIds){
|
||||
// String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId;
|
||||
// redisUtil.del(key);
|
||||
|
@ -668,7 +769,7 @@ public class EmailServiceManager {
|
|||
try {
|
||||
String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId;
|
||||
int numberKey = redisUtil.get(key) != null? (int) redisUtil.get(key):0;
|
||||
// exist = redisUtil.hasKey(key);
|
||||
// exist = redisUtil.hasKey(key);
|
||||
if(numberKey >= taskProperties.getForceDeletedNumber()){
|
||||
exist = true;
|
||||
log.info("Check: Remove Email:{},receiveTime:{}",message.getSubject(), DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss"));
|
||||
|
|
|
@ -281,39 +281,74 @@ public class FTPUtil {
|
|||
/**
|
||||
* 写入文件,若文件或文件目录不存在则自行创建
|
||||
* @param filePath 文件路径
|
||||
* @param fileName 文件名称
|
||||
* @param inputStream 文件输入流
|
||||
* @return 返回值true/false
|
||||
*/
|
||||
public synchronized boolean saveFile(String filePath,String fileName,InputStream inputStream){
|
||||
final FTPClient ftpClient = this.LoginFTP();
|
||||
try{
|
||||
final boolean flag = this.checkDirectory(ftpClient,filePath);
|
||||
if(flag){
|
||||
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
|
||||
String encodedName = new String(fileName.getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1);
|
||||
final boolean result = ftpClient.storeFile(encodedName, inputStream);
|
||||
return result;
|
||||
public synchronized boolean saveFile(String filePath, InputStream inputStream){
|
||||
//声明目标文件
|
||||
File targetFile = new File(filePath);
|
||||
//创建输出流
|
||||
FileOutputStream outputStream = null;
|
||||
try {
|
||||
//获取父级路径
|
||||
File directory = targetFile.getParentFile();
|
||||
//判断父级路径是否存在
|
||||
if (!directory.exists()) {
|
||||
directory.mkdirs();
|
||||
}
|
||||
}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();
|
||||
}
|
||||
// 创建输出流对象并写入数据到文件
|
||||
outputStream = new FileOutputStream(targetFile);
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = inputStream.read(buffer)) > 0) {
|
||||
outputStream.write(buffer, 0, length);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
// 关闭输入流和输出流
|
||||
try {
|
||||
ftpClient.disconnect();
|
||||
if (Objects.nonNull(inputStream)) {
|
||||
inputStream.close();
|
||||
}
|
||||
if (Objects.nonNull(outputStream)) {
|
||||
outputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
// final FTPClient ftpClient = this.LoginFTP();
|
||||
// try{
|
||||
// final boolean flag = this.checkDirectory(ftpClient,filePath);
|
||||
// if(flag){
|
||||
// ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
|
||||
// String encodedName = new String(fileName.getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1);
|
||||
// final boolean result = ftpClient.storeFile(encodedName, inputStream);
|
||||
// return result;
|
||||
// }
|
||||
// }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();
|
||||
// }
|
||||
// }
|
||||
// try {
|
||||
// ftpClient.disconnect();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -458,65 +493,85 @@ public class FTPUtil {
|
|||
/*
|
||||
* 将源FTP路径的文件保存为指定路径的临时文件
|
||||
* */
|
||||
public File downloadFile(String fromPath, String toPath) {
|
||||
FTPClient ftpClient = null;
|
||||
InputStream inputStream = null;
|
||||
// 声明一个临时文件
|
||||
File tempFile = null;
|
||||
try {
|
||||
ftpClient = LoginFTP();
|
||||
// 切换被动模式
|
||||
ftpClient.enterLocalPassiveMode();
|
||||
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
|
||||
// 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项
|
||||
ftpClient.setControlEncoding("UTF-8");
|
||||
ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE);
|
||||
inputStream = ftpClient.retrieveFileStream(fromPath);
|
||||
if (Objects.nonNull(inputStream)) {
|
||||
tempFile = File.createTempFile(toPath, null);
|
||||
// 将FTP文件的输入流复制给临时文件
|
||||
FileUtils.copyInputStreamToFile(inputStream, tempFile);
|
||||
}
|
||||
return tempFile;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
try {
|
||||
if (ObjectUtil.isNotNull(ftpClient))
|
||||
ftpClient.disconnect();
|
||||
if (ObjectUtil.isNotNull(inputStream))
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public File downloadFile(String fromPath) {
|
||||
//获取路径下的文件信息
|
||||
File tempFile = new File(fromPath);
|
||||
//判断文件是否存在
|
||||
if (!tempFile.exists()) {
|
||||
tempFile = null;
|
||||
}
|
||||
return tempFile;
|
||||
// FTPClient ftpClient = null;
|
||||
// InputStream inputStream = null;
|
||||
// // 声明一个临时文件
|
||||
// File tempFile = null;
|
||||
// try {
|
||||
// //连接ftp
|
||||
// ftpClient = LoginFTP();
|
||||
// // 切换被动模式
|
||||
// ftpClient.enterLocalPassiveMode();
|
||||
// ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
|
||||
// // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项
|
||||
// ftpClient.setControlEncoding("UTF-8");
|
||||
// ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE);
|
||||
// inputStream = ftpClient.retrieveFileStream(fromPath);
|
||||
// if (Objects.nonNull(inputStream)) {
|
||||
// tempFile = File.createTempFile(toPath, null);
|
||||
// // 将FTP文件的输入流复制给临时文件
|
||||
// FileUtils.copyInputStreamToFile(inputStream, tempFile);
|
||||
// }
|
||||
// return tempFile;
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// return null;
|
||||
// } finally {
|
||||
// try {
|
||||
// if (ObjectUtil.isNotNull(ftpClient))
|
||||
// ftpClient.disconnect();
|
||||
// if (ObjectUtil.isNotNull(inputStream))
|
||||
// inputStream.close();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/*
|
||||
* 将源FTP路径的文件转换为文件流
|
||||
* */
|
||||
public InputStream downloadFileStream(String fromPath) {
|
||||
FTPClient ftpClient = null;
|
||||
//获取路径下的文件信息
|
||||
File tempFile = new File(fromPath);
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
ftpClient = LoginFTP();
|
||||
// 切换被动模式
|
||||
ftpClient.enterLocalPassiveMode();
|
||||
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
|
||||
// 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项
|
||||
ftpClient.setControlEncoding("UTF-8");
|
||||
ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE);
|
||||
return ftpClient.retrieveFileStream(fromPath);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
try {
|
||||
if (ObjectUtil.isNotNull(ftpClient))
|
||||
ftpClient.disconnect();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
//判断文件是否存在
|
||||
if (tempFile.exists()) {
|
||||
inputStream = new FileInputStream(tempFile);
|
||||
}
|
||||
return inputStream;
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// FTPClient ftpClient = null;
|
||||
// try {
|
||||
// ftpClient = LoginFTP();
|
||||
// // 切换被动模式
|
||||
// ftpClient.enterLocalPassiveMode();
|
||||
// ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
|
||||
// // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项
|
||||
// ftpClient.setControlEncoding("UTF-8");
|
||||
// ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE);
|
||||
// return ftpClient.retrieveFileStream(fromPath);
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// return null;
|
||||
// } finally {
|
||||
// try {
|
||||
// if (ObjectUtil.isNotNull(ftpClient))
|
||||
// ftpClient.disconnect();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.jeecg.modules;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.constant.RedisConstant;
|
||||
|
@ -15,7 +16,6 @@ import org.jeecg.modules.spectrum.SpectrumServiceQuotes;
|
|||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -158,7 +158,7 @@ public class AutoProcessManager{
|
|||
//如果这时邮箱线程里已有执行的线程则设置停止标记
|
||||
if(emailExecThreadMap.containsKey(email.getId())){
|
||||
EmailParsingActuator actuator = emailExecThreadMap.get(email.getId());
|
||||
actuator.setStop(true);
|
||||
actuator.setThreadSleep(true);
|
||||
actuator.setStopTime(new Date());
|
||||
}
|
||||
log.info("{}邮箱测试连接失败,emailMap删除此邮箱数据,emailExecThreadMap设置线程停止标记",email.getUsername());
|
||||
|
@ -235,7 +235,7 @@ public class AutoProcessManager{
|
|||
if(testFlag){
|
||||
if (emailExecThreadMap.containsKey(databaseEmail.getId())) {
|
||||
EmailParsingActuator actuator = emailExecThreadMap.get(databaseEmail.getId());
|
||||
actuator.setStop(false);
|
||||
actuator.setThreadSleep(false);
|
||||
log.info("{}邮箱重新加入监测队列",databaseEmail.getUsername());
|
||||
} else {
|
||||
databaseEmail.setNewEmailFlag(true);
|
||||
|
|
|
@ -36,6 +36,8 @@ public class EmailParsingActuator extends Thread{
|
|||
@Setter @Getter
|
||||
private boolean isStop;
|
||||
@Setter @Getter
|
||||
private boolean threadSleep;
|
||||
@Setter @Getter
|
||||
private Date stopTime;
|
||||
|
||||
public void init(EmailProperties emailProperties,SpectrumServiceQuotes spectrumServiceQuotes,
|
||||
|
@ -62,8 +64,17 @@ public class EmailParsingActuator extends Thread{
|
|||
@Override
|
||||
public void run() {
|
||||
for(;;){
|
||||
String nowDate = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
|
||||
if (threadSleep) {
|
||||
log.info(nowDate + " " +this.emailProperties.getName()+" EmailParsingActuator is sleep!");
|
||||
try {
|
||||
Thread.sleep(1000L);
|
||||
} catch (InterruptedException e) {
|
||||
log.error("Thread sleep error");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (isStop) {
|
||||
String nowDate = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
|
||||
log.info(nowDate + " " +this.emailProperties.getName()+" EmailParsingActuator is Stop!");
|
||||
closeResource();
|
||||
return;
|
||||
|
@ -80,13 +91,11 @@ public class EmailParsingActuator extends Thread{
|
|||
//检验获取的邮件是否在之前删除失败列表中,若在直接调用邮件API删除,并且此次数组里元素也删除
|
||||
for(int i=messages.length-1;i>=0;i--){
|
||||
if (null == messages[i].getHeader("Message-ID")) {
|
||||
System.out.println("Message ID是空值信息!!!!!!!");
|
||||
messages = ArrayUtils.remove(messages, i);
|
||||
continue;
|
||||
}
|
||||
if (!messages[i].isExpunged()){
|
||||
String messageId = ((MimeMessage) messages[i]).getMessageID();
|
||||
System.out.println("正常获取到的Message ID是:"+messageId);
|
||||
final boolean exist = emailServiceManager.check(messages[i],messageId);
|
||||
messageIds.add(messageId);
|
||||
if(exist){
|
||||
|
@ -106,15 +115,14 @@ public class EmailParsingActuator extends Thread{
|
|||
poolExecutor.execute(spectrumParsingActuator);
|
||||
}
|
||||
taskLatch.await();
|
||||
log.info("EmailParsingActuator本次{}封邮件处理完成", messages.length);
|
||||
}
|
||||
}
|
||||
} catch (MessagingException e) {
|
||||
System.out.println("捕获MessagingException!!!!!!!!");
|
||||
} catch (Exception e) {
|
||||
log.error("EmailParsingActuator has exception: {}", e.getMessage());
|
||||
log.info("Mail-Parsing线程池资源关闭...");
|
||||
closeResource();
|
||||
throw new RuntimeException(e);
|
||||
} catch (Exception e) {
|
||||
closeResource();
|
||||
log.error(""+e);
|
||||
} finally {
|
||||
//清除本批次邮件日志缓存
|
||||
EmailLogManager.getInstance().clear();
|
||||
|
|
|
@ -84,7 +84,8 @@ public class GardsSampleDataServiceImpl extends ServiceImpl<GardsSampleDataMappe
|
|||
LambdaQueryWrapper<GardsSampleData> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(GardsSampleData::getInputFileName,inputFileName);
|
||||
final GardsSampleData sampleData = this.getOne(queryWrapper);
|
||||
if(Objects.nonNull(sampleData) && !SampleStatus.COMPLETE.getValue().equals(sampleData.getStatus())){
|
||||
if(Objects.nonNull(sampleData) && !SampleStatus.COMPLETE.getValue().equals(sampleData.getStatus())
|
||||
&& !SampleStatus.INTERACTIVE.getValue().equals(sampleData.getStatus())){
|
||||
this.baseMapper.updateStatus(status,inputFileName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -316,7 +316,7 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
|
|||
ex.printStackTrace();
|
||||
}
|
||||
} else if(SpectrumSource.FROM_FILE_SOURCE.getSourceType().equals(spectrumSource) && (e instanceof FileRepeatException)){
|
||||
this.spectrumFile.delete();
|
||||
this.spectrumFile.delete(); // TODO 删除原始谱文件
|
||||
} else if (SpectrumSource.FORM_FILE_UNDEL.getSourceType().equals(spectrumSource) && !(e instanceof FileRepeatException)) {
|
||||
try {
|
||||
if (isDateFormatErr) {
|
||||
|
|
|
@ -70,9 +70,9 @@ public class GammaFileUtil extends AbstractLogOrReport {
|
|||
//如果功能是人工交互模块则从ftp获取文件内容
|
||||
File file = null;
|
||||
if (sysSource.equals("BetaGamma")) {
|
||||
file = ftpUtil.downloadFile(fromPath, "betaGamma");
|
||||
file = ftpUtil.downloadFile(fromPath);
|
||||
if (Objects.isNull(file)) {
|
||||
result.error500("ftp file can't find");
|
||||
result.error500("file can't find");
|
||||
return false;
|
||||
}
|
||||
} else if (sysSource.equals("AUTO")) {//如果是自动处理则从本地文件中获取文件内容
|
||||
|
@ -265,7 +265,7 @@ public class GammaFileUtil extends AbstractLogOrReport {
|
|||
try {
|
||||
String lcFileName = prefixName+"_"+subFileName + ".lc";
|
||||
String fromPathLc = pathName + StringPool.SLASH + lcFileName;
|
||||
lcFile = ftpUtil.downloadFile(fromPathLc, "betaGamma");
|
||||
lcFile = ftpUtil.downloadFile(fromPathLc);
|
||||
if (Objects.nonNull(lcFile)) {
|
||||
List<String> readLinesLc = FileUtils.readLines(lcFile, "UTF-8");
|
||||
//得到行数据处理后的数据结果
|
||||
|
@ -275,7 +275,7 @@ public class GammaFileUtil extends AbstractLogOrReport {
|
|||
}
|
||||
String scacFileName = prefixName+"_"+subFileName + ".scac";
|
||||
String fromPathScac = pathName + StringPool.SLASH + scacFileName;
|
||||
scacFile = ftpUtil.downloadFile(fromPathScac, "betaGamma");
|
||||
scacFile = ftpUtil.downloadFile(fromPathScac);
|
||||
if (Objects.nonNull(scacFile)) {
|
||||
List<String> readLinesScac = FileUtils.readLines(scacFile, "UTF-8");
|
||||
//得到行数据处理后的数据结果
|
||||
|
@ -298,10 +298,6 @@ public class GammaFileUtil extends AbstractLogOrReport {
|
|||
try {
|
||||
if (ObjectUtil.isNotNull(inputStreamBase))
|
||||
inputStreamBase.close();
|
||||
if (ObjectUtil.isNotNull(lcFile))
|
||||
lcFile.delete();
|
||||
if (ObjectUtil.isNotNull(scacFile))
|
||||
scacFile.delete();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -3234,8 +3230,10 @@ public class GammaFileUtil extends AbstractLogOrReport {
|
|||
File sampleTmp = null;
|
||||
try {
|
||||
sampleTmp = new File(fileAnlyse.getTmpFilePath());
|
||||
if (Objects.nonNull(sampleTmp)) {
|
||||
bRet = ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + middleData.analyses_save_filePath.substring(0, middleData.analyses_save_filePath.lastIndexOf(StringPool.SLASH)), middleData.analyses_save_filePath.substring(middleData.analyses_save_filePath.lastIndexOf(StringPool.SLASH)+1), new FileInputStream(sampleTmp));
|
||||
//sample文件的存储路径
|
||||
String saveSamplePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + middleData.analyses_save_filePath;
|
||||
if (Objects.nonNull(sampleTmp) && !saveSamplePath.equals(fileAnlyse.getTmpFilePath().replace(StringPool.BACK_SLASH, StringPool.SLASH))) {
|
||||
bRet = ftpUtil.saveFile(saveSamplePath, new FileInputStream(sampleTmp));
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
@ -4369,7 +4367,7 @@ public class GammaFileUtil extends AbstractLogOrReport {
|
|||
public File analyzeFile(String path, String fileName) {
|
||||
path = path.replace("\\", "/");
|
||||
String fromPath = path + StringPool.SLASH + fileName;
|
||||
return ftpUtil.downloadFile(fromPath, "betaGamma");
|
||||
return ftpUtil.downloadFile(fromPath);
|
||||
}
|
||||
|
||||
public List<String> readLine(String filePath) {
|
||||
|
|
|
@ -2,7 +2,9 @@ package org.jeecg.modules.controller;
|
|||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.util.FTPUtil;
|
||||
import org.jeecg.modules.base.bizVo.FileVo;
|
||||
import org.jeecg.modules.entity.FileInfo;
|
||||
import org.jeecg.modules.entity.LogManage;
|
||||
import org.jeecg.modules.service.ILogManageService;
|
||||
|
@ -20,31 +22,24 @@ import java.util.List;
|
|||
@Api(value = "日志管理", tags = "日志管理")
|
||||
public class LogManageController {
|
||||
|
||||
@Autowired
|
||||
private FTPUtil ftpUtil;
|
||||
@Autowired
|
||||
private ILogManageService logManageService;
|
||||
|
||||
@GetMapping("findFtpFolders")
|
||||
@ApiOperation(value = "查询日志文件夹树形结构", notes = "查询日志文件夹树形结构")
|
||||
public List<LogManage> findFtpFolders(String workPath) {
|
||||
return logManageService.findFtpFolders(workPath);
|
||||
return logManageService.fileTree(workPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询目录下文件内容
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("findFiles")
|
||||
@ApiOperation(value = "查询目录下文件内容", notes = "查询目录下文件内容")
|
||||
public List<FileInfo> findFiles(String path) {
|
||||
return logManageService.findFiles(path);
|
||||
public Result<?> findFiles(String path, FileVo fileVo) {
|
||||
return logManageService.findFiles(path, fileVo);
|
||||
}
|
||||
|
||||
@PostMapping("downloadFile")
|
||||
@ApiOperation(value = "ftp文件下载", notes = "ftp文件下载")
|
||||
public void downloadFile(String localPath, String fileName, HttpServletResponse response) {
|
||||
ftpUtil.downloadFTPFile(localPath, response);
|
||||
public void downloadFile(String localPath, HttpServletResponse response) {
|
||||
logManageService.downloadFile(localPath, response);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
package org.jeecg.modules.service;
|
||||
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.modules.base.bizVo.FileVo;
|
||||
import org.jeecg.modules.entity.FileInfo;
|
||||
import org.jeecg.modules.entity.LogManage;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
public interface ILogManageService {
|
||||
|
||||
/**
|
||||
* 查询日志文件夹树形结构
|
||||
* @param workPath
|
||||
* @return
|
||||
*/
|
||||
List<LogManage> findFtpFolders(String workPath);
|
||||
List<LogManage> fileTree(String workPath);
|
||||
|
||||
/**
|
||||
* 查询目录下文件内容
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
List<FileInfo> findFiles(String path);
|
||||
Result<?> findFiles(String path, FileVo fileVo);
|
||||
|
||||
void downloadFile(String localPath, HttpServletResponse response);
|
||||
}
|
||||
|
|
|
@ -1,192 +1,159 @@
|
|||
package org.jeecg.modules.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.net.ftp.FTPClient;
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.constant.Prompt;
|
||||
import org.jeecg.common.properties.SpectrumPathProperties;
|
||||
import org.jeecg.common.util.DateUtils;
|
||||
import org.jeecg.common.util.FTPUtil;
|
||||
import org.jeecg.common.util.ExportUtil;
|
||||
import org.jeecg.common.util.PageUtil;
|
||||
import org.jeecg.modules.base.bizVo.FileVo;
|
||||
import org.jeecg.modules.entity.FileInfo;
|
||||
import org.jeecg.modules.entity.LogManage;
|
||||
import org.jeecg.modules.service.ILogManageService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service("logManageService")
|
||||
@Slf4j
|
||||
@Service
|
||||
public class LogManageServiceImpl implements ILogManageService {
|
||||
|
||||
@Autowired
|
||||
private FTPUtil ftpUtil;
|
||||
private SpectrumPathProperties spectrumPath;
|
||||
|
||||
@Override
|
||||
public List<LogManage> findFtpFolders(String workPath) {
|
||||
public List<LogManage> fileTree(String workPath) {
|
||||
List<LogManage> result = new ArrayList<>();
|
||||
FTPClient ftpClient = ftpUtil.LoginFTP();
|
||||
if(Objects.isNull(ftpClient)){
|
||||
throw new RuntimeException("ftp connection failed!");
|
||||
workPath = spectrumPath.getRootPath() + StringPool.SLASH + workPath;
|
||||
List<File> files = ListUtil.toList(FileUtil.ls(workPath));
|
||||
if (CollUtil.isEmpty(files)) return result;
|
||||
int num = 1;
|
||||
for (File file : files) {
|
||||
LogManage logManage = new LogManage();
|
||||
logManage.setName(file.getName());
|
||||
logManage.setOrderNum(num++);
|
||||
logManage.setPath(workPath + StringPool.SLASH + file.getName());
|
||||
List<LogManage> children = this.getChildren(logManage);
|
||||
logManage.setHashChild(CollUtil.isNotEmpty(children));
|
||||
logManage.setChildren(children);
|
||||
result.add(logManage);
|
||||
}
|
||||
try {
|
||||
//切换被动模式
|
||||
ftpClient.enterLocalPassiveMode();
|
||||
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
|
||||
// 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项
|
||||
ftpClient.setControlEncoding("UTF-8");
|
||||
ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE);
|
||||
//切换工作文件路径
|
||||
workPath = ftpUtil.getFtpRootPath()+StringPool.SLASH+workPath;
|
||||
ftpClient.changeWorkingDirectory(workPath);
|
||||
List<FTPFile> ftpFiles = Arrays.asList(ftpClient.listDirectories());
|
||||
if (CollectionUtils.isNotEmpty(ftpFiles)){
|
||||
int num =1;
|
||||
for (FTPFile ftpFile:ftpFiles) {
|
||||
LogManage logManage = new LogManage();
|
||||
logManage.setName(ftpFile.getName());
|
||||
logManage.setOrderNum(num);
|
||||
logManage.setParentNum(0);
|
||||
logManage.setPath(workPath + StringPool.SLASH + ftpFile.getName());
|
||||
result.add(logManage);
|
||||
num++;
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(result)){
|
||||
List<LogManage> list = new LinkedList<>();
|
||||
for (LogManage logManage:result) {
|
||||
list = this.findDirectory(ftpClient, list, logManage.getOrderNum(), workPath + StringPool.SLASH + logManage.getName() , logManage.getName());
|
||||
ftpClient.changeToParentDirectory();
|
||||
}
|
||||
result.addAll(list);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
if (ftpClient != null){
|
||||
ftpClient.disconnect();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
result = this.LogManageTree(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileInfo> findFiles(String path) {
|
||||
List<FileInfo> result = new ArrayList<>();
|
||||
FTPClient ftpClient = ftpUtil.LoginFTP();
|
||||
if (Objects.isNull(ftpClient)){
|
||||
throw new RuntimeException("ftp connection failed!");
|
||||
public Result<?> findFiles(String path, FileVo fileVo) {
|
||||
String name = fileVo.getName();
|
||||
Integer pageNo = fileVo.getPageNo();
|
||||
Integer pageSize = fileVo.getPageSize();
|
||||
Page<FileInfo> page = new Page<>(pageNo, pageSize);
|
||||
List<File> files = CollUtil.toList(FileUtil.ls(path));
|
||||
// 文件名过滤
|
||||
if (StrUtil.isNotBlank(name))
|
||||
files = files.stream().filter(file -> StrUtil.containsIgnoreCase(file.getName(), name))
|
||||
.collect(Collectors.toList());
|
||||
page.setTotal(files.size());
|
||||
// 分页
|
||||
files = PageUtil.page(pageNo, pageSize, files);
|
||||
List<FileInfo> records = new ArrayList<>();
|
||||
for (File file : files) {
|
||||
if (FileUtil.isDirectory(file)) continue;
|
||||
FileInfo fileInfo = new FileInfo();
|
||||
fileInfo.setFileName(file.getName());
|
||||
fileInfo.setFilePath(path + StringPool.SLASH + file.getName());
|
||||
fileInfo.setFileSize(FileUtil.readableFileSize(file));
|
||||
fileInfo.setFileDate(DateUtil.formatDateTime(FileUtil.lastModifiedTime(file)));
|
||||
records.add(fileInfo);
|
||||
}
|
||||
page.setRecords(records);
|
||||
return Result.OK(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadFile(String localPath, HttpServletResponse response) {
|
||||
OutputStream outputStream = null;
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
//切换被动模式
|
||||
ftpClient.enterLocalPassiveMode();
|
||||
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
|
||||
// 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项
|
||||
ftpClient.setControlEncoding("UTF-8");
|
||||
ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE);
|
||||
//切换工作文件路径
|
||||
ftpClient.changeWorkingDirectory(path);
|
||||
List<FTPFile> ftpFiles = Arrays.asList(ftpClient.listFiles());
|
||||
if (CollectionUtils.isNotEmpty(ftpFiles)){
|
||||
for (FTPFile ftpFile:ftpFiles) {
|
||||
if (ftpFile.isFile()){
|
||||
FileInfo fileInfo = new FileInfo();
|
||||
fileInfo.setFileName(ftpFile.getName());
|
||||
fileInfo.setFilePath(path + StringPool.SLASH + ftpFile.getName());
|
||||
fileInfo.setFileSize(String.format("%.2f", Double.valueOf(Double.valueOf(ftpFile.getSize())/1024)) + "KB");
|
||||
fileInfo.setFileDate(DateUtils.formatDate(ftpFile.getTimestamp(),"yyyy-MM-dd"));
|
||||
result.add(fileInfo);
|
||||
}
|
||||
}
|
||||
// 如果是目录 则直接退出方法
|
||||
if (FileUtil.isDirectory(localPath)) return;
|
||||
|
||||
// 判断是否存在此文件
|
||||
if (!FileUtil.exist(localPath)) return;
|
||||
|
||||
// 获取文件名
|
||||
String fileName = FileUtil.getName(localPath);
|
||||
|
||||
inputStream = FileUtil.getInputStream(localPath);
|
||||
outputStream = ExportUtil.stream(response, fileName);
|
||||
|
||||
// 缓冲区大小
|
||||
byte[] buffer = new byte[4096];
|
||||
int bytesRead;
|
||||
|
||||
// 将文件输出流写入到输出流中
|
||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||
outputStream.write(buffer, 0, bytesRead);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
log.error("文件{}下载失败 :{}", localPath, e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
if (ftpClient != null){
|
||||
ftpClient.disconnect();
|
||||
}
|
||||
if (ObjectUtil.isNotNull(inputStream))inputStream.close();
|
||||
if (ObjectUtil.isNotNull(outputStream))outputStream.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 遍历查询当前路径下的文件夹信息
|
||||
* @param ftpClient
|
||||
* @param list
|
||||
* @param filePath 以"/"开始和结束
|
||||
* @return
|
||||
* 获取当前目录节点所有子孙节点Tree
|
||||
*/
|
||||
public List<LogManage> findDirectory(FTPClient ftpClient, List<LogManage> list, Integer parentNum, String filePath, String fileName){
|
||||
try {
|
||||
//切换被动模式
|
||||
ftpClient.enterLocalPassiveMode();
|
||||
ftpClient.changeWorkingDirectory(fileName);
|
||||
List<FTPFile> ftpFiles = Arrays.asList(ftpClient.listDirectories());
|
||||
if (CollectionUtils.isNotEmpty(ftpFiles)){
|
||||
int num = 1;
|
||||
for (FTPFile file : ftpFiles) {
|
||||
if (file.isDirectory()) {
|
||||
LogManage logManage = new LogManage();
|
||||
logManage.setName(file.getName());
|
||||
logManage.setOrderNum(parentNum*10+num);
|
||||
logManage.setParentNum(parentNum);
|
||||
logManage.setPath(filePath + StringPool.SLASH + file.getName());
|
||||
list.add(logManage);
|
||||
// 需要加此判断。否则,ftp默认将‘项目文件所在目录之下的目录(./)’与‘项目文件所在目录向上一级目录下的目录(../)’都纳入递归,这样下去就陷入一个死循环了。需将其过滤掉。
|
||||
if (!".".equals(file.getName()) && !"..".equals(file.getName())) {
|
||||
findDirectory(ftpClient, list, parentNum*10+num, filePath + StringPool.SLASH + file.getName(), file.getName());
|
||||
ftpClient.changeToParentDirectory();
|
||||
}
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将当前的文件夹转换成树形结构
|
||||
* @param logManages
|
||||
* @return
|
||||
*/
|
||||
public List<LogManage> LogManageTree(List<LogManage> logManages){
|
||||
if (logManages == null) {
|
||||
return null;
|
||||
}
|
||||
private List<LogManage> getChildren(LogManage parent){
|
||||
List<LogManage> result = new LinkedList<>();
|
||||
Integer TOP_NODE_ID = 0;
|
||||
logManages.forEach(logManage -> {
|
||||
Integer pid = logManage.getParentNum();
|
||||
if (pid == null || TOP_NODE_ID.equals(pid)) {
|
||||
result.add(logManage);
|
||||
return;
|
||||
}
|
||||
for (LogManage manage : logManages) {
|
||||
Integer id = manage.getOrderNum();
|
||||
if (id != null && id.equals(pid)) {
|
||||
if (manage.getChildren() == null) {
|
||||
manage.initChildren();
|
||||
}
|
||||
logManage.setHashParent(true);
|
||||
manage.getChildren().add(logManage);
|
||||
manage.setHashChild(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
String parentPath = parent.getPath();
|
||||
// 如果是文件 则直接返回空集合
|
||||
if (FileUtil.isFile(parentPath)) return result;
|
||||
List<File> files = ListUtil.toList(FileUtil.ls(parentPath));
|
||||
// 如果当前目录不存在子文件 则返回空集合
|
||||
if (CollUtil.isEmpty(files)) return result;
|
||||
int parentOrderNum = parent.getOrderNum();
|
||||
int num = parentOrderNum * 10 + 1;
|
||||
for (File file : files) {
|
||||
// 过滤掉文件 只收集目录
|
||||
if (FileUtil.isFile(file)) continue;
|
||||
LogManage logManage = new LogManage();
|
||||
logManage.setName(file.getName());
|
||||
logManage.setOrderNum(num++);
|
||||
logManage.setHashParent(true);
|
||||
logManage.setParentNum(parentOrderNum);
|
||||
logManage.setPath(parentPath + StringPool.SLASH + file.getName());
|
||||
List<LogManage> children = getChildren(logManage);
|
||||
logManage.setHashChild(CollUtil.isNotEmpty(children));
|
||||
logManage.setChildren(children);
|
||||
result.add(logManage);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -817,7 +817,7 @@ public class PHDFileUtil extends AbstractLogOrReport {
|
|||
File file = null;
|
||||
try {
|
||||
String fromPath = filePath + StringPool.SLASH + sampleFileName;
|
||||
file = ftpUtil.downloadFile(fromPath, "betaGamma");
|
||||
file = ftpUtil.downloadFile(fromPath);
|
||||
//加载sampleFile内容
|
||||
EnergySpectrumStruct struct = EnergySpectrumHandler.getSourceData(file.getAbsolutePath());
|
||||
//获取所需要的数据
|
||||
|
@ -841,9 +841,6 @@ public class PHDFileUtil extends AbstractLogOrReport {
|
|||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return map;
|
||||
}finally {
|
||||
if (ObjectUtil.isNotNull(file))
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -852,7 +849,7 @@ public class PHDFileUtil extends AbstractLogOrReport {
|
|||
File file = null;
|
||||
try {
|
||||
String fromPath = filePath + StringPool.SLASH + fileName;
|
||||
file = ftpUtil.downloadFile(fromPath, "betaGamma");
|
||||
file = ftpUtil.downloadFile(fromPath);
|
||||
EnergySpectrumStruct sourceData = EnergySpectrumHandler.getSourceData(file.getAbsolutePath());
|
||||
String systemType = sourceData.system_type;
|
||||
String dataType = sourceData.data_type;
|
||||
|
@ -886,9 +883,6 @@ public class PHDFileUtil extends AbstractLogOrReport {
|
|||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return path.toString();
|
||||
}finally {
|
||||
if (ObjectUtil.isNotNull(file))
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1120,9 +1114,6 @@ public class PHDFileUtil extends AbstractLogOrReport {
|
|||
if (Objects.nonNull(inputStream)){
|
||||
inputStream.close();
|
||||
}
|
||||
if (Objects.nonNull(file)) {
|
||||
file.delete();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
|
@ -180,7 +180,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
|
|||
return result;
|
||||
}
|
||||
// 切割数据库存储的文件路径获取路径信息
|
||||
String pathName = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + sampleFilePath.substring(0, sampleFilePath.lastIndexOf(StringPool.SLASH));
|
||||
String pathName = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + sampleFilePath.substring(0, sampleFilePath.lastIndexOf(StringPool.SLASH));
|
||||
// 切割数据库存储的文件路径获取文件名称
|
||||
String fileName = sampleFilePath.substring(sampleFilePath.lastIndexOf(StringPool.SLASH) + 1);
|
||||
// 声明phd实体类
|
||||
|
@ -598,7 +598,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
|
|||
Map<String, Object> map = new HashMap<>();
|
||||
Cache<String, PHDFile> phdCache = localCache.getPHDCache();
|
||||
// 上传文件路径
|
||||
String path = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName;
|
||||
String path = spectrumPathProperties.getRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName;
|
||||
// 获取当前角色的颜色配置
|
||||
Map<String, String> colorMap = sysUserColorService.initColor(userName);
|
||||
PHDFile phd = phdCache.getIfPresent(fileName + StringPool.DASH + userName);
|
||||
|
@ -671,12 +671,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
|
|||
String key = fileName + StrUtil.DASHED + username;
|
||||
Cache<String, PHDFile> phdCache = localCache.getPHDCache();
|
||||
PHDFile phdFile = phdCache.getIfPresent(key);
|
||||
if (StringUtils.isNotBlank(phdFile.getTmpFilePath())) {
|
||||
File file = new File(phdFile.getTmpFilePath());
|
||||
if (Objects.nonNull(file)) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
// 删除指定key的Cache
|
||||
localCache.deletePHDCache(key);
|
||||
}
|
||||
|
@ -743,8 +737,8 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
|
|||
result.error500("The comparison file path does not exist");
|
||||
return result;
|
||||
}
|
||||
compareFilePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + compareFilePath;
|
||||
File compareFile = ftpUtil.downloadFile(compareFilePath, "betaGamma");
|
||||
compareFilePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + compareFilePath;
|
||||
File compareFile = ftpUtil.downloadFile(compareFilePath);
|
||||
if (Objects.isNull(compareFile)) {
|
||||
result.error500("The comparison file path does not exist");
|
||||
return result;
|
||||
|
@ -756,7 +750,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
|
|||
result.setSuccess(true);
|
||||
result.setResult(chartDataList);
|
||||
}
|
||||
compareFile.delete();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -776,9 +769,9 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
|
|||
long m_nCount = phd.getSpec().getNum_g_channel();
|
||||
List<Double> vEnergy = phd.getVEnergy();
|
||||
//加载compare文件
|
||||
String compareFilePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName;
|
||||
String compareFilePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName;
|
||||
String fromPath = compareFilePath + StringPool.SLASH + compareFileName;
|
||||
File compareFile = ftpUtil.downloadFile(fromPath, "betaGamma");
|
||||
File compareFile = ftpUtil.downloadFile(fromPath);
|
||||
if (Objects.nonNull(compareFile)) {
|
||||
// 获取Compare数据
|
||||
List<Long> m_vecCompare = gammaFileUtil.loadCompareData(compareFile, userName, m_nCount, result);
|
||||
|
@ -787,7 +780,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
|
|||
result.setSuccess(true);
|
||||
result.setResult(chartDataList);
|
||||
}
|
||||
compareFile.delete();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -827,8 +819,8 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
|
|||
result.error500("The comparison file path does not exist");
|
||||
return result;
|
||||
}
|
||||
stripFilePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + stripFilePath;
|
||||
File stripFile = ftpUtil.downloadFile(stripFilePath, "betaGamma");
|
||||
stripFilePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + stripFilePath;
|
||||
File stripFile = ftpUtil.downloadFile(stripFilePath);
|
||||
if (Objects.isNull(stripFile)) {
|
||||
result.error500("The comparison file path does not exist");
|
||||
return result;
|
||||
|
@ -843,7 +835,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
|
|||
result.setSuccess(true);
|
||||
result.setResult(stripMap);
|
||||
}
|
||||
stripFile.delete();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -877,9 +868,9 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
|
|||
m_vCount.add(0L);
|
||||
}
|
||||
//加载strip文件
|
||||
String stripFilePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName;
|
||||
String stripFilePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName;
|
||||
String fromPath = stripFilePath + StringPool.SLASH + stripFileName;
|
||||
File stripFile = ftpUtil.downloadFile(fromPath, "betaGamma");
|
||||
File stripFile = ftpUtil.downloadFile(fromPath);
|
||||
if (Objects.nonNull(stripFile)) {
|
||||
// 获取Compare数据
|
||||
List<Long> m_vecCompare = gammaFileUtil.loadCompareData(stripFile, userName, m_nCount, result);
|
||||
|
@ -891,7 +882,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
|
|||
result.setSuccess(true);
|
||||
result.setResult(stripMap);
|
||||
}
|
||||
stripFile.delete();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -3026,9 +3016,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
|
|||
if (Objects.nonNull(inputStream)) {
|
||||
inputStream.close();
|
||||
}
|
||||
if (Objects.nonNull(tmpFile)) {
|
||||
tmpFile.delete();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -3300,9 +3287,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
|
|||
if (Objects.nonNull(inputStream)) {
|
||||
inputStream.close();
|
||||
}
|
||||
if (Objects.nonNull(tmpFile)) {
|
||||
tmpFile.delete();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -3596,9 +3580,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
|
|||
if (Objects.nonNull(inputStream)) {
|
||||
inputStream.close();
|
||||
}
|
||||
if (Objects.nonNull(tmpFile)) {
|
||||
tmpFile.delete();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -3961,7 +3942,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
|
|||
if (StringUtils.isBlank(reportPath)) {
|
||||
throw new RuntimeException("The automatic handler generated report does not exist!");
|
||||
}
|
||||
String pathFileName = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath + ".txt";
|
||||
String pathFileName = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath + ".txt";
|
||||
InputStream inputStream = null;
|
||||
ServletOutputStream outputStream = null;
|
||||
try {
|
||||
|
@ -3995,7 +3976,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
|
|||
public void exportARR(Integer sampleId, HttpServletResponse response) {
|
||||
// 获取自动处理生成的报告地址
|
||||
String reportPath = spectrumAnalysisMapper.viewARR(sampleId);
|
||||
String pathFileName = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath + ".txt";
|
||||
String pathFileName = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath + ".txt";
|
||||
InputStream inputStream = null;
|
||||
ServletOutputStream outputStream = null;
|
||||
try {
|
||||
|
@ -4595,7 +4576,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
|
|||
if (StringUtils.isBlank(logPath)) {
|
||||
throw new RuntimeException("The log generated by the automatic processor does not exist!");
|
||||
}
|
||||
String pathFileName = ftpUtil.getFtpRootPath() + spectrumPathProperties.getLogPath() + StringPool.SLASH + logPath;
|
||||
String pathFileName = spectrumPathProperties.getRootPath() + spectrumPathProperties.getLogPath() + StringPool.SLASH + logPath;
|
||||
InputStream inputStream = null;
|
||||
ServletOutputStream outputStream = null;
|
||||
try {
|
||||
|
@ -4810,47 +4791,40 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
|
|||
phd.setStatus("R");
|
||||
//分析成功后存储日志文件和报告文件
|
||||
String rootPath = spectrumPathProperties.getRootPath();
|
||||
// {
|
||||
// File baselineFile = new File(rootPath+middleData.analyses_baseline_absolute_filePath);
|
||||
// try {
|
||||
// FileInputStream in = new FileInputStream(baselineFile);
|
||||
// ftpUtil.saveFile(spectrumPathProperties.getRootPath()+middleData.analyses_baseline_absolute_filePath, in);
|
||||
// } catch (FileNotFoundException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
// {
|
||||
// File lcFile = new File(rootPath+middleData.analyses_lc_absolute_filePath);
|
||||
// try {
|
||||
// FileInputStream in = new FileInputStream(lcFile);
|
||||
// ftpUtil.saveFile(spectrumPathProperties.getRootPath()+middleData.analyses_lc_absolute_filePath, in);
|
||||
// } catch (FileNotFoundException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
// {
|
||||
// File scacFile = new File(rootPath+middleData.analyses_scac_absolute_filePath);
|
||||
// try {
|
||||
// FileInputStream in = new FileInputStream(scacFile);
|
||||
// ftpUtil.saveFile(spectrumPathProperties.getRootPath()+middleData.analyses_scac_absolute_filePath, in);
|
||||
// } catch (FileNotFoundException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
{
|
||||
String baselinePathName = ftpUtil.getFtpRootPath()+middleData.analyses_baseline_absolute_filePath.substring(0, middleData.analyses_baseline_absolute_filePath.lastIndexOf(StringPool.SLASH));
|
||||
String baselineFileName = middleData.analyses_baseline_absolute_filePath.substring(middleData.analyses_baseline_absolute_filePath.lastIndexOf(StringPool.SLASH) + 1);
|
||||
File baselineFile = new File(rootPath+middleData.analyses_baseline_absolute_filePath);
|
||||
try {
|
||||
FileInputStream in = new FileInputStream(baselineFile);
|
||||
ftpUtil.saveFile(baselinePathName, baselineFileName, in);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
{
|
||||
String lcPathName = ftpUtil.getFtpRootPath()+middleData.analyses_lc_absolute_filePath.substring(0, middleData.analyses_lc_absolute_filePath.lastIndexOf(StringPool.SLASH));
|
||||
String lcFileName = middleData.analyses_lc_absolute_filePath.substring(middleData.analyses_lc_absolute_filePath.lastIndexOf(StringPool.SLASH) + 1);
|
||||
File lcFile = new File(rootPath+middleData.analyses_lc_absolute_filePath);
|
||||
try {
|
||||
FileInputStream in = new FileInputStream(lcFile);
|
||||
ftpUtil.saveFile(lcPathName, lcFileName, in);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
{
|
||||
String scacPathName = ftpUtil.getFtpRootPath()+middleData.analyses_scac_absolute_filePath.substring(0, middleData.analyses_scac_absolute_filePath.lastIndexOf(StringPool.SLASH));
|
||||
String scacFileName = middleData.analyses_scac_absolute_filePath.substring(middleData.analyses_scac_absolute_filePath.lastIndexOf(StringPool.SLASH) + 1);
|
||||
File scacFile = new File(rootPath+middleData.analyses_scac_absolute_filePath);
|
||||
try {
|
||||
FileInputStream in = new FileInputStream(scacFile);
|
||||
ftpUtil.saveFile(scacPathName, scacFileName, in);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
{
|
||||
String logPathName = middleData.analyses_absolute_LogPath.substring(0, middleData.analyses_absolute_LogPath.lastIndexOf(StringPool.SLASH));
|
||||
String logFileName = middleData.analyses_absolute_LogPath.substring(middleData.analyses_absolute_LogPath.lastIndexOf(StringPool.SLASH)+1);
|
||||
File logFile = new File(logFileName);
|
||||
try {
|
||||
FileUtil.writeString(gammaFileUtil.GetLogContent(middleData), logFile, "UTF-8");
|
||||
FileInputStream in = new FileInputStream(logFile);
|
||||
ftpUtil.saveFile(logPathName, logFileName, in);
|
||||
ftpUtil.saveFile(spectrumPathProperties.getRootPath()+middleData.analyses_absolute_LogPath, in);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
|
@ -4858,13 +4832,12 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
|
|||
}
|
||||
}
|
||||
{
|
||||
String rptPathName = middleData.analyses_absolute_ReportPath.substring(0, middleData.analyses_absolute_ReportPath.lastIndexOf(StringPool.SLASH));
|
||||
String rptFileName = middleData.analyses_absolute_ReportPath.substring(middleData.analyses_absolute_ReportPath.lastIndexOf(StringPool.SLASH)+1)+".txt";
|
||||
File rptFile = new File(rptFileName);
|
||||
try {
|
||||
FileUtil.writeString(gammaFileUtil.GetReportContent(middleData), rptFile, "UTF-8");
|
||||
FileInputStream in = new FileInputStream(rptFile);
|
||||
ftpUtil.saveFile(rptPathName, rptFileName, in);
|
||||
ftpUtil.saveFile(spectrumPathProperties.getRootPath()+middleData.analyses_absolute_ReportPath+".txt", in);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
|
|
|
@ -299,7 +299,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
|
|||
Result result = new Result();
|
||||
List<Map<String, Object>> resultList = new LinkedList<>();
|
||||
String userName = JwtUtil.getUserNameByToken(request);
|
||||
String filePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH +userName;
|
||||
String filePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH +userName;
|
||||
String sampleRx = "[a-zA-Z]{3}[0-9]{2}_[0-9]{3}-[0-9]{8}_[0-9]{4}_S_(FULL_|PREL_)\\d+\\.PHD";
|
||||
Pattern regexPattern = Pattern.compile(sampleRx);
|
||||
String sampleRx1 = "[a-zA-Z]{3}[0-9]{2}_[0-9]{3}-[0-9]{8}_[0-9]{4}_S_(FULL_|PREL_)\\d+\\.\\d+\\.PHD";
|
||||
|
@ -480,9 +480,9 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
|
|||
betaDataFile.setSampleId(String.valueOf(sampleId));
|
||||
//判断sample信息是否存在
|
||||
if (Objects.nonNull(sample)) {
|
||||
betaDataFile.setSampleFilePathName(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getSampleFilePath());
|
||||
betaDataFile.setSampleFilePathName(spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getSampleFilePath());
|
||||
betaDataFile.setSampleFileName(sampleFileName);
|
||||
sampleTmp = ftpUtil.downloadFile(betaDataFile.getSampleFilePathName(), "betaGamma");
|
||||
sampleTmp = ftpUtil.downloadFile(betaDataFile.getSampleFilePathName());
|
||||
if (Objects.nonNull(sampleTmp)) {
|
||||
//sample临时文件路径存储
|
||||
betaDataFile.setSampleTmpPath(sampleTmp.getAbsolutePath());
|
||||
|
@ -517,9 +517,9 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
|
|||
}
|
||||
//判断gas信息是否存在
|
||||
if (Objects.nonNull(gasBg)) {
|
||||
betaDataFile.setGasFilePathName(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getGasBgFilePath());
|
||||
betaDataFile.setGasFilePathName(spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getGasBgFilePath());
|
||||
betaDataFile.setGasFileName(gasFileName);
|
||||
gasTmp = ftpUtil.downloadFile(betaDataFile.getGasFilePathName(), "betaGamma");
|
||||
gasTmp = ftpUtil.downloadFile(betaDataFile.getGasFilePathName());
|
||||
if (Objects.nonNull(gasTmp)) {
|
||||
//存储gas临时文件路径
|
||||
betaDataFile.setGasTmpPath(gasTmp.getAbsolutePath());
|
||||
|
@ -554,9 +554,9 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
|
|||
}
|
||||
//判断det信息是否存在
|
||||
if (Objects.nonNull(detBg)) {
|
||||
betaDataFile.setDetFilePathName(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getDetBgFilePath());
|
||||
betaDataFile.setDetFilePathName(spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getDetBgFilePath());
|
||||
betaDataFile.setDetFileName(detFileName);
|
||||
detTmp = ftpUtil.downloadFile(betaDataFile.getDetFilePathName(), "betaGamma");
|
||||
detTmp = ftpUtil.downloadFile(betaDataFile.getDetFilePathName());
|
||||
if (Objects.nonNull(detTmp)) {
|
||||
//存储det临时文件路径
|
||||
betaDataFile.setDetTmpPath(detTmp.getAbsolutePath());
|
||||
|
@ -591,9 +591,9 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
|
|||
}
|
||||
//判断qc信息是否存在
|
||||
if (Objects.nonNull(qc)) {
|
||||
betaDataFile.setQcFilePathName(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbQcFilePath);
|
||||
betaDataFile.setQcFilePathName(spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbQcFilePath);
|
||||
betaDataFile.setQcFileName(qcFileName);
|
||||
qcTmp = ftpUtil.downloadFile(betaDataFile.getQcFilePathName(), "betaGamma");
|
||||
qcTmp = ftpUtil.downloadFile(betaDataFile.getQcFilePathName());
|
||||
if (Objects.nonNull(qcTmp)) {
|
||||
betaDataFile.setQcTmpPath(qcTmp.getAbsolutePath());
|
||||
EnergySpectrumStruct struct = EnergySpectrumHandler.getSourceData(qcTmp.getAbsolutePath());
|
||||
|
@ -671,7 +671,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
|
|||
//获取用户名
|
||||
String userName = JwtUtil.getUserNameByToken(request);
|
||||
//上传文件路径
|
||||
String path = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName;
|
||||
String path = spectrumPathProperties.getRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName;
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
Map<String, Object> sampleMap = new HashMap<>();
|
||||
Map<String, Object> gasBgMap = new HashMap<>();
|
||||
|
@ -783,7 +783,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
|
|||
File file = null;
|
||||
try {
|
||||
//根据完整的文件路径 获取临时文件
|
||||
file = ftpUtil.downloadFile(filePathName, "betaGamma");
|
||||
file = ftpUtil.downloadFile(filePathName);
|
||||
if (Objects.nonNull(file)) {
|
||||
if (type.equalsIgnoreCase("sample")) {
|
||||
betaDataFile.setSampleTmpPath(file.getAbsolutePath());
|
||||
|
@ -880,26 +880,6 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
|
|||
String betaKey = sampleFileName + "-" + userName;
|
||||
Cache<String, BetaDataFile> cache = betaCache.getBetaCache();
|
||||
BetaDataFile betaDataFile = cache.getIfPresent(betaKey);
|
||||
String sampleTmpPath = betaDataFile.getSampleTmpPath();
|
||||
if (StringUtils.isNotBlank(sampleTmpPath)) {
|
||||
File file = new File(sampleTmpPath);
|
||||
file.delete();
|
||||
}
|
||||
String gasTmpPath = betaDataFile.getGasTmpPath();
|
||||
if (StringUtils.isNotBlank(gasTmpPath)) {
|
||||
File file = new File(gasTmpPath);
|
||||
file.delete();
|
||||
}
|
||||
String detTmpPath = betaDataFile.getDetTmpPath();
|
||||
if (StringUtils.isNotBlank(detTmpPath)) {
|
||||
File file = new File(detTmpPath);
|
||||
file.delete();
|
||||
}
|
||||
String qcTmpPath = betaDataFile.getQcTmpPath();
|
||||
if (StringUtils.isNotBlank(qcTmpPath)) {
|
||||
File file = new File(qcTmpPath);
|
||||
file.delete();
|
||||
}
|
||||
betaCache.deleteBetaCache(betaKey);
|
||||
}
|
||||
|
||||
|
@ -948,7 +928,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
|
|||
InputStream inputStream = null;
|
||||
ServletOutputStream outputStream = null;
|
||||
try {
|
||||
inputStream = ftpUtil.downloadFileStream(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath + ".txt");
|
||||
inputStream = ftpUtil.downloadFileStream(spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath + ".txt");
|
||||
if (Objects.nonNull(inputStream)){
|
||||
outputStream = response.getOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
|
@ -4023,7 +4003,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
|
|||
InputStream inputStream = null;
|
||||
ServletOutputStream outputStream = null;
|
||||
try {
|
||||
inputStream = ftpUtil.downloadFileStream(ftpUtil.getFtpRootPath() + spectrumPathProperties.getLogPath() + StringPool.SLASH + logPath);
|
||||
inputStream = ftpUtil.downloadFileStream(spectrumPathProperties.getRootPath() + spectrumPathProperties.getLogPath() + StringPool.SLASH + logPath);
|
||||
if (Objects.nonNull(inputStream)){
|
||||
outputStream = response.getOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
|
@ -4302,26 +4282,41 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
|
|||
}
|
||||
//上传本次文件到ftp人工交互存储路径下
|
||||
try {
|
||||
if (StringUtils.isNotBlank(betaDataFile.getSampleTmpPath())) {
|
||||
File sampleTmp = new File(betaDataFile.getSampleTmpPath());
|
||||
ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + sampleFilePathName.substring(0, sampleFilePathName.lastIndexOf(StringPool.SLASH)), anlyseResultIn.getSampleFileName(), new FileInputStream(sampleTmp));
|
||||
if (StringUtils.isNotBlank(sampleFilePathName)) {
|
||||
//sample文件的saveFile存储路径
|
||||
String saveSamplePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + sampleFilePathName;
|
||||
if (StringUtils.isNotBlank(betaDataFile.getSampleTmpPath()) && !saveSamplePath.equals(betaDataFile.getSampleTmpPath().replace(StringPool.BACK_SLASH, StringPool.SLASH))) {
|
||||
File sampleTmp = new File(betaDataFile.getSampleTmpPath());
|
||||
ftpUtil.saveFile(saveSamplePath, new FileInputStream(sampleTmp));
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(betaDataFile.getGasTmpPath())) {
|
||||
File gasTmp = new File(betaDataFile.getGasTmpPath());
|
||||
ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + gasFilePathName.substring(0, gasFilePathName.lastIndexOf(StringPool.SLASH)), anlyseResultIn.getGasFileName(), new FileInputStream(gasTmp));
|
||||
if (StringUtils.isNotBlank(gasFilePathName)) {
|
||||
//gas文件的saveFile存储路径
|
||||
String saveGasPath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + gasFilePathName;
|
||||
if (StringUtils.isNotBlank(betaDataFile.getGasTmpPath()) && !saveGasPath.equals(betaDataFile.getGasTmpPath().replace(StringPool.BACK_SLASH, StringPool.SLASH))) {
|
||||
File gasTmp = new File(betaDataFile.getGasTmpPath());
|
||||
ftpUtil.saveFile(saveGasPath, new FileInputStream(gasTmp));
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(betaDataFile.getDetTmpPath())) {
|
||||
File detTmp = new File(betaDataFile.getDetTmpPath());
|
||||
ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + detFilePathName.substring(0, detFilePathName.lastIndexOf(StringPool.SLASH)), anlyseResultIn.getDetFileName(), new FileInputStream(detTmp));
|
||||
if (StringUtils.isNotBlank(detFilePathName)) {
|
||||
//det文件的saveFile存储路径
|
||||
String saveDetPath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + detFilePathName;
|
||||
if (StringUtils.isNotBlank(betaDataFile.getDetTmpPath()) && !saveDetPath.equals(betaDataFile.getDetTmpPath().replace(StringPool.BACK_SLASH, StringPool.SLASH))) {
|
||||
File detTmp = new File(betaDataFile.getDetTmpPath());
|
||||
ftpUtil.saveFile(saveDetPath, new FileInputStream(detTmp));
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(betaDataFile.getQcTmpPath())) {
|
||||
File qcTmp = new File(betaDataFile.getQcTmpPath());
|
||||
ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + qcFilePathName.substring(0, qcFilePathName.lastIndexOf(StringPool.SLASH)), anlyseResultIn.getQcFileName(), new FileInputStream(qcTmp));
|
||||
if (StringUtils.isNotBlank(qcFilePathName)) {
|
||||
//qc文件的saveFile存储路径
|
||||
String saveQcPath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + qcFilePathName;
|
||||
if (StringUtils.isNotBlank(betaDataFile.getQcTmpPath()) && !saveQcPath.equals(betaDataFile.getQcTmpPath().replace(StringPool.BACK_SLASH, StringPool.SLASH))) {
|
||||
File qcTmp = new File(betaDataFile.getQcTmpPath());
|
||||
ftpUtil.saveFile(saveQcPath, new FileInputStream(qcTmp));
|
||||
}
|
||||
}
|
||||
//分析成功后存储日志文件和报告文件
|
||||
{
|
||||
String logPathName = analyses_absolute_LogPath.substring(0, analyses_absolute_LogPath.lastIndexOf(StringPool.SLASH));
|
||||
String logFileName = analyses_absolute_LogPath.substring(analyses_absolute_LogPath.lastIndexOf(StringPool.SLASH)+1);
|
||||
String logFileName = betaDataFile.getSampleFileName().replace("PHD", "log");
|
||||
//获取日志的文件存放路径
|
||||
String logFilePath = parameterProperties.getLogFilePath() + File.separator + DateUtils.formatDate(new Date(), "yyyy-MM-dd");
|
||||
String localLogName = betaDataFile.getSampleFileName().replace("PHD", "log");
|
||||
|
@ -4337,20 +4332,19 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
|
|||
FileUtil.writeString("", logFile, "UTF-8");
|
||||
}
|
||||
FileInputStream in = new FileInputStream(logFile);
|
||||
ftpUtil.saveFile(logPathName, logFileName, in);
|
||||
ftpUtil.saveFile(spectrumPathProperties.getRootPath()+analyses_absolute_LogPath, in);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
{
|
||||
String rptContent = phdFileUtil.OutPutRnRpt(betaDataFile);
|
||||
String rptPathName = analyses_absolute_ReportPath.substring(0, analyses_absolute_ReportPath.lastIndexOf(StringPool.SLASH));
|
||||
String rptFileName = analyses_absolute_ReportPath.substring(analyses_absolute_ReportPath.lastIndexOf(StringPool.SLASH)+1)+".txt";
|
||||
File rptFile = new File(rptFileName);
|
||||
try {
|
||||
FileUtil.writeString(rptContent, rptFile, "UTF-8");
|
||||
FileInputStream in = new FileInputStream(rptFile);
|
||||
ftpUtil.saveFile(rptPathName, rptFileName, in);
|
||||
ftpUtil.saveFile(spectrumPathProperties.getRootPath()+analyses_absolute_ReportPath+".txt", in);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
|
|
|
@ -53,31 +53,49 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService {
|
|||
|
||||
@Override
|
||||
public Result<?> upload(MultipartFile file) {
|
||||
//压缩包文件名称
|
||||
String filename = file.getOriginalFilename();
|
||||
//判断是否是压缩包文件
|
||||
boolean isZip = filename.endsWith(FileTypeEnum.zip.getType());
|
||||
if (!isZip) return Result.error(Prompt.FILE_TYPE_ERR);
|
||||
//如果不是压缩包文件 返回错误提示信息
|
||||
if (!isZip) {
|
||||
return Result.error(Prompt.FILE_TYPE_ERR);
|
||||
}
|
||||
//获取登陆用户名
|
||||
LoginUser user = (LoginUser)SecurityUtils.getSubject().getPrincipal();
|
||||
String username = user.getUsername();
|
||||
FTPClient ftpClient = null;
|
||||
// FTPClient ftpClient = null;
|
||||
//获取文件输出流
|
||||
FileOutputStream fos = null;
|
||||
//获取压缩包文件输入流
|
||||
ZipInputStream zipInputStream = null;
|
||||
String slash = SymbolConstant.SINGLE_SLASH;
|
||||
//上传文件夹路径
|
||||
String filePath = spectrumPathProperties.getUploadPath() + slash + username;
|
||||
String filePath = spectrumPathProperties.getRootPath() + slash + spectrumPathProperties.getUploadPath() + slash + username;
|
||||
//本地临时文件夹路径
|
||||
String tempFilePath = System.getProperty("java.io.tmpdir") + username + slash;
|
||||
//文件名称集合
|
||||
List<String> fileNames = new ArrayList<>();
|
||||
//文件集合
|
||||
List<File> fileList = new ArrayList<>();
|
||||
//正则表达式
|
||||
String sampleRx = "[a-zA-Z]{3}[0-9]{2}_[0-9]{3}-[0-9]{8}_[0-9]{4}_(S|G|D|Q)_(FULL_|PREL_)\\d+\\.PHD";
|
||||
Pattern regexPattern = Pattern.compile(sampleRx);
|
||||
String sampleRx1 = "[a-zA-Z]{3}[0-9]{2}_[0-9]{3}-[0-9]{8}_[0-9]{4}_(S|G|D|Q)_(FULL_|PREL_)\\d+\\.\\d+\\.PHD";
|
||||
Pattern regexPattern1 = Pattern.compile(sampleRx1);
|
||||
try{
|
||||
//创建本地临时文件夹
|
||||
File tempDir = new File(tempFilePath);
|
||||
if (!tempDir.exists()) tempDir.mkdir();
|
||||
//判断本地临时文件夹是否存在
|
||||
if (!tempDir.exists()) {
|
||||
tempDir.mkdir();
|
||||
}
|
||||
//创建输入流
|
||||
zipInputStream = new ZipInputStream(file.getInputStream());
|
||||
ZipEntry entry;
|
||||
//遍历获取压缩包内文件
|
||||
while (ObjectUtil.isNotNull(entry = zipInputStream.getNextEntry())) {
|
||||
//文件名称
|
||||
String fileName = entry.getName();
|
||||
fileNames.add(fileName);
|
||||
File oneFile = new File(tempFilePath + fileName);
|
||||
|
@ -89,46 +107,61 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService {
|
|||
}
|
||||
fileList.add(oneFile);
|
||||
}
|
||||
if (CollUtil.isEmpty(fileList))
|
||||
//判断文件集合是否为空
|
||||
if (CollUtil.isEmpty(fileList)) {
|
||||
return Result.error(Prompt.FILE_IS_EMPTY);
|
||||
ftpClient = ftpUtil.LoginFTP();
|
||||
if (ObjectUtil.isNull(ftpClient))
|
||||
return Result.error(Prompt.FTP_ERR);
|
||||
// 如果指定目录不存在,逐级创建目录
|
||||
boolean created = FTPUtil.createDirs(ftpClient, filePath);
|
||||
if (!created) return Result.error(Prompt.DIR_CREATE_FAIL + filePath);
|
||||
}
|
||||
// //登陆ftp
|
||||
// ftpClient = ftpUtil.LoginFTP();
|
||||
// if (ObjectUtil.isNull(ftpClient)) {
|
||||
// return Result.error(Prompt.FTP_ERR);
|
||||
// }
|
||||
// // 如果指定目录不存在,逐级创建目录
|
||||
// boolean created = FTPUtil.createDirs(ftpClient, filePath);
|
||||
// if (!created) {
|
||||
// return Result.error(Prompt.DIR_CREATE_FAIL + filePath);
|
||||
// }
|
||||
// 上传所有文件
|
||||
List<String> failList = new ArrayList<>();
|
||||
for (File oneFile : fileList) {
|
||||
String fileName = oneFile.getName();
|
||||
// 判断能谱文件名称是否符合规则,不符合则进行重命名
|
||||
if (!regexPattern.matcher(fileName).find() && !regexPattern1.matcher(fileName).find()) {
|
||||
//分析文件
|
||||
EnergySpectrumStruct struct = phdFileUtil.analyzeFileSourceData(oneFile);
|
||||
//获取文件后缀
|
||||
String suffix = nameStandUtil.GetSuffix(struct.data_type, struct.spectrum_quantity, String.valueOf(struct.acquisition_live_time));
|
||||
//获取文件名称
|
||||
fileName = nameStandUtil.GetFileNameFromDateTime(struct.measurement_id, suffix);
|
||||
}
|
||||
String fullFilePath = filePath + slash + fileName;
|
||||
FileInputStream local = new FileInputStream(oneFile);
|
||||
boolean success = ftpClient.storeFile(fileName, local);
|
||||
if (!success) failList.add(fullFilePath);
|
||||
boolean success = ftpUtil.saveFile(fullFilePath, local);
|
||||
if (!success) {
|
||||
failList.add(fullFilePath);
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(failList))
|
||||
if (CollUtil.isNotEmpty(failList)) {
|
||||
return Result.error(Prompt.UPLOAD_ERR, failList);
|
||||
}
|
||||
return Result.OK(Prompt.UPLOAD_SUCC);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return Result.error(Prompt.UPLOAD_ERR);
|
||||
}finally {
|
||||
try {
|
||||
if (ObjectUtil.isNotNull(zipInputStream))
|
||||
if (ObjectUtil.isNotNull(zipInputStream)) {
|
||||
zipInputStream.close();
|
||||
if (ObjectUtil.isNotNull(fos))
|
||||
}
|
||||
if (ObjectUtil.isNotNull(fos)) {
|
||||
fos.close();
|
||||
if (ObjectUtil.isNotNull(ftpClient))
|
||||
if (ftpClient.isConnected()){
|
||||
ftpClient.logout();
|
||||
ftpClient.disconnect();
|
||||
}
|
||||
}
|
||||
// if (ObjectUtil.isNotNull(ftpClient)) {
|
||||
// if (ftpClient.isConnected()){
|
||||
// ftpClient.logout();
|
||||
// ftpClient.disconnect();
|
||||
// }
|
||||
// }
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -143,7 +176,7 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService {
|
|||
String username = user.getUsername();
|
||||
String slash = SymbolConstant.SINGLE_SLASH;
|
||||
String comma = SymbolConstant.COMMA;
|
||||
String filePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + slash + username;
|
||||
String filePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getUploadPath() + slash + username;
|
||||
FTPClient ftpClient = null;
|
||||
List<FileDto> fileDtos = new ArrayList<>();
|
||||
Page<FileDto> page = new Page<>(pageNo, pageSize);
|
||||
|
|
|
@ -34,7 +34,7 @@ public class ReadLineUtil {
|
|||
File file = null;
|
||||
try {
|
||||
filePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + filePath;
|
||||
file = ftpUtil.downloadFile(filePath, "betaGamma");
|
||||
file = ftpUtil.downloadFile(filePath);
|
||||
//判断文件路径是否为空
|
||||
if (Objects.nonNull(file)){
|
||||
List<String> allLines = FileUtils.readLines(file, encoding);
|
||||
|
@ -52,10 +52,6 @@ public class ReadLineUtil {
|
|||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (Objects.nonNull(file)) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl<GardsSampleDataWe
|
|||
GardsSampleDataWeb sampleData = getOneSample(sampleId);
|
||||
String filePath = sampleData.getInputFileName();
|
||||
if (StringUtils.isNotBlank(filePath)) {
|
||||
file = ftpUtil.downloadFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + filePath, "betaGamma");
|
||||
file = ftpUtil.downloadFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + filePath);
|
||||
if (Objects.nonNull(file)) {
|
||||
EnergySpectrumStruct sourceData = EnergySpectrumHandler.getSourceData(file.getAbsolutePath());
|
||||
//查询info
|
||||
|
|
|
@ -16,3 +16,4 @@ spring:
|
|||
import:
|
||||
- optional:nacos:armd.yaml
|
||||
- optional:nacos:armd-@profile.name@.yaml
|
||||
- optional:nacos:armd-analysis-@profile.name@.yaml
|
Loading…
Reference in New Issue
Block a user