EmailImpl.java 25 KB

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