EmailImpl.java 25 KB

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