Merge branch '于相涌/mail' into 于相涌/Lark
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
commit
7e848df561
@ -0,0 +1,25 @@
|
|||||||
|
package com.ruoyi.flyingbook.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【请填写功能名称】对象 lark_table_relation
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2023-03-15
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class LarkCompanyTableInfo implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private String appId;
|
||||||
|
private String appSecret;
|
||||||
|
private String fromAppToken;
|
||||||
|
private String fromTableId;
|
||||||
|
private String toAppToken;
|
||||||
|
private String toTableId;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package com.ruoyi.flyingbook.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import com.ruoyi.common.core.domain.BaseEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2023-04-09
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MailInfo extends BaseEntity {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private Long larkTableId;
|
||||||
|
|
||||||
|
/** 邮件服务器地址 */
|
||||||
|
private String mailServer;
|
||||||
|
|
||||||
|
/** 邮件服务器端口 */
|
||||||
|
private String mailPort;
|
||||||
|
|
||||||
|
/** 邮件服务器使用协议 */
|
||||||
|
private String mailProtocol;
|
||||||
|
|
||||||
|
/** 账号 */
|
||||||
|
private String mailUserName;
|
||||||
|
|
||||||
|
/** 邮箱授权码 */
|
||||||
|
private String mailAuthorizationCode;
|
||||||
|
|
||||||
|
/** 收件箱地址 */
|
||||||
|
private String mailReceiveFolder;
|
||||||
|
|
||||||
|
/** 邮件来源名称 */
|
||||||
|
private String sourceName;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see com.ruoyi.common.enums.FlagStatus
|
||||||
|
*/
|
||||||
|
private Long flag;
|
||||||
|
}
|
@ -0,0 +1,153 @@
|
|||||||
|
package com.ruoyi.flyingbook.mail;
|
||||||
|
|
||||||
|
import com.ruoyi.flyingbook.domain.lark.LarkTableRequest;
|
||||||
|
import com.ruoyi.flyingbook.mail.request.MailRequest;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.poi.ss.formula.functions.Index;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.mail.*;
|
||||||
|
import javax.mail.internet.InternetAddress;
|
||||||
|
import javax.mail.internet.MimeUtility;
|
||||||
|
import javax.mail.search.FlagTerm;
|
||||||
|
import java.security.Security;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yuxiangyong
|
||||||
|
* @create 2023-04-09 15:28
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class MailHttpHelper extends MailHelper{
|
||||||
|
|
||||||
|
private static final List<String> 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 文化一本线 意向美国伯克利 其他国家也可以考虑一下 费用没问题 了解过其他学校 过几天联系");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void receiveMail(MailRequest req, LarkTableRequest add){
|
||||||
|
// 定义连接imap服务器的属性信息
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.put("mail.store.protocol", req.getEmailProtocol());
|
||||||
|
props.put("mail.imap.host", req.getEmailServer());
|
||||||
|
props.put("mail.imap.port", req.getEmailPort());
|
||||||
|
props.put("mail.imap.starttls.enable", "true");
|
||||||
|
//创建会话
|
||||||
|
Session session = Session.getInstance(props, new Authenticator() {
|
||||||
|
@Override
|
||||||
|
protected PasswordAuthentication getPasswordAuthentication() {
|
||||||
|
return new PasswordAuthentication(req.getUserName(),req.getAuthorizationCode());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Store store = null;
|
||||||
|
Folder folder = null;
|
||||||
|
try {
|
||||||
|
//存储对象
|
||||||
|
store = session.getStore(req.getEmailProtocol());
|
||||||
|
//连接
|
||||||
|
store.connect(req.getEmailServer(),req.getEmailPort(),req.getUserName(),req.getAuthorizationCode());
|
||||||
|
// 获得收件箱
|
||||||
|
folder = store.getFolder(req.getReceiveFolder());
|
||||||
|
// 以读写模式打开收件箱
|
||||||
|
folder.open(Folder.READ_WRITE);
|
||||||
|
//false 表示未读
|
||||||
|
FlagTerm flagTerm = new FlagTerm(new Flags(Flags.Flag.SEEN),true);
|
||||||
|
//获得收件箱的邮件列表
|
||||||
|
Message[] messages = folder.search(flagTerm);
|
||||||
|
// 打印不同状态的邮件数量
|
||||||
|
log.info("收件箱中共{}封邮件!\n共{}封未读邮件!\n共{}封新邮件!\n共{}封已删除邮件!",
|
||||||
|
messages.length,
|
||||||
|
folder.getUnreadMessageCount(),
|
||||||
|
folder.getNewMessageCount(),
|
||||||
|
folder.getDeletedMessageCount());
|
||||||
|
this.parseMsg(messages,add,req);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("邮件解析失败",e);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (folder != null) {
|
||||||
|
folder.close(false);
|
||||||
|
}
|
||||||
|
if (store != null) {
|
||||||
|
store.close();
|
||||||
|
}
|
||||||
|
} catch (MessagingException e) {
|
||||||
|
log.error("邮件解析失败",e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 意向度、现有学历、学生姓名、报名时间、手机号码、省市、备注、回放记录、业务员、信息完成度、数据来源、目标国家、所属学校、邮箱来源
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected Map<String, Object> buildBody(Message message,String content) {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
map.clear();
|
||||||
|
map.put("异常信息",e.getMessage());
|
||||||
|
log.error("解析邮件文本失败",e);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
private void fillMap(Map<String, Object> map,String msg,Integer index){
|
||||||
|
switch (index){
|
||||||
|
case 1:
|
||||||
|
map.put("学生姓名",msg);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
map.put("省市",msg);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
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:
|
||||||
|
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;
|
||||||
|
case 6:
|
||||||
|
map.put("目标国家",msg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,105 @@
|
|||||||
|
package com.ruoyi.flyingbook.mail;
|
||||||
|
|
||||||
|
import com.ruoyi.flyingbook.mail.request.MailRequest;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.mail.*;
|
||||||
|
import javax.mail.internet.InternetAddress;
|
||||||
|
import javax.mail.internet.MimeUtility;
|
||||||
|
import javax.mail.search.*;
|
||||||
|
import java.security.Security;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yuxiangyong
|
||||||
|
* @create 2023-04-09 15:28
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class MailTencentHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ssl加密
|
||||||
|
*/
|
||||||
|
private static final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
MailTencentHelper mailHelper = new MailTencentHelper();
|
||||||
|
MailRequest req = new MailRequest("imap.qq.com",993,"932687738","ohziejkxqvsgbbag","新梦想");
|
||||||
|
mailHelper.receiveMail(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void receiveMail(MailRequest req){
|
||||||
|
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
|
||||||
|
// 定义连接imap服务器的属性信息
|
||||||
|
String portStr = String.valueOf(req.getEmailPort());
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.setProperty("mail.imap.socketFactory.class", SSL_FACTORY);
|
||||||
|
props.setProperty("mail.imap.socketFactory.fallback", "false");
|
||||||
|
props.setProperty("mail.transport.protocol", req.getEmailProtocol());
|
||||||
|
props.setProperty("mail.imap.port", portStr);
|
||||||
|
props.setProperty("mail.imap.socketFactory.port", portStr);
|
||||||
|
|
||||||
|
//创建会话
|
||||||
|
Session session = Session.getInstance(props, new Authenticator() {
|
||||||
|
@Override
|
||||||
|
protected PasswordAuthentication getPasswordAuthentication() {
|
||||||
|
return new PasswordAuthentication(req.getUserName(),req.getAuthorizationCode());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Store store = null;
|
||||||
|
Folder folder = null;
|
||||||
|
try {
|
||||||
|
//存储对象
|
||||||
|
store = session.getStore(req.getEmailProtocol());
|
||||||
|
//连接
|
||||||
|
store.connect(req.getEmailServer(),req.getEmailPort(),req.getUserName(),req.getAuthorizationCode());
|
||||||
|
// 获得收件箱
|
||||||
|
folder = store.getFolder(req.getReceiveFolder());
|
||||||
|
// 以读写模式打开收件箱
|
||||||
|
folder.open(Folder.READ_WRITE);
|
||||||
|
//false 表示未读
|
||||||
|
FlagTerm flagTerm = new FlagTerm(new Flags(Flags.Flag.SEEN),false);
|
||||||
|
//获得收件箱的邮件列表
|
||||||
|
Message[] messages = folder.search(flagTerm);
|
||||||
|
// 打印不同状态的邮件数量
|
||||||
|
log.info("------------------------开始解析邮件----------------------------------");
|
||||||
|
for (int i = 0; i < messages.length; i++) {
|
||||||
|
Message message = messages[i];
|
||||||
|
if (!message.getSubject().contains(req.getSourceName())){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
parseMsg(message);
|
||||||
|
//设置已读
|
||||||
|
message.setFlag(Flags.Flag.SEEN,true);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("邮件解析失败",e);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (folder != null) {
|
||||||
|
folder.close(false);
|
||||||
|
}
|
||||||
|
if (store != null) {
|
||||||
|
store.close();
|
||||||
|
}
|
||||||
|
} catch (MessagingException e) {
|
||||||
|
log.error("邮件解析失败",e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parseMsg(Message message){
|
||||||
|
try {
|
||||||
|
System.out.println("消息:"+ message.getSubject());
|
||||||
|
String from = MimeUtility.decodeText(message.getFrom()[0].toString());
|
||||||
|
InternetAddress internetAddress = new InternetAddress(from);
|
||||||
|
System.out.println("发件人:" + internetAddress.getPersonal() + '(' + internetAddress.getAddress() + ')');
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
package com.ruoyi.flyingbook.mail.request;
|
||||||
|
|
||||||
|
import com.ruoyi.flyingbook.domain.MailInfo;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yuxiangyong
|
||||||
|
* @create 2023-04-09 16:41
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class MailRequest {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮件服务器地址
|
||||||
|
* imap.qq.com
|
||||||
|
*/
|
||||||
|
private String emailServer;
|
||||||
|
/**
|
||||||
|
* 邮件服务器端口
|
||||||
|
* 993
|
||||||
|
*/
|
||||||
|
private Integer emailPort;
|
||||||
|
/**
|
||||||
|
* 邮件协议
|
||||||
|
* imap
|
||||||
|
*/
|
||||||
|
private String emailProtocol;
|
||||||
|
/**
|
||||||
|
* 登录用户名
|
||||||
|
*/
|
||||||
|
private String userName;
|
||||||
|
/**
|
||||||
|
* 开通协议的时候的授权码
|
||||||
|
*/
|
||||||
|
private String authorizationCode;
|
||||||
|
/**
|
||||||
|
* 收件箱目录
|
||||||
|
* INBOX
|
||||||
|
*/
|
||||||
|
private String receiveFolder;
|
||||||
|
|
||||||
|
/** 邮件来源名称 */
|
||||||
|
private String sourceName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否需要反馈已读信息
|
||||||
|
*/
|
||||||
|
private Boolean readFeedback;
|
||||||
|
|
||||||
|
private void fillDefault(Boolean readFeedback){
|
||||||
|
this.emailProtocol = "imap";
|
||||||
|
this.receiveFolder = "INBOX";
|
||||||
|
if (readFeedback != null){
|
||||||
|
this.readFeedback = readFeedback;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public MailRequest(String emailServer, Integer emailPort, String userName, String authorizationCode,String sourceName) {
|
||||||
|
this.emailServer = emailServer;
|
||||||
|
this.emailPort = emailPort;
|
||||||
|
this.userName = userName;
|
||||||
|
this.authorizationCode = authorizationCode;
|
||||||
|
this.sourceName = sourceName;
|
||||||
|
this.fillDefault(Boolean.TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MailRequest(MailInfo info,Boolean readFeedback) {
|
||||||
|
this.emailServer = info.getMailServer();
|
||||||
|
this.emailPort = Integer.valueOf(info.getMailPort());
|
||||||
|
this.userName = info.getMailUserName();
|
||||||
|
this.authorizationCode = info.getMailAuthorizationCode();
|
||||||
|
this.emailProtocol = info.getMailProtocol();
|
||||||
|
this.receiveFolder = info.getMailReceiveFolder();
|
||||||
|
this.readFeedback = Boolean.TRUE.equals(readFeedback);
|
||||||
|
this.sourceName = info.getSourceName();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
package com.ruoyi.flyingbook.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.ruoyi.flyingbook.domain.MailInfo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2023-04-09
|
||||||
|
*/
|
||||||
|
public interface MailInfoMapper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 查询【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param id 【请填写功能名称】ID
|
||||||
|
* @return 【请填写功能名称】
|
||||||
|
*/
|
||||||
|
public MailInfo selectMailInfoById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询【请填写功能名称】列表
|
||||||
|
*
|
||||||
|
* @param mailInfo 【请填写功能名称】
|
||||||
|
* @return 【请填写功能名称】集合
|
||||||
|
*/
|
||||||
|
public List<MailInfo> selectMailInfoList(MailInfo mailInfo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param mailInfo 【请填写功能名称】
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int insertMailInfo(MailInfo mailInfo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param mailInfo 【请填写功能名称】
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int updateMailInfo(MailInfo mailInfo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param id 【请填写功能名称】ID
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteMailInfoById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param ids 需要删除的数据ID
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteMailInfoByIds(Long[] ids);
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package com.ruoyi.flyingbook.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.ruoyi.flyingbook.domain.MailInfo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【请填写功能名称】Service接口
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2023-04-09
|
||||||
|
*/
|
||||||
|
public interface IMailInfoService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 查询【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param id 【请填写功能名称】ID
|
||||||
|
* @return 【请填写功能名称】
|
||||||
|
*/
|
||||||
|
public MailInfo selectMailInfoById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询【请填写功能名称】列表
|
||||||
|
*
|
||||||
|
* @param mailInfo 【请填写功能名称】
|
||||||
|
* @return 【请填写功能名称】集合
|
||||||
|
*/
|
||||||
|
public List<MailInfo> selectMailInfoList(MailInfo mailInfo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param mailInfo 【请填写功能名称】
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int insertMailInfo(MailInfo mailInfo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param mailInfo 【请填写功能名称】
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int updateMailInfo(MailInfo mailInfo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param ids 需要删除的【请填写功能名称】ID
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteMailInfoByIds(Long[] ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除【请填写功能名称】信息
|
||||||
|
*
|
||||||
|
* @param id 【请填写功能名称】ID
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteMailInfoById(Long id);
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
package com.ruoyi.flyingbook.service.impl;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
|
import com.ruoyi.flyingbook.domain.MailInfo;
|
||||||
|
import com.ruoyi.flyingbook.mapper.MailInfoMapper;
|
||||||
|
import com.ruoyi.flyingbook.service.IMailInfoService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【请填写功能名称】Service业务层处理
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2023-04-09
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class MailInfoServiceImpl implements IMailInfoService
|
||||||
|
{
|
||||||
|
@Autowired
|
||||||
|
private MailInfoMapper mailInfoMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param id 【请填写功能名称】ID
|
||||||
|
* @return 【请填写功能名称】
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public MailInfo selectMailInfoById(Long id)
|
||||||
|
{
|
||||||
|
return mailInfoMapper.selectMailInfoById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询【请填写功能名称】列表
|
||||||
|
*
|
||||||
|
* @param mailInfo 【请填写功能名称】
|
||||||
|
* @return 【请填写功能名称】
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<MailInfo> selectMailInfoList(MailInfo mailInfo)
|
||||||
|
{
|
||||||
|
return mailInfoMapper.selectMailInfoList(mailInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param mailInfo 【请填写功能名称】
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int insertMailInfo(MailInfo mailInfo)
|
||||||
|
{
|
||||||
|
mailInfo.setCreateTime(DateUtils.getNowDate());
|
||||||
|
return mailInfoMapper.insertMailInfo(mailInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param mailInfo 【请填写功能名称】
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int updateMailInfo(MailInfo mailInfo)
|
||||||
|
{
|
||||||
|
mailInfo.setUpdateTime(DateUtils.getNowDate());
|
||||||
|
return mailInfoMapper.updateMailInfo(mailInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param ids 需要删除的【请填写功能名称】ID
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int deleteMailInfoByIds(Long[] ids)
|
||||||
|
{
|
||||||
|
return mailInfoMapper.deleteMailInfoByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除【请填写功能名称】信息
|
||||||
|
*
|
||||||
|
* @param id 【请填写功能名称】ID
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int deleteMailInfoById(Long id)
|
||||||
|
{
|
||||||
|
return mailInfoMapper.deleteMailInfoById(id);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,116 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.ruoyi.flyingbook.mapper.MailInfoMapper">
|
||||||
|
|
||||||
|
<resultMap type="com.ruoyi.flyingbook.domain.MailInfo" id="MailInfoResult">
|
||||||
|
<result property="id" column="id" />
|
||||||
|
<result property="larkTableId" column="lark_table_id" />
|
||||||
|
<result property="mailServer" column="mail_server" />
|
||||||
|
<result property="mailPort" column="mail_port" />
|
||||||
|
<result property="mailProtocol" column="mail_protocol" />
|
||||||
|
<result property="mailUserName" column="mail_user_name" />
|
||||||
|
<result property="mailAuthorizationCode" column="mail_authorization_code" />
|
||||||
|
<result property="mailReceiveFolder" column="mail_receive_folder" />
|
||||||
|
<result property="sourceName" column="source_name" />
|
||||||
|
<result property="createBy" column="create_by" />
|
||||||
|
<result property="createTime" column="create_time" />
|
||||||
|
<result property="updateBy" column="update_by" />
|
||||||
|
<result property="updateTime" column="update_time" />
|
||||||
|
<result property="flag" column="flag" />
|
||||||
|
<result property="remark" column="remark" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="selectMailInfoVo">
|
||||||
|
select id,lark_table_id, mail_server, mail_port, mail_protocol, mail_user_name, mail_authorization_code, mail_receive_folder,source_name, create_by, create_time, update_by, update_time, flag, remark from mail_info
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="selectMailInfoList" parameterType="com.ruoyi.flyingbook.domain.MailInfo" resultMap="MailInfoResult">
|
||||||
|
<include refid="selectMailInfoVo"/>
|
||||||
|
<where>
|
||||||
|
<if test="larkTableId != null"> and lark_table_id = #{larkTableId}</if>
|
||||||
|
<if test="mailServer != null and mailServer != ''"> and mail_server = #{mailServer}</if>
|
||||||
|
<if test="mailPort != null and mailPort != ''"> and mail_port = #{mailPort}</if>
|
||||||
|
<if test="mailProtocol != null and mailProtocol != ''"> and mail_protocol = #{mailProtocol}</if>
|
||||||
|
<if test="mailUserName != null and mailUserName != ''"> and mail_user_name like concat('%', #{mailUserName}, '%')</if>
|
||||||
|
<if test="mailAuthorizationCode != null and mailAuthorizationCode != ''"> and mail_authorization_code = #{mailAuthorizationCode}</if>
|
||||||
|
<if test="mailReceiveFolder != null and mailReceiveFolder != ''"> and mail_receive_folder = #{mailReceiveFolder}</if>
|
||||||
|
<if test="sourceName != null and sourceName != ''"> and source_name = #{sourceName}</if>
|
||||||
|
<if test="flag != null "> and flag = #{flag}</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectMailInfoById" parameterType="Long" resultMap="MailInfoResult">
|
||||||
|
<include refid="selectMailInfoVo"/>
|
||||||
|
where id = #{id}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<insert id="insertMailInfo" parameterType="com.ruoyi.flyingbook.domain.MailInfo" useGeneratedKeys="true" keyProperty="id">
|
||||||
|
insert into mail_info
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="larkTableId != null">lark_table_id,</if>
|
||||||
|
<if test="mailServer != null and mailServer != ''">mail_server,</if>
|
||||||
|
<if test="mailPort != null and mailPort != ''">mail_port,</if>
|
||||||
|
<if test="mailProtocol != null and mailProtocol != ''">mail_protocol,</if>
|
||||||
|
<if test="mailUserName != null and mailUserName != ''">mail_user_name,</if>
|
||||||
|
<if test="mailAuthorizationCode != null and mailAuthorizationCode != ''">mail_authorization_code,</if>
|
||||||
|
<if test="mailReceiveFolder != null">mail_receive_folder,</if>
|
||||||
|
<if test="sourceName != null">source_name,</if>
|
||||||
|
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||||
|
<if test="createTime != null">create_time,</if>
|
||||||
|
<if test="updateBy != null">update_by,</if>
|
||||||
|
<if test="updateTime != null">update_time,</if>
|
||||||
|
<if test="flag != null">flag,</if>
|
||||||
|
<if test="remark != null">remark,</if>
|
||||||
|
</trim>
|
||||||
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="larkTableId != null">#{larkTableId},</if>
|
||||||
|
<if test="mailServer != null and mailServer != ''">#{mailServer},</if>
|
||||||
|
<if test="mailPort != null and mailPort != ''">#{mailPort},</if>
|
||||||
|
<if test="mailProtocol != null and mailProtocol != ''">#{mailProtocol},</if>
|
||||||
|
<if test="mailUserName != null and mailUserName != ''">#{mailUserName},</if>
|
||||||
|
<if test="mailAuthorizationCode != null and mailAuthorizationCode != ''">#{mailAuthorizationCode},</if>
|
||||||
|
<if test="mailReceiveFolder != null">#{mailReceiveFolder},</if>
|
||||||
|
<if test="sourceName != null">#{sourceName},</if>
|
||||||
|
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||||
|
<if test="createTime != null">#{createTime},</if>
|
||||||
|
<if test="updateBy != null">#{updateBy},</if>
|
||||||
|
<if test="updateTime != null">#{updateTime},</if>
|
||||||
|
<if test="flag != null">#{flag},</if>
|
||||||
|
<if test="remark != null">#{remark},</if>
|
||||||
|
</trim>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="updateMailInfo" parameterType="com.ruoyi.flyingbook.domain.MailInfo">
|
||||||
|
update mail_info
|
||||||
|
<trim prefix="SET" suffixOverrides=",">
|
||||||
|
<if test="larkTableId != null">lark_table_id = #{larkTableId},</if>
|
||||||
|
<if test="mailServer != null and mailServer != ''">mail_server = #{mailServer},</if>
|
||||||
|
<if test="mailPort != null and mailPort != ''">mail_port = #{mailPort},</if>
|
||||||
|
<if test="mailProtocol != null and mailProtocol != ''">mail_protocol = #{mailProtocol},</if>
|
||||||
|
<if test="mailUserName != null and mailUserName != ''">mail_user_name = #{mailUserName},</if>
|
||||||
|
<if test="mailAuthorizationCode != null and mailAuthorizationCode != ''">mail_authorization_code = #{mailAuthorizationCode},</if>
|
||||||
|
<if test="mailReceiveFolder != null">mail_receive_folder = #{mailReceiveFolder},</if>
|
||||||
|
<if test="sourceName != null">source_name = #{sourceName},</if>
|
||||||
|
<if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
|
||||||
|
<if test="createTime != null">create_time = #{createTime},</if>
|
||||||
|
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||||
|
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||||
|
<if test="flag != null">flag = #{flag},</if>
|
||||||
|
<if test="remark != null">remark = #{remark},</if>
|
||||||
|
</trim>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<delete id="deleteMailInfoById" parameterType="Long">
|
||||||
|
delete from mail_info where id = #{id}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<delete id="deleteMailInfoByIds" parameterType="String">
|
||||||
|
delete from mail_info where id in
|
||||||
|
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
</mapper>
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.ruoyi.quartz.controller;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.quartz.task.MailSyncTask;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
public class MailInfoController extends BaseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MailSyncTask mailSyncTask;
|
||||||
|
|
||||||
|
@PostMapping("/syncEmail")
|
||||||
|
public void syncEmail() {
|
||||||
|
mailSyncTask.syncMail();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,94 @@
|
|||||||
|
package com.ruoyi.quartz.task;
|
||||||
|
|
||||||
|
import com.ruoyi.common.enums.FlagStatus;
|
||||||
|
import com.ruoyi.common.enums.TableRelationTypeEnum;
|
||||||
|
import com.ruoyi.flyingbook.domain.LarkCompanyTableInfo;
|
||||||
|
import com.ruoyi.flyingbook.domain.MailInfo;
|
||||||
|
import com.ruoyi.flyingbook.domain.lark.LarkTableRequest;
|
||||||
|
import com.ruoyi.flyingbook.mail.MailHttpHelper;
|
||||||
|
import com.ruoyi.flyingbook.mail.request.MailRequest;
|
||||||
|
import com.ruoyi.flyingbook.mapper.LarkTableRelationMapper;
|
||||||
|
import com.ruoyi.flyingbook.service.IMailInfoService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务调度测试
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component("mailSyncTask")
|
||||||
|
public class MailSyncTask {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MailHttpHelper mailHttpHelper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IMailInfoService iMailInfoService;
|
||||||
|
@Autowired
|
||||||
|
private LarkTableRelationMapper larkTableRelationMapper;
|
||||||
|
|
||||||
|
public void syncMail() {
|
||||||
|
log.info("MailSyncTask start");
|
||||||
|
MailInfo mailInfo = new MailInfo();
|
||||||
|
mailInfo.setFlag(FlagStatus.OK.getCode());
|
||||||
|
List<MailInfo> mailInfos = iMailInfoService.selectMailInfoList(mailInfo);
|
||||||
|
log.info("MailSyncTask execute size:{}", mailInfos.size());
|
||||||
|
Map<Long, LarkTableRequest> larkMap = this.getLarkMap(mailInfos);
|
||||||
|
|
||||||
|
for (MailInfo info : mailInfos) {
|
||||||
|
LarkTableRequest addRequest = larkMap.get(info.getLarkTableId());
|
||||||
|
if (addRequest == null) {
|
||||||
|
log.info("待同步邮箱未配置飞书相关信息,mailInfo:{}", info);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
MailRequest request = new MailRequest(info, Boolean.TRUE);
|
||||||
|
mailHttpHelper.receiveMail(request,addRequest);
|
||||||
|
}
|
||||||
|
log.info("MailSyncTask end");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<Long, LarkTableRequest> getLarkMap(List<MailInfo> mailInfos) {
|
||||||
|
List<Long> tableIds = mailInfos.stream()
|
||||||
|
.filter(r -> {
|
||||||
|
return r.getLarkTableId() != null;
|
||||||
|
})
|
||||||
|
.map(MailInfo::getLarkTableId)
|
||||||
|
.distinct()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isEmpty(tableIds)) {
|
||||||
|
return new HashMap<>();
|
||||||
|
}
|
||||||
|
List<LarkCompanyTableInfo> larkCompanyTableInfos = larkTableRelationMapper.queryListByIdListJoinLarkCompany(tableIds, FlagStatus.OK.getCode(), TableRelationTypeEnum.SYNC_EMAIL.getCode());
|
||||||
|
return larkCompanyTableInfos.stream()
|
||||||
|
.filter(r -> {
|
||||||
|
return r.getId() != null
|
||||||
|
&& StringUtils.isNotBlank(r.getAppId())
|
||||||
|
&& StringUtils.isNotBlank(r.getAppSecret())
|
||||||
|
&& StringUtils.isNotBlank(r.getToAppToken())
|
||||||
|
&& StringUtils.isNotBlank(r.getToTableId());
|
||||||
|
})
|
||||||
|
.map(r -> {
|
||||||
|
LarkTableRequest request = new LarkTableRequest();
|
||||||
|
request.setId(r.getId());
|
||||||
|
request.setAppId(r.getAppId());
|
||||||
|
request.setAppSecret(r.getAppSecret());
|
||||||
|
request.setAppToken(r.getToAppToken());
|
||||||
|
request.setAppTable(r.getToTableId());
|
||||||
|
return request;
|
||||||
|
})
|
||||||
|
.collect(
|
||||||
|
Collectors.toMap(LarkTableRequest::getId, Function.identity(), (k1, k2) -> k1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
-- 菜单 SQL
|
||||||
|
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
|
values('【请填写功能名称】', '3', '1', 'info', 'system/info/index', 1, 0, 'C', '0', '0', 'system:info:list', '#', 'admin', sysdate(), '', null, '【请填写功能名称】菜单');
|
||||||
|
|
||||||
|
-- 按钮父菜单ID
|
||||||
|
SELECT @parentId := LAST_INSERT_ID();
|
||||||
|
|
||||||
|
-- 按钮 SQL
|
||||||
|
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
|
values('【请填写功能名称】查询', @parentId, '1', '#', '', 1, 0, 'F', '0', '0', 'system:info:query', '#', 'admin', sysdate(), '', null, '');
|
||||||
|
|
||||||
|
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
|
values('【请填写功能名称】新增', @parentId, '2', '#', '', 1, 0, 'F', '0', '0', 'system:info:add', '#', 'admin', sysdate(), '', null, '');
|
||||||
|
|
||||||
|
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
|
values('【请填写功能名称】修改', @parentId, '3', '#', '', 1, 0, 'F', '0', '0', 'system:info:edit', '#', 'admin', sysdate(), '', null, '');
|
||||||
|
|
||||||
|
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
|
values('【请填写功能名称】删除', @parentId, '4', '#', '', 1, 0, 'F', '0', '0', 'system:info:remove', '#', 'admin', sysdate(), '', null, '');
|
||||||
|
|
||||||
|
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
|
values('【请填写功能名称】导出', @parentId, '5', '#', '', 1, 0, 'F', '0', '0', 'system:info:export', '#', 'admin', sysdate(), '', null, '');
|
Loading…
Reference in new issue