Compare commits

...

36 Commits
mdc ... master

Author SHA1 Message Date
orgin
55b68da597 fix 2024-06-05 15:15:29 +08:00
orgin
99cd4bbbfe Merge branch 'mdc'
# Conflicts:
#	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-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumAnalysisServiceImpl.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
2024-06-05 10:40:51 +08:00
nieziyan
86968e383b fix:删除多余文件 2024-05-13 14:58:41 +08:00
qiaoqinzheng
9fffd2436c 自动处理模块模块同步代码 2024-05-13 14:14:01 +08:00
qiaoqinzheng
2407b65a06 自动处理模块下载邮件代码修改 2024-05-13 14:09:42 +08:00
qiaoqinzheng
6c5a0bf546 人工交互模块BetaDataFile实体类增加detectorId字段用于报警使用 2024-05-13 09:24:25 +08:00
qiaoqinzheng
caf47a58d5 人工交互模块增加判断如果不是正常谱提示异常信息内容 2024-05-10 16:12:26 +08:00
nieziyan
18b495d1d0 Merge remote-tracking branch 'origin/noFtp' into noFtp 2024-04-25 15:05:45 +08:00
nieziyan
6335a3f588 fix:修改FTP为本地文件 2024-04-24 09:34:59 +08:00
qiaoqinzheng
b0529f0f3d 同步mdc代码 2024-04-19 16:53:17 +08:00
qiaoqinzheng
01122e6daa 同步代码 2024-04-19 16:08:45 +08:00
qiaoqinzheng
85987985a1 邮箱下载邮件部分增加锁取消异步下载执行,增加关闭输出流 2024-04-19 14:14:51 +08:00
qiaoqinzheng
a38a242e03 同步代码 2024-04-18 15:09:54 +08:00
qiaoqinzheng
a025eb5098 人工交互模块Beta部分分析失败后将核素数据列表清空 2024-04-12 15:34:00 +08:00
qiaoqinzheng
ea3cc4ea0e 人工交互模块Gamma部分增加核素方法增加判断核素存在不重复添加核素信息
人工交互模块Beta部分重新分析全部谱信息,赋值位置修改
2024-04-12 11:50:02 +08:00
qiaoqinzheng
9f9466b529 人工交互模块Gamma部分增加核素方法增加判断核素存在不重复添加核素信息
人工交互模块Beta部分重新分析全部谱信息,赋值位置修改
2024-04-12 10:50:23 +08:00
qiaoqinzheng
3343412516 人工交互模块Gamma部分新增加逻辑,增加峰操作使用缓存的核素信息 2024-04-11 16:51:26 +08:00
qiaoqinzheng
2a99fabe53 人工交互模块Beta保存数据到数据库时,处理数据核素名称匹配时大小写问题修改 2024-04-11 11:03:22 +08:00
qiaoqinzheng
83017ee877 人工交互分析beta部分初始化数据时数据库查询的属于因为缓存已经存在的情况导致数据被重置,存储数据库时下标越界问题修改 2024-03-22 09:24:55 +08:00
nieziyan
89075bef6d feat:1.日志管理模块FTP服务替换为本地文件服务2.日志文件列表增加分页 2024-03-21 18:08:11 +08:00
qiaoqinzheng
c9ee863667 操作本地文件夹分支人工交互模块,文件夹的前缀路径读取不再使用FTP的路径 2024-03-20 14:02:54 +08:00
qiaoqinzheng
46eba27ace 人工交互分析模块Beta保存代码输出语句移除 2024-03-19 17:16:45 +08:00
qiaoqinzheng
924cddb1f2 人工交互分析模块Beta保存数据代码优化,存储前的分析操作移除,根据分析结果数据存储数据 2024-03-19 17:00:16 +08:00
qiaoqinzheng
0c5eadbb2c 人工交互分析模块保存数据到数据库上传日志文件时,获取文件名称错误问题修改 2024-03-15 16:51:49 +08:00
qiaoqinzheng
765ea99ad8 人工交互分析模块Beta在分析失败的情况下不进行存储,提示正确需要分析文件 2024-03-15 16:00:36 +08:00
qiaoqinzheng
0654872c3b 人工交互分析模块Beta在分析失败的情况下不进行存储,提示正确需要分析文件 2024-03-15 15:54:47 +08:00
qiaoqinzheng
953dd61988 人工交互模块Beta部分分析算法,失败的情况下BProcessd,savedAnalysisResult参数修改为false并传递给前端 2024-03-15 11:47:50 +08:00
qiaoqinzheng
f8da6c3aae 人工交互模块Beta部分分析算法,失败的情况下BProcessd参数修改为false并传递给前端 2024-03-15 11:34:57 +08:00
qiaoqinzheng
8d7bee4735 人工交互模块保存文件代码,文件路径\改为/匹配,避免文件被覆盖为0KB的问题 2024-03-15 11:20:21 +08:00
qiaoqinzheng
29821e708d 人工交互模块保存文件代码修改 2024-03-15 11:12:57 +08:00
qiaoqinzheng
1408424893 人工交互模块Beta分析算法返回内容增加message字段提示信息 2024-03-15 10:57:57 +08:00
qiaoqinzheng
70f3d172b6 人工交互模块存储方法,存储数据到数据库文件已经存在的情况下,重复文件提交导致文件大小变成0的问题修改 2024-03-15 10:27:53 +08:00
qiaoqinzheng
17c487ca32 人工交互模块存储方法,存储数据到数据库文件已经存在的情况下,重复文件提交导致文件大小变成0的问题修改 2024-03-15 10:24:51 +08:00
qiaoqinzheng
fb8077531d 人工交互模块测试方法删除 2024-03-14 09:57:21 +08:00
qiaoqinzheng
bc2b3ca4f2 人工交互模块ftp服务上传文件方法修改
人工交互保存数据库方法保存文件修改
2024-03-13 16:37:48 +08:00
qiaoqinzheng
ec24147e3f 人工交互模块修改不使用ftp服务上传,下载远程服务文件,改为本地上传,下载文件 2024-03-13 15:37:26 +08:00
14 changed files with 459 additions and 448 deletions

View File

