|
@@ -103,7 +103,8 @@ public class EmailImpl extends ServiceImpl<EmailMapper, Email> implements EmailS
|
|
|
store.connect(host, user, password);
|
|
|
store.id(IAM);
|
|
|
IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX"); // 收件箱
|
|
|
- /* Folder.READ_ONLY:只读权限
|
|
|
+ /*
|
|
|
+ * Folder.READ_ONLY:只读权限
|
|
|
* Folder.READ_WRITE:可读可写(可以修改邮件的状态)
|
|
|
*/
|
|
|
folder.open(Folder.READ_WRITE); //打开收件箱
|
|
@@ -122,21 +123,18 @@ public class EmailImpl extends ServiceImpl<EmailMapper, Email> implements EmailS
|
|
|
messages1 = folder.search(ft);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
for (Message message : messages1) {
|
|
|
//存在附件返回true 不存在返回false
|
|
|
- Flags flags = message.getFlags();
|
|
|
- if (flags.contains(Flags.Flag.SEEN)) {
|
|
|
- } else {
|
|
|
- //未读
|
|
|
- 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);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//释放资源
|
|
@@ -467,32 +465,47 @@ public class EmailImpl extends ServiceImpl<EmailMapper, Email> implements EmailS
|
|
|
File file = new File("D:\\in\\");
|
|
|
//遍历所有文件
|
|
|
File[] files = file.listFiles();
|
|
|
+ if (null == files || files.length == 0) {
|
|
|
+ log.warn("路径:{} 下为空,没有要解析的文件");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, WindTowerInfo> windTowerInfoMap = windTowerInfoService.list().stream().collect(Collectors.toMap(x -> x.getEquipmentNo() + "", x -> x, (x1, x2) -> x1));
|
|
|
+ Map<String, EmailWindTowerInfo> emailWindTowerInfoMap = emailWindTowerInfoService.list().stream().collect(Collectors.toMap(x -> x.getEquipmentNo() + "", x -> x, (x1, x2) -> x1));
|
|
|
for (File f : files) {
|
|
|
- String[] fileType = f.getName().split("\\.");
|
|
|
- if (fileType[1].equals("RWD")) {
|
|
|
- //RWD文件类型
|
|
|
- String id = f.getName().substring(0, 4);
|
|
|
- //根据编号过滤
|
|
|
- List<WindTowerInfo> windTowerInfoList = windTowerInfoService.list().stream().filter(wind -> wind.getEquipmentNo().equals(id)).collect(Collectors.toList());
|
|
|
+ try {
|
|
|
+ //文件类型,做解析区分使用
|
|
|
+ String fileTypeStr = "";
|
|
|
+
|
|
|
+ String fileEquipmentNo = "";
|
|
|
+ String fileType = f.getName().split("\\.")[1];
|
|
|
+ if (fileType.equals("RWD")) {
|
|
|
+ //RWD文件类型
|
|
|
+ fileEquipmentNo = f.getName().substring(0, 4);
|
|
|
+ } else {
|
|
|
+ //rld文件类型
|
|
|
+ fileEquipmentNo = f.getName().split("_")[0];
|
|
|
+ }
|
|
|
+ WindTowerInfo windTowerInfo = windTowerInfoMap.get(fileEquipmentNo);
|
|
|
//没有这个编号的塔
|
|
|
- if (windTowerInfoList.size() == 0) {
|
|
|
- List<EmailWindTowerInfo> emailWindTowerInfos = emailWindTowerInfoService.list().stream().filter(wind -> wind.getEquipmentNo().equals(id)).collect(Collectors.toList());
|
|
|
- if (emailWindTowerInfos.size() == 0) {
|
|
|
+ if (null == windTowerInfo) {
|
|
|
+ EmailWindTowerInfo emailWindTowerInfo = emailWindTowerInfoMap.get(fileEquipmentNo);
|
|
|
+ if (null == emailWindTowerInfo) {
|
|
|
//如果测风塔里面没有这个塔并且邮件测风塔里也没有这个塔 则添加到邮箱读取的测风塔表中
|
|
|
- EmailWindTowerInfo emailWindTowerInfo = new EmailWindTowerInfo();
|
|
|
- emailWindTowerInfo.setEquipmentNo(id);
|
|
|
- emailWindTowerInfoService.save(emailWindTowerInfo);
|
|
|
- log.info(id + " 测风塔信息里没有这个的塔 并且邮件测风塔里也没有这个塔");
|
|
|
+ EmailWindTowerInfo emailWindTowerInfoNew = new EmailWindTowerInfo();
|
|
|
+ emailWindTowerInfoNew.setEquipmentNo(fileEquipmentNo);
|
|
|
+ emailWindTowerInfoService.save(emailWindTowerInfoNew);
|
|
|
+ log.info(fileEquipmentNo + " 测风塔信息里没有这个的塔 并且邮件测风塔里也没有这个塔");
|
|
|
} else {
|
|
|
- log.info(id + " 测风塔信息里没有这个的塔 邮件测风塔里已存在这个塔");
|
|
|
+ log.info(fileEquipmentNo + " 测风塔信息里没有这个的塔 邮件测风塔里已存在这个塔");
|
|
|
}
|
|
|
- }
|
|
|
- for (WindTowerInfo w : windTowerInfoList) {
|
|
|
- if (id.equals(w.getEquipmentNo())) {
|
|
|
- if (w.getPassword().equals("")) {
|
|
|
+ } else {
|
|
|
+ if (fileType.equals("RWD")) {
|
|
|
+ //RWD文件类型
|
|
|
+ if (windTowerInfo.getPassword().equals("")) {
|
|
|
log.error("该测风塔没有配置密码");
|
|
|
+ return;
|
|
|
} else {
|
|
|
- String password = w.getPassword();
|
|
|
+ String password = windTowerInfo.getPassword();
|
|
|
String cmd = "\"D:\\NRG\\SymDR\\SDR.exe\"" + " /z " + password + " " + f.getPath();
|
|
|
Process ipconfig = runtime.exec(cmd);
|
|
|
ipconfig.waitFor();
|
|
@@ -500,67 +513,46 @@ public class EmailImpl extends ServiceImpl<EmailMapper, Email> implements EmailS
|
|
|
byte[] bytes = new byte[1024];
|
|
|
int len = 0;
|
|
|
while ((len = inputStream.read(bytes)) != -1) {
|
|
|
- log.info(new String(bytes, 0, len, "GBK"));
|
|
|
+ log.info("解析RWD文件完成:{}", new String(bytes, 0, len, "GBK"));
|
|
|
+ }
|
|
|
+
|
|
|
+ //转换成txt的文件在D:\NRG\ScaledData\目录下 移动到 D:\out\下 转换文件后会有两个文件一个txt 一个log 删除log 移动txt
|
|
|
+ File file1 = new File("D:\\NRG\\ScaledData\\");
|
|
|
+ File[] files1 = file1.listFiles();
|
|
|
+ for (File e : files1) {
|
|
|
+ String[] name = e.getName().split("\\.");
|
|
|
+ if (name[1].equals("txt")) {
|
|
|
+ FileUtil.move(e.getPath(), outPutDir);
|
|
|
+ } else {
|
|
|
+ e.delete();
|
|
|
+ }
|
|
|
}
|
|
|
+ //转成txt后把文件移动到系统文件备份目录下
|
|
|
+ File file2 = new File("D:\\in\\");
|
|
|
+ File[] files2 = file2.listFiles();
|
|
|
+ //xls移动系统文件目录下
|
|
|
+ for (File e : files2) {
|
|
|
+ String[] str = e.getName().split("\\.");
|
|
|
+ if (str[1].equals("RWD")) {
|
|
|
+ FileUtil.move(e.getPath(), FileUtil.getSystemFilePath() + File.separator + str[0].substring(0, 4));
|
|
|
+ } else {
|
|
|
+ String[] strs = str[0].split("_");
|
|
|
+ FileUtil.move(e.getPath(), FileUtil.getSystemFilePath() + File.separator + strs[0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //把txt文件转成excel文件并解析
|
|
|
+ fileTypeStr = "RWD";
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- //转换成txt的文件在D:\NRG\ScaledData\目录下 移动到 D:\out\下 转换文件后会有两个文件一个txt 一个log 删除log 移动txt
|
|
|
- File file1 = new File("D:\\NRG\\ScaledData\\");
|
|
|
- File[] files1 = file1.listFiles();
|
|
|
- for (File e : files1) {
|
|
|
- String[] name = e.getName().split("\\.");
|
|
|
- if (name[1].equals("txt")) {
|
|
|
- FileUtil.move(e.getPath(), "D:\\out\\new\\");
|
|
|
} else {
|
|
|
- e.delete();
|
|
|
- }
|
|
|
- }
|
|
|
- //转成txt后把文件移动到系统文件备份目录下
|
|
|
- File file2 = new File("D:\\in\\");
|
|
|
- File[] files2 = file2.listFiles();
|
|
|
- //xls移动系统文件目录下
|
|
|
- for (File e : files2) {
|
|
|
- String[] str = e.getName().split("\\.");
|
|
|
- if (str[1].equals("RWD")) {
|
|
|
- FileUtil.move(e.getPath(), FileUtil.getSystemFilePath() + File.separator + str[0].substring(0, 4));
|
|
|
- } else {
|
|
|
- String[] strs = str[0].split("_");
|
|
|
- FileUtil.move(e.getPath(), FileUtil.getSystemFilePath() + File.separator + strs[0]);
|
|
|
- }
|
|
|
- }
|
|
|
- //把txt文件转成excel文件并解析
|
|
|
- String type = "RWD";
|
|
|
- analysisDataService.analysisData(type);
|
|
|
- } else {
|
|
|
- //rld文件类型
|
|
|
- String[] id = f.getName().split("_");
|
|
|
- //根据编号过滤
|
|
|
- List<WindTowerInfo> windTowerInfoList = windTowerInfoService.list().stream().filter(wind -> wind.getEquipmentNo().equals(id[0])).collect(Collectors.toList());
|
|
|
- //没有这个编号的塔
|
|
|
- if (windTowerInfoList.size() == 0) {
|
|
|
- List<EmailWindTowerInfo> emailWindTowerInfos = emailWindTowerInfoService.list().stream().filter(wind -> wind.getEquipmentNo().equals(id[0])).collect(Collectors.toList());
|
|
|
- if (emailWindTowerInfos.size() == 0) {
|
|
|
- //如果测风塔里面没有这个塔并且邮件测风塔里也没有这个塔 则添加到邮箱读取的测风塔表中
|
|
|
- EmailWindTowerInfo emailWindTowerInfo = new EmailWindTowerInfo();
|
|
|
- emailWindTowerInfo.setEquipmentNo(id[0]);
|
|
|
- emailWindTowerInfoService.save(emailWindTowerInfo);
|
|
|
- log.info(id[0] + " 测风塔信息里没有这个的塔 并且邮件测风塔里也没有这个塔");
|
|
|
- } else {
|
|
|
- log.info(id[0] + " 测风塔信息里没有这个的塔 邮件测风塔里已存在这个塔");
|
|
|
- }
|
|
|
- }
|
|
|
- //如果有 有可能会有编号相同 但是记录仪编号不同的情况 不解析看不到记录仪编号 所以只能用相同编号的测风塔密码解析
|
|
|
- //如果是从邮件里读到的塔新增的话是没有数据密码的 所以需要人为的手动配置密码
|
|
|
- for (WindTowerInfo w : windTowerInfoList) {
|
|
|
- if (id[0].equals(w.getEquipmentNo())) {
|
|
|
- if ("".equals(w.getPassword())) {
|
|
|
- log.error(w.getEquipmentNo() + "测风塔没有配置数据密码");
|
|
|
+ //rld文件类型
|
|
|
+ if ("".equals(windTowerInfo.getPassword())) {
|
|
|
+ log.error(windTowerInfo.getEquipmentNo() + "测风塔没有配置数据密码");
|
|
|
+ return;
|
|
|
} else {
|
|
|
String[] s = new String[]{
|
|
|
- "\"D:\\Program Files (x86)\\Renewable NRG Systems\\SymPRO Desktop\\SymPRODesktop.exe\"",
|
|
|
+ "\"D:\\soft\\SymphoniePRO\\SymPRODesktop.exe\"",
|
|
|
"/cmd", "convert", "/file", f.getPath(),
|
|
|
- "/pass", w.getPassword(), "/type", "\"meas\"", "/outputdir", "\"D:\\out\\new\""
|
|
|
+ "/pass", windTowerInfo.getPassword(), "/type", "\"meas\"", "/outputdir", "\"D:\\out\\new\""
|
|
|
};
|
|
|
Process ipconfig = runtime.exec(s);
|
|
|
ipconfig.waitFor();
|
|
@@ -568,34 +560,37 @@ public class EmailImpl extends ServiceImpl<EmailMapper, Email> implements EmailS
|
|
|
byte[] bytes = new byte[1024];
|
|
|
int len = 0;
|
|
|
while ((len = inputStream.read(bytes)) != -1) {
|
|
|
- log.info(new String(bytes, 0, len, "GBK"));
|
|
|
+ log.info("解析RLD文件完成:{}", new String(bytes, 0, len, "GBK"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //转成txt后把文件移动到系统文件备份目录下
|
|
|
+ File file1 = new File("D:\\in\\");
|
|
|
+ File[] files1 = file1.listFiles();
|
|
|
+ //xls移动系统文件目录下
|
|
|
+ for (File e : files1) {
|
|
|
+ String[] str = e.getName().split("\\.");
|
|
|
+ if (str[1].equals("RWD")) {
|
|
|
+ FileUtil.move(e.getPath(), FileUtil.getSystemFilePath() + File.separator + str[0].substring(0, 4));
|
|
|
+ } else {
|
|
|
+ String[] strs = str[0].split("_");
|
|
|
+ FileUtil.move(e.getPath(), FileUtil.getSystemFilePath() + File.separator + strs[0]);
|
|
|
}
|
|
|
}
|
|
|
+ //把txt文件转成excel文件并解析
|
|
|
+ fileTypeStr = "rld";
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- }
|
|
|
- //转成txt后把文件移动到系统文件备份目录下
|
|
|
- File file1 = new File("D:\\in\\");
|
|
|
- File[] files1 = file1.listFiles();
|
|
|
- //xls移动系统文件目录下
|
|
|
- for (File e : files1) {
|
|
|
- String[] str = e.getName().split("\\.");
|
|
|
- if (str[1].equals("RWD")) {
|
|
|
- FileUtil.move(e.getPath(), FileUtil.getSystemFilePath() + File.separator + str[0].substring(0, 4));
|
|
|
- } else {
|
|
|
- String[] strs = str[0].split("_");
|
|
|
- FileUtil.move(e.getPath(), FileUtil.getSystemFilePath() + File.separator + strs[0]);
|
|
|
}
|
|
|
+ analysisDataService.analysisData(fileTypeStr);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("处理文件:{} 异常:{}", file.getAbsolutePath(), e);
|
|
|
}
|
|
|
- //把txt文件转成excel文件并解析
|
|
|
- String type = "rld";
|
|
|
- analysisDataService.analysisData(type);
|
|
|
}
|
|
|
|
|
|
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("执行系统命令失败:" + e);
|
|
|
+ } catch (
|
|
|
+ Exception e) {
|
|
|
+ log.error("执行系统命令失败:{}", e);
|
|
|
}
|
|
|
}
|
|
|
}
|