|
@@ -1,18 +1,5 @@
|
|
|
package com.jiayue.biz.service.impl;
|
|
|
|
|
|
-import java.io.*;
|
|
|
-import java.security.Security;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-import javax.mail.*;
|
|
|
-import javax.mail.internet.InternetAddress;
|
|
|
-import javax.mail.internet.MimeMessage;
|
|
|
-import javax.mail.internet.MimeMultipart;
|
|
|
-import javax.mail.internet.MimeUtility;
|
|
|
-import javax.mail.search.*;
|
|
|
-
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.jiayue.biz.domain.Email;
|
|
|
import com.jiayue.biz.domain.EmailWindTowerInfo;
|
|
@@ -28,6 +15,21 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.mail.*;
|
|
|
+import javax.mail.internet.InternetAddress;
|
|
|
+import javax.mail.internet.MimeMessage;
|
|
|
+import javax.mail.internet.MimeMultipart;
|
|
|
+import javax.mail.internet.MimeUtility;
|
|
|
+import javax.mail.search.FlagTerm;
|
|
|
+import java.io.*;
|
|
|
+import java.security.Security;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Properties;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* 使用imap协议获取未读邮件数
|
|
|
*
|
|
@@ -116,14 +118,14 @@ public class EmailImpl extends ServiceImpl<EmailMapper, Email> implements EmailS
|
|
|
Message[] messages1 = folder.search(ft);
|
|
|
|
|
|
for (Message message : messages1) {
|
|
|
- //未读
|
|
|
- Multipart m = (Multipart) message.getContent();
|
|
|
- for (int s = 0; s < m.getCount(); s++) {
|
|
|
- BodyPart mimeMultipart = m.getBodyPart(s);
|
|
|
- log.info(mimeMultipart.getFileName());
|
|
|
- }
|
|
|
- //解析邮件
|
|
|
- parseMessage(message);
|
|
|
+ //未读
|
|
|
+ Multipart m = (Multipart) message.getContent();
|
|
|
+ for (int s = 0; s < m.getCount(); s++) {
|
|
|
+ BodyPart mimeMultipart = m.getBodyPart(s);
|
|
|
+ log.info(mimeMultipart.getFileName());
|
|
|
+ }
|
|
|
+ //解析邮件
|
|
|
+ parseMessage(message);
|
|
|
}
|
|
|
|
|
|
//得到收件箱中的所有邮件并且删除邮件
|
|
@@ -363,9 +365,9 @@ public class EmailImpl extends ServiceImpl<EmailMapper, Email> implements EmailS
|
|
|
//如果是文本类型的附件,通过getContent方法可以取到文本内容,但这不是我们需要的结果,所以在这里要做判断
|
|
|
boolean isContainTextAttach = part.getContentType().indexOf("name") > 0;
|
|
|
if (part.isMimeType("text/*") && !isContainTextAttach) {
|
|
|
- try{
|
|
|
+ try {
|
|
|
content.append(part.getContent().toString());
|
|
|
- }catch(UnsupportedEncodingException e) {
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
InputStream is = part.getInputStream();
|
|
|
content.append(inputStream2String(is));
|
|
|
}
|
|
@@ -382,11 +384,11 @@ public class EmailImpl extends ServiceImpl<EmailMapper, Email> implements EmailS
|
|
|
}
|
|
|
|
|
|
//处理编码错误问题
|
|
|
- public static String inputStream2String(InputStream in)throws IOException {
|
|
|
+ public static String inputStream2String(InputStream in) throws IOException {
|
|
|
StringBuffer out = new StringBuffer();
|
|
|
byte[] b = new byte[4096];
|
|
|
- for(int n; (n=in.read(b))!=-1;){
|
|
|
- out.append(new String(b,0,n));
|
|
|
+ for (int n; (n = in.read(b)) != -1; ) {
|
|
|
+ out.append(new String(b, 0, n));
|
|
|
}
|
|
|
return out.toString();
|
|
|
|
|
@@ -484,14 +486,14 @@ public class EmailImpl extends ServiceImpl<EmailMapper, Email> implements EmailS
|
|
|
//根据编号过滤
|
|
|
List<WindTowerInfo> windTowerInfoList = windTowerInfoService.getByEquipmentNo(id);
|
|
|
//没有这个编号的塔
|
|
|
- windTowerInfoType(id,windTowerInfoList);
|
|
|
+ windTowerInfoType(id, windTowerInfoList);
|
|
|
for (WindTowerInfo w : windTowerInfoList) {
|
|
|
if (id.equals(w.getEquipmentNo())) {
|
|
|
if (w.getPassword().equals("")) {
|
|
|
log.error("该测风塔没有配置密码");
|
|
|
} else {
|
|
|
String password = w.getPassword();
|
|
|
- String cmd = "\"D:\\NRG\\SymDR\\SDR.exe\"" + " /z " + password + " " + f.getPath();
|
|
|
+ String cmd = "\"C:\\NRG\\SymDR\\SDR.exe\"" + " /z " + password + " " + f.getPath();
|
|
|
Process ipconfig = runtime.exec(cmd);
|
|
|
ipconfig.waitFor();
|
|
|
InputStream inputStream = ipconfig.getInputStream();
|
|
@@ -519,12 +521,12 @@ public class EmailImpl extends ServiceImpl<EmailMapper, Email> implements EmailS
|
|
|
this.tranFile();
|
|
|
//把txt文件转成excel文件并解析
|
|
|
analysisDataService.analysisData(type);
|
|
|
- } else if(type.equals("rld")){
|
|
|
+ } else if (type.equals("rld")) {
|
|
|
//rld文件类型
|
|
|
String[] id = f.getName().split("_");
|
|
|
//根据编号过滤
|
|
|
List<WindTowerInfo> windTowerInfoList = windTowerInfoService.getByEquipmentNo(id[0]);
|
|
|
- windTowerInfoType(id[0],windTowerInfoList);
|
|
|
+ windTowerInfoType(id[0], windTowerInfoList);
|
|
|
//如果有 有可能会有编号相同 但是记录仪编号不同的情况 不解析看不到记录仪编号 所以只能用相同编号的测风塔密码解析
|
|
|
//如果是从邮件里读到的塔新增的话是没有数据密码的 所以需要人为的手动配置密码
|
|
|
for (WindTowerInfo w : windTowerInfoList) {
|
|
@@ -533,7 +535,7 @@ public class EmailImpl extends ServiceImpl<EmailMapper, Email> implements EmailS
|
|
|
log.error(w.getEquipmentNo() + "测风塔没有配置数据密码");
|
|
|
} else {
|
|
|
String[] s = new String[]{
|
|
|
- "\"D:\\Program Files (x86)\\Renewable NRG Systems\\SymPRO Desktop\\SymPRODesktop.exe\"",
|
|
|
+ "\"C:\\Program Files (x86)\\Renewable NRG Systems\\SymPRO Desktop\\SymPRODesktop.exe\"",
|
|
|
"/cmd", "convert", "/file", f.getPath(),
|
|
|
"/pass", w.getPassword(), "/type", "\"meas\"", "/outputdir", "\"D:\\out\\new\""
|
|
|
};
|
|
@@ -553,20 +555,20 @@ public class EmailImpl extends ServiceImpl<EmailMapper, Email> implements EmailS
|
|
|
this.tranFile();
|
|
|
//把txt文件转成excel文件并解析
|
|
|
analysisDataService.analysisData(type);
|
|
|
- }else if(type.equals("csv")){
|
|
|
- if(!subjectId.contains("[") || !subjectId.contains("]")){
|
|
|
+ } else if (type.equals("csv")) {
|
|
|
+ if (!subjectId.contains("[") || !subjectId.contains("]")) {
|
|
|
cn.hutool.core.io.FileUtil.del(f);
|
|
|
continue;
|
|
|
}
|
|
|
String id = subjectId.substring(subjectId.indexOf("[") + 1, subjectId.lastIndexOf("]"));
|
|
|
List<WindTowerInfo> equipmentNo = windTowerInfoService.getByEquipmentNo(id);
|
|
|
- if(equipmentNo.size() == 0){
|
|
|
- windTowerInfoType(id,equipmentNo);
|
|
|
- }else {
|
|
|
- analysisDataService.acousticRadar(f,id);
|
|
|
+ if (equipmentNo.size() == 0) {
|
|
|
+ windTowerInfoType(id, equipmentNo);
|
|
|
+ } else {
|
|
|
+ analysisDataService.acousticRadar(f, id);
|
|
|
}
|
|
|
|
|
|
- }else if(type.equals("dat")){
|
|
|
+ } else if (type.equals("dat")) {
|
|
|
analysisDataService.parseByDat(f);
|
|
|
|
|
|
}
|
|
@@ -613,5 +615,4 @@ public class EmailImpl extends ServiceImpl<EmailMapper, Email> implements EmailS
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|