EmailImpl.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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. if (pattern == null || "".equals(pattern))
  224. pattern = "yyyy年MM月dd日 E HH:mm ";
  225. return new SimpleDateFormat(pattern).format(receivedDate);
  226. }
  227. /**
  228. * 判断邮件中是否包含附件
  229. *
  230. * @param part 邮件内容
  231. * @return 邮件中存在附件返回true,不存在返回false
  232. * @throws MessagingException
  233. * @throws IOException
  234. */
  235. public boolean isContainAttachment(Part part) throws MessagingException, IOException {
  236. boolean flag = false;
  237. if (part.isMimeType("multipart/*")) {
  238. MimeMultipart multipart = (MimeMultipart) part.getContent();
  239. int partCount = multipart.getCount();
  240. for (int i = 0; i < partCount; i++) {
  241. BodyPart bodyPart = multipart.getBodyPart(i);
  242. String disp = bodyPart.getDisposition();
  243. if (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE))) {
  244. flag = true;
  245. } else if (bodyPart.isMimeType("multipart/*")) {
  246. flag = isContainAttachment(bodyPart);
  247. } else {
  248. String contentType = bodyPart.getContentType();
  249. if (contentType.indexOf("application") != -1) {
  250. flag = true;
  251. }
  252. if (contentType.indexOf("name") != -1) {
  253. flag = true;
  254. }
  255. }
  256. if (flag) break;
  257. }
  258. } else if (part.isMimeType("message/rfc822")) {
  259. flag = isContainAttachment((Part) part.getContent());
  260. }
  261. return flag;
  262. }
  263. /**
  264. * 判断邮件是否已读 imap有效 pop3无效
  265. *
  266. * @param msg 邮件内容
  267. * @return 如果邮件已读返回true, 否则返回false
  268. * @throws MessagingException
  269. */
  270. public boolean isSeen(MimeMessage msg) throws MessagingException {
  271. return msg.getFlags().contains(Flags.Flag.SEEN);
  272. }
  273. /**
  274. * 设置邮件为已读
  275. *
  276. * @param msg 邮件内容
  277. * @throws MessagingException
  278. */
  279. public void isTrue(MimeMessage msg) throws MessagingException {
  280. msg.setFlag(Flags.Flag.SEEN, true);
  281. }
  282. /**
  283. * 判断邮件是否需要阅读回执
  284. *
  285. * @param msg 邮件内容
  286. * @return 需要回执返回true, 否则返回false
  287. * @throws MessagingException
  288. */
  289. public boolean isReplySign(MimeMessage msg) throws MessagingException {
  290. boolean replySign = false;
  291. String[] headers = msg.getHeader("Disposition-Notification-To");
  292. if (headers != null)
  293. replySign = true;
  294. return replySign;
  295. }
  296. /**
  297. * 获得邮件的优先级
  298. *
  299. * @param msg 邮件内容
  300. * @return 1(High):紧急 3:普通(Normal) 5:低(Low)
  301. * @throws MessagingException
  302. */
  303. public String getPriority(MimeMessage msg) throws MessagingException {
  304. String priority = "普通";
  305. String[] headers = msg.getHeader("X-Priority");
  306. if (headers != null) {
  307. String headerPriority = headers[0];
  308. if (headerPriority.indexOf("1") != -1 || headerPriority.indexOf("High") != -1)
  309. priority = "紧急";
  310. else if (headerPriority.indexOf("5") != -1 || headerPriority.indexOf("Low") != -1)
  311. priority = "低";
  312. else
  313. priority = "普通";
  314. }
  315. return priority;
  316. }
  317. /**
  318. * 获得邮件文本内容
  319. *
  320. * @param part 邮件体
  321. * @param content 存储邮件文本内容的字符串
  322. * @throws MessagingException
  323. * @throws IOException
  324. */
  325. public void getMailTextContent(Part part, StringBuffer content) throws MessagingException, IOException {
  326. //如果是文本类型的附件,通过getContent方法可以取到文本内容,但这不是我们需要的结果,所以在这里要做判断
  327. boolean isContainTextAttach = part.getContentType().indexOf("name") > 0;
  328. if (part.isMimeType("text/*") && !isContainTextAttach) {
  329. try{
  330. content.append(part.getContent().toString());
  331. }catch(UnsupportedEncodingException e) {
  332. InputStream is = part.getInputStream();
  333. content.append(inputStream2String(is));
  334. }
  335. } else if (part.isMimeType("message/rfc822")) {
  336. getMailTextContent((Part) part.getContent(), content);
  337. } else if (part.isMimeType("multipart/*")) {
  338. Multipart multipart = (Multipart) part.getContent();
  339. int partCount = multipart.getCount();
  340. for (int i = 0; i < partCount; i++) {
  341. BodyPart bodyPart = multipart.getBodyPart(i);
  342. getMailTextContent(bodyPart, content);
  343. }
  344. }
  345. }
  346. //处理编码错误问题
  347. public static String inputStream2String(InputStream in)throws IOException {
  348. StringBuffer out = new StringBuffer();
  349. byte[] b = new byte[4096];
  350. for(int n; (n=in.read(b))!=-1;){
  351. out.append(new String(b,0,n));
  352. }
  353. return out.toString();
  354. }
  355. /**
  356. * 保存附件
  357. *
  358. * @param part 邮件中多个组合体中的其中一个组合体
  359. * @param destDir 附件保存目录
  360. * @throws UnsupportedEncodingException
  361. * @throws MessagingException
  362. * @throws FileNotFoundException
  363. * @throws IOException
  364. */
  365. public void saveAttachment(Part part, String destDir) throws MessagingException, IOException {
  366. if (part.isMimeType("multipart/*")) {
  367. Multipart multipart = (Multipart) part.getContent(); //复杂体邮件
  368. //复杂体邮件包含多个邮件体
  369. int partCount = multipart.getCount();
  370. for (int i = 0; i < partCount; i++) {
  371. //获得复杂体邮件中其中一个邮件体
  372. BodyPart bodyPart = multipart.getBodyPart(i);
  373. //某一个邮件体也有可能是由多个邮件体组成的复杂体
  374. String disp = bodyPart.getDisposition();
  375. if (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE))) {
  376. InputStream is = bodyPart.getInputStream();
  377. saveFile(is, destDir, decodeText(bodyPart.getFileName()));
  378. } else if (bodyPart.isMimeType("multipart/*")) {
  379. saveAttachment(bodyPart, destDir);
  380. } else {
  381. String contentType = bodyPart.getContentType();
  382. if (contentType.indexOf("name") != -1 || contentType.indexOf("application") != -1) {
  383. saveFile(bodyPart.getInputStream(), destDir, decodeText(bodyPart.getFileName()));
  384. }
  385. }
  386. }
  387. } else if (part.isMimeType("message/rfc822")) {
  388. saveAttachment((Part) part.getContent(), destDir);
  389. }
  390. }
  391. /**
  392. * 读取输入流中的数据保存至指定目录
  393. *
  394. * @param is 输入流
  395. * @param fileName 文件名
  396. * @param destDir 文件存储目录
  397. * @throws FileNotFoundException
  398. * @throws IOException
  399. */
  400. private void saveFile(InputStream is, String destDir, String fileName) throws FileNotFoundException, IOException {
  401. BufferedInputStream bis = new BufferedInputStream(is);
  402. BufferedOutputStream bos = new BufferedOutputStream(
  403. new FileOutputStream(new File(destDir + fileName)));
  404. int len = -1;
  405. while ((len = bis.read()) != -1) {
  406. bos.write(len);
  407. bos.flush();
  408. }
  409. bos.close();
  410. bis.close();
  411. }
  412. /**
  413. * 文本解码
  414. *
  415. * @param encodeText 解码MimeUtility.encodeText(String text)方法编码后的文本
  416. * @return 解码后的文本
  417. * @throws UnsupportedEncodingException
  418. */
  419. public String decodeText(String encodeText) throws UnsupportedEncodingException {
  420. if (encodeText == null || "".equals(encodeText)) {
  421. return "";
  422. } else {
  423. return MimeUtility.decodeText(encodeText);
  424. }
  425. }
  426. /**
  427. * 执行命令通过软件解压rld文件到D:\out\new\下
  428. */
  429. public void systemCommand(String subjectId) {
  430. try {
  431. Runtime runtime = Runtime.getRuntime();
  432. File file = new File("D:\\in\\");
  433. //遍历所有文件
  434. File[] files = file.listFiles();
  435. for (File f : files) {
  436. String type = f.getName().split("\\.")[1];
  437. if (type.equals("RWD")) {
  438. //RWD文件类型
  439. String id = f.getName().substring(0, 4);
  440. //根据编号过滤
  441. List<WindTowerInfo> windTowerInfoList = windTowerInfoService.getByEquipmentNo(id);
  442. //没有这个编号的塔
  443. windTowerInfoType(id,windTowerInfoList);
  444. for (WindTowerInfo w : windTowerInfoList) {
  445. if (id.equals(w.getEquipmentNo())) {
  446. if (w.getPassword().equals("")) {
  447. log.error("该测风塔没有配置密码");
  448. } else {
  449. String password = w.getPassword();
  450. String cmd = "\"D:\\NRG\\SymDR\\SDR.exe\"" + " /z " + password + " " + f.getPath();
  451. Process ipconfig = runtime.exec(cmd);
  452. ipconfig.waitFor();
  453. InputStream inputStream = ipconfig.getInputStream();
  454. byte[] bytes = new byte[1024];
  455. int len = 0;
  456. while ((len = inputStream.read(bytes)) != -1) {
  457. log.info(new String(bytes, 0, len, "GBK"));
  458. }
  459. }
  460. }
  461. }
  462. //转换成txt的文件在D:\NRG\ScaledData\目录下 移动到 D:\out\下 转换文件后会有两个文件一个txt 一个log 删除log 移动txt
  463. File file1 = new File("D:\\NRG\\ScaledData\\");
  464. File[] files1 = file1.listFiles();
  465. for (File e : files1) {
  466. String[] name = e.getName().split("\\.");
  467. if (name[1].equals("txt")) {
  468. FileUtil.move(e.getPath(), "D:\\out\\new\\");
  469. } else {
  470. e.delete();
  471. }
  472. }
  473. //转成txt后把文件移动到系统文件备份目录下
  474. //xls移动系统文件目录下
  475. this.tranFile();
  476. //把txt文件转成excel文件并解析
  477. analysisDataService.analysisData(type);
  478. } else if(type.equals("rld")){
  479. //rld文件类型
  480. String[] id = f.getName().split("_");
  481. //根据编号过滤
  482. List<WindTowerInfo> windTowerInfoList = windTowerInfoService.getByEquipmentNo(id[0]);
  483. windTowerInfoType(id[0],windTowerInfoList);
  484. //如果有 有可能会有编号相同 但是记录仪编号不同的情况 不解析看不到记录仪编号 所以只能用相同编号的测风塔密码解析
  485. //如果是从邮件里读到的塔新增的话是没有数据密码的 所以需要人为的手动配置密码
  486. for (WindTowerInfo w : windTowerInfoList) {
  487. if (id[0].equals(w.getEquipmentNo())) {
  488. if ("".equals(w.getPassword())) {
  489. log.error(w.getEquipmentNo() + "测风塔没有配置数据密码");
  490. } else {
  491. String[] s = new String[]{
  492. "\"D:\\Program Files (x86)\\Renewable NRG Systems\\SymPRO Desktop\\SymPRODesktop.exe\"",
  493. "/cmd", "convert", "/file", f.getPath(),
  494. "/pass", w.getPassword(), "/type", "\"meas\"", "/outputdir", "\"D:\\out\\new\""
  495. };
  496. Process ipconfig = runtime.exec(s);
  497. ipconfig.waitFor();
  498. InputStream inputStream = ipconfig.getInputStream();
  499. byte[] bytes = new byte[1024];
  500. int len = 0;
  501. while ((len = inputStream.read(bytes)) != -1) {
  502. log.info(new String(bytes, 0, len, "GBK"));
  503. }
  504. }
  505. }
  506. }
  507. //转成txt后把文件移动到系统文件备份目录下
  508. //xls移动系统文件目录下
  509. this.tranFile();
  510. //把txt文件转成excel文件并解析
  511. analysisDataService.analysisData(type);
  512. }else if(type.equals("csv")){
  513. String id = subjectId.substring(subjectId.indexOf("[") + 1, subjectId.lastIndexOf("]"));
  514. analysisDataService.acousticRadar(f,id);
  515. }
  516. }
  517. } catch (Exception e) {
  518. log.error("执行系统命令失败:" + e);
  519. }
  520. }
  521. //检测是否存在
  522. public void windTowerInfoType(String id, List<WindTowerInfo> windTowerInfoList) {
  523. //没有这个编号的塔
  524. if (windTowerInfoList.size() == 0) {
  525. List<EmailWindTowerInfo> emailWindTowerInfos = emailWindTowerInfoService.list().stream().filter(wind -> wind.getEquipmentNo().equals(id)).collect(Collectors.toList());
  526. if (emailWindTowerInfos.size() == 0) {
  527. //如果测风塔里面没有这个塔并且邮件测风塔里也没有这个塔 则添加到邮箱读取的测风塔表中
  528. EmailWindTowerInfo emailWindTowerInfo = new EmailWindTowerInfo();
  529. emailWindTowerInfo.setEquipmentNo(id);
  530. emailWindTowerInfoService.save(emailWindTowerInfo);
  531. log.info(id + " 测风塔信息里没有这个的塔 并且邮件测风塔里也没有这个塔");
  532. } else {
  533. log.info(id + " 测风塔信息里没有这个的塔 邮件测风塔里已存在这个塔");
  534. }
  535. }
  536. }
  537. //转移文件
  538. public void tranFile() throws Exception {
  539. //转成txt后把文件移动到系统文件备份目录下
  540. File file1 = new File("D:\\in\\");
  541. File[] files1 = file1.listFiles();
  542. //xls移动系统文件目录下
  543. for (File e : files1) {
  544. String[] str = e.getName().split("\\.");
  545. if (str[1].equals("RWD")) {
  546. FileUtil.move(e.getPath(), FileUtil.getSystemFilePath() + File.separator + str[0].substring(0, 4));
  547. } else {
  548. String[] strs = str[0].split("_");
  549. FileUtil.move(e.getPath(), FileUtil.getSystemFilePath() + File.separator + strs[0]);
  550. }
  551. }
  552. }
  553. }