From fe6cd6bdc0b9009be66b449743d120c363fdf0a3 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Thu, 26 Oct 2023 11:57:23 +0800 Subject: [PATCH] =?UTF-8?q?gamma=E5=8A=9F=E8=83=BD=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A2=9E=E5=8A=A0=E8=BF=94=E5=9B=9E=E5=86=85?= =?UTF-8?q?=E5=AE=B9vPeak=E6=95=B0=E6=8D=AE=20error=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E4=BF=A1=E6=81=AF=E5=8E=BB=E6=8E=89=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/common/util/LogFileUtil.java | 131 ++++++++++++++++++ .../org/jeecg/common/util/LogFileUtil.java | 64 --------- .../modules/FileSourceHandleManager.java | 2 +- .../jeecg/modules/UndealHandleManager.java | 2 +- .../spectrum/SpectrumParsingActuator.java | 8 +- .../service/impl/GammaServiceImpl.java | 2 + 6 files changed, 141 insertions(+), 68 deletions(-) create mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/common/util/LogFileUtil.java delete mode 100644 jeecg-module-auto-process/src/main/java/org/jeecg/common/util/LogFileUtil.java diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/LogFileUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/LogFileUtil.java new file mode 100644 index 00000000..10186b0e --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/LogFileUtil.java @@ -0,0 +1,131 @@ +package org.jeecg.common.util; + +import com.baomidou.mybatisplus.core.toolkit.StringPool; +import org.jeecg.common.properties.SpectrumPathProperties; +import org.jeecg.common.properties.TaskProperties; +import org.jeecg.modules.base.entity.postgre.SysEmail; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Date; +import java.util.Objects; + +@Component +public class LogFileUtil { + /** + * 相关Spring组件引用 + */ + @Autowired + private SpectrumPathProperties spectrumPathProperties; + + + public void errorLog(String spectrumFileName, String warning) { + String logFilePath = spectrumPathProperties.getRootPath() + File.separator + spectrumPathProperties.getLogPath() + File.separator + "Error"; + File logPath = new File(logFilePath); + if (!logPath.exists()) { + logPath.mkdir(); + } + String logFileName = logFilePath + File.separator + spectrumFileName.replace("PHD", "log"); + File logFile = new File(logFileName); + StringBuffer out = new StringBuffer(); + String nowDate = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"); + out.append(nowDate+ StringPool.SPACE + "Data Anlyse Error:"); + out.append(warning); + out.append(System.lineSeparator()); + out.append(System.lineSeparator()); + out.append(System.lineSeparator()); + FileWriter writer = null; + try { + writer = new FileWriter(logFile, true); + writer.write(out.toString()); + } catch (IOException ex) { + throw new RuntimeException(ex); + } finally { + try { + if (Objects.nonNull(writer)) { + writer.close(); + } + } catch (IOException ex) { + throw new RuntimeException(ex); + } + } + } + + /** + * GSType 区分日志生成是getEmail还是sendEmail的日志 warning是日志内容 state是状态 成功、失败 logProccess是当前位于邮箱流程的位置 + * @param GSType + * @param email + * @param state + * @param logProcess + */ + public void emailLog(String GSType, SysEmail email, String state, String logProcess) { + String warning = ""; + switch (logProcess) { + case "CONNECT": + warning="Connect Server:"+email.getEmailServerAddress()+" Port:"+email.getPort()+" "+state+"....."; + break; + case "GETALLID": + warning="Get All FileName "+state+"....."; + break; + case "GETIDHEADER": + warning="Get FileNameHeader "+state+"....."; + break; + case "GETIDBODY": + warning="Get File "+"FileName"+" FileNameBody "+state+"....."; + break; + case "GETIDATTACH": + warning="Get File "+"subject"+" AttachFile "+"FileName"+" "+state+"....."; + break; + case "GETIDEML": + warning="Get File "+"subject"+" EmlFile "+"FileName"; + break; + case "DELETEID": + warning="Delete File "+"subject"+" "+state+"....."; + break; + case "EXPUNGE": + warning="Expunge File "+"subject"+" "+state+"....."; + break; + case "DONE": + warning="Done"; + break; + default: + break; + } + LocalDateTime now = LocalDateTime.now(); + String logFilePath = spectrumPathProperties.getRootPath() + File.separator + spectrumPathProperties.getLogPath() + File.separator + "Mail" + File.separator + GSType + File.separator + now.getYear() + File.separator + now.getMonthValue(); + File logPath = new File(logFilePath); + if (!logPath.exists()) { + logPath.mkdirs(); + } + String logFileName = logFilePath + File.separator + now.getYear() + StringPool.DASH + now.getMonthValue() + StringPool.DASH + now.getDayOfMonth() + StringPool.UNDERSCORE + "Mail.log"; + File logFile = new File(logFileName); + StringBuffer out = new StringBuffer(); + String nowDate = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"); + out.append(nowDate+ StringPool.SPACE); + out.append(warning); + out.append(System.lineSeparator()); + out.append(System.lineSeparator()); + out.append(System.lineSeparator()); + FileWriter writer = null; + try { + writer = new FileWriter(logFile, true); + writer.write(out.toString()); + } catch (IOException ex) { + throw new RuntimeException(ex); + } finally { + try { + if (Objects.nonNull(writer)) { + writer.close(); + } + } catch (IOException ex) { + throw new RuntimeException(ex); + } + } + } + +} diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/common/util/LogFileUtil.java b/jeecg-module-auto-process/src/main/java/org/jeecg/common/util/LogFileUtil.java deleted file mode 100644 index 513e0b0a..00000000 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/common/util/LogFileUtil.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.jeecg.common.util; - -import com.baomidou.mybatisplus.core.toolkit.StringPool; -import org.jeecg.common.properties.SpectrumPathProperties; -import org.jeecg.common.properties.TaskProperties; -import org.jeecg.modules.exception.StationNotFoundException; -import org.jeecg.modules.spectrum.SpectrumServiceQuotes; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.Date; -import java.util.Objects; - -@Component -public class LogFileUtil { - - /** - * 任务属性 - */ - @Autowired - private TaskProperties taskProperties; - /** - * 相关Spring组件引用 - */ - @Autowired - private SpectrumPathProperties spectrumPathProperties; - - - public void errorLog(String spectrumFileName, String warning, Exception e) { - String logFilePath = spectrumPathProperties.getRootPath() + File.separator + spectrumPathProperties.getLogPath() + File.separator + "Error"; - File logPath = new File(logFilePath); - if (!logPath.exists()) { - logPath.mkdir(); - } - String logFileName = logFilePath + File.separator + spectrumFileName.replace("PHD", "log"); - File logFile = new File(logFileName); - StringBuffer out = new StringBuffer(); - String nowDate = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"); - out.append(nowDate+ StringPool.SPACE + "Data Anlyse Error:"); - out.append(warning); - out.append(System.lineSeparator()); - out.append(System.lineSeparator()); - out.append(System.lineSeparator()); - FileWriter writer = null; - try { - writer = new FileWriter(logFile, true); - writer.write(out.toString()); - } catch (IOException ex) { - throw new RuntimeException(ex); - } finally { - try { - if (Objects.nonNull(writer)) { - writer.close(); - } - } catch (IOException ex) { - throw new RuntimeException(ex); - } - } - } - -} diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/FileSourceHandleManager.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/FileSourceHandleManager.java index 7207ee4d..026f2d22 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/FileSourceHandleManager.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/FileSourceHandleManager.java @@ -154,7 +154,7 @@ public class FileSourceHandleManager{ } else { warning = e.getMessage(); } - spectrumServiceQuotes.getLogFileUtil().errorLog(finalFileName.toString(), warning, e); + spectrumServiceQuotes.getLogFileUtil().errorLog(finalFileName.toString(), warning); log.error("Parsing the {} file of the filesource directory failed.The reason is {}",spectrumFile.getName(),e.getMessage()); e.printStackTrace(); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/UndealHandleManager.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/UndealHandleManager.java index 1035c708..11586233 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/UndealHandleManager.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/UndealHandleManager.java @@ -164,7 +164,7 @@ public class UndealHandleManager{ } else { warning = e.getMessage(); } - spectrumServiceQuotes.getLogFileUtil().errorLog(finalFileName.toString(), warning, e); + spectrumServiceQuotes.getLogFileUtil().errorLog(finalFileName.toString(), warning); log.error("The {} file of the undeal directory fails to be parsed again.The reason is {}",spectrumFile.getName(),e.getMessage()); e.printStackTrace(); }finally { diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java index 582ceb50..67cddaf1 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java @@ -87,9 +87,10 @@ public class SpectrumParsingActuator implements Runnable{ subject = MimeUtility.decodeText(message.getSubject()); sendTime = DateUtils.formatDate(message.getSentDate(),"yyyy-MM-dd HH:mm:ss"); receiveTime = DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss"); - System.out.println(subject); mailContent = new StringBuilder(); emailServiceManager.getMailContent(message,mailContent); + //读取文件内容成功后写入日志 + spectrumServiceQuotes.getLogFileUtil().emailLog("Get", emailProperties, "Successful", "GETALLID"); //所有邮件都需以.eml格式存储到eml文件夹中 downloadEmailToEmlDir(); //判断是否是IMS2.0协议文件 @@ -107,6 +108,9 @@ public class SpectrumParsingActuator implements Runnable{ } } } catch (Exception e) { + if (e.getClass().equals(MessagingException.class)) { + spectrumServiceQuotes.getLogFileUtil().emailLog("Get", emailProperties, "Error", "GETALLID"); + } //生成日志 String warning = ""; if (e.getClass().equals(StationNotFoundException.class)) { @@ -114,7 +118,7 @@ public class SpectrumParsingActuator implements Runnable{ } else { warning = e.getMessage(); } - spectrumServiceQuotes.getLogFileUtil().errorLog(finalFileName.toString(), warning, e); + spectrumServiceQuotes.getLogFileUtil().errorLog(finalFileName.toString(), warning); log.error("This email failed to parse. The email subject is: {}, sent on: {}, received on: {}, and the reason for the failure is: {}",subject,sendTime,receiveTime,e.getMessage()); e.printStackTrace(); }finally { diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java index 1e6caccf..0a65408a 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java @@ -463,6 +463,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi map.put("dead_time", String.format("%.2f", deadTime*100)); map.put("checkBox_updateCal", phd.getSetting().isBUpdateCal()); map.put("bAnalyed", phd.isBAnalyed()); + map.put("peak", phd.getVPeak()); // 更新页面折线图信息 gammaFileUtil.UpdateChart(phd, map, colorMap); //将当前加载的phd信息加入到缓存中 文件名称作为缓存信息的key @@ -800,6 +801,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi map.put("dead_time", String.format("%.2f", deadTime*100)); map.put("checkBox_updateCal", phd.getSetting().isBUpdateCal()); map.put("bAnalyed", phd.isBAnalyed()); + map.put("peak", phd.getVPeak()); gammaFileUtil.UpdateChart(phd, map, colorMap); phdCache.put(fileName+"-"+userName, phd); localCache.setPHDCache(phdCache);