diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mail/MailHelper.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mail/MailHelper.java index c669b6a..792ff1c 100644 --- a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mail/MailHelper.java +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mail/MailHelper.java @@ -18,6 +18,7 @@ import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; import javax.mail.internet.MimeUtility; import java.io.IOException; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -121,6 +122,8 @@ public class MailHelper { getMailTextContent(message,content); Map body = this.buildBody(message,content.toString()); body.put("邮箱来源",sourceName); + body.put("数据时间",this.getReceiveDate(message)); + body.put("备注",content); add.setBody(body); CreateAppTableRecordRespBody respBody = larkTableHelper.addTableRecord(add); return respBody.getRecord().getRecordId(); @@ -130,4 +133,13 @@ public class MailHelper { return new HashMap<>(); } + protected String getReceiveDate(Message message){ + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + return sdf.format(message.getReceivedDate()); + } catch (MessagingException e) { + } + return null; + } + } diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mail/MailHttpHelper.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mail/MailHttpHelper.java index 1a2e2cd..250d409 100644 --- a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mail/MailHttpHelper.java +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mail/MailHttpHelper.java @@ -12,9 +12,7 @@ import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeUtility; import javax.mail.search.FlagTerm; import java.security.Security; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; +import java.util.*; /** * @author yuxiangyong @@ -24,12 +22,14 @@ import java.util.Properties; @Component public class MailHttpHelper extends MailHelper{ + private static final List degreeList = Arrays.asList("初一","初二","初三","中专","专科","高考","高中","高一","高二","高三","本科","大一","大二","大三","大四"); + public static void main(String[] args) { MailHttpHelper mailHelper = new MailHttpHelper(); // MailRequest req = new MailRequest("xjia.synology.me",5000,"xjzsb","12345678"); // req = new MailRequest("xjia.synology.me",143,"xjzsb@xjia-edu.com","12345678"); // mailHelper.receiveMail(req,null); - mailHelper.buildBody(null,"刘畅文祺 13996409399父亲微信同 重庆 高三作曲 英语120 文化一本线 意向美国伯克利 其他国家也可以考虑一下 费用没问题 了解过其他学校 过几天联系"); +// mailHelper.buildBody(null,"刘畅文祺 13996409399父亲微信同 重庆 高三作曲 英语120 文化一本线 意向美国伯克利 其他国家也可以考虑一下 费用没问题 了解过其他学校 过几天联系"); } public void receiveMail(MailRequest req, LarkTableRequest add){ @@ -90,44 +90,55 @@ public class MailHttpHelper extends MailHelper{ @Override protected Map buildBody(Message message,String content) { Map map = new HashMap<>(); - Integer index = 1; - StringBuilder str = new StringBuilder(); - for (String s : content.split("")) { - if (StringUtils.isNotBlank(str) && s.equals(" ")){ - this.fillMap(map,str.toString(),index); - str = new StringBuilder(); - index ++; - continue; - } - if (s.equals(" ")){ - continue; + try { + Integer index = 1; + StringBuilder str = new StringBuilder(); + for (String s : content.split("")) { + if (StringUtils.isNotBlank(str) && s.equals(" ")){ + this.fillMap(map,str.toString(),index); + str = new StringBuilder(); + index ++; + continue; + } + if (s.equals(" ")){ + continue; + } + str.append(s); } - str.append(s); + }catch (Exception e){ + map.clear(); + map.put("异常信息",e.getMessage()); + log.error("解析邮件文本失败",e); } - - map.put("意向度",null); - map.put("报名时间",null); - map.put("回放记录",null); - map.put("业务员",null); - map.put("信息完成度",null); - map.put("数据来源",null); - map.put("所属学校",null); - map.put("原始线索",content); return map; } private void fillMap(Map map,String msg,Integer index){ switch (index){ case 1: - map.put("学生姓名",msg); + map.put("学生姓名",msg); break; case 2: map.put("省市",msg); break; case 3: - map.put("现有学历",msg); + Boolean degreeExist = Boolean.FALSE; + for (String degree : degreeList) { + if (msg.contains(degree)){ + degreeExist = Boolean.TRUE; + map.put("现有学历",msg); + } + } + if (!degreeExist){ + throw new RuntimeException("学历格式不正确"); + } break; case 4: - map.put("手机号码",msg); + int startIndex = msg.indexOf("1"); + if (startIndex >= 0 && msg.length() - startIndex >= 11){ + map.put("手机号码",msg.substring(startIndex,startIndex + 11)); + }else { + throw new RuntimeException("电话号码格式不正确"); + } break; case 5: break; @@ -138,4 +149,5 @@ public class MailHttpHelper extends MailHelper{ break; } } + }