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 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.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,23 +535,20 @@ 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){
if(subject.contains(StringConstant.SLASH)){
subject = StringUtils.replace(subject,StringConstant.SLASH,"");
}
if(subject.indexOf(StringConstant.COLON) != -1){
if(subject.contains(StringConstant.COLON)){
subject = StringUtils.replace(subject,StringConstant.COLON,"");
}
receivedDate = message.getReceivedDate();
@ -573,20 +571,36 @@ public class EmailServiceManager {
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);
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<String> 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());
}
}
} catch (MessagingException | IOException e) {
// 下载邮件失败 抛出自定义邮件下载异常
status = EmailLogManager.STATUS_ERROR;
@ -594,26 +608,14 @@ public class EmailServiceManager {
log.error(errorMsg);
throw new DownloadEmailException(errorMsg);
}catch (Exception e) {
log.error("",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);
try {
if (Objects.nonNull(inputStream)) {
inputStream.close();
}
if (Objects.nonNull(outputStream)) {
outputStream.flush();
outputStream.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return emlFile;
}
}
/**
* 删除邮件

View File

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

View File

@ -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);
}