fix:Bugs

This commit is contained in:
nieziyan 2024-07-08 10:03:25 +08:00
parent d5dce1c3fc
commit 3f22b0edba
4 changed files with 97 additions and 80 deletions

View File

@ -126,4 +126,8 @@ public class SymbolConstant {
public static final String LINE = "\n"; public static final String LINE = "\n";
public static final String AT = "@"; public static final String AT = "@";
public static final String VERTICAL = "|";
public static final char VERTICAL_CHAR = '|';
} }

View File

@ -2,6 +2,7 @@ package org.jeecg.common.email;
import cn.hutool.core.codec.Base64; import cn.hutool.core.codec.Base64;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil; import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
@ -534,85 +535,86 @@ public class EmailServiceManager {
* 当计数大于10000后从0开始服务重启后也从0开始 * 当计数大于10000后从0开始服务重启后也从0开始
*/ */
public File downloadEmailToEmlDir(@NotNull Message message,Integer emailCounter,Integer batchesCounter) throws MessagingException { public File downloadEmailToEmlDir(@NotNull Message message,Integer emailCounter,Integer batchesCounter) throws MessagingException {
synchronized (downloadEmlLocal) { String subject = "";
String subject = ""; File emlFile = null;
File emlFile = null; String status = EmailLogManager.STATUS_SUCCESS;
String status = EmailLogManager.STATUS_SUCCESS; Date receivedDate = null;
Date receivedDate = null; try {
InputStream inputStream = null; //获取发件人
BufferedOutputStream outputStream = null; final String address = ((InternetAddress) message.getFrom()[0]).getAddress();
try { final String from = address.substring(0,address.indexOf(StringConstant.AT));
//获取发件人 //获取主题
final String address = ((InternetAddress) message.getFrom()[0]).getAddress(); subject = MimeUtility.decodeText(message.getSubject());
final String from = address.substring(0,address.indexOf(StringConstant.AT)); if(subject.contains(StringConstant.SLASH)){
//获取主题 subject = StringUtils.replace(subject,StringConstant.SLASH,"");
subject = MimeUtility.decodeText(message.getSubject()); }
if(subject.indexOf(StringConstant.SLASH) != -1){ if(subject.contains(StringConstant.COLON)){
subject = StringUtils.replace(subject,StringConstant.SLASH,""); subject = StringUtils.replace(subject,StringConstant.COLON,"");
} }
if(subject.indexOf(StringConstant.COLON) != -1){ receivedDate = message.getReceivedDate();
subject = StringUtils.replace(subject,StringConstant.COLON,""); StringBuilder fileName = new StringBuilder();
} fileName.append(from);
receivedDate = message.getReceivedDate(); fileName.append(StringConstant.UNDER_LINE);
StringBuilder fileName = new StringBuilder(); fileName.append(subject);
fileName.append(from); fileName.append(StringConstant.UNDER_LINE);
fileName.append(StringConstant.UNDER_LINE); fileName.append(DateUtils.formatDate(new Date(),"YYMMdd"));
fileName.append(subject); fileName.append(StringConstant.UNDER_LINE);
fileName.append(StringConstant.UNDER_LINE); fileName.append(DateUtils.formatDate(new Date(),"HHmmssSSS"));
fileName.append(DateUtils.formatDate(new Date(),"YYMMdd")); fileName.append(StringConstant.UNDER_LINE);
fileName.append(StringConstant.UNDER_LINE); fileName.append("receive");
fileName.append(DateUtils.formatDate(new Date(),"HHmmssSSS")); fileName.append(StringConstant.UNDER_LINE);
fileName.append(StringConstant.UNDER_LINE); fileName.append(DateUtils.formatDate(receivedDate,"YYMMdd"));
fileName.append("receive"); fileName.append(StringConstant.UNDER_LINE);
fileName.append(StringConstant.UNDER_LINE); fileName.append(DateUtils.formatDate(receivedDate,"HHmmssSSS"));
fileName.append(DateUtils.formatDate(receivedDate,"YYMMdd")); fileName.append(StringConstant.UNDER_LINE);
fileName.append(StringConstant.UNDER_LINE); fileName.append(emailCounter);
fileName.append(DateUtils.formatDate(receivedDate,"HHmmssSSS")); fileName.append(SAVE_EML_SUFFIX);
fileName.append(StringConstant.UNDER_LINE); final String rootPath = spectrumPathProperties.getRootPath();
fileName.append(emailCounter); final String emlPath = spectrumPathProperties.getEmlPath();
fileName.append(SAVE_EML_SUFFIX); emlFile = new File(rootPath + emlPath + File.separator + fileName);
final String rootPath = spectrumPathProperties.getRootPath(); /* 如果邮件内容经过Base64编码 需要解码后再生成.eml文件 否则直接生成.eml文件 */
final String emlPath = spectrumPathProperties.getEmlPath(); // 先将邮件的内容保存为.eml文件
emlFile = new File(rootPath+emlPath+File.separator+fileName); // message.writeTo(Files.newOutputStream(emlFile.toPath()));
// outputStream = new FileOutputStream(emlFile); FileUtil.writeFromStream(message.getInputStream(), emlFile);
// message.writeTo(outputStream); // 判断是否需要对正文内容进行解码
// String content = (String) message.getContent();
int bufferSize = 1024 * 1024; // 1M String content = FileUtil.readUtf8String(emlFile);
inputStream = message.getInputStream(); List<String> contents = ListUtil.toList(StrUtil.split(content, SymbolConstant.VERTICAL));
outputStream = new BufferedOutputStream(new FileOutputStream(emlFile), bufferSize); // 如果邮件正文被|分割为4部分 说明邮件内容经过了编码 尝试进行解码
// 从邮件的输入流读取内容并写入到本地文件 if (contents.size() == 4){
byte[] buffer = new byte[bufferSize]; contents = ListUtil.toList(StrUtil.split(content, SymbolConstant.VERTICAL_CHAR, 2));
int bytesRead; String md5 = contents.get(0);
while ((bytesRead = inputStream.read(buffer)) != -1) { content = contents.get(1);
outputStream.write(buffer, 0, bytesRead); // 去除可能产生的多余的空格 否则影响MD5的生成结果
} content = StrUtil.cleanBlank(content);
String md5Verified = MD5.create().digestHex(content);
} catch (MessagingException | IOException e) { // 如果md5验证失败 则不进行解码
// 下载邮件失败 抛出自定义邮件下载异常 if (!StrUtil.equals(md5, md5Verified)) return emlFile;
status = EmailLogManager.STATUS_ERROR; contents = ListUtil.toList(StrUtil.split(content, SymbolConstant.VERTICAL));
String errorMsg = StrUtil.format("The email download failed, the subject of the email is {}, the reason is {}.", subject, e.getMessage()); String base64 = contents.get(contents.size() - 1);
log.error(errorMsg); // 解码Base64字符串 并用解码后的内容覆盖原始文件内容
throw new DownloadEmailException(errorMsg); byte[] data = Base64.decode(base64);
}catch (Exception e) { try (OutputStream out = Files.newOutputStream(emlFile.toPath());
log.error("",e); InflaterOutputStream inflaterOutputStream = new InflaterOutputStream(out)) {
}finally { inflaterOutputStream.write(data);
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"), } catch (Exception e) {
(Objects.isNull(emlFile)?" ":emlFile.getAbsolutePath())); log.error("Decoded the Base64 eml file[{}] error: {}", emlFile.getAbsolutePath(), e.getMessage());
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);
} }
} }
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;
} }
/** /**

View File

@ -98,6 +98,17 @@ public class EnergySpectrumStruct {
*/ */
public double acquisition_live_time; public double acquisition_live_time;
/*************************** GPS Block ***********************/
/*
* 坐标: 经度值
* */
public double longitude;
/*
* 坐标: 纬度值
* */
public double latitude;
/************************* Collection Block ******************/ /************************* Collection Block ******************/
/** /**

View File

@ -189,15 +189,15 @@ public class SelfStationUtil extends AbstractLogOrReport {
Long count = hCounts.get(index.intValue()); Long count = hCounts.get(index.intValue());
if (count > 0){ if (count > 0){
HistogramData his = new HistogramData(); HistogramData his = new HistogramData();
his.setG(i); his.setG(j);
his.setB(j); his.setB(i);
his.setC(count); his.setC(count);
histogramDataList.add(his); histogramDataList.add(his);
histogramDataDList.add(his); histogramDataDList.add(his);
}else { }else {
HistogramData his = new HistogramData(); HistogramData his = new HistogramData();
his.setG(i); his.setG(j);
his.setB(j); his.setB(i);
his.setC(count); his.setC(count);
histogramDataDList.add(his); histogramDataDList.add(his);
} }