This commit is contained in:
orgin 2024-06-05 15:15:29 +08:00
parent 99cd4bbbfe
commit 55b68da597

View File

@ -14,6 +14,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.cache.Cache;
import com.google.common.collect.Maps;
import io.swagger.models.auth.In;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
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.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.thymeleaf.TemplateEngine;
@ -299,7 +301,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 +482,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 +519,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 +556,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 +593,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 +673,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 +785,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 +882,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 +930,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 +4005,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,55 +4284,68 @@ 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");
//判断文件路径是否存在
File logPath = new File(logFilePath);
if (!logPath.exists()) {
logPath.mkdirs();
}
File logFile = new File(logFilePath + File.separator +localLogName);
File logFile = new File(logFilePath + File.separator +logFileName);
try {
//判断日志文件是否存在 如果不存在创建一个空的文件 上传到ftp
if (!logFile.exists()) {
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 {
@ -4425,6 +4420,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
String error = "get station_id or detect_id error";
return false;
}
betaDataFile.setDetectorId(detectorId.toString());
//新增Gards_Sample_Data表数据
sampleDataSpectrumService.saveSampleData(sourceData, stationId, detectorId, filePathName, readLines);
//获取sampleId