gamma缓存核素信息key修改

gamma生成日志,报告,保存公用方法增加标识区分
beta查看BG Log Viewer接口如果文件不存在则返回空内容
This commit is contained in:
qiaoqinzheng 2023-11-07 17:27:02 +08:00
parent c9c1ab26bf
commit e087e80196
5 changed files with 64 additions and 53 deletions

View File

@ -12,14 +12,18 @@ import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import org.jeecg.common.constant.SymbolConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;

View File

@ -152,7 +152,7 @@ public class Sample_G_Analysis {
}
// 执行分析业务代码
gammaFileUtil.GetMiddleData(phdFile, CommonConstant.REPORT_PREFIX_AUTO, nuclideLibs, middleData, MiddleDataType.Auto.getType());
gammaFileUtil.GetMiddleData(phdFile, CommonConstant.REPORT_PREFIX_AUTO, nuclideLibs, middleData, MiddleDataType.Auto.getType(), "");
// 数据插入数据库
this.storageDataToDatabase(middleData, phdFile.getQcItems());

View File

@ -274,7 +274,9 @@ public class GammaFileUtil extends AbstractLogOrReport {
String baselineFileName = prefixName+"_"+subFileName + ".baseline";
String fromPathBase = pathName + StringPool.SLASH + baselineFileName;
inputStreamBase = ftpUtil.downloadFileStream(fromPathBase);
File file = ftpUtil.downloadFile(fromPathBase, "betaGamma");
inputStreamBase = new FileInputStream(file);
// inputStreamBase = ftpUtil.downloadFileStream(fromPathBase);
// 调用处理BaseCtrl的方法
ReadBaseCtrlInfo(phd, inputStreamBase);
// 将phdFile的BaseCtrls的BaseLine部分数据 赋值给 phdFile的vBase
@ -2228,9 +2230,9 @@ public class GammaFileUtil extends AbstractLogOrReport {
map.put("AllData", datalist);
}
public String GetReportContent(PHDFile phd, String userName, boolean bLog) {
public String GetReportContent(PHDFile phd, String userName, boolean bLog, String flag) {
GStoreMiddleProcessData middleData = new GStoreMiddleProcessData();
GetInterMiddlData(phd, userName, middleData);
GetInterMiddlData(phd, userName, middleData, flag);
if(bLog) {
return GetLogContent(middleData);
} else {
@ -2238,11 +2240,11 @@ public class GammaFileUtil extends AbstractLogOrReport {
}
}
public boolean GetInterMiddlData(PHDFile phd, String userName, GStoreMiddleProcessData middleData) {
public boolean GetInterMiddlData(PHDFile phd, String userName, GStoreMiddleProcessData middleData, String flag) {
boolean bRet = true;
Map<String, NuclideLines> temp = new HashMap<>();
try {
bRet = GetMiddleData(phd, userName, temp,middleData, MiddleDataType.InterAction.getType());
bRet = GetMiddleData(phd, userName, temp,middleData, MiddleDataType.InterAction.getType(), flag);
middleData.analyses_type ="Interactive";
} catch (ParseException e) {
throw new RuntimeException(e);
@ -2989,7 +2991,7 @@ public class GammaFileUtil extends AbstractLogOrReport {
return name;
}
public boolean GetMiddleData(PHDFile fileAnlyse, String userName,Map<String, NuclideLines> nucline,GStoreMiddleProcessData middleData, String type) throws ParseException {
public boolean GetMiddleData(PHDFile fileAnlyse, String userName,Map<String, NuclideLines> nucline,GStoreMiddleProcessData middleData, String type, String flag) throws ParseException {
boolean bRet=true;
//标准名称规范化
String dataType = fileAnlyse.getMsgInfo().getData_type();
@ -3024,7 +3026,7 @@ public class GammaFileUtil extends AbstractLogOrReport {
anylseEnd = DateUtils.formatDate(new Date(), "yyyy/MM/dd HH:mm:ss");
middleData.analyses_analysisBegin = anylseBegin;
middleData.analyses_analysisEnd = anylseEnd;
} else if (type.equals(MiddleDataType.InterAction.getType())){ //如果是人工交互分析 则先上传phd对应文件信息
} else if (type.equals(MiddleDataType.InterAction.getType()) && flag.equalsIgnoreCase("save")){ //如果是人工交互分析 则先上传phd对应文件信息
//上传本次文件到ftp人工交互存储路径下
File sampleTmp = null;
try {
@ -3055,9 +3057,11 @@ public class GammaFileUtil extends AbstractLogOrReport {
String qsSaveBaseLine = savePath + StringPool.SLASH + qsBaseLinePath;
String qsSaveLc = savePath + StringPool.SLASH + qsLcPath;
String qsSaveScac = savePath + StringPool.SLASH + qsScacPath;
GammaReportUtil.writeFile(fileAnlyse.getBaseCtrls(), rootPath + qsSaveBaseLine);
GammaReportUtil.writeFile(fileAnlyse.getVLc(), "LC", rootPath + qsSaveLc);
GammaReportUtil.writeFile(fileAnlyse.getVScac(), "SCSC", rootPath + qsSaveScac);
if((type.equals(MiddleDataType.Auto.getType())) || (type.equals(MiddleDataType.InterAction.getType()) && flag.equalsIgnoreCase("save")) ) {
GammaReportUtil.writeFile(fileAnlyse.getBaseCtrls(), rootPath + qsSaveBaseLine);
GammaReportUtil.writeFile(fileAnlyse.getVLc(), "LC", rootPath + qsSaveLc);
GammaReportUtil.writeFile(fileAnlyse.getVScac(), "SCSC", rootPath + qsSaveScac);
}
double totalNumber = 0.0;
for(int m=0;m<fileAnlyse.getSpec().getCounts().size();m++) {

View File

@ -138,6 +138,8 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
private IGardsQcCheckSpectrumService qcCheckSpectrumService;
@Autowired
private IGardsAnalySettingSpectrumService analySettingSpectrumService;
@Autowired
private FTPClient ftpClient;
@Override
public Result initValue(Integer sampleId, String dbName, String samfileName, HttpServletRequest request) {
@ -169,7 +171,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
}
// 从数据库中读取相关信息
boolean bRet = getResultFromDB(dbName, userName, sampleId, phd, result);
if (!redisUtil.hasKey(fileName+"-"+userName)) {
if (!redisUtil.hasKey(userName+"-"+phd.getHeader().getSystem_type())) {
// 查询当前用户关联的核素信息
List<String> userLib = new LinkedList<>();
// 从postgreSql中获取当前用户关注的核素信息 如果当前用户没有 则返回管理员的
@ -178,7 +180,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
userLib = defaultNuclideSpectrumService.findNuclidesByUserName("admin", phd.getHeader().getSystem_type().toUpperCase());
}
Map<String, NuclideLines> nuclideMap = GetNuclideLines(userLib);
redisUtil.set(fileName+"-"+userName, nuclideMap);
redisUtil.set(userName+"-"+phd.getHeader().getSystem_type(), nuclideMap);
}
if (!bRet) {
return result;
@ -188,7 +190,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
String pathName = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName;
String fileName = samfileName;
boolean flag = gammaFileUtil.loadFile(pathName, fileName, phd, result);
if (!redisUtil.hasKey(userName)) {
if (!redisUtil.hasKey(userName+"-"+phd.getHeader().getSystem_type())) {
// 查询当前用户关联的核素信息
List<String> userLib = new LinkedList<>();
// 从postgreSql中获取当前用户关注的核素信息 如果当前用户没有 则返回管理员的
@ -197,7 +199,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
userLib = defaultNuclideSpectrumService.findNuclidesByUserName("admin", phd.getHeader().getSystem_type().toUpperCase());
}
Map<String, NuclideLines> nuclideMap = GetNuclideLines(userLib);
redisUtil.set(userName, nuclideMap);
redisUtil.set(userName+"-"+phd.getHeader().getSystem_type(), nuclideMap);
}
if (!flag) {
return result;
@ -224,7 +226,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
result.error500("Please select the parse file first");
return result;
}
Map<String, NuclideLines> nuclideLinesMap = (Map<String, NuclideLines>) redisUtil.get(fileName+"-"+userName);//GetNuclideLines(nuclides);
Map<String, NuclideLines> nuclideLinesMap = (Map<String, NuclideLines>) redisUtil.get(userName+"-"+phd.getHeader().getSystem_type());//GetNuclideLines(nuclides);
// 解析获取临时文件信息
File tmpFile = gammaFileUtil.analyzeFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName, fileName);
ObjectMapper mapper = new ObjectMapper();
@ -472,7 +474,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
}
// 从数据库中读取phd其他相关信息
boolean bRet = getResultFromDB(dbName, userName, sampleId, phd, result);
if (!redisUtil.hasKey(userName)) {
if (!redisUtil.hasKey(userName+"-"+phd.getHeader().getSystem_type())) {
// 查询当前用户关联的核素信息
List<String> userLib = new LinkedList<>();
// 从postgreSql中获取当前用户关注的核素信息 如果当前用户没有 则返回管理员的
@ -481,7 +483,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
userLib = defaultNuclideSpectrumService.findNuclidesByUserName("admin", phd.getHeader().getSystem_type().toUpperCase());
}
Map<String, NuclideLines> nuclideMap = GetNuclideLines(userLib);
redisUtil.set(userName, nuclideMap);
redisUtil.set(userName+"-"+phd.getHeader().getSystem_type(), nuclideMap);
}
// 判断数据库信息是否读取正常
if (!bRet) {
@ -837,7 +839,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
if (!bRet) {
return result;
}
if (!redisUtil.hasKey(userName)) {
if (!redisUtil.hasKey(userName+"-"+phd.getHeader().getSystem_type())) {
// 查询当前用户关联的核素信息
List<String> userLib = new LinkedList<>();
// 从postgreSql中获取当前用户关注的核素信息 如果当前用户没有 则返回管理员的
@ -846,7 +848,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
userLib = defaultNuclideSpectrumService.findNuclidesByUserName("admin", phd.getHeader().getSystem_type().toUpperCase());
}
Map<String, NuclideLines> nuclideMap = GetNuclideLines(userLib);
redisUtil.set(userName, nuclideMap);
redisUtil.set(userName+"-"+phd.getHeader().getSystem_type(), nuclideMap);
}
}
// 更新 QC Flags 状态
@ -1051,7 +1053,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
"2. You didn't change any setting or calibration.";
result.error500(warning);
} else if (flag == -1) {
Map<String, NuclideLines> nuclideLinesMap = (Map<String, NuclideLines>) redisUtil.get(fileName+"-"+userName);//GetNuclideLines(nuclides);
Map<String, NuclideLines> nuclideLinesMap = (Map<String, NuclideLines>) redisUtil.get(userName+"-"+phd.getHeader().getSystem_type());//GetNuclideLines(nuclides);
gammaFileUtil.NuclidesIdent(phd, nuclideLinesMap);
gammaFileUtil.RunQC(phd);
String warning = "Finish three tasks:\n" +
@ -1060,7 +1062,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
"\t3.Test QC again.";
result.error500(warning);
} else {
Map<String, NuclideLines> nuclideLinesMap = (Map<String, NuclideLines>) redisUtil.get(fileName+"-"+userName);//GetNuclideLines(nuclides);
Map<String, NuclideLines> nuclideLinesMap = (Map<String, NuclideLines>) redisUtil.get(userName+"-"+phd.getHeader().getSystem_type());//GetNuclideLines(nuclides);
gammaFileUtil.AnalyseSpectrum(phd, nuclideLinesMap);
// 重新分析各峰值对应的核素信息
// gammaFileUtil.NuclidesIdent(phd, nuclideLinesMap);
@ -1467,8 +1469,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
Result result = new Result();
//获取用户名称
String userName = JwtUtil.getUserNameByToken(request);
//获取缓存的核素信息
Map<String, NuclideLines> nuclideMap = (Map<String, NuclideLines>) redisUtil.get(fileName + "-" + userName);
//获取PHDFile的缓存信息
Cache<String, PHDFile> phdCache = localCache.getPHDCache();
PHDFile phd = phdCache.getIfPresent(fileName + "-" + userName);
@ -1476,6 +1476,8 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
result.error500("Please select the parse file first");
return result;
}
//获取缓存的核素信息
Map<String, NuclideLines> nuclideMap = (Map<String, NuclideLines>) redisUtil.get(userName+"-"+phd.getHeader().getSystem_type());
//获取颜色信息
Map<String, String> colorMap = sysUserColorService.initColor(userName);
//声明一个结果的map
@ -1657,7 +1659,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
// if (CollectionUtils.isEmpty(userLib)) {
// userLib = defaultNuclideSpectrumService.findNuclidesByUserName("admin", phd.getHeader().getSystem_type().toUpperCase());
// }
Map<String, NuclideLines> mapNucLines = (Map<String, NuclideLines>) redisUtil.get(fileName+"-"+userName);//GetNuclideLines(userLib);
Map<String, NuclideLines> mapNucLines = (Map<String, NuclideLines>) redisUtil.get(userName+"-"+phd.getHeader().getSystem_type());//GetNuclideLines(userLib);
// 查询出核素信息
NuclideLines it_line = mapNucLines.get(nuclideName);
// 如果核素信息不存在返回
@ -1686,8 +1688,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
Result result = new Result();
//获取用户名
String userName = JwtUtil.getUserNameByToken(request);
Map<String, Object> map = new HashMap<>();
Map<String, NuclideLines> nuclideMap = (Map<String, NuclideLines>) redisUtil.get(fileName + "-" + userName);
//缓存中获取缓存信息
Cache<String, PHDFile> phdCache = localCache.getPHDCache();
PHDFile phd = phdCache.getIfPresent(fileName + "-" + userName);
@ -1695,6 +1695,8 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
result.error500("Please select the parse file first");
return result;
}
Map<String, Object> map = new HashMap<>();
Map<String, NuclideLines> nuclideMap = (Map<String, NuclideLines>) redisUtil.get(userName+"-"+phd.getHeader().getSystem_type());
//判断当前选择的核素名称是否包含在当前Peak的核素列表中
int index = list_identify.indexOf(nuclideName);
if (index >= 0) {
@ -3575,7 +3577,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
userLib = defaultNuclideSpectrumService.findNuclidesByUserName("admin", phd.getHeader().getSystem_type().toUpperCase());
}
Map<String, NuclideLines> nuclideMap = GetNuclideLines(userLib);
redisUtil.set(fileName+"-"+userName, nuclideMap);
redisUtil.set(userName+"-"+phd.getHeader().getSystem_type(), nuclideMap);
} else {
result.success("Modification failure");
}
@ -3683,7 +3685,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
String pathName = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath.substring(0, reportPath.lastIndexOf(StringPool.SLASH));
String fileName = reportPath.substring(reportPath.lastIndexOf(StringPool.SLASH) + 1) + ".txt";
// 连接ftp
FTPClient ftpClient = ftpUtil.LoginFTP();
if (Objects.isNull(ftpClient)) {
throw new RuntimeException("ftp connection failed");
}
@ -3711,14 +3712,15 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
throw new RuntimeException(e);
} finally {
try {
if (Objects.nonNull(ftpClient)) {
ftpClient.disconnect();
}
// if (Objects.nonNull(ftpClient)) {
// ftpClient.disconnect();
// }
if (ObjectUtil.isNotNull(inputStream)) {
inputStream.close();
}
if (ObjectUtil.isNotNull(outputStream)) {
outputStream.close();
ftpClient.completePendingCommand();
}
} catch (IOException e) {
throw new RuntimeException(e);
@ -3733,7 +3735,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
String pathName = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath.substring(0, reportPath.lastIndexOf(StringPool.SLASH));
String fileName = reportPath.substring(reportPath.lastIndexOf(StringPool.SLASH) + 1) + ".txt";
// 连接ftp
FTPClient ftpClient = ftpUtil.LoginFTP();
FTPClient ftpClient = null;
if (Objects.isNull(ftpClient)) {
throw new RuntimeException("ftp connection failed");
}
@ -3765,14 +3767,15 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
throw new RuntimeException(e);
} finally {
try {
if (Objects.nonNull(ftpClient)) {
ftpClient.disconnect();
}
// if (Objects.nonNull(ftpClient)) {
// ftpClient.disconnect();
// }
if (ObjectUtil.isNotNull(inputStream)) {
inputStream.close();
}
if (ObjectUtil.isNotNull(outputStream)) {
outputStream.close();
ftpClient.completePendingCommand();
}
} catch (IOException e) {
throw new RuntimeException(e);
@ -3790,7 +3793,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
result.error500("Please select the parse file first");
return result;
}
String reportContent = gammaFileUtil.GetReportContent(phd, userName, false);
String reportContent = gammaFileUtil.GetReportContent(phd, userName, false, "log");
result.setSuccess(true);
result.setResult(reportContent);
return result;
@ -3804,7 +3807,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
if (Objects.isNull(phd)) {
return;
}
String reportContent = gammaFileUtil.GetReportContent(phd, userName, false);
String reportContent = gammaFileUtil.GetReportContent(phd, userName, false, "log");
OutputStream fos = null;
try {
// 设置响应类型
@ -4271,7 +4274,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
String pathName = ftpUtil.getFtpRootPath() + spectrumPathProperties.getLogPath() + StringPool.SLASH + logPath.substring(0, logPath.lastIndexOf(StringPool.SLASH));
String fileName = logPath.substring(logPath.lastIndexOf(StringPool.SLASH) + 1);
// 连接ftp
FTPClient ftpClient = ftpUtil.LoginFTP();
if (Objects.isNull(ftpClient)) {
throw new RuntimeException("ftp connection failed");
}
@ -4324,7 +4326,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
result.error500("Please select the parse file first");
return result;
}
String reportContent = gammaFileUtil.GetReportContent(phd, userName, true);
String reportContent = gammaFileUtil.GetReportContent(phd, userName, true, "log");
result.setSuccess(true);
result.setResult(reportContent);
return result;
@ -4416,7 +4418,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
// 如果有权限则开始保存数据库操作
// 将PHDFile数据 生成用于数据库存储的数据结构
GStoreMiddleProcessData middleData = new GStoreMiddleProcessData();
bRet = gammaFileUtil.GetInterMiddlData(phd, userName, middleData);
bRet = gammaFileUtil.GetInterMiddlData(phd, userName, middleData, "save");
if (!bRet) {
result.error500("Transform PHDFile into structGStoreMiddleProcessData failed.");
return result;

View File

@ -518,8 +518,6 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
Map<String, Object> gasBgMap = new HashMap<>();
Map<String, Object> detBgMap = new HashMap<>();
Map<String, Object> qcMap = new HashMap<>();
boolean bProcessed = false;
boolean savedAnalysisResult = false;
//页面展示结果数组
List<GardsXeResultsSpectrum> xeResultsSpectrumList = new LinkedList<>();
//获取本地缓存信息
@ -3494,13 +3492,16 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
FileInputStream inputStream = null;
OutputStream fos = null;
try {
inputStream = new FileInputStream(new File(logFilePath));
fos = response.getOutputStream();
byte[] buffer = new byte[1024];
int bytesRead;
// 将文件输出流写入到输出流中
while ((bytesRead = inputStream.read(buffer)) != -1) {
fos.write(buffer, 0, bytesRead);
File file = new File(logFilePath);
if (file.exists()) {
inputStream = new FileInputStream(file);
fos = response.getOutputStream();
byte[] buffer = new byte[1024];
int bytesRead;
// 将文件输出流写入到输出流中
while ((bytesRead = inputStream.read(buffer)) != -1) {
fos.write(buffer, 0, bytesRead);
}
}
} catch (Exception e) {
e.printStackTrace();