fix:1.修改所有能谱文件日志的sourcefile属性路径

This commit is contained in:
panbaolin 2023-12-04 19:44:45 +08:00
parent 3b062b2de8
commit ff6d8b9baa
11 changed files with 46 additions and 54 deletions

View File

@ -2,7 +2,6 @@ package org.jeecg.modules;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.jeecg.common.properties.TaskProperties; import org.jeecg.common.properties.TaskProperties;
import org.jeecg.modules.enums.SpectrumSource; import org.jeecg.modules.enums.SpectrumSource;
import org.jeecg.modules.service.BlockConstant; import org.jeecg.modules.service.BlockConstant;
@ -77,7 +76,7 @@ public class FileSourceHandleManager{
TimeUnit.SECONDS.sleep(5); TimeUnit.SECONDS.sleep(5);
} }
ParseingFileSourceThread parseingFileSourceThread = new ParseingFileSourceThread(); ParseingFileSourceThread parseingFileSourceThread = new ParseingFileSourceThread();
parseingFileSourceThread.init(spectrumFile,filePath,taskLatch); parseingFileSourceThread.init(spectrumFile,taskLatch);
poolExecutor.execute(parseingFileSourceThread); poolExecutor.execute(parseingFileSourceThread);
} }
taskLatch.await(); taskLatch.await();
@ -107,20 +106,11 @@ public class FileSourceHandleManager{
* 能谱文件名称 * 能谱文件名称
*/ */
private File spectrumFile; private File spectrumFile;
/**
* 手动放置能谱文件获取路径
*/
private String filePath;
/**
* 获取文件内容
*/
private String fileContent;
private CountDownLatch taskLatch; private CountDownLatch taskLatch;
public void init(File spectrumFile,String filePath,CountDownLatch taskLatch){ public void init(File spectrumFile,CountDownLatch taskLatch){
this.spectrumFile = spectrumFile; this.spectrumFile = spectrumFile;
this.filePath = filePath;
this.taskLatch = taskLatch; this.taskLatch = taskLatch;
} }
@ -128,11 +118,9 @@ public class FileSourceHandleManager{
public void run() { public void run() {
StringBuilder finalFileName = new StringBuilder(); StringBuilder finalFileName = new StringBuilder();
try { try {
//获取文件内容
fileContent = FileUtils.readFileToString(spectrumFile,"UTF-8");
//解析文件 //解析文件
AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum(); AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum();
spectrumHandler.init(fileContent,spectrumServiceQuotes,finalFileName,SpectrumSource.FROM_FILE_SOURCE.getSourceType()); spectrumHandler.init(spectrumFile,spectrumServiceQuotes,finalFileName,SpectrumSource.FROM_FILE_SOURCE.getSourceType());
final boolean matchResult = spectrumHandler.saveEmailToLocal(); final boolean matchResult = spectrumHandler.saveEmailToLocal();
if(matchResult){ if(matchResult){
//开始解析 //开始解析
@ -144,7 +132,7 @@ public class FileSourceHandleManager{
}finally { }finally {
taskLatch.countDown(); taskLatch.countDown();
//解析成功或者失败都会删除源文件 //解析成功或者失败都会删除源文件
spectrumFile.delete(); // spectrumFile.delete();
} }
} }
} }

View File

@ -2,7 +2,6 @@ package org.jeecg.modules;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.jeecg.common.properties.TaskProperties; import org.jeecg.common.properties.TaskProperties;
import org.jeecg.modules.enums.SpectrumSource; import org.jeecg.modules.enums.SpectrumSource;
import org.jeecg.modules.service.BlockConstant; import org.jeecg.modules.service.BlockConstant;
@ -77,7 +76,7 @@ public class UndealHandleManager{
TimeUnit.SECONDS.sleep(5); TimeUnit.SECONDS.sleep(5);
} }
ParseingFaliFileThread faliFileThread = new ParseingFaliFileThread(); ParseingFaliFileThread faliFileThread = new ParseingFaliFileThread();
faliFileThread.init(spectrumFile,filePath,taskLatch); faliFileThread.init(spectrumFile,taskLatch);
poolExecutor.execute(faliFileThread); poolExecutor.execute(faliFileThread);
} }
taskLatch.await(); taskLatch.await();
@ -108,16 +107,11 @@ public class UndealHandleManager{
* 能谱文件名称 * 能谱文件名称
*/ */
private File spectrumFile; private File spectrumFile;
/**
* 失败文件存储路径
*/
private String filePath;
private CountDownLatch taskLatch; private CountDownLatch taskLatch;
public void init(File spectrumFile,String filePath,CountDownLatch taskLatch){ public void init(File spectrumFile,CountDownLatch taskLatch){
this.spectrumFile = spectrumFile; this.spectrumFile = spectrumFile;
this.filePath = filePath;
this.taskLatch = taskLatch; this.taskLatch = taskLatch;
} }
@ -133,11 +127,9 @@ public class UndealHandleManager{
spectrumServiceQuotes.getRedisStreamUtil().set(spectrumFile.getName(), currentMillis); spectrumServiceQuotes.getRedisStreamUtil().set(spectrumFile.getName(), currentMillis);
} }
try { try {
//获取文件内容
final String fileContent = FileUtils.readFileToString(spectrumFile,"UTF-8");
//解析文件 //解析文件
AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum(); AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum();
spectrumHandler.init(fileContent,spectrumServiceQuotes,finalFileName,SpectrumSource.FORM_FILE_UNDEL.getSourceType()); spectrumHandler.init(spectrumFile,spectrumServiceQuotes,finalFileName,SpectrumSource.FORM_FILE_UNDEL.getSourceType());
final boolean matchResult = spectrumHandler.saveEmailToLocal(); final boolean matchResult = spectrumHandler.saveEmailToLocal();
if(matchResult){ if(matchResult){
//开始解析 //开始解析
@ -151,7 +143,6 @@ public class UndealHandleManager{
//满足undeal文件处理周期时长会删除源文件 //满足undeal文件处理周期时长会删除源文件
if ((currentMillis - createMillis) >= taskProperties.getUndealFileTimeOut()) { if ((currentMillis - createMillis) >= taskProperties.getUndealFileTimeOut()) {
spectrumServiceQuotes.getRedisStreamUtil().del(spectrumFile.getName()); spectrumServiceQuotes.getRedisStreamUtil().del(spectrumFile.getName());
//解析成功或者失败都会删除源文件
spectrumFile.delete(); spectrumFile.delete();
} }
} }

View File

@ -3,6 +3,7 @@ package org.jeecg.modules.spectrum;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.jeecg.common.email.EmailLogEvent; import org.jeecg.common.email.EmailLogEvent;
import org.jeecg.common.email.EmailLogManager; import org.jeecg.common.email.EmailLogManager;
import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.properties.SpectrumPathProperties;
@ -39,7 +40,11 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
*/ */
protected DataType currDataType; protected DataType currDataType;
/** /**
* 当前解析的能谱文件路径 * 源文件路径(临时undelfilesource路径)
*/
protected String sourceFilePath;
/**
* 当前解析的能谱文件路径前期在临时undelfilesource路径解析完毕后移动到savefile
*/ */
protected File spectrumFile = null; protected File spectrumFile = null;
/** /**
@ -59,15 +64,6 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
*/ */
protected List<String> spectrumFileLabels = Lists.newArrayList(); protected List<String> spectrumFileLabels = Lists.newArrayList();
/**
* 初始化参数
*/
public void init(String mailContent,SpectrumServiceQuotes spectrumServiceQuotes,StringBuilder returnFileName) throws Exception{
this.mailContent = mailContent;
this.spectrumServiceQuotes = spectrumServiceQuotes;
this.returnFileName = returnFileName;
}
/** /**
* 初始化参数 * 初始化参数
*/ */
@ -81,10 +77,25 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
/** /**
* 初始化参数 * 初始化参数
*/ */
protected void initNext(SpectrumServiceQuotes spectrumServiceQuotes,File spectrumFile,DataType currDataType, public void init(File phdFile,SpectrumServiceQuotes spectrumServiceQuotes,StringBuilder returnFileName,Integer spectrumSource) throws Exception{
this.spectrumServiceQuotes = spectrumServiceQuotes;
this.returnFileName = returnFileName;
this.spectrumSource = spectrumSource;
this.spectrumFile = phdFile;
this.mailContent = FileUtils.readFileToString(spectrumFile,"UTF-8");
this.sourceFilePath = spectrumFile.getAbsolutePath();
}
/**
* 初始化参数
*/
protected void initNext(SpectrumServiceQuotes spectrumServiceQuotes,File spectrumFile,
String sourceFilePath,DataType currDataType,
String mailContent,Integer spectrumSource,StringBuilder returnFileName){ String mailContent,Integer spectrumSource,StringBuilder returnFileName){
this.spectrumServiceQuotes = spectrumServiceQuotes; this.spectrumServiceQuotes = spectrumServiceQuotes;
this.spectrumFile = spectrumFile; this.spectrumFile = spectrumFile;
this.sourceFilePath = sourceFilePath;
this.currDataType = currDataType; this.currDataType = currDataType;
this.mailContent = mailContent; this.mailContent = mailContent;
this.spectrumSource = spectrumSource; this.spectrumSource = spectrumSource;
@ -166,12 +177,15 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
for(DataType value : values){ for(DataType value : values){
// 判断能谱数据类型是否正确 // 判断能谱数据类型是否正确
if(this.mailContent.contains(DATA_TYPE_PREFIX + value.getType())){ if(this.mailContent.contains(DATA_TYPE_PREFIX + value.getType())){
StringBuilder localPath = new StringBuilder(); if(SpectrumSource.FORM_EMAIL_SERVICE.getSourceType().equals(spectrumSource)){
localPath.append(this.spectrumServiceQuotes.getTaskProperties().getTemporaryStoragePath()); StringBuilder localPath = new StringBuilder();
localPath.append(File.separator); localPath.append(this.spectrumServiceQuotes.getTaskProperties().getTemporaryStoragePath());
localPath.append(UUID.randomUUID()); localPath.append(File.separator);
localPath.append(value.getSuffix()); localPath.append(UUID.randomUUID());
this.spectrumFile = FileUtil.writeString(this.mailContent, localPath.toString(), "UTF-8"); localPath.append(value.getSuffix());
this.spectrumFile = FileUtil.writeString(this.mailContent, localPath.toString(), "UTF-8");
this.sourceFilePath = spectrumFile.getAbsolutePath();
}
// 能谱数据类型如果是 SPHDP 或者 SPHDF 统一改为 SAMPLEPHD // 能谱数据类型如果是 SPHDP 或者 SPHDF 统一改为 SAMPLEPHD
if (value.equals(DataType.SPHDP) || value.equals(DataType.SPHDF)) { if (value.equals(DataType.SPHDP) || value.equals(DataType.SPHDF)) {
this.currDataType = DataType.SAMPLEPHD; this.currDataType = DataType.SAMPLEPHD;

View File

@ -48,7 +48,7 @@ public class AlertSpectrum extends AbstractSpectrumHandler{
@Override @Override
protected void setChina() { protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new HealthStatusSpectrum(); AbstractSpectrumHandler spectrumHandler = new HealthStatusSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile, spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,super.sourceFilePath,
super.currDataType,super.mailContent,super.spectrumSource,super.returnFileName); super.currDataType,super.mailContent,super.spectrumSource,super.returnFileName);
spectrumHandler.setPrevious(this); spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler); super.setNext(spectrumHandler);

View File

@ -15,7 +15,7 @@ public class DetbkphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler {
@Override @Override
protected void setChina() { protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new QcphdSpectrum(); AbstractSpectrumHandler spectrumHandler = new QcphdSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile, spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,super.sourceFilePath,
super.currDataType,super.mailContent,super.spectrumSource,super.returnFileName); super.currDataType,super.mailContent,super.spectrumSource,super.returnFileName);
spectrumHandler.setPrevious(this); spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler); super.setNext(spectrumHandler);

View File

@ -17,7 +17,7 @@ public class GasbkphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler {
@Override @Override
protected void setChina() { protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new MetSpectrum(); AbstractSpectrumHandler spectrumHandler = new MetSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile, spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,super.sourceFilePath,
super.currDataType,super.mailContent,super.spectrumSource,super.returnFileName); super.currDataType,super.mailContent,super.spectrumSource,super.returnFileName);
spectrumHandler.setPrevious(this); spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler); super.setNext(spectrumHandler);

View File

@ -43,7 +43,7 @@ public class MetSpectrum extends AbstractSpectrumHandler{
@Override @Override
protected void setChina() { protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new AlertSpectrum(); AbstractSpectrumHandler spectrumHandler = new AlertSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile, spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,super.sourceFilePath,
super.currDataType,super.mailContent,super.spectrumSource,super.returnFileName); super.currDataType,super.mailContent,super.spectrumSource,super.returnFileName);
spectrumHandler.setPrevious(this); spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler); super.setNext(spectrumHandler);

View File

@ -94,14 +94,13 @@ public class ParsingProcessLog extends AbstractAutoLogOrReport{
final String oraUsername = spectrumHandler.spectrumServiceQuotes.getOraDataSourceProperties().getUsername(); final String oraUsername = spectrumHandler.spectrumServiceQuotes.getOraDataSourceProperties().getUsername();
final String oraUrl = spectrumHandler.spectrumServiceQuotes.getOraDataSourceProperties().getUrl(); final String oraUrl = spectrumHandler.spectrumServiceQuotes.getOraDataSourceProperties().getUrl();
final String startIntoDatabaseTime = DateUtils.formatDate(spectrumHandler.startIntoDatabaseTime, "yyyy-MM-dd HH:mm:ss"); final String startIntoDatabaseTime = DateUtils.formatDate(spectrumHandler.startIntoDatabaseTime, "yyyy-MM-dd HH:mm:ss");
final String sourceFile = spectrumHandler.spectrumServiceQuotes.getTaskProperties().getTemporaryStoragePath()+File.separator+spectrumHandler.spectrumFile.getName();
storageLog.append(titleFormat(WRITE_INTO_START,26, StringConstant.DASH,startIntoDatabaseTime,StringConstant.DASH)); storageLog.append(titleFormat(WRITE_INTO_START,26, StringConstant.DASH,startIntoDatabaseTime,StringConstant.DASH));
storageLog.append(System.lineSeparator()).append(System.lineSeparator()); storageLog.append(System.lineSeparator()).append(System.lineSeparator());
storageLog.append(rowFormat(APPLICATION_PATH,spectrumHandler.getProjectAbsolutePath(),spectrumHandler.getProjectName(),startIntoDatabaseTime)); storageLog.append(rowFormat(APPLICATION_PATH,spectrumHandler.getProjectAbsolutePath(),spectrumHandler.getProjectName(),startIntoDatabaseTime));
storageLog.append(System.lineSeparator()).append(System.lineSeparator()); storageLog.append(System.lineSeparator()).append(System.lineSeparator());
storageLog.append(rowFormat(DATABASE_CONNECTED,oraUrl.substring(oraUrl.lastIndexOf(":")+1),oraUsername)); storageLog.append(rowFormat(DATABASE_CONNECTED,oraUrl.substring(oraUrl.lastIndexOf(":")+1),oraUsername));
storageLog.append(System.lineSeparator()).append(System.lineSeparator()); storageLog.append(System.lineSeparator()).append(System.lineSeparator());
storageLog.append(rowFormat(SOURCE_FILE,sourceFile)); storageLog.append(rowFormat(SOURCE_FILE,spectrumHandler.sourceFilePath));
storageLog.append(System.lineSeparator()); storageLog.append(System.lineSeparator());
storageLog.append(rowFormat(STANDARD_FILE,spectrumHandler.spectrumFile.getAbsolutePath())); storageLog.append(rowFormat(STANDARD_FILE,spectrumHandler.spectrumFile.getAbsolutePath()));
storageLog.append(System.lineSeparator()).append(System.lineSeparator()); storageLog.append(System.lineSeparator()).append(System.lineSeparator());

View File

@ -15,7 +15,7 @@ public class QcphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler {
@Override @Override
protected void setChina() { protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new GasbkphdSpectrum(); AbstractSpectrumHandler spectrumHandler = new GasbkphdSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile, spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,super.sourceFilePath,
super.currDataType,super.mailContent,super.spectrumSource,super.returnFileName); super.currDataType,super.mailContent,super.spectrumSource,super.returnFileName);
spectrumHandler.setPrevious(this); spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler); super.setNext(spectrumHandler);

View File

@ -16,7 +16,7 @@ public class SamplephdSpectrum extends AbstractS_D_Q_G_SpectrumHandler {
@Override @Override
protected void setChina() { protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new DetbkphdSpectrum(); AbstractSpectrumHandler spectrumHandler = new DetbkphdSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile, spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,super.sourceFilePath,
super.currDataType,super.mailContent,super.spectrumSource,super.returnFileName); super.currDataType,super.mailContent,super.spectrumSource,super.returnFileName);
spectrumHandler.setPrevious(this); spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler); super.setNext(spectrumHandler);

View File

@ -80,7 +80,7 @@ public class JeecgAutoProcessApplication extends SpringBootServletInitializer im
EmailLogManager.init(spectrumPathProperties); EmailLogManager.init(spectrumPathProperties);
//校验存储目录是否存在不存在则创建存在无操作 //校验存储目录是否存在不存在则创建存在无操作
checkStorageDirectory(); checkStorageDirectory();
autoProcessManager.start(systemStartupTime); // autoProcessManager.start(systemStartupTime);
undealHandleManager.start(); undealHandleManager.start();
fileSourceHandleManager.start(); fileSourceHandleManager.start();
// 删除过期的文件 // 删除过期的文件