From fb2517ccbcc2cab43346349a61e7218b115bf076 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 24 Nov 2023 10:17:43 +0800 Subject: [PATCH 1/3] =?UTF-8?q?beta=E8=87=AA=E5=8A=A8=E5=A4=84=E7=90=86?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=8A=A5=E5=91=8A=E6=96=87=E4=BB=B6=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=A8=A1=E5=9D=97=E5=B0=8F=E6=95=B0=E7=BA=A6=E5=88=86?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/spectrum/Sample_B_Analysis.java | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_B_Analysis.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_B_Analysis.java index 7a22ba12..f66669c7 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_B_Analysis.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_B_Analysis.java @@ -6,6 +6,7 @@ import org.apache.commons.lang3.StringUtils; import org.jeecg.common.constant.StringConstant; import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.util.DateUtils; +import org.jeecg.common.util.NumberFormatUtil; import org.jeecg.modules.base.dto.Info; import org.jeecg.modules.base.entity.original.GardsSampleData; import org.jeecg.modules.base.entity.rnauto.GardsAnalyses; @@ -459,7 +460,7 @@ public class Sample_B_Analysis implements BlockConstant { reportContent.append(System.lineSeparator()); reportContent.append(super.rowFormat(collectionStop,StringConstant.SPACE,sampleStruct.collection_stop_date+StringConstant.SPACE+sampleStruct.collection_stop_time)); reportContent.append(System.lineSeparator()); - reportContent.append(super.rowFormat(collectionTime,StringConstant.SPACE,String.valueOf((sampleData.getCollectStart().getTime()-sampleData.getCollectStop().getTime())/1000))); + reportContent.append(super.rowFormat(collectionTime,StringConstant.SPACE,String.valueOf((sampleData.getCollectStop().getTime()-sampleData.getCollectStart().getTime())/1000))); reportContent.append(System.lineSeparator()); reportContent.append(super.rowFormat(airVolume,StringConstant.SPACE,String.valueOf(sampleStruct.air_volume))); reportContent.append(System.lineSeparator()); @@ -662,9 +663,9 @@ public class Sample_B_Analysis implements BlockConstant { String rowValue = " %-50s %-51s %-21s %s"; List roi = analyseResult.ROI.stream().map(Object::toString).collect(Collectors.toList()); - List s_roi_cts = analyseResult.s_roi_cts.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); - List g_roi_cts = analyseResult.g_roi_cts.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); - List d_roi_cts = analyseResult.d_roi_cts.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); + List s_roi_cts = analyseResult.s_roi_cts.stream().map(v->NumberFormatUtil.numberFormat(String.valueOf(v))).collect(Collectors.toList()); + List g_roi_cts = analyseResult.g_roi_cts.stream().map(v->NumberFormatUtil.numberFormat(String.valueOf(v))).collect(Collectors.toList()); + List d_roi_cts = analyseResult.d_roi_cts.stream().map(v->NumberFormatUtil.numberFormat(String.valueOf(v))).collect(Collectors.toList()); reportContent.append(grossCountsBlock); reportContent.append(System.lineSeparator()); @@ -693,14 +694,14 @@ public class Sample_B_Analysis implements BlockConstant { List roi_net_count_err = analyseResult.ROI_net_coutns_err; //此参数需第一位补0 analyseResult.LC_CTS.add(0,0D); - List lc = analyseResult.LC_CTS.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); + List lc = analyseResult.LC_CTS.stream().map(v->NumberFormatUtil.numberFormat(String.valueOf(v))).collect(Collectors.toList()); reportContent.append(netCountsBlock); reportContent.append(System.lineSeparator()); reportContent.append(super.rowFormat(rowTitle,StringConstant.SPACE,StringConstant.SPACE)); reportContent.append(System.lineSeparator()); for (int i=0;i conErr = analyseResult.ROI_con_uncer_err; analyseResult.LC.add(0,0.0D); analyseResult.MDC.add(0,0.0D); - List lc = analyseResult.LC.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); - List mdc = analyseResult.MDC.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList()); + List lc = analyseResult.LC.stream().map(v->NumberFormatUtil.numberFormat(String.valueOf(v))).collect(Collectors.toList()); + List mdc = analyseResult.MDC.stream().map(v->NumberFormatUtil.numberFormat(String.valueOf(v))).collect(Collectors.toList()); reportContent.append(grossCountsBlock); reportContent.append(System.lineSeparator()); reportContent.append(super.rowFormat(rowTitle,StringConstant.SPACE,StringConstant.SPACE,StringConstant.SPACE)); reportContent.append(System.lineSeparator()); for (int i=0;ianalyseResult.MDC_Xe135?"1":"0"; String xe_131m_nid_flag = analyseResult.Xe131m_con>analyseResult.MDC_Xe131m?"1":"0"; From fc89b36c959a0a0cc95f903ac135e026df394f50 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 24 Nov 2023 11:13:47 +0800 Subject: [PATCH 2/3] =?UTF-8?q?gamma=E8=87=AA=E5=8A=A8=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A4=84=E7=90=86=E7=BB=93=E6=9D=9F=E5=90=8E?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=B4=E6=97=B6=E6=96=87=E4=BB=B6=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BB=A3=E7=A0=81=20=E4=BA=BA=E5=B7=A5=E4=BA=A4?= =?UTF-8?q?=E4=BA=92=E5=88=86=E6=9E=90gamma=E6=A8=A1=E5=9D=97saveToPHD?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8D=E7=A7=B0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeecg/modules/spectrum/Sample_G_Analysis.java | 12 +++++++++--- .../modules/service/impl/GammaServiceImpl.java | 13 +++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_G_Analysis.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_G_Analysis.java index 1a1381dd..02aea1b5 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_G_Analysis.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_G_Analysis.java @@ -111,6 +111,7 @@ public class Sample_G_Analysis { public void analysis() throws GAnalyseException{ log.info("Gamma自动处理分析--Start"); + PHDFile phdFile = new PHDFile(); try { /* 准备Gamma分析需要的数据 */ GStoreMiddleProcessData middleData = new GStoreMiddleProcessData(); @@ -120,7 +121,6 @@ public class Sample_G_Analysis { GammaFileUtil gammaFileUtil = ApplicationContextUtil.getContext().getBean(GammaFileUtil.class); parameterProperties = ApplicationContextUtil.getContext().getBean(ParameterProperties.class); - PHDFile phdFile = new PHDFile(); phdFile.setXmlFilePath(parameterProperties.getFilePath()); // 解析PHD文件 spectrumPathProperties = SpringContextUtils.getBean(SpectrumPathProperties.class); @@ -173,8 +173,14 @@ public class Sample_G_Analysis { e.printStackTrace(); log.error("Sample_G_Analysis", e); throw new GAnalyseException("Sample Analyse Error at "+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss")); - }finally { - + } finally { + //删除临时文件 + if (StringUtils.isNotBlank(phdFile.getTmpFilePath())) { + File tmpFile = new File(phdFile.getTmpFilePath()); + if (Objects.nonNull(tmpFile)) { + tmpFile.delete(); + } + } } log.info("Gamma自动处理分析--End"); } 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 0544e81e..00503a48 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 @@ -887,7 +887,9 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi PHDFile phdFile = phdCache.getIfPresent(key); if (StringUtils.isNotBlank(phdFile.getTmpFilePath())) { File file = new File(phdFile.getTmpFilePath()); - file.delete(); + if (Objects.nonNull(file)) { + file.delete(); + } } // 删除指定key的Cache localCache.deletePHDCache(key); @@ -4951,7 +4953,14 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi String date = phd.getAcq().getAcquisition_start_date().replace("/", ""); String time = phd.getAcq().getAcquisition_start_time().replace(":", "").substring(0, 4); String dataType = phd.getMsgInfo().getData_type().substring(0, 1); - String phdFileName = String.format("%s-%s_%s_%s.PHD", detectorCode, date, time, dataType); + String spectrumQuantity = phd.getHeader().getSpectrum_quantity(); + double acquisitionLiveTime = phd.getAcq().getAcquisition_live_time(); + DecimalFormat df = new DecimalFormat("#.##########"); + //AUX09_003-20151226_1855 _S_FULL_40184.8.PHD + //将acquisition_live_time保留六位有效数字 如果保留一位小数后小数点后的值是0则四舍五入保留整数,否则按正常条件四舍五入保留小数位 + String numberCal = NumberFormatUtil.numberCal(String.valueOf(acquisitionLiveTime)); + numberCal = df.format(Double.valueOf(numberCal)); + String phdFileName = String.format("%s-%s_%s_%s_%s_%s.PHD", detectorCode, date, time, dataType, spectrumQuantity, numberCal); String spectrum = gammaFileUtil.makeUpSpectrum(phd); // 导出数据内容到txt文本 OutputStream fos = null; From 5a2c670a109dea65d7eed9e97c732e4378c6cfb0 Mon Sep 17 00:00:00 2001 From: panbaolin <123456> Date: Fri, 24 Nov 2023 16:09:39 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:1.=E5=AE=8C=E6=88=90=E9=82=AE=E4=BB=B6?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E6=97=A5=E5=BF=97=E5=8A=9F=E8=83=BD2.?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=82=AE=E4=BB=B6=E8=A7=A3=E6=9E=90=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E6=8A=A5=E5=91=8Asql=203.=E4=BF=AE=E6=94=B9=E8=83=BD?= =?UTF-8?q?=E8=B0=B1=E8=A7=A3=E6=9E=90=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/common/email/EmailLogEvent.java | 103 +++++ .../jeecg/common/email/EmailLogManager.java | 368 ++++++++++++++++++ .../common/email/EmailServiceManager.java | 255 ++++++++---- .../org/jeecg/common/util/LogFileUtil.java | 124 ------ .../jeecg/modules/EmailParsingActuator.java | 13 +- .../modules/FileSourceHandleManager.java | 21 +- .../jeecg/modules/UndealHandleManager.java | 25 +- .../modules/eneity/event/ErrorEvent.java | 24 ++ .../jeecg/modules/enums/SpectrumSource.java | 30 ++ .../modules/mapper/xml/StatReportMapper.xml | 115 +++--- .../modules/service/GardsStationsService.java | 5 +- .../impl/AlertSpectrumServiceImpl.java | 2 +- .../impl/GardsStationsServiceImpl.java | 23 +- .../service/impl/MetSpectrumServiceImpl.java | 2 +- .../service/impl/SOHSpectrumServiceImpl.java | 2 +- .../impl/SpectrumBaseBlockServiceImpl.java | 2 +- .../AbstractS_D_Q_G_SpectrumHandler.java | 5 - .../spectrum/AbstractSpectrumHandler.java | 75 ++-- .../jeecg/modules/spectrum/AlertSpectrum.java | 4 +- .../modules/spectrum/DetbkphdSpectrum.java | 4 +- .../modules/spectrum/GasbkphdSpectrum.java | 4 +- .../spectrum/HealthStatusSpectrum.java | 2 +- .../jeecg/modules/spectrum/MetSpectrum.java | 4 +- .../modules/spectrum/ParsingProcessLog.java | 6 +- .../jeecg/modules/spectrum/QcphdSpectrum.java | 4 +- .../modules/spectrum/SamplephdSpectrum.java | 4 +- .../spectrum/SpectrumParsingActuator.java | 115 +----- .../spectrum/SpectrumServiceQuotes.java | 3 - .../jeecg/JeecgAutoProcessApplication.java | 6 +- .../src/main/resources/application.yml | 2 +- 30 files changed, 859 insertions(+), 493 deletions(-) create mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailLogEvent.java create mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailLogManager.java delete mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/common/util/LogFileUtil.java create mode 100644 jeecg-module-auto-process/src/main/java/org/jeecg/modules/eneity/event/ErrorEvent.java create mode 100644 jeecg-module-auto-process/src/main/java/org/jeecg/modules/enums/SpectrumSource.java diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailLogEvent.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailLogEvent.java new file mode 100644 index 00000000..c086e40a --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailLogEvent.java @@ -0,0 +1,103 @@ +package org.jeecg.common.email; + +import lombok.Data; +import org.jeecg.modules.base.entity.postgre.SysEmail; + +import java.util.Date; + +/** + * 邮件日志事件 + */ +@Data +public class EmailLogEvent { + + /** + * 区分日志生成是getEmail还是sendEmail的日志 + */ + private String gsType; + /** + * 邮件配置对象 + */ + private SysEmail email; + /** + * 状态 + */ + private String state; + /** + * 当前位于邮箱流程的位置 + */ + private String logProcess; + /** + * 邮件主题 + */ + private String subject; + /** + * 接收时间 + */ + private Date recieveTime; + /** + * 能谱文件名称 + */ + private String emlPath; + /** + * PHD文件临时存储路径 + */ + private String phdMailLoadPath; + /** + * + * 日志时间 + */ + private Date logTime; + + public EmailLogEvent(){ + + } + + public EmailLogEvent(String gsType, SysEmail email, String state, String logProcess) { + this.gsType = gsType; + this.email = email; + this.state = state; + this.logProcess = logProcess; + this.logTime = new Date(); + } + + public EmailLogEvent(String gsType,String logProcess) { + this.gsType = gsType; + this.logProcess = logProcess; + this.logTime = new Date(); + } + + public EmailLogEvent(String gsType,String state, String logProcess) { + this.gsType = gsType; + this.state = state; + this.logProcess = logProcess; + this.logTime = new Date(); + } + + public EmailLogEvent(String gsType,String state, String logProcess,String phdMailLoadPath) { + this.gsType = gsType; + this.state = state; + this.logProcess = logProcess; + this.phdMailLoadPath = phdMailLoadPath; + this.logTime = new Date(); + } + + public EmailLogEvent(String gsType,String state, String logProcess,String subject,Date recieveTime,String emlPath) { + this.gsType = gsType; + this.state = state; + this.logProcess = logProcess; + this.subject = subject; + this.recieveTime = recieveTime; + this.emlPath = emlPath; + this.logTime = new Date(); + } + + public EmailLogEvent(String gsType,String state, String logProcess,String subject,Date recieveTime) { + this.gsType = gsType; + this.state = state; + this.logProcess = logProcess; + this.subject = subject; + this.recieveTime = recieveTime; + this.logTime = new Date(); + } +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailLogManager.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailLogManager.java new file mode 100644 index 00000000..668bf016 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailLogManager.java @@ -0,0 +1,368 @@ +package org.jeecg.common.email; + +import cn.hutool.core.io.FileUtil; +import com.baomidou.mybatisplus.core.toolkit.StringPool; +import lombok.Setter; +import org.jeecg.common.constant.StringConstant; +import org.jeecg.common.properties.SpectrumPathProperties; +import org.jeecg.common.util.DateUtils; + +import java.io.File; +import java.time.LocalDateTime; +import java.util.*; + +/** + * 邮件过程日志 + */ +public class EmailLogManager { + + public static final String GS_TYPE_GET = "GET"; + public static final String GS_TYPE_SEND = "SEND"; + public static final String CONNECT = "CONNECT"; + public static final String GETALLID = "GETALLID"; + public static final String GETIDHEADER = "GETIDHEADER"; + public static final String GETIDBODY = "GETIDBODY"; + public static final String GETIDEML = "GETIDEML"; + public static final String DELETEID = "DELETEID"; + public static final String EXPUNGE = "EXPUNGE"; + public static final String DONE = "DONE"; + public static final String STATUS_SUCCESS = " SUCCESS"; + public static final String STATUS_ERROR = " ERROR"; + + private static final String FIXED_FILE_NAME = "Mail"; + private static final String FIXED_FILE_SUFFIX = ".log"; + private static final String LOG_SUFFIX = "....."; + + /** + * 邮箱连接全局日志事件 + */ + @Setter + private EmailLogEvent connectLogEvent = null; + /** + * 邮件同步全局日志事件 + */ + @Setter + private EmailLogEvent getAllIdLogEvent = null; + + /** + * 完成解析邮件流程的线程id集合 + */ + private LinkedList completeThreadIds = new LinkedList<>(); + + /** + * 线程邮件日志队列 + */ + private LinkedHashMap> queue = new LinkedHashMap<>(); + + private SpectrumPathProperties spectrumPathProperties; + + private static EmailLogManager emailLogManager = null; + + public static EmailLogManager getInstance(){ + return emailLogManager; + } + + public EmailLogManager(SpectrumPathProperties spectrumPathProperties) { + this.spectrumPathProperties = spectrumPathProperties; + EmailLogExecThread logExecThread = new EmailLogExecThread(); + logExecThread.setName("email-get-exec-thread"); + logExecThread.start(); + } + + /** + * 初始化 + * @param spectrumPathProperties + */ + public static void init(SpectrumPathProperties spectrumPathProperties){ + emailLogManager = new EmailLogManager(spectrumPathProperties); + } + + /** + * 追加日志事件 + * @param event + */ + public void offer(Long threadId,EmailLogEvent event){ + synchronized (completeThreadIds){ + if(queue.containsKey(threadId)){ + queue.get(threadId).offer(event); + if(EmailLogManager.DONE.equals(event.getLogProcess())){ + completeThreadIds.offer(threadId); + completeThreadIds.notify(); + } + }else{ + LinkedList logEventList = new LinkedList<>(); + logEventList.offer(event); + queue.put(threadId,logEventList); + } + } + } + + /** + * 获取日志事件 + * @return + * @throws InterruptedException + */ + public LinkedList take(Long threadId) throws InterruptedException { + synchronized (completeThreadIds){ + final LinkedList logEventList = queue.remove(threadId); + return logEventList; + } + } + + /** + * 获取解析邮件完成的线程id + * @return + * @throws InterruptedException + */ + public Long getCompleteThreadId() throws InterruptedException { + synchronized (completeThreadIds){ + if(completeThreadIds.isEmpty()){ + completeThreadIds.wait(); + return null; + } + final Long threadId = completeThreadIds.removeFirst(); + return threadId; + } + } + + /** + * 邮件日志执行线程 + */ + private class EmailLogExecThread extends Thread{ + + @Override + public void run() { + for(;;){ + try { + final Long threadId = EmailLogManager.getInstance().getCompleteThreadId(); + if(Objects.nonNull(threadId)){ + final LinkedList logEventList = EmailLogManager.getInstance().take(threadId); + if(Objects.nonNull(getAllIdLogEvent)){ + logEventList.addFirst(getAllIdLogEvent); + } + if(Objects.nonNull(connectLogEvent)){ + logEventList.addFirst(connectLogEvent); + } + List logContentList = new ArrayList<>(); + logEventList.forEach(logEvent->{ + final String logContent = getLogContent(logEvent); + logContentList.add(logContent); + }); + writeLog(GS_TYPE_GET,logContentList); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + + /** + * 获取日志内容 + * @param event + */ + private String getLogContent(EmailLogEvent event) { + String logContent = ""; + switch (event.getLogProcess()) { + case CONNECT: + logContent = this.getConnectLog(event); + break; + case GETALLID: + logContent = this.getGetAllIdLog(event); + break; + case GETIDHEADER: + logContent = this.getIdHeaderLog(event); + break; + case GETIDBODY: + logContent = this.getIdBodyLog(event); + break; + case GETIDEML: + logContent = this.getIdEmlLog(event); + break; + case DELETEID: + logContent = this.getDeleteLog(event); + break; + case EXPUNGE: + logContent = this.getExpungeLog(event); + break; + case DONE: + logContent = this.getDoneLog(event); + break; + default: + break; + } + return logContent; + } + + /** + * 获取连接日志 + * @param event + * @return + */ + private String getConnectLog(EmailLogEvent event){ + StringBuilder logContent = new StringBuilder(); + logContent.append(DateUtils.formatDate(event.getLogTime(),"yyyy-MM-dd HH:mm:ss")); + logContent.append(" Connect Server:"); + logContent.append(event.getEmail().getEmailServerAddress()); + logContent.append(" Port:"); + logContent.append(event.getEmail().getPort()); + logContent.append(event.getState()); + logContent.append(LOG_SUFFIX); + logContent.append(System.lineSeparator()); + logContent.append(System.lineSeparator()); + return logContent.toString(); + } + + /** + * 获取邮件同步日志 + * @param event + * @return + */ + private String getGetAllIdLog(EmailLogEvent event){ + StringBuilder logContent = new StringBuilder(); + logContent.append(DateUtils.formatDate(event.getLogTime(),"yyyy-MM-dd HH:mm:ss")); + logContent.append(" Get All FileName "); + logContent.append(event.getState()); + logContent.append(LOG_SUFFIX); + logContent.append(System.lineSeparator()); + logContent.append(System.lineSeparator()); + return logContent.toString(); + } + + /** + * 获取获取邮件主题日志 + * @param event + * @return + */ + private String getIdHeaderLog(EmailLogEvent event){ + StringBuilder logContent = new StringBuilder(); + logContent.append(DateUtils.formatDate(event.getLogTime(),"yyyy-MM-dd HH:mm:ss")); + logContent.append(" Get FileNameHeader "); + logContent.append(event.getState()); + logContent.append(LOG_SUFFIX); + logContent.append(System.lineSeparator()); + logContent.append(System.lineSeparator()); + return logContent.toString(); + } + + /** + * 获取邮件内容日志 + * @param event + * @return + */ + private String getIdBodyLog(EmailLogEvent event){ + StringBuilder logContent = new StringBuilder(); + logContent.append(DateUtils.formatDate(event.getLogTime(),"yyyy-MM-dd HH:mm:ss")); + logContent.append(" Get File "); + logContent.append(event.getPhdMailLoadPath()); + logContent.append(event.getState()); + logContent.append(LOG_SUFFIX); + logContent.append(System.lineSeparator()); + logContent.append(System.lineSeparator()); + return logContent.toString(); + } + + /** + * 下载邮件日志 + * @param event + * @return + */ + private String getIdEmlLog(EmailLogEvent event){ + StringBuilder logContent = new StringBuilder(); + logContent.append(DateUtils.formatDate(event.getLogTime(),"yyyy-MM-dd HH:mm:ss")); + logContent.append(" Get File subject:"); + logContent.append(event.getSubject()); + logContent.append(" recieve datetime:"); + logContent.append(DateUtils.formatDate(event.getRecieveTime(),"yyyy-MM-dd HH:mm:ss:SSS")); + logContent.append(event.getState()); + logContent.append(" EmlFile "); + logContent.append(event.getEmlPath()); + logContent.append(LOG_SUFFIX); + logContent.append(System.lineSeparator()); + logContent.append(System.lineSeparator()); + return logContent.toString(); + } + + /** + * 下载邮件日志 + * @param event + * @return + */ + private String getDeleteLog(EmailLogEvent event){ + StringBuilder logContent = new StringBuilder(); + logContent.append(DateUtils.formatDate(event.getLogTime(),"yyyy-MM-dd HH:mm:ss")); + logContent.append(" Delete File subject:"); + logContent.append(event.getSubject()); + logContent.append(" recieve datetime:"); + logContent.append(DateUtils.formatDate(event.getRecieveTime(),"yyyy-MM-dd HH:mm:ss:SSS")); + logContent.append(event.getState()); + logContent.append(LOG_SUFFIX); + logContent.append(System.lineSeparator()); + logContent.append(System.lineSeparator()); + return logContent.toString(); + } + + /** + * 下载邮件日志 + * @param event + * @return + */ + private String getExpungeLog(EmailLogEvent event){ + StringBuilder logContent = new StringBuilder(); + logContent.append(DateUtils.formatDate(event.getLogTime(),"yyyy-MM-dd HH:mm:ss")); + logContent.append(" Expunge File subject:"); + logContent.append(event.getSubject()); + logContent.append(" recieve datetime:"); + logContent.append(DateUtils.formatDate(event.getRecieveTime(),"yyyy-MM-dd HH:mm:ss:SSS")); + logContent.append(event.getState()); + logContent.append(LOG_SUFFIX); + logContent.append(System.lineSeparator()); + logContent.append(System.lineSeparator()); + return logContent.toString(); + } + + /** + * 完成日志 + * @param event + * @return + */ + private String getDoneLog(EmailLogEvent event){ + StringBuilder logContent = new StringBuilder(); + logContent.append(DateUtils.formatDate(event.getLogTime(),"yyyy-MM-dd HH:mm:ss")); + logContent.append(" Done"); + logContent.append(LOG_SUFFIX); + logContent.append(System.lineSeparator()); + logContent.append(System.lineSeparator()); + return logContent.toString(); + } + + /** + * 把日志写入文件 + */ + private void writeLog(String gsType, List logContentList){ + LocalDateTime now = LocalDateTime.now(); + StringBuilder logFilePath = new StringBuilder(); + logFilePath.append(spectrumPathProperties.getRootPath()); + logFilePath.append(File.separator); + logFilePath.append(spectrumPathProperties.getLogPath()); + logFilePath.append(File.separator); + logFilePath.append(FIXED_FILE_NAME); + logFilePath.append(File.separator); + logFilePath.append(gsType); + logFilePath.append(File.separator); + logFilePath.append(now.getYear()); + logFilePath.append(File.separator); + logFilePath.append(now.getMonthValue()); + logFilePath.append(File.separator); + logFilePath.append(now.getYear()); + logFilePath.append(StringConstant.DASH); + logFilePath.append(now.getMonthValue()); + logFilePath.append(StringConstant.DASH); + logFilePath.append(now.getDayOfMonth()); + logFilePath.append(StringConstant.UNDER_LINE); + logFilePath.append(FIXED_FILE_NAME); + logFilePath.append(FIXED_FILE_SUFFIX); + + FileUtil.appendLines(logContentList,logFilePath.toString(),"UTF-8"); + } +} \ No newline at end of file diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java index a1ebb99c..eeb1dc4c 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java @@ -1,25 +1,22 @@ package org.jeecg.common.email; import cn.hutool.core.util.ArrayUtil; -import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.google.common.collect.Lists; import com.sun.mail.imap.IMAPStore; import com.sun.mail.smtp.SMTPAddressFailedException; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.jeecg.common.api.dto.message.MessageDTO; +import org.jeecg.common.constant.StringConstant; import org.jeecg.common.constant.SymbolConstant; import org.jeecg.common.email.emuns.MailContentType; import org.jeecg.common.properties.SpectrumPathProperties; -import org.jeecg.common.util.LogFileUtil; +import org.jeecg.common.util.DateUtils; import org.jeecg.modules.base.entity.postgre.SysEmail; import org.jetbrains.annotations.NotNull; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.stereotype.Component; import javax.mail.*; -import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeUtility; @@ -38,6 +35,11 @@ import java.util.stream.Collectors; @Slf4j public class EmailServiceManager { + /** + * 存储到eml目录的Email文件后缀 + */ + private final static String SAVE_EML_SUFFIX = ".eml"; + private SysEmail email; private SpectrumPathProperties spectrumPathProperties; /** @@ -105,63 +107,77 @@ public class EmailServiceManager { /** * 接收邮件 */ - public Message[] receiveMail() throws MessagingException { - //配置邮件服务属性 - Properties props = new Properties(); - props.put("mail.store.protocol","imap"); - props.put("mail.imap.host",email.getEmailServerAddress()); - props.put("mail.imap.port",email.getPort()); - //获取邮件回话 - final Session session = Session.getInstance(props, new Authenticator() { - @Override - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(email.getUsername(), email.getPassword()); - } - }); - Map iam = new HashMap<>(); - iam.put("name", "myname"); - iam.put("version", "1.0.0"); - iam.put("vendor", "myclient"); - iam.put("support-email", "testmail@test.com"); - //获取smtp协议的存储对象 - store = (IMAPStore) session.getStore(); - //连接 - store.connect(); - store.id(iam); - //获取收件箱 - folder = store.getFolder("INBOX");//INBOX - folder.open(Folder.READ_WRITE); - //如果邮箱邮件数量 > 0 - final int messageCount = folder.getMessageCount(); - if(messageCount > 0){ - Message[] messages = null; - if(Objects.isNull(this.systemStartupTime)){ - int finalNum = messageCount > this.receiveNum?this.receiveNum:messageCount; - //邮箱邮件下标是从1开始的 - return folder.getMessages(1,finalNum); - } - SearchTerm searchTerm = new ReceivedDateTerm(ComparisonTerm.GE,this.systemStartupTime); - messages = folder.search(searchTerm); - Arrays.sort(messages, (o1, o2) -> { - try { - return o1.getReceivedDate().compareTo(o2.getReceivedDate()); - } catch (MessagingException e) { - e.printStackTrace(); + public Message[] receiveMail() { + String status = EmailLogManager.STATUS_SUCCESS; + try{ + //配置邮件服务属性 + Properties props = new Properties(); + props.put("mail.store.protocol","imap"); + props.put("mail.imap.host",email.getEmailServerAddress()); + props.put("mail.imap.port",email.getPort()); + //获取邮件回话 + final Session session = Session.getInstance(props, new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(email.getUsername(), email.getPassword()); } - return 0; }); - if(this.receiveNum >= messages.length){ - return messages; - }else{ - return Arrays.copyOfRange(messages,0,this.receiveNum-1); + Map iam = new HashMap<>(); + iam.put("name", "myname"); + iam.put("version", "1.0.0"); + iam.put("vendor", "myclient"); + iam.put("support-email", "testmail@test.com"); + //获取smtp协议的存储对象 + store = (IMAPStore) session.getStore(); + //连接 + store.connect(); + store.id(iam); + //获取收件箱 + folder = store.getFolder("INBOX");//INBOX + folder.open(Folder.READ_WRITE); + //如果邮箱邮件数量 > 0 + final int messageCount = folder.getMessageCount(); + if(messageCount > 0){ + Message[] messages = null; + if(Objects.isNull(this.systemStartupTime)){ + int finalNum = messageCount > this.receiveNum?this.receiveNum:messageCount; + //邮箱邮件下标是从1开始的 + return folder.getMessages(1,finalNum); + } + SearchTerm searchTerm = new ReceivedDateTerm(ComparisonTerm.GE,this.systemStartupTime); + messages = folder.search(searchTerm); + Arrays.sort(messages, (o1, o2) -> { + try { + return o1.getReceivedDate().compareTo(o2.getReceivedDate()); + } catch (MessagingException e) { + e.printStackTrace(); + } + return 0; + }); + if(this.receiveNum >= messages.length){ + return messages; + }else{ + return Arrays.copyOfRange(messages,0,this.receiveNum-1); + } } + }catch (MessagingException e){ + status = EmailLogManager.STATUS_ERROR; + log.error("Email connection is abnormal, account is {}, service is {},the reason is {}.",email.getName(),email.getEmailServerAddress(),e.getMessage()); + e.printStackTrace(); + return null; + }finally { + EmailLogEvent connectEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,email,status,EmailLogManager.CONNECT); + EmailLogManager.getInstance().setConnectLogEvent(connectEvent); + //GetAllId C++原业务是把远程邮箱邮件同步到C++,本次java编写没有这一步,所以和Connect绑定,若Connect成功则GetAllId成功 + EmailLogEvent getAllEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETALLID); + EmailLogManager.getInstance().setGetAllIdLogEvent(getAllEvent); } return null; } /* - * 测试收件邮箱账号是否可以正常使用 - * */ + * 测试收件邮箱账号是否可以正常使用 + * */ public boolean canReceive(){ Integer port = email.getPort(); String username = email.getUsername(); @@ -174,6 +190,7 @@ public class EmailServiceManager { props.put("mail.imap.port", port); Session session = Session.getInstance(props, new Authenticator() { + @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } @@ -189,8 +206,8 @@ public class EmailServiceManager { } /* - * 测试发件邮箱账号是否可以正常使用 - * */ + * 测试发件邮箱账号是否可以正常使用 + * */ public boolean canSend(){ Integer port = email.getPort(); String username = email.getUsername(); @@ -204,6 +221,7 @@ public class EmailServiceManager { props.put("mail.smtp.auth", "true"); Session session = Session.getInstance(props, new Authenticator() { + @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } @@ -331,6 +349,28 @@ public class EmailServiceManager { } } + /** + * 获取邮件主题 + * @param message + * @return + */ + public String getMailSubject(@NotNull Message message) throws MessagingException { + String subject = ""; + String status = EmailLogManager.STATUS_SUCCESS; + try { + subject = MimeUtility.decodeText(message.getSubject()); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (MessagingException e) { + status = EmailLogManager.STATUS_ERROR; + throw e; + }finally { + EmailLogEvent event = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETIDHEADER); + EmailLogManager.getInstance().offer(Thread.currentThread().getId(),event); + } + return subject; + } + /** * 获取邮件内容 * @param part @@ -339,24 +379,14 @@ public class EmailServiceManager { * @throws IOException */ public void getMailContent(@NotNull Part part, StringBuilder content) throws MessagingException, IOException { - try { - if(part.isMimeType(MailContentType.PLAIN.getContentType())){ - content.append(part.getContent()); - }else if(part.isMimeType("multipart/*")){ - Multipart multipart = (Multipart) part.getContent(); - for(int i=0;i select - r.stationName as stationName, - r.dataType as dataType, - r.originalDataNumber as originalDataNumber, - r.anlyseDataNumber as anlyseDataNumber - from ( - select - substr(t.site_det_code,1,5) as stationName, - t.data_type as dataType, - ( - 1+ - (select count(*) from original.GARDS_ROI_LIMITS grl where grl.sample_id = t.sample_id)+ - (select count(*) from original.GARDS_SAMPLE_AUX gsa where gsa.sample_id = t.sample_id)+ - (select count(*) from original.GARDS_SAMPLE_CERT gsc where gsc.sample_id = t.sample_id)+ - (select count(*) from original.GARDS_SAMPLE_CERT_LINE gscl where gscl.sample_id = t.sample_id)+ - (select count(*) from original.GARDS_SAMPLE_DESCRIPTION gsd where gsd.sample_id = t.sample_id)+ - (select count(*) from original.GARDS_SAMPLE_RATIOS gsr where gsr.sample_id = t.sample_id)+ - (select count(*) from original.GARDS_SPECTRUM gs where gs.sample_id = t.sample_id)+ - (select count(*) from original.GARDS_TOTAL_EFFICIENCY_PAIRS gtep where gtep.sample_id = t.sample_id)+ - (select count(*) from original.GARDS_HISTOGRAM gh where gh.sample_id = t.sample_id)+ - (select count(*) from original.GARDS_CALIBRATION_PAIRS_ORIG gcp where gcp.sample_id = t.sample_id)+ - (select count(*) from original.GARDS_BG_EFFICIENCY_PAIRS gbep where gbep.sample_id = t.sample_id) - ) as originalDataNumber, - ( - (select count(*) from rnauto.GARDS_ANALYSES ga where ga.sample_id = t.sample_id)+ - (select count(*) from rnauto.GARDS_CALIBRATION gc where gc.sample_id = t.sample_id)+ - (select count(*) from rnauto.GARDS_CALIBRATION_PAIRS gcp where gcp.sample_id = t.sample_id)+ - (select count(*) from rnauto.GARDS_NUCL_IDED gn where gn.sample_id = t.sample_id)+ - (select count(*) from rnauto.GARDS_NUCL_LINES_IDED gnli where gnli.sample_id = t.sample_id)+ - (select count(*) from rnauto.GARDS_ROI_CHANNELS grc where grc.sample_id = t.sample_id)+ - (select count(*) from rnauto.GARDS_ROI_RESULTS grr where grr.sample_id = t.sample_id)+ - (select count(*) from rnauto.GARDS_XE_RESULTS gxr where gxr.sample_id = t.sample_id)+ - (select count(*) from rnauto.GARDS_PEAKS gp where gp.sample_id = t.sample_id)+ - (select count(*) from rnauto.GARDS_QC_CHECK gqc where gqc.sample_id = t.sample_id) - ) as anlyseDataNumber, - t.moddate - from original.GARDS_SAMPLE_DATA t - where t.moddate between #{beginDate} and #{endDate} - union all - select - min(t.station_code) as stationName, - 'MET' as dataType, - count(*) as originalDataNumber, - 0 as anlyseDataNumber, - min(t.moddate) as moddate - from original.GARDS_MET_DATA t - where t.moddate between #{beginDate} and #{endDate} - group by t.input_file_name - union all - select - min(t.station_code) as stationName, - 'SOH' as dataType, - count(*) as originalDataNumber, - 0 as anlyseDataNumber, - min(t.moddate) as moddate - from original.GARDS_SOH_DATA t - where t.moddate between #{beginDate} and #{endDate} - group by t.input_file_name - union all - select - t.station_code as stationName, - 'ALERT' as dataType, - 1 as originalDataNumber, - 0 as anlyseDataNumber, - t.time as moddate - from original.GARDS_ALERT_DATA t - where t.time between #{beginDate} and #{endDate} - ) r order by r.moddate asc + f.station_name as stationName, + f.data_type as dataType, + f.original_data_number as originalDataNumber, + f.anlyse_data_number as anlyseDataNumber + from( + select + r.station_name, + r.data_type, + sum(r.original_data_number) as original_data_number, + sum(r.anlyse_data_number) as anlyse_data_number + from( + select + substr(t.site_det_code,1,5) as station_name, + t.data_type, + 1 as original_data_number, + nvl2((select t.sample_id from rnauto.GARDS_ANALYSES ga where ga.sample_id = t.sample_id),1,0) as anlyse_data_number + from original.GARDS_SAMPLE_DATA t + where t.moddate between #{beginDate} and #{endDate} + ) r + group by r.station_name,r.data_type + union all + select + t.station_code as station_name, + 'MET' as data_type, + count(*) as original_data_number, + 0 as anlyse_data_number + from original.GARDS_MET_DATA t + where t.moddate between #{beginDate} and #{endDate} + group by t.station_code + union all + select + t.station_code as station_name, + 'SOH' as data_type, + count(*) as original_data_number, + 0 as anlyse_data_number + from original.GARDS_SOH_DATA t + where t.moddate between #{beginDate} and #{endDate} + group by t.station_code + union all + select + t.station_code as station_name, + 'ALERT' as data_type, + count(*) as original_data_number, + 0 as anlyseDataNumber + from original.GARDS_ALERT_DATA t + where t.time between #{beginDate} and #{endDate} + group by t.station_code + ) f order by f.station_name,f.data_type asc \ No newline at end of file diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/GardsStationsService.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/GardsStationsService.java index f462b7e0..636453aa 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/GardsStationsService.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/GardsStationsService.java @@ -11,7 +11,10 @@ public interface GardsStationsService extends IService { /** * 校验台站编码是否存在 + * @param site_code + * @param fileName * @return + * @throws StationNotFoundException */ - GardsStations check(String site_code) throws StationNotFoundException; + GardsStations check(String site_code,String fileName) throws StationNotFoundException; } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/AlertSpectrumServiceImpl.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/AlertSpectrumServiceImpl.java index aed8319b..93008725 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/AlertSpectrumServiceImpl.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/AlertSpectrumServiceImpl.java @@ -39,7 +39,7 @@ public class AlertSpectrumServiceImpl extends ServiceImpl implements GardsStationsService { + private final TaskProperties taskProperties; + private SpectrumPathProperties spectrumPathProperties; /** * 校验台站编码是否存在 - * * @param site_code + * @param fileName * @return + * @throws StationNotFoundException */ @Override - public GardsStations check(String site_code) throws StationNotFoundException { + public GardsStations check(String site_code,String fileName) throws StationNotFoundException { LambdaQueryWrapper gardsStationsQuery = new LambdaQueryWrapper<>(); gardsStationsQuery.select(GardsStations::getStationId); gardsStationsQuery.eq(GardsStations::getStationCode,site_code); final GardsStations station = this.baseMapper.selectOne(gardsStationsQuery); if (Objects.isNull(station)) { - throw new StationNotFoundException("station_code:"+site_code+"=0"); + StringBuilder logContent = new StringBuilder(); + logContent.append("station_code:"+site_code+"=0"); + logContent.append(StringConstant.SPACE); + logContent.append(taskProperties.getUndealFileTimeOut()); + + log.error("This station does not exist, the number is {}.",site_code); +// LogFileUtil.errorLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(), finalFileName.toString(), warning); + throw new StationNotFoundException("This station does not exist, the number is "+site_code+"."); } return station; } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/MetSpectrumServiceImpl.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/MetSpectrumServiceImpl.java index 01b09677..400b2225 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/MetSpectrumServiceImpl.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/MetSpectrumServiceImpl.java @@ -45,7 +45,7 @@ public class MetSpectrumServiceImpl extends ServiceImpl list = Lists.newArrayList(); if(struct.record_count > 0){ for(int i=0;i