@ -281,39 +281,74 @@ public class FTPUtil {
/** /**
* 写入文件若文件或文件目录不存在则自行创建 * 写入文件若文件或文件目录不存在则自行创建
* @param filePath 文件路径 * @param filePath 文件路径
* @param fileName 文件名称
* @param inputStream 文件输入流 * @param inputStream 文件输入流
* @return 返回值true/false * @return 返回值true/false
*/ */
public synchronized boolean saveFile(String filePath,String fileName,InputStream inputStream){ public synchronized boolean saveFile(String filePath, InputStream inputStream){
final FTPClient ftpClient = this.LoginFTP(); //声明目标文件
try{ File targetFile = new File(filePath);
final boolean flag = this.checkDirectory(ftpClient,filePath); //创建输出流
if(flag){ FileOutputStream outputStream = null;
ftpClient.setFileType(FTP.BINARY_FILE_TYPE); try {
String encodedName = new String(fileName.getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1); //获取父级路径
final boolean result = ftpClient.storeFile(encodedName, inputStream); File directory = targetFile.getParentFile();
return result; //判断父级路径是否存在
if (!directory.exists()) {
directory.mkdirs();
} }
}catch (IOException e){ // 创建输出流对象并写入数据到文件
log.error("{}文件创建失败,原因为:{}",filePath+"/"+fileName,e.getMessage()); outputStream = new FileOutputStream(targetFile);
e.printStackTrace(); byte[] buffer = new byte[1024];
return false; int length;
}finally { while ((length = inputStream.read(buffer)) > 0) {
if(null != inputStream){ outputStream.write(buffer, 0, length);
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
// 关闭输入流和输出流
try { try {
ftpClient.disconnect(); if (Objects.nonNull(inputStream)) {
inputStream.close();
}
if (Objects.nonNull(outputStream)) {
outputStream.close();
}
} catch (IOException e) { } 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路径的文件保存为指定路径的临时文件 * 将源FTP路径的文件保存为指定路径的临时文件
* */ * */
public File downloadFile(String fromPath, String toPath) { public File downloadFile(String fromPath) {
FTPClient ftpClient = null; //获取路径下的文件信息
InputStream inputStream = null; File tempFile = new File(fromPath);
// 声明一个临时文件 //判断文件是否存在
File tempFile = null; if (!tempFile.exists()) {
try { tempFile = null;
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();
}
} }
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路径的文件转换为文件流 * 将源FTP路径的文件转换为文件流
* */ * */
public InputStream downloadFileStream(String fromPath) { public InputStream downloadFileStream(String fromPath) {
FTPClient ftpClient = null; //获取路径下的文件信息
File tempFile = new File(fromPath);
InputStream inputStream = null;
try { try {
ftpClient = LoginFTP(); //判断文件是否存在
// 切换被动模式 if (tempFile.exists()) {
ftpClient.enterLocalPassiveMode(); inputStream = new FileInputStream(tempFile);
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();
} }
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();
// }
// }
} }
} }

View File

@ -70,9 +70,9 @@ public class GammaFileUtil extends AbstractLogOrReport {
//如果功能是人工交互模块则从ftp获取文件内容 //如果功能是人工交互模块则从ftp获取文件内容
File file = null; File file = null;
if (sysSource.equals("BetaGamma")) { if (sysSource.equals("BetaGamma")) {
file = ftpUtil.downloadFile(fromPath, "betaGamma"); file = ftpUtil.downloadFile(fromPath);
if (Objects.isNull(file)) { if (Objects.isNull(file)) {
result.error500("ftp file can't find"); result.error500("file can't find");
return false; return false;
} }
} else if (sysSource.equals("AUTO")) {//如果是自动处理则从本地文件中获取文件内容 } else if (sysSource.equals("AUTO")) {//如果是自动处理则从本地文件中获取文件内容
@ -265,7 +265,7 @@ public class GammaFileUtil extends AbstractLogOrReport {
try { try {
String lcFileName = prefixName+"_"+subFileName + ".lc"; String lcFileName = prefixName+"_"+subFileName + ".lc";
String fromPathLc = pathName + StringPool.SLASH + lcFileName; String fromPathLc = pathName + StringPool.SLASH + lcFileName;
lcFile = ftpUtil.downloadFile(fromPathLc, "betaGamma"); lcFile = ftpUtil.downloadFile(fromPathLc);
if (Objects.nonNull(lcFile)) { if (Objects.nonNull(lcFile)) {
List<String> readLinesLc = FileUtils.readLines(lcFile, "UTF-8"); List<String> readLinesLc = FileUtils.readLines(lcFile, "UTF-8");
//得到行数据处理后的数据结果 //得到行数据处理后的数据结果
@ -275,7 +275,7 @@ public class GammaFileUtil extends AbstractLogOrReport {
} }
String scacFileName = prefixName+"_"+subFileName + ".scac"; String scacFileName = prefixName+"_"+subFileName + ".scac";
String fromPathScac = pathName + StringPool.SLASH + scacFileName; String fromPathScac = pathName + StringPool.SLASH + scacFileName;
scacFile = ftpUtil.downloadFile(fromPathScac, "betaGamma"); scacFile = ftpUtil.downloadFile(fromPathScac);
if (Objects.nonNull(scacFile)) { if (Objects.nonNull(scacFile)) {
List<String> readLinesScac = FileUtils.readLines(scacFile, "UTF-8"); List<String> readLinesScac = FileUtils.readLines(scacFile, "UTF-8");
//得到行数据处理后的数据结果 //得到行数据处理后的数据结果
@ -298,10 +298,6 @@ public class GammaFileUtil extends AbstractLogOrReport {
try { try {
if (ObjectUtil.isNotNull(inputStreamBase)) if (ObjectUtil.isNotNull(inputStreamBase))
inputStreamBase.close(); inputStreamBase.close();
if (ObjectUtil.isNotNull(lcFile))
lcFile.delete();
if (ObjectUtil.isNotNull(scacFile))
scacFile.delete();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -3234,8 +3230,10 @@ public class GammaFileUtil extends AbstractLogOrReport {
File sampleTmp = null; File sampleTmp = null;
try { try {
sampleTmp = new File(fileAnlyse.getTmpFilePath()); sampleTmp = new File(fileAnlyse.getTmpFilePath());
if (Objects.nonNull(sampleTmp)) { //sample文件的存储路径
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)); 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) { } catch (FileNotFoundException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@ -4369,7 +4367,7 @@ public class GammaFileUtil extends AbstractLogOrReport {
public File analyzeFile(String path, String fileName) { public File analyzeFile(String path, String fileName) {
path = path.replace("\\", "/"); path = path.replace("\\", "/");
String fromPath = path + StringPool.SLASH + fileName; String fromPath = path + StringPool.SLASH + fileName;
return ftpUtil.downloadFile(fromPath, "betaGamma"); return ftpUtil.downloadFile(fromPath);
} }
public List<String> readLine(String filePath) { public List<String> readLine(String filePath) {

View File

@ -2,7 +2,9 @@ package org.jeecg.modules.controller;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.FTPUtil; import org.jeecg.common.util.FTPUtil;
import org.jeecg.modules.base.bizVo.FileVo;
import org.jeecg.modules.entity.FileInfo; import org.jeecg.modules.entity.FileInfo;
import org.jeecg.modules.entity.LogManage; import org.jeecg.modules.entity.LogManage;
import org.jeecg.modules.service.ILogManageService; import org.jeecg.modules.service.ILogManageService;
@ -20,31 +22,24 @@ import java.util.List;
@Api(value = "日志管理", tags = "日志管理") @Api(value = "日志管理", tags = "日志管理")
public class LogManageController { public class LogManageController {
@Autowired
private FTPUtil ftpUtil;
@Autowired @Autowired
private ILogManageService logManageService; private ILogManageService logManageService;
@GetMapping("findFtpFolders") @GetMapping("findFtpFolders")
@ApiOperation(value = "查询日志文件夹树形结构", notes = "查询日志文件夹树形结构") @ApiOperation(value = "查询日志文件夹树形结构", notes = "查询日志文件夹树形结构")
public List<LogManage> findFtpFolders(String workPath) { public List<LogManage> findFtpFolders(String workPath) {
return logManageService.findFtpFolders(workPath); return logManageService.fileTree(workPath);
} }
/**
* 查询目录下文件内容
* @param path
* @return
*/
@GetMapping("findFiles") @GetMapping("findFiles")
@ApiOperation(value = "查询目录下文件内容", notes = "查询目录下文件内容") @ApiOperation(value = "查询目录下文件内容", notes = "查询目录下文件内容")
public List<FileInfo> findFiles(String path) { public Result<?> findFiles(String path, FileVo fileVo) {
return logManageService.findFiles(path); return logManageService.findFiles(path, fileVo);
} }
@PostMapping("downloadFile") @PostMapping("downloadFile")
@ApiOperation(value = "ftp文件下载", notes = "ftp文件下载") @ApiOperation(value = "ftp文件下载", notes = "ftp文件下载")
public void downloadFile(String localPath, String fileName, HttpServletResponse response) { public void downloadFile(String localPath, HttpServletResponse response) {
ftpUtil.downloadFTPFile(localPath, response); logManageService.downloadFile(localPath, response);
} }
} }

View File

@ -1,24 +1,24 @@
package org.jeecg.modules.service; 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.FileInfo;
import org.jeecg.modules.entity.LogManage; import org.jeecg.modules.entity.LogManage;
import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
public interface ILogManageService { 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);
} }

View File

@ -1,192 +1,159 @@
package org.jeecg.modules.service.impl; 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.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringPool; 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.FTPClient;
import org.apache.commons.net.ftp.FTPFile; 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.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.FileInfo;
import org.jeecg.modules.entity.LogManage; import org.jeecg.modules.entity.LogManage;
import org.jeecg.modules.service.ILogManageService; import org.jeecg.modules.service.ILogManageService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@Service("logManageService") @Slf4j
@Service
public class LogManageServiceImpl implements ILogManageService { public class LogManageServiceImpl implements ILogManageService {
@Autowired @Autowired
private FTPUtil ftpUtil; private SpectrumPathProperties spectrumPath;
@Override @Override
public List<LogManage> findFtpFolders(String workPath) { public List<LogManage> fileTree(String workPath) {
List<LogManage> result = new ArrayList<>(); List<LogManage> result = new ArrayList<>();
FTPClient ftpClient = ftpUtil.LoginFTP(); workPath = spectrumPath.getRootPath() + StringPool.SLASH + workPath;
if(Objects.isNull(ftpClient)){ List<File> files = ListUtil.toList(FileUtil.ls(workPath));
throw new RuntimeException("ftp connection failed!"); 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; return result;
} }
@Override @Override
public List<FileInfo> findFiles(String path) { public Result<?> findFiles(String path, FileVo fileVo) {
List<FileInfo> result = new ArrayList<>(); String name = fileVo.getName();
FTPClient ftpClient = ftpUtil.LoginFTP(); Integer pageNo = fileVo.getPageNo();
if (Objects.isNull(ftpClient)){ Integer pageSize = fileVo.getPageSize();
throw new RuntimeException("ftp connection failed!"); 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 { try {
//切换被动模式 // 如果是目录 则直接退出方法
ftpClient.enterLocalPassiveMode(); if (FileUtil.isDirectory(localPath)) return;
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
// 设置编码当文件中存在中文且上传后文件乱码时可使用此配置项 // 判断是否存在此文件
ftpClient.setControlEncoding("UTF-8"); if (!FileUtil.exist(localPath)) return;
ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE);
//切换工作文件路径 // 获取文件名
ftpClient.changeWorkingDirectory(path); String fileName = FileUtil.getName(localPath);
List<FTPFile> ftpFiles = Arrays.asList(ftpClient.listFiles());
if (CollectionUtils.isNotEmpty(ftpFiles)){ inputStream = FileUtil.getInputStream(localPath);
for (FTPFile ftpFile:ftpFiles) { outputStream = ExportUtil.stream(response, fileName);
if (ftpFile.isFile()){
FileInfo fileInfo = new FileInfo(); // 缓冲区大小
fileInfo.setFileName(ftpFile.getName()); byte[] buffer = new byte[4096];
fileInfo.setFilePath(path + StringPool.SLASH + ftpFile.getName()); int bytesRead;
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); while ((bytesRead = inputStream.read(buffer)) != -1) {
} outputStream.write(buffer, 0, bytesRead);
}
} }
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); log.error("文件{}下载失败 :{}", localPath, e.getMessage());
} finally { } finally {
try { try {
if (ftpClient != null){ if (ObjectUtil.isNotNull(inputStream))inputStream.close();
ftpClient.disconnect(); if (ObjectUtil.isNotNull(outputStream))outputStream.close();
}
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); e.printStackTrace();
} }
} }
return result;
} }
/** /**
* 遍历查询当前路径下的文件夹信息 * 获取当前目录节点所有子孙节点Tree
* @param ftpClient
* @param list
* @param filePath "/"开始和结束
* @return
*/ */
public List<LogManage> findDirectory(FTPClient ftpClient, List<LogManage> list, Integer parentNum, String filePath, String fileName){ private List<LogManage> getChildren(LogManage parent){
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;
}
List<LogManage> result = new LinkedList<>(); List<LogManage> result = new LinkedList<>();
Integer TOP_NODE_ID = 0; String parentPath = parent.getPath();
logManages.forEach(logManage -> { // 如果是文件 则直接返回空集合
Integer pid = logManage.getParentNum(); if (FileUtil.isFile(parentPath)) return result;
if (pid == null || TOP_NODE_ID.equals(pid)) { List<File> files = ListUtil.toList(FileUtil.ls(parentPath));
result.add(logManage); // 如果当前目录不存在子文件 则返回空集合
return; if (CollUtil.isEmpty(files)) return result;
} int parentOrderNum = parent.getOrderNum();
for (LogManage manage : logManages) { int num = parentOrderNum * 10 + 1;
Integer id = manage.getOrderNum(); for (File file : files) {
if (id != null && id.equals(pid)) { // 过滤掉文件 只收集目录
if (manage.getChildren() == null) { if (FileUtil.isFile(file)) continue;
manage.initChildren(); LogManage logManage = new LogManage();
} logManage.setName(file.getName());
logManage.setHashParent(true); logManage.setOrderNum(num++);
manage.getChildren().add(logManage); logManage.setHashParent(true);
manage.setHashChild(true); logManage.setParentNum(parentOrderNum);
return; 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; return result;
} }
} }

View File

@ -817,7 +817,7 @@ public class PHDFileUtil extends AbstractLogOrReport {
File file = null; File file = null;
try { try {
String fromPath = filePath + StringPool.SLASH + sampleFileName; String fromPath = filePath + StringPool.SLASH + sampleFileName;
file = ftpUtil.downloadFile(fromPath, "betaGamma"); file = ftpUtil.downloadFile(fromPath);
//加载sampleFile内容 //加载sampleFile内容
EnergySpectrumStruct struct = EnergySpectrumHandler.getSourceData(file.getAbsolutePath()); EnergySpectrumStruct struct = EnergySpectrumHandler.getSourceData(file.getAbsolutePath());
//获取所需要的数据 //获取所需要的数据
@ -841,9 +841,6 @@ public class PHDFileUtil extends AbstractLogOrReport {
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
return map; return map;
}finally {
if (ObjectUtil.isNotNull(file))
file.delete();
} }
} }
@ -852,7 +849,7 @@ public class PHDFileUtil extends AbstractLogOrReport {
File file = null; File file = null;
try { try {
String fromPath = filePath + StringPool.SLASH + fileName; String fromPath = filePath + StringPool.SLASH + fileName;
file = ftpUtil.downloadFile(fromPath, "betaGamma"); file = ftpUtil.downloadFile(fromPath);
EnergySpectrumStruct sourceData = EnergySpectrumHandler.getSourceData(file.getAbsolutePath()); EnergySpectrumStruct sourceData = EnergySpectrumHandler.getSourceData(file.getAbsolutePath());
String systemType = sourceData.system_type; String systemType = sourceData.system_type;
String dataType = sourceData.data_type; String dataType = sourceData.data_type;
@ -886,9 +883,6 @@ public class PHDFileUtil extends AbstractLogOrReport {
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
return path.toString(); return path.toString();
}finally {
if (ObjectUtil.isNotNull(file))
file.delete();
} }
} }
@ -1120,9 +1114,6 @@ public class PHDFileUtil extends AbstractLogOrReport {
if (Objects.nonNull(inputStream)){ if (Objects.nonNull(inputStream)){
inputStream.close(); inputStream.close();
} }
if (Objects.nonNull(file)) {
file.delete();
}
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View File

@ -41,6 +41,8 @@ public class BetaDataFile implements Serializable {
private String stationId; private String stationId;
private String detectorId;
private boolean bProcessed; private boolean bProcessed;
private boolean saveAnalysisResult; private boolean saveAnalysisResult;

View File

@ -180,7 +180,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
return result; 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); String fileName = sampleFilePath.substring(sampleFilePath.lastIndexOf(StringPool.SLASH) + 1);
// 声明phd实体类 // 声明phd实体类
@ -194,6 +194,10 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
if (!flag) { if (!flag) {
return result; return result;
} }
if (Objects.nonNull(phd) && !phd.isValid()) {
result.error500("This Spectrum is invalid! it's counts are all zero");
return result;
}
// 加载phd数据所需的lcscacbaseline数据 // 加载phd数据所需的lcscacbaseline数据
if (dbName.equals("auto")) { if (dbName.equals("auto")) {
gammaFileUtil.SetBaseInfo(phd, "RNAUTO"); gammaFileUtil.SetBaseInfo(phd, "RNAUTO");
@ -598,7 +602,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
Cache<String, PHDFile> phdCache = localCache.getPHDCache(); 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); Map<String, String> colorMap = sysUserColorService.initColor(userName);
PHDFile phd = phdCache.getIfPresent(fileName + StringPool.DASH + userName); PHDFile phd = phdCache.getIfPresent(fileName + StringPool.DASH + userName);
@ -609,6 +613,10 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
if (!bRet) { if (!bRet) {
return result; return result;
} }
if (Objects.nonNull(phd) && !phd.isValid()) {
result.error500("This Spectrum is invalid! it's counts are all zero");
return result;
}
if (!redisUtil.hasKey(userName+StringPool.DASH+phd.getHeader().getSystem_type()) || !redisUtil.hasKey(userName+StringPool.DASH+phd.getHeader().getSystem_type()+"-list")) { if (!redisUtil.hasKey(userName+StringPool.DASH+phd.getHeader().getSystem_type()) || !redisUtil.hasKey(userName+StringPool.DASH+phd.getHeader().getSystem_type()+"-list")) {
//读取缓存的全部核素信息 //读取缓存的全部核素信息
Map<String, NuclideLines> allNuclideMap = (Map<String, NuclideLines>) redisUtil.get("AllNuclideMap"); Map<String, NuclideLines> allNuclideMap = (Map<String, NuclideLines>) redisUtil.get("AllNuclideMap");
@ -671,12 +679,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
String key = fileName + StrUtil.DASHED + username; String key = fileName + StrUtil.DASHED + username;
Cache<String, PHDFile> phdCache = localCache.getPHDCache(); Cache<String, PHDFile> phdCache = localCache.getPHDCache();
PHDFile phdFile = phdCache.getIfPresent(key); PHDFile phdFile = phdCache.getIfPresent(key);
if (StringUtils.isNotBlank(phdFile.getTmpFilePath())) {
File file = new File(phdFile.getTmpFilePath());
if (Objects.nonNull(file)) {
file.delete();
}
}
// 删除指定key的Cache // 删除指定key的Cache
localCache.deletePHDCache(key); localCache.deletePHDCache(key);
} }
@ -743,8 +745,8 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
result.error500("The comparison file path does not exist"); result.error500("The comparison file path does not exist");
return result; return result;
} }
compareFilePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + compareFilePath; compareFilePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + compareFilePath;
File compareFile = ftpUtil.downloadFile(compareFilePath, "betaGamma"); File compareFile = ftpUtil.downloadFile(compareFilePath);
if (Objects.isNull(compareFile)) { if (Objects.isNull(compareFile)) {
result.error500("The comparison file path does not exist"); result.error500("The comparison file path does not exist");
return result; return result;
@ -756,7 +758,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
result.setSuccess(true); result.setSuccess(true);
result.setResult(chartDataList); result.setResult(chartDataList);
} }
compareFile.delete();
return result; return result;
} }
@ -776,9 +777,9 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
long m_nCount = phd.getSpec().getNum_g_channel(); long m_nCount = phd.getSpec().getNum_g_channel();
List<Double> vEnergy = phd.getVEnergy(); List<Double> vEnergy = phd.getVEnergy();
//加载compare文件 //加载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; String fromPath = compareFilePath + StringPool.SLASH + compareFileName;
File compareFile = ftpUtil.downloadFile(fromPath, "betaGamma"); File compareFile = ftpUtil.downloadFile(fromPath);
if (Objects.nonNull(compareFile)) { if (Objects.nonNull(compareFile)) {
// 获取Compare数据 // 获取Compare数据
List<Long> m_vecCompare = gammaFileUtil.loadCompareData(compareFile, userName, m_nCount, result); List<Long> m_vecCompare = gammaFileUtil.loadCompareData(compareFile, userName, m_nCount, result);
@ -787,7 +788,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
result.setSuccess(true); result.setSuccess(true);
result.setResult(chartDataList); result.setResult(chartDataList);
} }
compareFile.delete();
} }
return result; return result;
} }
@ -827,8 +827,8 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
result.error500("The comparison file path does not exist"); result.error500("The comparison file path does not exist");
return result; return result;
} }
stripFilePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + stripFilePath; stripFilePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + stripFilePath;
File stripFile = ftpUtil.downloadFile(stripFilePath, "betaGamma"); File stripFile = ftpUtil.downloadFile(stripFilePath);
if (Objects.isNull(stripFile)) { if (Objects.isNull(stripFile)) {
result.error500("The comparison file path does not exist"); result.error500("The comparison file path does not exist");
return result; return result;
@ -843,7 +843,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
result.setSuccess(true); result.setSuccess(true);
result.setResult(stripMap); result.setResult(stripMap);
} }
stripFile.delete();
return result; return result;
} }
@ -877,9 +876,9 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
m_vCount.add(0L); m_vCount.add(0L);
} }
//加载strip文件 //加载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; String fromPath = stripFilePath + StringPool.SLASH + stripFileName;
File stripFile = ftpUtil.downloadFile(fromPath, "betaGamma"); File stripFile = ftpUtil.downloadFile(fromPath);
if (Objects.nonNull(stripFile)) { if (Objects.nonNull(stripFile)) {
// 获取Compare数据 // 获取Compare数据
List<Long> m_vecCompare = gammaFileUtil.loadCompareData(stripFile, userName, m_nCount, result); List<Long> m_vecCompare = gammaFileUtil.loadCompareData(stripFile, userName, m_nCount, result);
@ -891,7 +890,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
result.setSuccess(true); result.setSuccess(true);
result.setResult(stripMap); result.setResult(stripMap);
} }
stripFile.delete();
} }
return result; return result;
} }
@ -3026,9 +3024,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
if (Objects.nonNull(inputStream)) { if (Objects.nonNull(inputStream)) {
inputStream.close(); inputStream.close();
} }
if (Objects.nonNull(tmpFile)) {
tmpFile.delete();
}
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -3300,9 +3295,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
if (Objects.nonNull(inputStream)) { if (Objects.nonNull(inputStream)) {
inputStream.close(); inputStream.close();
} }
if (Objects.nonNull(tmpFile)) {
tmpFile.delete();
}
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -3596,9 +3588,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
if (Objects.nonNull(inputStream)) { if (Objects.nonNull(inputStream)) {
inputStream.close(); inputStream.close();
} }
if (Objects.nonNull(tmpFile)) {
tmpFile.delete();
}
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -3961,7 +3950,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
if (StringUtils.isBlank(reportPath)) { if (StringUtils.isBlank(reportPath)) {
throw new RuntimeException("The automatic handler generated report does not exist"); 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; InputStream inputStream = null;
ServletOutputStream outputStream = null; ServletOutputStream outputStream = null;
try { try {
@ -3995,7 +3984,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
public void exportARR(Integer sampleId, HttpServletResponse response) { public void exportARR(Integer sampleId, HttpServletResponse response) {
// 获取自动处理生成的报告地址 // 获取自动处理生成的报告地址
String reportPath = spectrumAnalysisMapper.viewARR(sampleId); 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; InputStream inputStream = null;
ServletOutputStream outputStream = null; ServletOutputStream outputStream = null;
try { try {
@ -4595,7 +4584,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
if (StringUtils.isBlank(logPath)) { if (StringUtils.isBlank(logPath)) {
throw new RuntimeException("The log generated by the automatic processor does not exist"); 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; InputStream inputStream = null;
ServletOutputStream outputStream = null; ServletOutputStream outputStream = null;
try { try {
@ -4810,47 +4799,40 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
phd.setStatus("R"); phd.setStatus("R");
//分析成功后存储日志文件和报告文件 //分析成功后存储日志文件和报告文件
String rootPath = spectrumPathProperties.getRootPath(); 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); String logFileName = middleData.analyses_absolute_LogPath.substring(middleData.analyses_absolute_LogPath.lastIndexOf(StringPool.SLASH)+1);
File logFile = new File(logFileName); File logFile = new File(logFileName);
try { try {
FileUtil.writeString(gammaFileUtil.GetLogContent(middleData), logFile, "UTF-8"); FileUtil.writeString(gammaFileUtil.GetLogContent(middleData), logFile, "UTF-8");
FileInputStream in = new FileInputStream(logFile); FileInputStream in = new FileInputStream(logFile);
ftpUtil.saveFile(logPathName, logFileName, in); ftpUtil.saveFile(spectrumPathProperties.getRootPath()+middleData.analyses_absolute_LogPath, in);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally { } finally {
@ -4858,13 +4840,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"; String rptFileName = middleData.analyses_absolute_ReportPath.substring(middleData.analyses_absolute_ReportPath.lastIndexOf(StringPool.SLASH)+1)+".txt";
File rptFile = new File(rptFileName); File rptFile = new File(rptFileName);
try { try {
FileUtil.writeString(gammaFileUtil.GetReportContent(middleData), rptFile, "UTF-8"); FileUtil.writeString(gammaFileUtil.GetReportContent(middleData), rptFile, "UTF-8");
FileInputStream in = new FileInputStream(rptFile); FileInputStream in = new FileInputStream(rptFile);
ftpUtil.saveFile(rptPathName, rptFileName, in); ftpUtil.saveFile(spectrumPathProperties.getRootPath()+middleData.analyses_absolute_ReportPath+".txt", in);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally { } finally {

View File

@ -14,6 +14,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import io.swagger.models.auth.In;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
@ -43,6 +44,7 @@ import org.jeecg.modules.native_jni.struct.BgAnalyseResult;
import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct; import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct;
import org.jeecg.modules.service.*; import org.jeecg.modules.service.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.thymeleaf.TemplateEngine; import org.thymeleaf.TemplateEngine;
@ -299,7 +301,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
Result result = new Result(); Result result = new Result();
List<Map<String, Object>> resultList = new LinkedList<>(); List<Map<String, Object>> resultList = new LinkedList<>();
String userName = JwtUtil.getUserNameByToken(request); 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"; 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); 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"; 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 +482,9 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
betaDataFile.setSampleId(String.valueOf(sampleId)); betaDataFile.setSampleId(String.valueOf(sampleId));
//判断sample信息是否存在 //判断sample信息是否存在
if (Objects.nonNull(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); betaDataFile.setSampleFileName(sampleFileName);
sampleTmp = ftpUtil.downloadFile(betaDataFile.getSampleFilePathName(), "betaGamma"); sampleTmp = ftpUtil.downloadFile(betaDataFile.getSampleFilePathName());
if (Objects.nonNull(sampleTmp)) { if (Objects.nonNull(sampleTmp)) {
//sample临时文件路径存储 //sample临时文件路径存储
betaDataFile.setSampleTmpPath(sampleTmp.getAbsolutePath()); betaDataFile.setSampleTmpPath(sampleTmp.getAbsolutePath());
@ -517,9 +519,9 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
} }
//判断gas信息是否存在 //判断gas信息是否存在
if (Objects.nonNull(gasBg)) { 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); betaDataFile.setGasFileName(gasFileName);
gasTmp = ftpUtil.downloadFile(betaDataFile.getGasFilePathName(), "betaGamma"); gasTmp = ftpUtil.downloadFile(betaDataFile.getGasFilePathName());
if (Objects.nonNull(gasTmp)) { if (Objects.nonNull(gasTmp)) {
//存储gas临时文件路径 //存储gas临时文件路径
betaDataFile.setGasTmpPath(gasTmp.getAbsolutePath()); betaDataFile.setGasTmpPath(gasTmp.getAbsolutePath());
@ -554,9 +556,9 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
} }
//判断det信息是否存在 //判断det信息是否存在
if (Objects.nonNull(detBg)) { 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); betaDataFile.setDetFileName(detFileName);
detTmp = ftpUtil.downloadFile(betaDataFile.getDetFilePathName(), "betaGamma"); detTmp = ftpUtil.downloadFile(betaDataFile.getDetFilePathName());
if (Objects.nonNull(detTmp)) { if (Objects.nonNull(detTmp)) {
//存储det临时文件路径 //存储det临时文件路径
betaDataFile.setDetTmpPath(detTmp.getAbsolutePath()); betaDataFile.setDetTmpPath(detTmp.getAbsolutePath());
@ -591,9 +593,9 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
} }
//判断qc信息是否存在 //判断qc信息是否存在
if (Objects.nonNull(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); betaDataFile.setQcFileName(qcFileName);
qcTmp = ftpUtil.downloadFile(betaDataFile.getQcFilePathName(), "betaGamma"); qcTmp = ftpUtil.downloadFile(betaDataFile.getQcFilePathName());
if (Objects.nonNull(qcTmp)) { if (Objects.nonNull(qcTmp)) {
betaDataFile.setQcTmpPath(qcTmp.getAbsolutePath()); betaDataFile.setQcTmpPath(qcTmp.getAbsolutePath());
EnergySpectrumStruct struct = EnergySpectrumHandler.getSourceData(qcTmp.getAbsolutePath()); EnergySpectrumStruct struct = EnergySpectrumHandler.getSourceData(qcTmp.getAbsolutePath());
@ -671,7 +673,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
//获取用户名 //获取用户名
String userName = JwtUtil.getUserNameByToken(request); 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> resultMap = new HashMap<>();
Map<String, Object> sampleMap = new HashMap<>(); Map<String, Object> sampleMap = new HashMap<>();
Map<String, Object> gasBgMap = new HashMap<>(); Map<String, Object> gasBgMap = new HashMap<>();
@ -783,7 +785,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
File file = null; File file = null;
try { try {
//根据完整的文件路径 获取临时文件 //根据完整的文件路径 获取临时文件
file = ftpUtil.downloadFile(filePathName, "betaGamma"); file = ftpUtil.downloadFile(filePathName);
if (Objects.nonNull(file)) { if (Objects.nonNull(file)) {
if (type.equalsIgnoreCase("sample")) { if (type.equalsIgnoreCase("sample")) {
betaDataFile.setSampleTmpPath(file.getAbsolutePath()); betaDataFile.setSampleTmpPath(file.getAbsolutePath());
@ -880,26 +882,6 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
String betaKey = sampleFileName + "-" + userName; String betaKey = sampleFileName + "-" + userName;
Cache<String, BetaDataFile> cache = betaCache.getBetaCache(); Cache<String, BetaDataFile> cache = betaCache.getBetaCache();
BetaDataFile betaDataFile = cache.getIfPresent(betaKey); 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); betaCache.deleteBetaCache(betaKey);
} }
@ -948,7 +930,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
InputStream inputStream = null; InputStream inputStream = null;
ServletOutputStream outputStream = null; ServletOutputStream outputStream = null;
try { 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)){ if (Objects.nonNull(inputStream)){
outputStream = response.getOutputStream(); outputStream = response.getOutputStream();
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
@ -4023,7 +4005,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
InputStream inputStream = null; InputStream inputStream = null;
ServletOutputStream outputStream = null; ServletOutputStream outputStream = null;
try { 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)){ if (Objects.nonNull(inputStream)){
outputStream = response.getOutputStream(); outputStream = response.getOutputStream();
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
@ -4302,55 +4284,68 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
} }
//上传本次文件到ftp人工交互存储路径下 //上传本次文件到ftp人工交互存储路径下
try { try {
if (StringUtils.isNotBlank(betaDataFile.getSampleTmpPath())) { if (StringUtils.isNotBlank(sampleFilePathName)) {
File sampleTmp = new File(betaDataFile.getSampleTmpPath()); //sample文件的saveFile存储路径
ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + sampleFilePathName.substring(0, sampleFilePathName.lastIndexOf(StringPool.SLASH)), anlyseResultIn.getSampleFileName(), new FileInputStream(sampleTmp)); 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())) { if (StringUtils.isNotBlank(gasFilePathName)) {
File gasTmp = new File(betaDataFile.getGasTmpPath()); //gas文件的saveFile存储路径
ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + gasFilePathName.substring(0, gasFilePathName.lastIndexOf(StringPool.SLASH)), anlyseResultIn.getGasFileName(), new FileInputStream(gasTmp)); 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())) { if (StringUtils.isNotBlank(detFilePathName)) {
File detTmp = new File(betaDataFile.getDetTmpPath()); //det文件的saveFile存储路径
ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + detFilePathName.substring(0, detFilePathName.lastIndexOf(StringPool.SLASH)), anlyseResultIn.getDetFileName(), new FileInputStream(detTmp)); 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())) { if (StringUtils.isNotBlank(qcFilePathName)) {
File qcTmp = new File(betaDataFile.getQcTmpPath()); //qc文件的saveFile存储路径
ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + qcFilePathName.substring(0, qcFilePathName.lastIndexOf(StringPool.SLASH)), anlyseResultIn.getQcFileName(), new FileInputStream(qcTmp)); 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 = betaDataFile.getSampleFileName().replace("PHD", "log");
String logFileName = analyses_absolute_LogPath.substring(analyses_absolute_LogPath.lastIndexOf(StringPool.SLASH)+1);
//获取日志的文件存放路径 //获取日志的文件存放路径
String logFilePath = parameterProperties.getLogFilePath() + File.separator + DateUtils.formatDate(new Date(), "yyyy-MM-dd"); String logFilePath = parameterProperties.getLogFilePath() + File.separator + DateUtils.formatDate(new Date(), "yyyy-MM-dd");
String localLogName = betaDataFile.getSampleFileName().replace("PHD", "log");
//判断文件路径是否存在 //判断文件路径是否存在
File logPath = new File(logFilePath); File logPath = new File(logFilePath);
if (!logPath.exists()) { if (!logPath.exists()) {
logPath.mkdirs(); logPath.mkdirs();
} }
File logFile = new File(logFilePath + File.separator +localLogName); File logFile = new File(logFilePath + File.separator +logFileName);
try { try {
//判断日志文件是否存在 如果不存在创建一个空的文件 上传到ftp //判断日志文件是否存在 如果不存在创建一个空的文件 上传到ftp
if (!logFile.exists()) { if (!logFile.exists()) {
FileUtil.writeString("", logFile, "UTF-8"); FileUtil.writeString("", logFile, "UTF-8");
} }
FileInputStream in = new FileInputStream(logFile); FileInputStream in = new FileInputStream(logFile);
ftpUtil.saveFile(logPathName, logFileName, in); ftpUtil.saveFile(spectrumPathProperties.getRootPath()+analyses_absolute_LogPath, in);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
{ {
String rptContent = phdFileUtil.OutPutRnRpt(betaDataFile); 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"; String rptFileName = analyses_absolute_ReportPath.substring(analyses_absolute_ReportPath.lastIndexOf(StringPool.SLASH)+1)+".txt";
File rptFile = new File(rptFileName); File rptFile = new File(rptFileName);
try { try {
FileUtil.writeString(rptContent, rptFile, "UTF-8"); FileUtil.writeString(rptContent, rptFile, "UTF-8");
FileInputStream in = new FileInputStream(rptFile); FileInputStream in = new FileInputStream(rptFile);
ftpUtil.saveFile(rptPathName, rptFileName, in); ftpUtil.saveFile(spectrumPathProperties.getRootPath()+analyses_absolute_ReportPath+".txt", in);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally { } finally {
@ -4425,6 +4420,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
String error = "get station_id or detect_id error"; String error = "get station_id or detect_id error";
return false; return false;
} }
betaDataFile.setDetectorId(detectorId.toString());
//新增Gards_Sample_Data表数据 //新增Gards_Sample_Data表数据
sampleDataSpectrumService.saveSampleData(sourceData, stationId, detectorId, filePathName, readLines); sampleDataSpectrumService.saveSampleData(sourceData, stationId, detectorId, filePathName, readLines);
//获取sampleId //获取sampleId

View File

@ -53,31 +53,49 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService {
@Override @Override
public Result<?> upload(MultipartFile file) { public Result<?> upload(MultipartFile file) {
//压缩包文件名称
String filename = file.getOriginalFilename(); String filename = file.getOriginalFilename();
//判断是否是压缩包文件
boolean isZip = filename.endsWith(FileTypeEnum.zip.getType()); 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(); LoginUser user = (LoginUser)SecurityUtils.getSubject().getPrincipal();
String username = user.getUsername(); String username = user.getUsername();
FTPClient ftpClient = null; // FTPClient ftpClient = null;
//获取文件输出流
FileOutputStream fos = null; FileOutputStream fos = null;
//获取压缩包文件输入流
ZipInputStream zipInputStream = null; ZipInputStream zipInputStream = null;
String slash = SymbolConstant.SINGLE_SLASH; 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; String tempFilePath = System.getProperty("java.io.tmpdir") + username + slash;
//文件名称集合
List<String> fileNames = new ArrayList<>(); List<String> fileNames = new ArrayList<>();
//文件集合
List<File> fileList = 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"; 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); 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"; 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); Pattern regexPattern1 = Pattern.compile(sampleRx1);
try{ try{
//创建本地临时文件夹
File tempDir = new File(tempFilePath); File tempDir = new File(tempFilePath);
if (!tempDir.exists()) tempDir.mkdir(); //判断本地临时文件夹是否存在
if (!tempDir.exists()) {
tempDir.mkdir();
}
//创建输入流
zipInputStream = new ZipInputStream(file.getInputStream()); zipInputStream = new ZipInputStream(file.getInputStream());
ZipEntry entry; ZipEntry entry;
//遍历获取压缩包内文件
while (ObjectUtil.isNotNull(entry = zipInputStream.getNextEntry())) { while (ObjectUtil.isNotNull(entry = zipInputStream.getNextEntry())) {
//文件名称
String fileName = entry.getName(); String fileName = entry.getName();
fileNames.add(fileName); fileNames.add(fileName);
File oneFile = new File(tempFilePath + fileName); File oneFile = new File(tempFilePath + fileName);
@ -89,46 +107,61 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService {
} }
fileList.add(oneFile); fileList.add(oneFile);
} }
if (CollUtil.isEmpty(fileList)) //判断文件集合是否为空
if (CollUtil.isEmpty(fileList)) {
return Result.error(Prompt.FILE_IS_EMPTY); return Result.error(Prompt.FILE_IS_EMPTY);
ftpClient = ftpUtil.LoginFTP(); }
if (ObjectUtil.isNull(ftpClient)) // //登陆ftp
return Result.error(Prompt.FTP_ERR); // ftpClient = ftpUtil.LoginFTP();
// 如果指定目录不存在,逐级创建目录 // if (ObjectUtil.isNull(ftpClient)) {
boolean created = FTPUtil.createDirs(ftpClient, filePath); // return Result.error(Prompt.FTP_ERR);
if (!created) return Result.error(Prompt.DIR_CREATE_FAIL + filePath); // }
// // 如果指定目录不存在,逐级创建目录
// boolean created = FTPUtil.createDirs(ftpClient, filePath);
// if (!created) {
// return Result.error(Prompt.DIR_CREATE_FAIL + filePath);
// }
// 上传所有文件 // 上传所有文件
List<String> failList = new ArrayList<>(); List<String> failList = new ArrayList<>();
for (File oneFile : fileList) { for (File oneFile : fileList) {
String fileName = oneFile.getName(); String fileName = oneFile.getName();
// 判断能谱文件名称是否符合规则不符合则进行重命名 // 判断能谱文件名称是否符合规则不符合则进行重命名
if (!regexPattern.matcher(fileName).find() && !regexPattern1.matcher(fileName).find()) { if (!regexPattern.matcher(fileName).find() && !regexPattern1.matcher(fileName).find()) {
//分析文件
EnergySpectrumStruct struct = phdFileUtil.analyzeFileSourceData(oneFile); EnergySpectrumStruct struct = phdFileUtil.analyzeFileSourceData(oneFile);
//获取文件后缀
String suffix = nameStandUtil.GetSuffix(struct.data_type, struct.spectrum_quantity, String.valueOf(struct.acquisition_live_time)); String suffix = nameStandUtil.GetSuffix(struct.data_type, struct.spectrum_quantity, String.valueOf(struct.acquisition_live_time));
//获取文件名称
fileName = nameStandUtil.GetFileNameFromDateTime(struct.measurement_id, suffix); fileName = nameStandUtil.GetFileNameFromDateTime(struct.measurement_id, suffix);
} }
String fullFilePath = filePath + slash + fileName; String fullFilePath = filePath + slash + fileName;
FileInputStream local = new FileInputStream(oneFile); FileInputStream local = new FileInputStream(oneFile);
boolean success = ftpClient.storeFile(fileName, local); boolean success = ftpUtil.saveFile(fullFilePath, local);
if (!success) failList.add(fullFilePath); if (!success) {
failList.add(fullFilePath);
}
} }
if (CollUtil.isNotEmpty(failList)) if (CollUtil.isNotEmpty(failList)) {
return Result.error(Prompt.UPLOAD_ERR, failList); return Result.error(Prompt.UPLOAD_ERR, failList);
}
return Result.OK(Prompt.UPLOAD_SUCC); return Result.OK(Prompt.UPLOAD_SUCC);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
return Result.error(Prompt.UPLOAD_ERR); return Result.error(Prompt.UPLOAD_ERR);
}finally { }finally {
try { try {
if (ObjectUtil.isNotNull(zipInputStream)) if (ObjectUtil.isNotNull(zipInputStream)) {
zipInputStream.close(); zipInputStream.close();
if (ObjectUtil.isNotNull(fos)) }
if (ObjectUtil.isNotNull(fos)) {
fos.close(); fos.close();
if (ObjectUtil.isNotNull(ftpClient)) }
if (ftpClient.isConnected()){ // if (ObjectUtil.isNotNull(ftpClient)) {
ftpClient.logout(); // if (ftpClient.isConnected()){
ftpClient.disconnect(); // ftpClient.logout();
} // ftpClient.disconnect();
// }
// }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -143,7 +176,7 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService {
String username = user.getUsername(); String username = user.getUsername();
String slash = SymbolConstant.SINGLE_SLASH; String slash = SymbolConstant.SINGLE_SLASH;
String comma = SymbolConstant.COMMA; String comma = SymbolConstant.COMMA;
String filePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + slash + username; String filePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getUploadPath() + slash + username;
FTPClient ftpClient = null; FTPClient ftpClient = null;
List<FileDto> fileDtos = new ArrayList<>(); List<FileDto> fileDtos = new ArrayList<>();
Page<FileDto> page = new Page<>(pageNo, pageSize); Page<FileDto> page = new Page<>(pageNo, pageSize);

View File

@ -1,8 +1,10 @@
package org.jeecg.modules.system.service.impl; package org.jeecg.modules.system.service.impl;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil; import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
@ -14,6 +16,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlRunner; import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
import com.google.common.io.Files;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
@ -49,9 +52,6 @@ public class GardsSampleDataServiceImpl extends ServiceImpl<GardsSampleDataMappe
@Autowired @Autowired
private RedisUtil redisUtil; private RedisUtil redisUtil;
@Autowired
private FTPUtil ftpUtil;
@Autowired @Autowired
private SpectrumPathProperties pathProperties; private SpectrumPathProperties pathProperties;
@ -112,9 +112,9 @@ public class GardsSampleDataServiceImpl extends ServiceImpl<GardsSampleDataMappe
TransactionDefinition txDef = new DefaultTransactionDefinition(); TransactionDefinition txDef = new DefaultTransactionDefinition();
final TransactionStatus txStatus = transactionManager.getTransaction(txDef); final TransactionStatus txStatus = transactionManager.getTransaction(txDef);
try { try {
String ftpRootPath = ftpUtil.getFtpRootPath(); String rootPath = pathProperties.getRootPath();
String savePath = ftpRootPath + pathProperties.getSaveFilePath() + StrUtil.SLASH; String savePath = rootPath + pathProperties.getSaveFilePath() + StrUtil.SLASH;
String logPath = ftpRootPath + pathProperties.getLogPath() + StrUtil.SLASH; String logPath = rootPath + pathProperties.getLogPath() + StrUtil.SLASH;
/* 删除数据库数据 */ /* 删除数据库数据 */
// 过滤掉多余的表 // 过滤掉多余的表
String ORIGINAL = "ORIGINAL";String RNAUTO = "RNAUTO";String RNMAN = "RNMAN"; String ORIGINAL = "ORIGINAL";String RNAUTO = "RNAUTO";String RNMAN = "RNMAN";
@ -172,16 +172,14 @@ public class GardsSampleDataServiceImpl extends ServiceImpl<GardsSampleDataMappe
needDel = needDel.stream().filter(StrUtil::isNotBlank).collect(Collectors.toList()); needDel = needDel.stream().filter(StrUtil::isNotBlank).collect(Collectors.toList());
if (CollUtil.isEmpty(needDel)) if (CollUtil.isEmpty(needDel))
return Result.OK("Data cleaning is complete. No files need to be cleaned!"); return Result.OK("Data cleaning is complete. No files need to be cleaned!");
// 删除FTP文件 // 删除本地文件
List<String> failList = new ArrayList<>(); List<String> fails = new ArrayList<>();
for (String path:needDel) { for (String path : needDel) {
boolean success = ftpUtil.removeFiles(path); boolean success = FileUtil.del(path);
if (!success) { if (!success) fails.add(path);
failList.add(path);
}
} }
if (CollUtil.isNotEmpty(failList)) if (CollUtil.isNotEmpty(fails))
return Result.error("Data clearing is complete, but file clearing fails!", failList); return Result.error("Data clearing is complete, but file clearing fails!", fails);
return Result.OK("Data and file cleanup complete!"); return Result.OK("Data and file cleanup complete!");
}catch (Exception e){ }catch (Exception e){
transactionManager.rollback(txStatus); transactionManager.rollback(txStatus);
@ -226,27 +224,25 @@ public class GardsSampleDataServiceImpl extends ServiceImpl<GardsSampleDataMappe
Integer sampleId, String owner){ Integer sampleId, String owner){
List<String> fileList = new ArrayList<>(); List<String> fileList = new ArrayList<>();
List<AnalysesDto> AnalysesDtoList = baseMapper.getAnalysis(owner, sampleId); List<AnalysesDto> AnalysesDtoList = baseMapper.getAnalysis(owner, sampleId);
if (CollectionUtils.isNotEmpty(AnalysesDtoList)) { for (AnalysesDto AnalysesDto:AnalysesDtoList) {
for (AnalysesDto AnalysesDto:AnalysesDtoList) { String baselinePath = AnalysesDto.getBaselinePath();
String baselinePath = AnalysesDto.getBaselinePath(); if (StrUtil.isNotBlank(baselinePath)) {
if (StrUtil.isNotBlank(baselinePath)) { fileList.add(savePath + baselinePath);
fileList.add(savePath + baselinePath); }
} String lcPath = AnalysesDto.getLcPath();
String lcPath = AnalysesDto.getLcPath(); if (StrUtil.isNotBlank(lcPath)) {
if (StrUtil.isNotBlank(lcPath)) { fileList.add(savePath + lcPath);
fileList.add(savePath + lcPath); }
} String scacPath = AnalysesDto.getScacPath();
String scacPath = AnalysesDto.getScacPath(); if (StrUtil.isNotBlank(scacPath)) {
if (StrUtil.isNotBlank(scacPath)) { fileList.add(savePath + scacPath);
fileList.add(savePath + scacPath); }
} if (StrUtil.isNotBlank(AnalysesDto.getLogPath())) {
if (StrUtil.isNotBlank(AnalysesDto.getLogPath())) { fileList.add(logPath + AnalysesDto.getLogPath());
fileList.add(logPath + AnalysesDto.getLogPath()); }
} String reportPath = AnalysesDto.getReportPath();
String reportPath = AnalysesDto.getReportPath(); if (StrUtil.isNotBlank(reportPath)) {
if (StrUtil.isNotBlank(reportPath)) { fileList.add(savePath + reportPath + FileTypeEnum.txt.getType());
fileList.add(savePath + reportPath + FileTypeEnum.txt.getType());
}
} }
} }
return fileList; return fileList;

View File

@ -34,7 +34,7 @@ public class ReadLineUtil {
File file = null; File file = null;
try { try {
filePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + filePath; filePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + filePath;
file = ftpUtil.downloadFile(filePath, "betaGamma"); file = ftpUtil.downloadFile(filePath);
//判断文件路径是否为空 //判断文件路径是否为空
if (Objects.nonNull(file)){ if (Objects.nonNull(file)){
List<String> allLines = FileUtils.readLines(file, encoding); List<String> allLines = FileUtils.readLines(file, encoding);
@ -52,10 +52,6 @@ public class ReadLineUtil {
} }
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally {
if (Objects.nonNull(file)) {
file.delete();
}
} }
return Collections.emptyMap(); return Collections.emptyMap();
} }

View File

@ -133,7 +133,7 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl<GardsSampleDataWe
GardsSampleDataWeb sampleData = getOneSample(sampleId); GardsSampleDataWeb sampleData = getOneSample(sampleId);
String filePath = sampleData.getInputFileName(); String filePath = sampleData.getInputFileName();
if (StringUtils.isNotBlank(filePath)) { 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)) { if (Objects.nonNull(file)) {
EnergySpectrumStruct sourceData = EnergySpectrumHandler.getSourceData(file.getAbsolutePath()); EnergySpectrumStruct sourceData = EnergySpectrumHandler.getSourceData(file.getAbsolutePath());
//查询info //查询info

View File

@ -15,4 +15,5 @@ spring:
config: config:
import: import:
- optional:nacos:armd.yaml - optional:nacos:armd.yaml
- optional:nacos:armd-@profile.name@.yaml - optional:nacos:armd-@profile.name@.yaml
- optional:nacos:armd-analysis-@profile.name@.yaml