From 3f22b0edba6a15159d7cc617247cf9140c093fd0 Mon Sep 17 00:00:00 2001 From: nieziyan Date: Mon, 8 Jul 2024 10:03:25 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9ABugs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeecg/common/constant/SymbolConstant.java | 4 + .../common/email/EmailServiceManager.java | 154 +++++++++--------- .../struct/EnergySpectrumStruct.java | 11 ++ .../jeecg/common/util/SelfStationUtil.java | 8 +- 4 files changed, 97 insertions(+), 80 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/SymbolConstant.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/SymbolConstant.java index 998e865b..3978517a 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/SymbolConstant.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/SymbolConstant.java @@ -126,4 +126,8 @@ public class SymbolConstant { public static final String LINE = "\n"; public static final String AT = "@"; + + public static final String VERTICAL = "|"; + + public static final char VERTICAL_CHAR = '|'; } \ 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 8a3e9e25..c8742bbe 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 @@ -2,6 +2,7 @@ package org.jeecg.common.email; import cn.hutool.core.codec.Base64; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.ArrayUtil; @@ -534,85 +535,86 @@ public class EmailServiceManager { * 当计数大于10000后从0开始,服务重启后也从0开始 */ public File downloadEmailToEmlDir(@NotNull Message message,Integer emailCounter,Integer batchesCounter) throws MessagingException { - synchronized (downloadEmlLocal) { - String subject = ""; - File emlFile = null; - String status = EmailLogManager.STATUS_SUCCESS; - Date receivedDate = null; - InputStream inputStream = null; - BufferedOutputStream outputStream = null; - try { - //获取发件人 - final String address = ((InternetAddress) message.getFrom()[0]).getAddress(); - final String from = address.substring(0,address.indexOf(StringConstant.AT)); - //获取主题 - subject = MimeUtility.decodeText(message.getSubject()); - if(subject.indexOf(StringConstant.SLASH) != -1){ - subject = StringUtils.replace(subject,StringConstant.SLASH,""); - } - if(subject.indexOf(StringConstant.COLON) != -1){ - subject = StringUtils.replace(subject,StringConstant.COLON,""); - } - receivedDate = message.getReceivedDate(); - StringBuilder fileName = new StringBuilder(); - fileName.append(from); - fileName.append(StringConstant.UNDER_LINE); - fileName.append(subject); - fileName.append(StringConstant.UNDER_LINE); - fileName.append(DateUtils.formatDate(new Date(),"YYMMdd")); - fileName.append(StringConstant.UNDER_LINE); - fileName.append(DateUtils.formatDate(new Date(),"HHmmssSSS")); - fileName.append(StringConstant.UNDER_LINE); - fileName.append("receive"); - fileName.append(StringConstant.UNDER_LINE); - fileName.append(DateUtils.formatDate(receivedDate,"YYMMdd")); - fileName.append(StringConstant.UNDER_LINE); - fileName.append(DateUtils.formatDate(receivedDate,"HHmmssSSS")); - fileName.append(StringConstant.UNDER_LINE); - fileName.append(emailCounter); - fileName.append(SAVE_EML_SUFFIX); - final String rootPath = spectrumPathProperties.getRootPath(); - final String emlPath = spectrumPathProperties.getEmlPath(); - emlFile = new File(rootPath+emlPath+File.separator+fileName); -// outputStream = new FileOutputStream(emlFile); -// message.writeTo(outputStream); - - int bufferSize = 1024 * 1024; // 1M - inputStream = message.getInputStream(); - outputStream = new BufferedOutputStream(new FileOutputStream(emlFile), bufferSize); - // 从邮件的输入流读取内容,并写入到本地文件 - byte[] buffer = new byte[bufferSize]; - int bytesRead; - while ((bytesRead = inputStream.read(buffer)) != -1) { - outputStream.write(buffer, 0, bytesRead); - } - - } catch (MessagingException | IOException e) { - // 下载邮件失败 抛出自定义邮件下载异常 - status = EmailLogManager.STATUS_ERROR; - String errorMsg = StrUtil.format("The email download failed, the subject of the email is {}, the reason is {}.", subject, e.getMessage()); - log.error(errorMsg); - throw new DownloadEmailException(errorMsg); - }catch (Exception e) { - log.error("",e); - }finally { - EmailLogEvent event = new EmailLogEvent(batchesCounter,Thread.currentThread().getId(),EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETIDEML,subject,DateUtils.formatDate(receivedDate,"yyyy-MM-dd HH:mm:ss:SSS"), - (Objects.isNull(emlFile)?" ":emlFile.getAbsolutePath())); - EmailLogManager.getInstance().offer(Thread.currentThread().getId(),event); - try { - if (Objects.nonNull(inputStream)) { - inputStream.close(); - } - if (Objects.nonNull(outputStream)) { - outputStream.flush(); - outputStream.close(); - } - } catch (IOException e) { - throw new RuntimeException(e); + String subject = ""; + File emlFile = null; + String status = EmailLogManager.STATUS_SUCCESS; + Date receivedDate = null; + try { + //获取发件人 + final String address = ((InternetAddress) message.getFrom()[0]).getAddress(); + final String from = address.substring(0,address.indexOf(StringConstant.AT)); + //获取主题 + subject = MimeUtility.decodeText(message.getSubject()); + if(subject.contains(StringConstant.SLASH)){ + subject = StringUtils.replace(subject,StringConstant.SLASH,""); + } + if(subject.contains(StringConstant.COLON)){ + subject = StringUtils.replace(subject,StringConstant.COLON,""); + } + receivedDate = message.getReceivedDate(); + StringBuilder fileName = new StringBuilder(); + fileName.append(from); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(subject); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(DateUtils.formatDate(new Date(),"YYMMdd")); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(DateUtils.formatDate(new Date(),"HHmmssSSS")); + fileName.append(StringConstant.UNDER_LINE); + fileName.append("receive"); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(DateUtils.formatDate(receivedDate,"YYMMdd")); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(DateUtils.formatDate(receivedDate,"HHmmssSSS")); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(emailCounter); + fileName.append(SAVE_EML_SUFFIX); + final String rootPath = spectrumPathProperties.getRootPath(); + final String emlPath = spectrumPathProperties.getEmlPath(); + emlFile = new File(rootPath + emlPath + File.separator + fileName); + /* 如果邮件内容经过Base64编码 需要解码后再生成.eml文件 否则直接生成.eml文件 */ + // 先将邮件的内容保存为.eml文件 + // message.writeTo(Files.newOutputStream(emlFile.toPath())); + FileUtil.writeFromStream(message.getInputStream(), emlFile); + // 判断是否需要对正文内容进行解码 + // String content = (String) message.getContent(); + String content = FileUtil.readUtf8String(emlFile); + List contents = ListUtil.toList(StrUtil.split(content, SymbolConstant.VERTICAL)); + // 如果邮件正文被|分割为4部分 说明邮件内容经过了编码 尝试进行解码 + if (contents.size() == 4){ + contents = ListUtil.toList(StrUtil.split(content, SymbolConstant.VERTICAL_CHAR, 2)); + String md5 = contents.get(0); + content = contents.get(1); + // 去除可能产生的多余的空格 否则影响MD5的生成结果 + content = StrUtil.cleanBlank(content); + String md5Verified = MD5.create().digestHex(content); + // 如果md5验证失败 则不进行解码 + if (!StrUtil.equals(md5, md5Verified)) return emlFile; + contents = ListUtil.toList(StrUtil.split(content, SymbolConstant.VERTICAL)); + String base64 = contents.get(contents.size() - 1); + // 解码Base64字符串 并用解码后的内容覆盖原始文件内容 + byte[] data = Base64.decode(base64); + try (OutputStream out = Files.newOutputStream(emlFile.toPath()); + InflaterOutputStream inflaterOutputStream = new InflaterOutputStream(out)) { + inflaterOutputStream.write(data); + } catch (Exception e) { + log.error("Decoded the Base64 eml file[{}] error: {}", emlFile.getAbsolutePath(), e.getMessage()); } } - return emlFile; + } catch (MessagingException | IOException e) { + // 下载邮件失败 抛出自定义邮件下载异常 + status = EmailLogManager.STATUS_ERROR; + String errorMsg = StrUtil.format("The email download failed, the subject of the email is {}, the reason is {}.", subject, e.getMessage()); + log.error(errorMsg); + throw new DownloadEmailException(errorMsg); + }catch (Exception e) { + log.error("The email download failed: {}", e.getMessage()); + }finally { + EmailLogEvent event = new EmailLogEvent(batchesCounter,Thread.currentThread().getId(),EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETIDEML,subject,DateUtils.formatDate(receivedDate,"yyyy-MM-dd HH:mm:ss:SSS"), + (Objects.isNull(emlFile)?" ":emlFile.getAbsolutePath())); + EmailLogManager.getInstance().offer(Thread.currentThread().getId(),event); } + return emlFile; } /** diff --git a/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/modules/native_jni/struct/EnergySpectrumStruct.java b/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/modules/native_jni/struct/EnergySpectrumStruct.java index d0279728..ec50dd3c 100644 --- a/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/modules/native_jni/struct/EnergySpectrumStruct.java +++ b/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/modules/native_jni/struct/EnergySpectrumStruct.java @@ -98,6 +98,17 @@ public class EnergySpectrumStruct { */ public double acquisition_live_time; + /*************************** GPS Block ***********************/ + /* + * 坐标: 经度值 + * */ + public double longitude; + + /* + * 坐标: 纬度值 + * */ + public double latitude; + /************************* Collection Block ******************/ /** diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/SelfStationUtil.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/SelfStationUtil.java index 5ae201a7..7ff49c9d 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/SelfStationUtil.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/SelfStationUtil.java @@ -189,15 +189,15 @@ public class SelfStationUtil extends AbstractLogOrReport { Long count = hCounts.get(index.intValue()); if (count > 0){ HistogramData his = new HistogramData(); - his.setG(i); - his.setB(j); + his.setG(j); + his.setB(i); his.setC(count); histogramDataList.add(his); histogramDataDList.add(his); }else { HistogramData his = new HistogramData(); - his.setG(i); - his.setB(j); + his.setG(j); + his.setB(i); his.setC(count); histogramDataDList.add(his); }