EmailImpl.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. package com.jiayue.biz.service.impl;
  2. import java.io.*;
  3. import java.security.Security;
  4. import java.text.SimpleDateFormat;
  5. import java.util.*;
  6. import java.util.stream.Collectors;
  7. import javax.mail.*;
  8. import javax.mail.internet.InternetAddress;
  9. import javax.mail.internet.MimeMessage;
  10. import javax.mail.internet.MimeMultipart;
  11. import javax.mail.internet.MimeUtility;
  12. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  13. import com.jiayue.biz.domain.Email;
  14. import com.jiayue.biz.domain.EmailWindTowerInfo;
  15. import com.jiayue.biz.domain.WindTowerInfo;
  16. import com.jiayue.biz.mapper.EmailMapper;
  17. import com.jiayue.biz.service.EmailService;
  18. import com.jiayue.biz.service.EmailWindTowerInfoService;
  19. import com.jiayue.biz.util.FileUtil;
  20. import com.sun.mail.imap.IMAPFolder;
  21. import com.sun.mail.imap.IMAPStore;
  22. import lombok.extern.slf4j.Slf4j;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.beans.factory.annotation.Value;
  25. import org.springframework.stereotype.Service;
  26. /**
  27. * 使用imap协议获取未读邮件数
  28. *
  29. * @author w
  30. */
  31. @Slf4j
  32. @Service
  33. public class EmailImpl extends ServiceImpl<EmailMapper, Email> implements EmailService {
  34. @Value("${email.user}")
  35. private String user;
  36. @Value("${email.password}")
  37. private String password;
  38. @Value("${email.host}")
  39. private String host;
  40. @Value("${email.path}")
  41. private String path;
  42. @Value("${file.outPutDir}")
  43. private String outPutDir;
  44. @Autowired
  45. EmailService emailService;
  46. private final WindTowerInfoServiceImpl windTowerInfoService;
  47. private final EmailWindTowerInfoService emailWindTowerInfoService;
  48. private final AnalysisDataImpl analysisDataService;
  49. public EmailImpl(WindTowerInfoServiceImpl windTowerInfoService, EmailWindTowerInfoService emailWindTowerInfoService, AnalysisDataImpl analysisDataService) {
  50. this.windTowerInfoService = windTowerInfoService;
  51. this.emailWindTowerInfoService = emailWindTowerInfoService;
  52. this.analysisDataService = analysisDataService;
  53. }
  54. /**
  55. * 获取所有邮件账号信息
  56. *
  57. * @return
  58. */
  59. public List<Email> selectEmail() {
  60. return emailService.list();
  61. }
  62. public void readMail() {
  63. List<Email> emails = this.selectEmail();
  64. for (Email email : emails) {
  65. user = email.getUserName();
  66. password = email.getPassword();
  67. host = email.getHost();
  68. path = email.getPath();
  69. Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
  70. Properties prop = System.getProperties();
  71. prop.put("mail.imap.port", "993");
  72. prop.put("mail.imap.ssl.enable", true);
  73. //如果设置,并且未指定套接字工厂,则启用MailSSLSocketFactory的使用。 如果设置为“ *”,则所有主机都是受信任的。
  74. //如果设置为以空格分隔的主机列表,则这些主机是可信任的。 否则,信任取决于服务器提供的证书。(设置主机可信任)
  75. prop.put("mail.imap.ssl.trust", host);
  76. //这部分就是解决异常的关键所在,设置IAMP ID信息
  77. HashMap IAM = new HashMap();
  78. //带上IMAP ID信息,由key和value组成,例如name,version,vendor,support-email等。
  79. // 这个value的值随便写就行
  80. IAM.put("name", "myname");
  81. IAM.put("version", "1.0.0");
  82. IAM.put("vendor", "myclient");
  83. IAM.put("support-email", "testmail@test.com");
  84. try {
  85. Session session = Session.getDefaultInstance(prop, null);
  86. session.setDebug(false);
  87. IMAPStore store = (IMAPStore) session.getStore("imap"); // 使用imap会话机制,连接服务器
  88. store.connect(host, user, password);
  89. store.id(IAM);
  90. IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX"); // 收件箱
  91. /* Folder.READ_ONLY:只读权限
  92. * Folder.READ_WRITE:可读可写(可以修改邮件的状态)
  93. */
  94. folder.open(Folder.READ_WRITE); //打开收件箱
  95. // 获得收件箱中的未读邮件数
  96. log.warn("未读邮件数: {}", folder.getUnreadMessageCount());
  97. log.warn("总邮件个数: {}", folder.getMessageCount());
  98. Message[] messages1 = folder.getMessages();
  99. for (Message message : messages1) {
  100. //存在附件返回true 不存在返回false
  101. Flags flags = message.getFlags();
  102. if (flags.contains(Flags.Flag.SEEN)) {
  103. } else {
  104. //未读
  105. Multipart m = (Multipart) message.getContent();
  106. for (int s = 0; s < m.getCount(); s++) {
  107. BodyPart mimeMultipart = m.getBodyPart(s);
  108. log.info(mimeMultipart.getFileName());
  109. }
  110. //解析邮件
  111. parseMessage(message);
  112. }
  113. }
  114. //得到收件箱中的所有邮件并且删除邮件
  115. //deleteMessage(messages);
  116. //释放资源
  117. folder.close(true);
  118. store.close();
  119. } catch (Exception e) {
  120. log.error("读取邮件异常" + e);
  121. }
  122. }
  123. }
  124. public void parseMessage(Message... messages) throws MessagingException, IOException, InterruptedException {
  125. if (messages == null || messages.length < 1)
  126. throw new MessagingException("未找到要解析的邮件!");
  127. String subject = "";
  128. // 解析所有邮件
  129. for (int i = 0, count = messages.length; i < count; i++) {
  130. MimeMessage msg = (MimeMessage) messages[i];
  131. log.info("------------------解析第" + msg.getMessageNumber() + "封邮件-------------------- ");
  132. //获取邮件主题
  133. subject = getSubject(msg);
  134. boolean isContainerAttachment = isContainAttachment(msg);
  135. File file = new File(path);
  136. if (!file.exists()) {
  137. file.mkdirs();
  138. }
  139. if (isContainerAttachment) {
  140. saveAttachment(msg, path); //保存附件
  141. }
  142. StringBuffer content = new StringBuffer(30);
  143. //解析邮件正文
  144. getMailTextContent(msg, content);
  145. //邮件设置为已读
  146. isTrue(msg);
  147. log.info("------------------第" + msg.getMessageNumber() + "封邮件解析结束-------------------- ");
  148. }
  149. //执行系统命令转为txt文件sdf.parse("20220428")
  150. systemCommand(subject);
  151. }
  152. /**
  153. * 获得邮件主题
  154. *
  155. * @param msg 邮件内容
  156. * @return 解码后的邮件主题
  157. */
  158. public String getSubject(MimeMessage msg) throws UnsupportedEncodingException, MessagingException {
  159. return MimeUtility.decodeText(msg.getSubject());
  160. }
  161. /**
  162. * 获得邮件发件人
  163. *
  164. * @param msg 邮件内容
  165. * @return 姓名 <Email地址>
  166. * @throws MessagingException
  167. * @throws UnsupportedEncodingException
  168. */
  169. public String getFrom(MimeMessage msg) throws MessagingException, UnsupportedEncodingException {
  170. String from = "";
  171. Address[] froms = msg.getFrom();
  172. if (froms.length < 1)
  173. throw new MessagingException("没有发件人!");
  174. InternetAddress address = (InternetAddress) froms[0];
  175. String person = address.getPersonal();
  176. if (person != null) {
  177. person = MimeUtility.decodeText(person) + " ";
  178. } else {
  179. person = "";
  180. }
  181. from = person + "<" + address.getAddress() + ">";
  182. return from;
  183. }
  184. /**
  185. * 根据收件人类型,获取邮件收件人、抄送和密送地址。如果收件人类型为空,则获得所有的收件人
  186. * <p>Message.RecipientType.TO 收件人</p>
  187. * <p>Message.RecipientType.CC 抄送</p>
  188. * <p>Message.RecipientType.BCC 密送</p>
  189. *
  190. * @param msg 邮件内容
  191. * @param type 收件人类型
  192. * @return 收件人1 <邮件地址1>, 收件人2 <邮件地址2>, ...
  193. * @throws MessagingException
  194. */
  195. public String getReceiveAddress(MimeMessage msg, Message.RecipientType type) throws MessagingException {
  196. StringBuffer receiveAddress = new StringBuffer();
  197. Address[] addresss = null;
  198. if (type == null) {
  199. addresss = msg.getAllRecipients();
  200. } else {
  201. addresss = msg.getRecipients(type);
  202. }
  203. if (addresss == null || addresss.length < 1)
  204. throw new MessagingException("没有收件人!");
  205. for (Address address : addresss) {
  206. InternetAddress internetAddress = (InternetAddress) address;
  207. receiveAddress.append(internetAddress.toUnicodeString()).append(",");
  208. }
  209. receiveAddress.deleteCharAt(receiveAddress.length() - 1); //删除最后一个逗号
  210. return receiveAddress.toString();
  211. }
  212. /**
  213. * 获得邮件发送时间
  214. *
  215. * @param msg 邮件内容
  216. * @return yyyy年mm月dd日 星期X HH:mm
  217. * @throws MessagingException
  218. */
  219. public String getSentDate(MimeMessage msg, String pattern) throws MessagingException {
  220. Date receivedDate = msg.getSentDate();
  221. if (receivedDate == null) {
  222. return "";
  223. }
  224. if (pattern == null || "".equals(pattern)) {
  225. pattern = "yyyy年MM月dd日 E HH:mm ";
  226. }
  227. return new SimpleDateFormat(pattern).format(receivedDate);
  228. }
  229. /**
  230. * 判断邮件中是否包含附件
  231. *
  232. * @param part 邮件内容
  233. * @return 邮件中存在附件返回true,不存在返回false
  234. * @throws MessagingException
  235. * @throws IOException
  236. */
  237. public boolean isContainAttachment(Part part) throws MessagingException, IOException {
  238. boolean flag = false;
  239. if (part.isMimeType("multipart/*")) {
  240. MimeMultipart multipart = (MimeMultipart) part.getContent();
  241. int partCount = multipart.getCount();
  242. for (int i = 0; i < partCount; i++) {
  243. BodyPart bodyPart = multipart.getBodyPart(i);
  244. String disp = bodyPart.getDisposition();
  245. if (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE))) {
  246. flag = true;
  247. } else if (bodyPart.isMimeType("multipart/*")) {
  248. flag = isContainAttachment(bodyPart);
  249. } else {
  250. String contentType = bodyPart.getContentType();
  251. if (contentType.indexOf("application") != -1) {
  252. flag = true;
  253. }
  254. if (contentType.indexOf("name") != -1) {
  255. flag = true;
  256. }
  257. }
  258. if (flag) break;
  259. }
  260. } else if (part.isMimeType("message/rfc822")) {
  261. flag = isContainAttachment((Part) part.getContent());
  262. }
  263. return flag;
  264. }
  265. /**
  266. * 判断邮件是否已读 imap有效 pop3无效
  267. *
  268. * @param msg 邮件内容
  269. * @return 如果邮件已读返回true, 否则返回false
  270. * @throws MessagingException
  271. */
  272. public boolean isSeen(MimeMessage msg) throws MessagingException {
  273. return msg.getFlags().contains(Flags.Flag.SEEN);
  274. }
  275. /**
  276. * 设置邮件为已读
  277. *
  278. * @param msg 邮件内容
  279. * @throws MessagingException
  280. */
  281. public void isTrue(MimeMessage msg) throws MessagingException {
  282. msg.setFlag(Flags.Flag.SEEN, true);
  283. }
  284. /**
  285. * 判断邮件是否需要阅读回执
  286. *
  287. * @param msg 邮件内容
  288. * @return 需要回执返回true, 否则返回false
  289. * @throws MessagingException
  290. */
  291. public boolean isReplySign(MimeMessage msg) throws MessagingException {
  292. boolean replySign = false;
  293. String[] headers = msg.getHeader("Disposition-Notification-To");
  294. if (headers != null)
  295. replySign = true;
  296. return replySign;
  297. }
  298. /**
  299. * 获得邮件的优先级
  300. *
  301. * @param msg 邮件内容
  302. * @return 1(High):紧急 3:普通(Normal) 5:低(Low)
  303. * @throws MessagingException
  304. */
  305. public String getPriority(MimeMessage msg) throws MessagingException {
  306. String priority = "普通";
  307. String[] headers = msg.getHeader("X-Priority");
  308. if (headers != null) {
  309. String headerPriority = headers[0];
  310. if (headerPriority.indexOf("1") != -1 || headerPriority.indexOf("High") != -1)
  311. priority = "紧急";
  312. else if (headerPriority.indexOf("5") != -1 || headerPriority.indexOf("Low") != -1)
  313. priority = "低";
  314. else
  315. priority = "普通";
  316. }
  317. return priority;
  318. }
  319. /**
  320. * 获得邮件文本内容
  321. *
  322. * @param part 邮件体
  323. * @param content 存储邮件文本内容的字符串
  324. * @throws MessagingException
  325. * @throws IOException
  326. */
  327. public void getMailTextContent(Part part, StringBuffer content) throws MessagingException, IOException {
  328. //如果是文本类型的附件,通过getContent方法可以取到文本内容,但这不是我们需要的结果,所以在这里要做判断
  329. boolean isContainTextAttach = part.getContentType().indexOf("name") > 0;
  330. if (part.isMimeType("text/*") && !isContainTextAttach) {
  331. try{
  332. content.append(part.getContent().toString());
  333. }catch(UnsupportedEncodingException e) {
  334. InputStream is = part.getInputStream();
  335. content.append(inputStream2String(is));
  336. }
  337. } else if (part.isMimeType("message/rfc822")) {
  338. getMailTextContent((Part) part.getContent(), content);
  339. } else if (part.isMimeType("multipart/*")) {
  340. Multipart multipart = (Multipart) part.getContent();
  341. int partCount = multipart.getCount();
  342. for (int i = 0; i < partCount; i++) {
  343. BodyPart bodyPart = multipart.getBodyPart(i);
  344. getMailTextContent(bodyPart, content);
  345. }
  346. }
  347. }
  348. //处理编码错误问题
  349. public static String inputStream2String(InputStream in)throws IOException {
  350. StringBuffer out = new StringBuffer();
  351. byte[] b = new byte[4096];
  352. for(int n; (n=in.read(b))!=-1;){
  353. out.append(new String(b,0,n));
  354. }
  355. return out.toString();
  356. }
  357. /**
  358. * 保存附件
  359. *
  360. * @param part 邮件中多个组合体中的其中一个组合体
  361. * @param destDir 附件保存目录
  362. * @throws UnsupportedEncodingException
  363. * @throws MessagingException
  364. * @throws FileNotFoundException
  365. * @throws IOException
  366. */
  367. public void saveAttachment(Part part, String destDir) throws MessagingException, IOException {
  368. if (part.isMimeType("multipart/*")) {
  369. Multipart multipart = (Multipart) part.getContent(); //复杂体邮件
  370. //复杂体邮件包含多个邮件体
  371. int partCount = multipart.getCount();
  372. for (int i = 0; i < partCount; i++) {
  373. //获得复杂体邮件中其中一个邮件体
  374. BodyPart bodyPart = multipart.getBodyPart(i);
  375. //某一个邮件体也有可能是由多个邮件体组成的复杂体
  376. String disp = bodyPart.getDisposition();
  377. if (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE))) {
  378. InputStream is = bodyPart.getInputStream();
  379. saveFile(is, destDir, decodeText(bodyPart.getFileName()));
  380. } else if (bodyPart.isMimeType("multipart/*")) {
  381. saveAttachment(bodyPart, destDir);
  382. } else {
  383. String contentType = bodyPart.getContentType();
  384. if (contentType.indexOf("name") != -1 || contentType.indexOf("application") != -1) {
  385. saveFile(bodyPart.getInputStream(), destDir, decodeText(bodyPart.getFileName()));
  386. }
  387. }
  388. }
  389. } else if (part.isMimeType("message/rfc822")) {
  390. saveAttachment((Part) part.getContent(), destDir);
  391. }
  392. }
  393. /**
  394. * 读取输入流中的数据保存至指定目录
  395. *
  396. * @param is 输入流
  397. * @param fileName 文件名
  398. * @param destDir 文件存储目录
  399. * @throws FileNotFoundException
  400. * @throws IOException
  401. */
  402. private void saveFile(InputStream is, String destDir, String fileName) throws FileNotFoundException, IOException {
  403. BufferedInputStream bis = new BufferedInputStream(is);
  404. BufferedOutputStream bos = new BufferedOutputStream(
  405. new FileOutputStream(new File(destDir + fileName)));
  406. int len = -1;
  407. while ((len = bis.read()) != -1) {
  408. bos.write(len);
  409. bos.flush();
  410. }
  411. bos.close();
  412. bis.close();
  413. }
  414. /**
  415. * 文本解码
  416. *
  417. * @param encodeText 解码MimeUtility.encodeText(String text)方法编码后的文本
  418. * @return 解码后的文本
  419. * @throws UnsupportedEncodingException
  420. */
  421. public String decodeText(String encodeText) throws UnsupportedEncodingException {
  422. if (encodeText == null || "".equals(encodeText)) {
  423. return "";
  424. } else {
  425. return MimeUtility.decodeText(encodeText);
  426. }
  427. }
  428. /**
  429. * 执行命令通过软件解压rld文件到D:\out\new\下
  430. */
  431. public void systemCommand(String subjectId) {
  432. try {
  433. Runtime runtime = Runtime.getRuntime();
  434. File file = new File("D:\\in\\");
  435. //遍历所有文件
  436. File[] files = file.listFiles();
  437. for (File f : files) {
  438. String type = f.getName().substring(f.getName().lastIndexOf(".") + 1);
  439. if (type.equals("RWD")) {
  440. //RWD文件类型
  441. String id = f.getName().substring(0, 4);
  442. //根据编号过滤
  443. List<WindTowerInfo> windTowerInfoList = windTowerInfoService.getByEquipmentNo(id);
  444. //没有这个编号的塔
  445. windTowerInfoType(id,windTowerInfoList);
  446. for (WindTowerInfo w : windTowerInfoList) {
  447. if (id.equals(w.getEquipmentNo())) {
  448. if (w.getPassword().equals("")) {
  449. log.error("该测风塔没有配置密码");
  450. } else {
  451. String password = w.getPassword();
  452. String cmd = "\"D:\\NRG\\SymDR\\SDR.exe\"" + " /z " + password + " " + f.getPath();
  453. Process ipconfig = runtime.exec(cmd);
  454. ipconfig.waitFor();
  455. InputStream inputStream = ipconfig.getInputStream();
  456. byte[] bytes = new byte[1024];
  457. int len = 0;
  458. while ((len = inputStream.read(bytes)) != -1) {
  459. log.info(new String(bytes, 0, len, "GBK"));
  460. }
  461. }
  462. }
  463. }
  464. //转换成txt的文件在D:\NRG\ScaledData\目录下 移动到 D:\out\下 转换文件后会有两个文件一个txt 一个log 删除log 移动txt
  465. File file1 = new File("D:\\NRG\\ScaledData\\");
  466. File[] files1 = file1.listFiles();
  467. for (File e : files1) {
  468. String[] name = e.getName().split("\\.");
  469. if (name[1].equals("txt")) {
  470. FileUtil.move(e.getPath(), "D:\\out\\new\\");
  471. } else {
  472. e.delete();
  473. }
  474. }
  475. //转成txt后把文件移动到系统文件备份目录下
  476. //xls移动系统文件目录下
  477. this.tranFile();
  478. //把txt文件转成excel文件并解析
  479. analysisDataService.analysisData(type);
  480. } else if(type.equals("rld")){
  481. //rld文件类型
  482. String[] id = f.getName().split("_");
  483. //根据编号过滤
  484. List<WindTowerInfo> windTowerInfoList = windTowerInfoService.getByEquipmentNo(id[0]);
  485. windTowerInfoType(id[0],windTowerInfoList);
  486. //如果有 有可能会有编号相同 但是记录仪编号不同的情况 不解析看不到记录仪编号 所以只能用相同编号的测风塔密码解析
  487. //如果是从邮件里读到的塔新增的话是没有数据密码的 所以需要人为的手动配置密码
  488. for (WindTowerInfo w : windTowerInfoList) {
  489. if (id[0].equals(w.getEquipmentNo())) {
  490. if ("".equals(w.getPassword())) {
  491. log.error(w.getEquipmentNo() + "测风塔没有配置数据密码");
  492. } else {
  493. String[] s = new String[]{
  494. "\"D:\\Program Files (x86)\\Renewable NRG Systems\\SymPRO Desktop\\SymPRODesktop.exe\"",
  495. "/cmd", "convert", "/file", f.getPath(),
  496. "/pass", w.getPassword(), "/type", "\"meas\"", "/outputdir", "\"D:\\out\\new\""
  497. };
  498. Process ipconfig = runtime.exec(s);
  499. ipconfig.waitFor();
  500. InputStream inputStream = ipconfig.getInputStream();
  501. byte[] bytes = new byte[1024];
  502. int len = 0;
  503. while ((len = inputStream.read(bytes)) != -1) {
  504. log.info(new String(bytes, 0, len, "GBK"));
  505. }
  506. }
  507. }
  508. }
  509. //转成txt后把文件移动到系统文件备份目录下
  510. //xls移动系统文件目录下
  511. this.tranFile();
  512. //把txt文件转成excel文件并解析
  513. analysisDataService.analysisData(type);
  514. }else if(type.equals("csv")){
  515. if(!subjectId.contains("[") || !subjectId.contains("]")){
  516. cn.hutool.core.io.FileUtil.del(f);
  517. continue;
  518. }
  519. String id = subjectId.substring(subjectId.indexOf("[") + 1, subjectId.lastIndexOf("]"));
  520. List<WindTowerInfo> equipmentNo = windTowerInfoService.getByEquipmentNo(id);
  521. if(equipmentNo.size() == 0){
  522. windTowerInfoType(id,equipmentNo);
  523. }else {
  524. analysisDataService.acousticRadar(f,id);
  525. }
  526. }else if(type.equals("dat")){
  527. analysisDataService.parseByDat(f);
  528. }
  529. }
  530. } catch (Exception e) {
  531. log.error("执行系统命令失败:" + e);
  532. }
  533. }
  534. //检测是否存在
  535. public void windTowerInfoType(String id, List<WindTowerInfo> windTowerInfoList) {
  536. //没有这个编号的塔
  537. if (windTowerInfoList.size() == 0) {
  538. List<EmailWindTowerInfo> emailWindTowerInfos = emailWindTowerInfoService.list().stream().filter(wind -> wind.getEquipmentNo().equals(id)).collect(Collectors.toList());
  539. if (emailWindTowerInfos.size() == 0) {
  540. //如果测风塔里面没有这个塔并且邮件测风塔里也没有这个塔 则添加到邮箱读取的测风塔表中
  541. EmailWindTowerInfo emailWindTowerInfo = new EmailWindTowerInfo();
  542. emailWindTowerInfo.setEquipmentNo(id);
  543. emailWindTowerInfoService.save(emailWindTowerInfo);
  544. log.info(id + " 测风塔信息里没有这个的塔 并且邮件测风塔里也没有这个塔");
  545. } else {
  546. log.info(id + " 测风塔信息里没有这个的塔 邮件测风塔里已存在这个塔");
  547. }
  548. }
  549. }
  550. //转移文件
  551. public void tranFile() throws Exception {
  552. //转成txt后把文件移动到系统文件备份目录下
  553. File file1 = new File("D:\\in\\");
  554. File[] files1 = file1.listFiles();
  555. //xls移动系统文件目录下
  556. for (File e : files1) {
  557. String[] str = e.getName().split("\\.");
  558. if (str[1].equals("RWD")) {
  559. FileUtil.move(e.getPath(), FileUtil.getSystemFilePath() + File.separator + str[0].substring(0, 4));
  560. } else {
  561. String[] strs = str[0].split("_");
  562. FileUtil.move(e.getPath(), FileUtil.getSystemFilePath() + File.separator + strs[0]);
  563. }
  564. }
  565. }
  566. }