|
|
|
@ -7,6 +7,7 @@ import cn.hutool.http.HttpRequest; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.dxhy.common.constant.DbConstant; |
|
|
|
|
import com.dxhy.common.datasource.config.DynamicContextHolder; |
|
|
|
|
import com.dxhy.common.util.FileUtil; |
|
|
|
|
import com.dxhy.common.util.MD5; |
|
|
|
|
import com.dxhy.common.util.UUIDUtils; |
|
|
|
|
import com.dxhy.core.job.entity.ScheduleJobEntity; |
|
|
|
@ -19,19 +20,24 @@ import com.dxhy.core.service.mailGather.EmailMaintainService; |
|
|
|
|
import com.dxhy.core.service.mailGather.MailGatherLogService; |
|
|
|
|
import com.dxhy.core.service.openservice.IOpenServicePlatformService; |
|
|
|
|
import com.dxhy.core.service.openservice.impl.OpenServicePlatformServiceImpl; |
|
|
|
|
import com.dxhy.core.service.openservice.model.ocr.SnpjInvoiceTypeEnum; |
|
|
|
|
import com.dxhy.core.service.openservice.model.ocr.*; |
|
|
|
|
import com.dxhy.core.util.EmailParseUtils; |
|
|
|
|
import com.github.pagehelper.util.StringUtil; |
|
|
|
|
import com.google.common.collect.Lists; |
|
|
|
|
import com.google.common.collect.Maps; |
|
|
|
|
import com.sun.mail.pop3.POP3Folder; |
|
|
|
|
import com.sun.mail.util.MailConnectException; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import javax.mail.*; |
|
|
|
|
import javax.mail.internet.InternetAddress; |
|
|
|
|
import javax.mail.internet.MimeMessage; |
|
|
|
|
import javax.mail.internet.MimeUtility; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
|
import java.security.NoSuchAlgorithmException; |
|
|
|
@ -39,6 +45,7 @@ import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Properties; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Component("snEmailGatherTask") |
|
|
|
@ -98,19 +105,22 @@ public class SnEmailGatherTask { |
|
|
|
|
|
|
|
|
|
public void parseEmail(EmailMaintainVo maintainVo){ |
|
|
|
|
log.info("邮箱采集内部方法开始执行--"); |
|
|
|
|
log.info("解析用户"+maintainVo.getUsername()+"邮箱"); |
|
|
|
|
// log.info("邮箱:{}密码:{}",maintainVo.getEmailAddress(),maintainVo.getEmailPassword());
|
|
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
|
String password = Base64Decoder.decodeStr(maintainVo.getEmailPassword()); |
|
|
|
|
String emailName = maintainVo.getEmailAddress(); |
|
|
|
|
|
|
|
|
|
String uid = maintainVo.getEmailUid(); |
|
|
|
|
Folder folder = null; |
|
|
|
|
Store store = null; |
|
|
|
|
List<String> uids = Lists.newArrayList(); |
|
|
|
|
try { |
|
|
|
|
Store store = mailAuth(emailName, password); |
|
|
|
|
store = mailAuth(emailName, password); |
|
|
|
|
if(store == null){ |
|
|
|
|
MailGatherLogVo gatherLogVo = new MailGatherLogVo(); |
|
|
|
|
gatherLogVo.setFromAddress(emailName); |
|
|
|
|
buildMsg(gatherLogVo,"1","邮箱认证失败"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
Folder folder = store.getFolder("INBOX"); |
|
|
|
|
folder = store.getFolder("INBOX"); |
|
|
|
|
//获取邮件列表
|
|
|
|
|
folder.open(Folder.READ_WRITE); |
|
|
|
|
// 由于POP3协议无法获知邮件的状态,所以getUnreadMessageCount得到的是收件箱的邮件总数
|
|
|
|
@ -120,9 +130,18 @@ public class SnEmailGatherTask { |
|
|
|
|
log.debug("新邮件: " + folder.getNewMessageCount()); |
|
|
|
|
// 获得收件箱中的邮件总数
|
|
|
|
|
log.debug("邮件总数: " + folder.getMessageCount()); |
|
|
|
|
EmailMaintainVo emailMaintainVo = new EmailMaintainVo(); |
|
|
|
|
emailMaintainVo.setId(maintainVo.getId()); |
|
|
|
|
// EmailMaintainVo emailMaintainVo = new EmailMaintainVo();
|
|
|
|
|
// emailMaintainVo.setId(maintainVo.getId());
|
|
|
|
|
Message[] messages = folder.getMessages(); |
|
|
|
|
POP3Folder inbox = (POP3Folder) folder; |
|
|
|
|
for (int i = 0; i < messages.length; i++) { |
|
|
|
|
String euid = inbox.getUID(messages[i]); |
|
|
|
|
uids.add(euid); |
|
|
|
|
} |
|
|
|
|
boolean flag = true; |
|
|
|
|
if (StringUtils.isBlank(maintainVo.getEmailUid()) || !uids.contains(maintainVo.getEmailUid())){ |
|
|
|
|
flag = false; |
|
|
|
|
} |
|
|
|
|
for (int i = 0, count = messages.length; i < count; i++) { |
|
|
|
|
MimeMessage msg = (MimeMessage) messages[i]; |
|
|
|
|
log.debug("------------------解析第" + msg.getMessageNumber() + "封邮件-------------------- "); |
|
|
|
@ -130,9 +149,10 @@ public class SnEmailGatherTask { |
|
|
|
|
MailGatherLogVo gatherLogVo = new MailGatherLogVo(); |
|
|
|
|
gatherLogVo.setId(IdUtil.nanoId()); |
|
|
|
|
gatherLogVo.setSubject(EmailParseUtils.getSubject(msg)); |
|
|
|
|
// String address = EmailParseUtils.getReceiveAddress(msg, null);
|
|
|
|
|
String from = getFrom(msg); |
|
|
|
|
gatherLogVo.setFromAddress(emailName); |
|
|
|
|
// String address = EmailParseUtils.getReceiveAddress(msg, null);
|
|
|
|
|
gatherLogVo.setReceiveAddress(emailName); |
|
|
|
|
gatherLogVo.setReceiveAddress(from); |
|
|
|
|
String sentDate = EmailParseUtils.getSentDate(msg, null); |
|
|
|
|
gatherLogVo.setSentDate(sentDate); |
|
|
|
|
gatherLogVo.setCreateTime(new Date()); |
|
|
|
@ -146,17 +166,22 @@ public class SnEmailGatherTask { |
|
|
|
|
// log.debug("是否需要回执:" + EmailParseUtils.isReplySign(msg));
|
|
|
|
|
log.debug("邮件大小:" + msg.getSize() * 1024 + "kb"); |
|
|
|
|
|
|
|
|
|
POP3Folder inbox = (POP3Folder) folder; |
|
|
|
|
String uid = inbox.getUID(msg); |
|
|
|
|
if(StringUtils.isBlank(maintainVo.getEmailUid()) && i+1 == messages.length){ |
|
|
|
|
emailMaintainVo.setEmailUid(uid); |
|
|
|
|
buildEmailMaintainVo(emailMaintainVo); |
|
|
|
|
} else if(i+1 == messages.length){ |
|
|
|
|
emailMaintainVo.setEmailUid(uid); |
|
|
|
|
buildEmailMaintainVo(emailMaintainVo); |
|
|
|
|
} |
|
|
|
|
uid = inbox.getUID(msg); |
|
|
|
|
log.info("uid{}",uid); |
|
|
|
|
// if(StringUtils.isBlank(maintainVo.getEmailUid()) && i+1 == messages.length){
|
|
|
|
|
// emailMaintainVo.setEmailUid(uid);
|
|
|
|
|
// buildEmailMaintainVo(emailMaintainVo);
|
|
|
|
|
// } else if(i+1 == messages.length){
|
|
|
|
|
// emailMaintainVo.setEmailUid(uid);
|
|
|
|
|
// buildEmailMaintainVo(emailMaintainVo);
|
|
|
|
|
// }
|
|
|
|
|
//增量处理 等于之后就跳过本地循环
|
|
|
|
|
if(StringUtils.isNotBlank(maintainVo.getEmailUid()) && maintainVo.getEmailUid().equals(uid)){ |
|
|
|
|
if (StringUtils.isNotBlank(uid) && uid.equals(maintainVo.getEmailUid())){ |
|
|
|
|
flag = false; |
|
|
|
|
log.debug("跳过本次循环: "+maintainVo.getEmailUid()+"===="+uid); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
if(flag){ |
|
|
|
|
log.debug("跳过本次循环: "+maintainVo.getEmailUid()+"===="+uid); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
@ -190,9 +215,9 @@ public class SnEmailGatherTask { |
|
|
|
|
log.info("调用影像票夹接口返回参数:{}",body); |
|
|
|
|
Map resultMap = JSONObject.parseObject(body, Map.class); |
|
|
|
|
Object status = resultMap.get("status"); |
|
|
|
|
gatherLogVo.setFileType(map.get("contentType")); |
|
|
|
|
gatherLogVo.setFileName(map.get("fileName")); |
|
|
|
|
if(status != null && "200".equals(String.valueOf(status))){ |
|
|
|
|
gatherLogVo.setFileName(map.get("fileName")); |
|
|
|
|
gatherLogVo.setFileType(map.get("contentType")); |
|
|
|
|
buildMsg(gatherLogVo,"0","推送影像票夹成功"); |
|
|
|
|
}else { |
|
|
|
|
gatherLogVo.setFphm(""); |
|
|
|
@ -221,8 +246,8 @@ public class SnEmailGatherTask { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 释放资源
|
|
|
|
|
folder.close(false); // false为不更新邮件,true为更新,一般在删除邮件后使用
|
|
|
|
|
store.close(); |
|
|
|
|
// folder.close(false); // false为不更新邮件,true为更新,一般在删除邮件后使用
|
|
|
|
|
// store.close();
|
|
|
|
|
log.info("邮箱采集使用时间:{}",System.currentTimeMillis() - startTime); |
|
|
|
|
} catch (MessagingException e) { |
|
|
|
|
log.error("邮箱采集邮件解析异常:{}", e); |
|
|
|
@ -230,6 +255,27 @@ public class SnEmailGatherTask { |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
log.error("邮箱采集IO异常:{}", e); |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
}finally { |
|
|
|
|
//更新uid信息
|
|
|
|
|
if (StringUtils.isNotBlank(uid) && (uids.isEmpty() ||uids.indexOf(uid)>uids.indexOf(maintainVo.getEmailUid()))){ |
|
|
|
|
EmailMaintainVo emailMaintainVo = new EmailMaintainVo(); |
|
|
|
|
emailMaintainVo.setId(maintainVo.getId()); |
|
|
|
|
emailMaintainVo.setEmailUid(uid); |
|
|
|
|
log.debug("uid:"+emailMaintainVo.getEmailUid()); |
|
|
|
|
buildEmailMaintainVo(emailMaintainVo); |
|
|
|
|
} |
|
|
|
|
// 释放资源
|
|
|
|
|
// false为不更新邮件,true为更新,一般在删除邮件后使用
|
|
|
|
|
try { |
|
|
|
|
if (folder != null){ |
|
|
|
|
folder.close(false); |
|
|
|
|
} |
|
|
|
|
if (store != null){ |
|
|
|
|
store.close(); |
|
|
|
|
} |
|
|
|
|
} catch (MessagingException e) { |
|
|
|
|
log.debug("关流失败"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -273,6 +319,32 @@ public class SnEmailGatherTask { |
|
|
|
|
|
|
|
|
|
return hashMap; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 获得邮件发件人 |
|
|
|
|
* |
|
|
|
|
* @param msg 邮件内容 |
|
|
|
|
* @return 姓名 <Email地址> |
|
|
|
|
* @throws MessagingException |
|
|
|
|
* @throws UnsupportedEncodingException |
|
|
|
|
*/ |
|
|
|
|
public String getFrom(MimeMessage msg) throws MessagingException, UnsupportedEncodingException { |
|
|
|
|
String from = ""; |
|
|
|
|
Address[] froms = msg.getFrom(); |
|
|
|
|
if (froms.length < 1){ |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
InternetAddress address = (InternetAddress) froms[0]; |
|
|
|
|
String person = address.getPersonal(); |
|
|
|
|
if (person != null) { |
|
|
|
|
person = MimeUtility.decodeText(person) + " "; |
|
|
|
|
} else { |
|
|
|
|
person = ""; |
|
|
|
|
} |
|
|
|
|
from = person + "<" + address.getAddress() + ">"; |
|
|
|
|
|
|
|
|
|
return from; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Store mailAuth(String emailName, String password){ |
|
|
|
|
//判断是否为QQ还是163
|
|
|
|
@ -312,10 +384,35 @@ public class SnEmailGatherTask { |
|
|
|
|
// });
|
|
|
|
|
//Session session = Session.getInstance(props);
|
|
|
|
|
Store store = null; |
|
|
|
|
MailGatherLogVo gatherLogVo = new MailGatherLogVo(); |
|
|
|
|
gatherLogVo.setFromAddress(emailName); |
|
|
|
|
try { |
|
|
|
|
store = session.getStore("pop3"); |
|
|
|
|
store.connect(emailName, password); |
|
|
|
|
}catch(AuthenticationFailedException e){ |
|
|
|
|
buildMsg(gatherLogVo,"1","密码错误连接邮箱失败"); |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
log.error("连接邮箱异常信息{}",e); |
|
|
|
|
try { |
|
|
|
|
store.close(); |
|
|
|
|
} catch (MessagingException ex) { |
|
|
|
|
throw new RuntimeException(ex); |
|
|
|
|
} |
|
|
|
|
store = null; |
|
|
|
|
}catch(MailConnectException e){ |
|
|
|
|
buildMsg(gatherLogVo,"1","连接超时"); |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
log.error("连接邮箱异常信息{}",e); |
|
|
|
|
try { |
|
|
|
|
store.close(); |
|
|
|
|
} catch (MessagingException ex) { |
|
|
|
|
throw new RuntimeException(ex); |
|
|
|
|
} |
|
|
|
|
store = null; |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
buildMsg(gatherLogVo,"1","未知连接异常"); |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
log.error("连接邮箱异常信息{}",e); |
|
|
|
|
try { |
|
|
|
|
store.close(); |
|
|
|
|
} catch (MessagingException ex) { |
|
|
|
@ -326,6 +423,463 @@ public class SnEmailGatherTask { |
|
|
|
|
return store; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void main3(String[] args){ |
|
|
|
|
//判断是否为QQ还是163
|
|
|
|
|
//邮件接收协议
|
|
|
|
|
String emailName = "1149953701@qq.com"; |
|
|
|
|
String password = "pmdzleyabmlzgdhc"; |
|
|
|
|
String mail_protocol = "mail.store.protocol"; |
|
|
|
|
//邮件接收协议类型
|
|
|
|
|
String mail_protocol_type2 = "pop3"; |
|
|
|
|
String mail_protocol_type = "pop"; |
|
|
|
|
//邮件接收服务器端口
|
|
|
|
|
String mail_port = "mail.pop3.port"; |
|
|
|
|
//邮件接收服务器端口
|
|
|
|
|
String port = "110"; |
|
|
|
|
//邮件接收服务器地址
|
|
|
|
|
String mail_host = "mail.pop3.host"; |
|
|
|
|
String mailSuffix = emailName.split("@")[1]; |
|
|
|
|
//邮箱类型
|
|
|
|
|
String mailType = mailSuffix.split("\\.")[0]; |
|
|
|
|
Properties props = new Properties(); |
|
|
|
|
if(mailType.equalsIgnoreCase("qq")){ |
|
|
|
|
//qq邮箱
|
|
|
|
|
props.setProperty(mail_protocol, mail_protocol_type2); // 协议
|
|
|
|
|
props.setProperty(mail_host, mail_protocol_type+"."+mailSuffix); // pop3服务器
|
|
|
|
|
props.setProperty(mail_port, port); // 端口
|
|
|
|
|
}else { |
|
|
|
|
props.setProperty(mail_protocol, mail_protocol_type); // 协议
|
|
|
|
|
props.setProperty(mail_host, mail_protocol_type+"."+mailSuffix); // pop3服务器
|
|
|
|
|
props.setProperty(mail_port, port); // 端口
|
|
|
|
|
} |
|
|
|
|
Session session = Session.getInstance(props); |
|
|
|
|
Store store = null; |
|
|
|
|
try { |
|
|
|
|
store = session.getStore("pop3"); |
|
|
|
|
store.connect(emailName, password); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
try { |
|
|
|
|
store.close(); |
|
|
|
|
} catch (MessagingException ex) { |
|
|
|
|
throw new RuntimeException(ex); |
|
|
|
|
} |
|
|
|
|
store = null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void main1(String[] args) { |
|
|
|
|
EmailMaintainVo maintainVo = new EmailMaintainVo(); |
|
|
|
|
maintainVo.setCompanyCode("9250"); |
|
|
|
|
maintainVo.setEmailAddress("1191093413@qq.com"); |
|
|
|
|
maintainVo.setEmailPassword("dWZobmdibGx5ZGRjZ2dlaA=="); |
|
|
|
|
maintainVo.setEmailUid("ZL0006_d9LNZsKMdoguImQAO4OILd7sss"); |
|
|
|
|
maintainVo.setId("RtDaFlwqZKU47MHi2Y_S4"); |
|
|
|
|
|
|
|
|
|
log.info("邮箱采集内部方法开始执行--"); |
|
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
|
String password = Base64Decoder.decodeStr(maintainVo.getEmailPassword()); |
|
|
|
|
String emailName = maintainVo.getEmailAddress(); |
|
|
|
|
|
|
|
|
|
String uid = maintainVo.getEmailUid(); |
|
|
|
|
Folder folder = null; |
|
|
|
|
Store store = null; |
|
|
|
|
List<String> uids = Lists.newArrayList(); |
|
|
|
|
try { |
|
|
|
|
//判断是否为QQ还是163
|
|
|
|
|
//邮件接收协议
|
|
|
|
|
String mail_protocol = "mail.store.protocol"; |
|
|
|
|
//邮件接收协议类型
|
|
|
|
|
String mail_protocol_type2 = "pop3"; |
|
|
|
|
String mail_protocol_type = "pop"; |
|
|
|
|
//邮件接收服务器端口
|
|
|
|
|
String mail_port = "mail.pop3.port"; |
|
|
|
|
//邮件接收服务器端口
|
|
|
|
|
String port = "110"; |
|
|
|
|
//邮件接收服务器地址
|
|
|
|
|
String mail_host = "mail.pop3.host"; |
|
|
|
|
String mailSuffix = emailName.split("@")[1]; |
|
|
|
|
//邮箱类型
|
|
|
|
|
String mailType = mailSuffix.split("\\.")[0]; |
|
|
|
|
Properties props = new Properties(); |
|
|
|
|
if(mailType.equalsIgnoreCase("qq")){ |
|
|
|
|
//qq邮箱
|
|
|
|
|
props.setProperty(mail_protocol, mail_protocol_type2); // 协议
|
|
|
|
|
props.setProperty(mail_host, mail_protocol_type+"."+mailSuffix); // pop3服务器
|
|
|
|
|
props.setProperty(mail_port, port); // 端口
|
|
|
|
|
}else { |
|
|
|
|
props.setProperty(mail_protocol, mail_protocol_type); // 协议
|
|
|
|
|
props.setProperty(mail_host, mail_protocol_type+"."+mailSuffix); // pop3服务器
|
|
|
|
|
props.setProperty(mail_port, port); // 端口
|
|
|
|
|
} |
|
|
|
|
Session session = Session.getInstance(props); |
|
|
|
|
try { |
|
|
|
|
store = session.getStore("pop3"); |
|
|
|
|
store.connect(emailName, password); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
try { |
|
|
|
|
store.close(); |
|
|
|
|
} catch (MessagingException ex) { |
|
|
|
|
throw new RuntimeException(ex); |
|
|
|
|
} |
|
|
|
|
store = null; |
|
|
|
|
} |
|
|
|
|
if(store == null){ |
|
|
|
|
log.info("store为空"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
folder = store.getFolder("INBOX"); |
|
|
|
|
//获取邮件列表
|
|
|
|
|
folder.open(Folder.READ_WRITE); |
|
|
|
|
// 由于POP3协议无法获知邮件的状态,所以getUnreadMessageCount得到的是收件箱的邮件总数
|
|
|
|
|
log.debug("未读邮件数: " + folder.getUnreadMessageCount()); |
|
|
|
|
// 由于POP3协议无法获知邮件的状态,所以下面得到的结果始终都是为0
|
|
|
|
|
log.debug("删除邮件数: " + folder.getDeletedMessageCount()); |
|
|
|
|
log.debug("新邮件: " + folder.getNewMessageCount()); |
|
|
|
|
// 获得收件箱中的邮件总数
|
|
|
|
|
log.debug("邮件总数: " + folder.getMessageCount()); |
|
|
|
|
EmailMaintainVo emailMaintainVo = new EmailMaintainVo(); |
|
|
|
|
emailMaintainVo.setId(maintainVo.getId()); |
|
|
|
|
Message[] messages = folder.getMessages(); |
|
|
|
|
POP3Folder inbox = (POP3Folder) folder; |
|
|
|
|
for (int i = 0; i < messages.length; i++) { |
|
|
|
|
String euid = inbox.getUID(messages[i]); |
|
|
|
|
uids.add(euid); |
|
|
|
|
} |
|
|
|
|
boolean flag = true; |
|
|
|
|
if (StringUtils.isBlank(maintainVo.getEmailUid()) || !uids.contains(maintainVo.getEmailUid())){ |
|
|
|
|
flag = false; |
|
|
|
|
} |
|
|
|
|
for (int i = 0, count = messages.length; i < count; i++) { |
|
|
|
|
MimeMessage msg = (MimeMessage) messages[i]; |
|
|
|
|
log.debug("------------------解析第" + msg.getMessageNumber() + "封邮件-------------------- "); |
|
|
|
|
|
|
|
|
|
MailGatherLogVo gatherLogVo = new MailGatherLogVo(); |
|
|
|
|
gatherLogVo.setId(IdUtil.nanoId()); |
|
|
|
|
gatherLogVo.setSubject(EmailParseUtils.getSubject(msg)); |
|
|
|
|
gatherLogVo.setFromAddress(emailName); |
|
|
|
|
gatherLogVo.setReceiveAddress(emailName); |
|
|
|
|
String sentDate = EmailParseUtils.getSentDate(msg, null); |
|
|
|
|
gatherLogVo.setSentDate(sentDate); |
|
|
|
|
gatherLogVo.setCreateTime(new Date()); |
|
|
|
|
|
|
|
|
|
log.debug("主题: " + EmailParseUtils.getSubject(msg)); |
|
|
|
|
log.debug("发件人: " + EmailParseUtils.getFrom(msg)); |
|
|
|
|
log.debug("发送时间:" + sentDate); |
|
|
|
|
log.debug("是否已读:" + EmailParseUtils.isSeen(msg)); |
|
|
|
|
log.debug("邮件大小:" + msg.getSize() * 1024 + "kb"); |
|
|
|
|
|
|
|
|
|
uid = inbox.getUID(msg); |
|
|
|
|
log.info("uid{}",uid); |
|
|
|
|
//增量处理 等于之后就跳过本地循环
|
|
|
|
|
if (StringUtils.isNotBlank(uid) && uid.equals(maintainVo.getEmailUid())){ |
|
|
|
|
flag = false; |
|
|
|
|
log.debug("跳过本次循环: "+maintainVo.getEmailUid()+"===="+uid); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
if(flag){ |
|
|
|
|
log.debug("跳过本次循环: "+maintainVo.getEmailUid()+"===="+uid); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
gatherLogVo.setMsgUid(uid); |
|
|
|
|
boolean isContainerAttachment = EmailParseUtils.isContainAttachment(msg); |
|
|
|
|
log.debug("是否有附件: "+isContainerAttachment); |
|
|
|
|
if(isContainerAttachment){ |
|
|
|
|
List<Map<String, String>> mapList = Lists.newArrayList(); |
|
|
|
|
EmailParseUtils.saveAttachment(msg, mapList); |
|
|
|
|
log.debug("获取附件的数量:"+mapList.size()); |
|
|
|
|
|
|
|
|
|
String username = "一十七画生"; |
|
|
|
|
maintainVo.setUserId(username); |
|
|
|
|
|
|
|
|
|
for (Map<String, String> map : mapList) { |
|
|
|
|
map.put("emailName",emailName); |
|
|
|
|
String pdfStream = map.get("pdfStream"); |
|
|
|
|
if(StringUtils.isNotBlank(pdfStream)){ |
|
|
|
|
log.debug("开始调用山能OCR识别---------"); |
|
|
|
|
//判断是否为图片流文件, 兼容公司平台进行base64解密
|
|
|
|
|
String requestUrl = "http://192.168.33.102:30006/cci_ai/service/v1/receipt_crop_and_recog?crop_complete_image=1"; |
|
|
|
|
log.info("调用山能OCR识别请求路径:"+requestUrl); |
|
|
|
|
String result = FileUtil.uploadFile(requestUrl, Base64Decoder.decode(pdfStream)); |
|
|
|
|
List<OpenServiceOcr> openServices = Lists.newArrayList(); |
|
|
|
|
if(StringUtils.isBlank(result)){ |
|
|
|
|
log.info("调用山能ocr识别失败"); |
|
|
|
|
}else { |
|
|
|
|
OcrResponseVo ocrResponseVo = JSONObject.parseObject(result, OcrResponseVo.class); |
|
|
|
|
if(ocrResponseVo != null && ocrResponseVo.getCode() == 200){ |
|
|
|
|
List<OcrDataListEntity> ocrDataListEntities = ocrResponseVo.getResult().getObjectList(); |
|
|
|
|
for (OcrDataListEntity ocrDataListEntity : ocrDataListEntities) { |
|
|
|
|
List<List<OcrProductListEntity>> productList = ocrDataListEntity.getProductList(); |
|
|
|
|
|
|
|
|
|
List<OcrItemListEntity> itemList = ocrDataListEntity.getItemList(); |
|
|
|
|
|
|
|
|
|
String type = ocrDataListEntity.getType(); |
|
|
|
|
if("other".equals(type)){ |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
Map<String, String> itemData = itemList.stream().collect(Collectors.toMap(OcrItemListEntity::getKey, OcrItemListEntity::getValue)); |
|
|
|
|
OpenServiceOcr openServiceOcr = new OpenServiceOcr(); |
|
|
|
|
openServiceOcr.setIMAGE(ocrDataListEntity.getImage()); |
|
|
|
|
openServiceOcr.setFPLXDM(OcrDataTypeEnum.getVal(type)); |
|
|
|
|
OpenServiceOcr.InvoiceOcrData invoiceOcrData = new OpenServiceOcr.InvoiceOcrData(); |
|
|
|
|
invoiceOcrData.setSFCY("0"); //是否查验
|
|
|
|
|
//判断发票类型
|
|
|
|
|
if("vat_special_invoice".equals(type) || "vat_electronic_invoice".equals(type) || "vat_common_invoice".equals(type) || "vat_electronic_toll_invoice".equals(type)){ |
|
|
|
|
invoiceOcrData.setJYM(itemData.get(OcrDataTypeEnum.VAT_INVOICE_CORRECT_CODE.getKey())); |
|
|
|
|
invoiceOcrData.setFPDM(itemData.get(OcrDataTypeEnum.VAT_INVOICE_DAIMA.getKey())); |
|
|
|
|
invoiceOcrData.setFPHM(itemData.get(OcrDataTypeEnum.VAT_INVOICE_HAOMA.getKey())); |
|
|
|
|
invoiceOcrData.setKPRQ(itemData.get(OcrDataTypeEnum.VAT_INVOICE_ISSUE_DATE.getKey())); |
|
|
|
|
invoiceOcrData.setGMFSBH(itemData.get(OcrDataTypeEnum.VAT_INVOICE_RATE_PAYER_ID.getKey())); |
|
|
|
|
invoiceOcrData.setJDHM(itemData.get(OcrDataTypeEnum.VAT_INVOICE_JIDA_HAOMA.getKey())); |
|
|
|
|
invoiceOcrData.setXHFMC(itemData.get(OcrDataTypeEnum.VAT_INVOICE_SELLER_NAME.getKey())); |
|
|
|
|
invoiceOcrData.setXHFSBH(itemData.get(OcrDataTypeEnum.VAT_INVOICE_SELLER_ID.getKey())); |
|
|
|
|
invoiceOcrData.setXHFDZDH(itemData.get(OcrDataTypeEnum.VAT_INVOICE_SELLER_ADDR_TELL.getKey())); |
|
|
|
|
invoiceOcrData.setXHFYHZH(itemData.get(OcrDataTypeEnum.VAT_INVOICE_SELLER_BANK_ACCOUNT.getKey())); |
|
|
|
|
invoiceOcrData.setGMFMC(itemData.get(OcrDataTypeEnum.VAT_INVOICE_PAYER_NAME.getKey())); |
|
|
|
|
invoiceOcrData.setGMFDZDH(itemData.get(OcrDataTypeEnum.VAT_INVOICE_PAYER_ADDR_TELL.getKey())); |
|
|
|
|
invoiceOcrData.setGMFYHZH(itemData.get(OcrDataTypeEnum.VAT_INVOICE_PAYER_BANK_ACCOUNT.getKey())); |
|
|
|
|
invoiceOcrData.setHJJE(itemData.get(OcrDataTypeEnum.VAT_INVOICE_PRICE.getKey())); |
|
|
|
|
invoiceOcrData.setSFDK(itemData.get(OcrDataTypeEnum.VAT_INVOICE_DAI_KAI_FLAG.getKey())); |
|
|
|
|
invoiceOcrData.setHJSE(itemData.get(OcrDataTypeEnum.VAT_INVOICE_TAX_TOTAL.getKey())); |
|
|
|
|
invoiceOcrData.setJSHJ(itemData.get(OcrDataTypeEnum.VAT_INVOICE_TOTAL_COVER_TAX_DIGITS.getKey())); |
|
|
|
|
invoiceOcrData.setFPLC(itemData.get(OcrDataTypeEnum.VAT_INVOICE_PAGE_NUMBER.getKey())); |
|
|
|
|
openServiceOcr.setFPLXDM(itemData.get(OcrDataTypeEnum.VAT_INVOICE_TYPE.getKey())); |
|
|
|
|
invoiceOcrData.setBZ(itemData.get(OcrDataTypeEnum.VAT_INVOICE_TOTAL_NOTE.getKey())); |
|
|
|
|
invoiceOcrData.setFWM(itemData.get(OcrDataTypeEnum.VAT_INVOICE_CIPHER_FIELD.getKey())); |
|
|
|
|
invoiceOcrData.setSKR(itemData.get(OcrDataTypeEnum.VAT_INVOICE_PAYEE.getKey())); |
|
|
|
|
invoiceOcrData.setFHR(itemData.get(OcrDataTypeEnum.VAT_INVOICE_REVIEW.getKey())); |
|
|
|
|
invoiceOcrData.setKPR(itemData.get(OcrDataTypeEnum.VAT_INVOICE_DRAWER.getKey())); |
|
|
|
|
invoiceOcrData.setSFYGSYZ("False".equals(itemData.get(OcrDataTypeEnum.EXIST_STAMPLE.getKey()))?"0":"1"); |
|
|
|
|
|
|
|
|
|
List<OpenServiceOcr.InvoiceOcrDetail> invoiceOcrDetailList = Lists.newArrayList(); |
|
|
|
|
for (List<OcrProductListEntity> productListEntities: productList) { |
|
|
|
|
Map<String, String> productMap = productListEntities.stream().collect(Collectors.toMap(OcrProductListEntity::getKey, OcrProductListEntity::getValue)); |
|
|
|
|
OpenServiceOcr.InvoiceOcrDetail invoiceOcrDetail = new OpenServiceOcr.InvoiceOcrDetail(); |
|
|
|
|
invoiceOcrDetail.setHWMC(productMap.get(OcrDataTypeEnum.VAT_INVOICE_GOODS.getKey())); |
|
|
|
|
invoiceOcrDetail.setGGXH(productMap.get(OcrDataTypeEnum.VAT_INVOICE_PLATE_SPECIFIC.getKey())); |
|
|
|
|
invoiceOcrDetail.setDW(productMap.get(OcrDataTypeEnum.VAT_INVOICE_ELECTRANS_UNIT.getKey())); |
|
|
|
|
invoiceOcrDetail.setSPSL(productMap.get(OcrDataTypeEnum.VAT_INVOICE_ELECTRANS_QUANTITY.getKey())); |
|
|
|
|
invoiceOcrDetail.setDJ(productMap.get(OcrDataTypeEnum.VAT_INVOICE_ELECTRANS_UNIT_PRICE.getKey())); |
|
|
|
|
invoiceOcrDetail.setJE(productMap.get(OcrDataTypeEnum.VAT_INVOICE_PRICE.getKey())); |
|
|
|
|
invoiceOcrDetail.setSL(productMap.get(OcrDataTypeEnum.VAT_INVOICE_TAX_RATE.getKey())); |
|
|
|
|
invoiceOcrDetail.setSE(productMap.get(OcrDataTypeEnum.VAT_INVOICE_TAX.getKey())); |
|
|
|
|
invoiceOcrDetailList.add(invoiceOcrDetail); |
|
|
|
|
} |
|
|
|
|
invoiceOcrData.setFPMX(invoiceOcrDetailList); |
|
|
|
|
} else if ("vat_roll_invoice".equals(type)) { |
|
|
|
|
invoiceOcrData.setKPRQ(itemData.get(OcrDataTypeEnum.DATE_OF_INVOICE.getKey())); |
|
|
|
|
invoiceOcrData.setFPBT(itemData.get(OcrDataTypeEnum.INVOICE_HEAD.getKey())); |
|
|
|
|
invoiceOcrData.setJYM(itemData.get(OcrDataTypeEnum.CHECK_NUMBER.getKey())); |
|
|
|
|
invoiceOcrData.setFPDM(itemData.get(OcrDataTypeEnum.INVOICE_NUMBER.getKey())); |
|
|
|
|
invoiceOcrData.setFPHM(itemData.get(OcrDataTypeEnum.INVOICE_NUMBER.getKey())); |
|
|
|
|
invoiceOcrData.setJQBM(itemData.get(OcrDataTypeEnum.MACHINE_CODE.getKey())); |
|
|
|
|
invoiceOcrData.setGMFSBH(itemData.get(OcrDataTypeEnum.BUY_TAX_NUMBER.getKey())); |
|
|
|
|
invoiceOcrData.setJSHJ(itemData.get(OcrDataTypeEnum.TOTAL_MONEY.getKey())); |
|
|
|
|
invoiceOcrData.setXHFMC(itemData.get(OcrDataTypeEnum.SOLD_NAME.getKey())); |
|
|
|
|
invoiceOcrData.setXHFSBH(itemData.get(OcrDataTypeEnum.SOLD_TAX_NUMBER.getKey())); |
|
|
|
|
invoiceOcrData.setGMFMC(itemData.get(OcrDataTypeEnum.BUY_NAME.getKey())); |
|
|
|
|
invoiceOcrData.setSKR(itemData.get(OcrDataTypeEnum.CASHIER_NAME.getKey())); |
|
|
|
|
invoiceOcrData.setSFYGSYZ("False".equals(itemData.get(OcrDataTypeEnum.EXIST_STAMPLE.getKey()))?"0":"1"); |
|
|
|
|
|
|
|
|
|
List<OpenServiceOcr.InvoiceOcrDetail> invoiceOcrDetailList = Lists.newArrayList(); |
|
|
|
|
for (List<OcrProductListEntity> productListEntities : productList) { |
|
|
|
|
Map<String, String> productMap = productListEntities.stream().collect(Collectors.toMap(OcrProductListEntity::getKey, OcrProductListEntity::getValue)); |
|
|
|
|
OpenServiceOcr.InvoiceOcrDetail invoiceOcrDetail = new OpenServiceOcr.InvoiceOcrDetail(); |
|
|
|
|
invoiceOcrDetail.setHWMC(productMap.get(OcrDataTypeEnum.VAT_INVOICE_GOODS.getKey())); |
|
|
|
|
invoiceOcrDetail.setGGXH(productMap.get(OcrDataTypeEnum.VAT_INVOICE_PLATE_SPECIFIC.getKey())); |
|
|
|
|
invoiceOcrDetail.setDW(productMap.get(OcrDataTypeEnum.VAT_INVOICE_ELECTRANS_UNIT.getKey())); |
|
|
|
|
invoiceOcrDetail.setSPSL(productMap.get(OcrDataTypeEnum.VAT_INVOICE_ELECTRANS_QUANTITY.getKey())); |
|
|
|
|
invoiceOcrDetail.setDJ(productMap.get(OcrDataTypeEnum.VAT_INVOICE_ELECTRANS_UNIT_PRICE.getKey())); |
|
|
|
|
invoiceOcrDetail.setJE(productMap.get(OcrDataTypeEnum.VAT_INVOICE_PRICE.getKey())); |
|
|
|
|
invoiceOcrDetail.setSL(productMap.get(OcrDataTypeEnum.VAT_INVOICE_TAX_RATE.getKey())); |
|
|
|
|
invoiceOcrDetail.setSE(productMap.get(OcrDataTypeEnum.VAT_INVOICE_TAX.getKey())); |
|
|
|
|
invoiceOcrDetailList.add(invoiceOcrDetail); |
|
|
|
|
} |
|
|
|
|
invoiceOcrData.setFPMX(invoiceOcrDetailList); |
|
|
|
|
} else if ("motor_vehicle_sale_invoice".equals(type)) { |
|
|
|
|
// -------------机动车销售统一发票特殊字段--------------
|
|
|
|
|
invoiceOcrData.setGMFMC(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_BUYER.getKey())); |
|
|
|
|
invoiceOcrData.setGMFSBH(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_BUYER_ID.getKey())); |
|
|
|
|
invoiceOcrData.setCPXH(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_CAR_MODEL.getKey())); |
|
|
|
|
invoiceOcrData.setHGZH(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_CERT_ID.getKey())); |
|
|
|
|
invoiceOcrData.setFDJHM(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_ENGINE_ID.getKey())); |
|
|
|
|
invoiceOcrData.setCLSBH(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_CAR_VIN.getKey())); |
|
|
|
|
invoiceOcrData.setHJJE(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_PRICE_WITHOUT_TAX.getKey())); |
|
|
|
|
invoiceOcrData.setZGSWJG(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_TAX_AUTHORITH.getKey())); |
|
|
|
|
invoiceOcrData.setZGSWJGDM(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_TAX_AUTHORITH_ID.getKey())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
invoiceOcrData.setJSHJ(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_TOTAL_PRICE_DIGITS.getKey())); |
|
|
|
|
invoiceOcrData.setKPRQ(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_ISSUE_DATE.getKey())); |
|
|
|
|
invoiceOcrData.setFPDM(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_DAIMA.getKey())); |
|
|
|
|
invoiceOcrData.setFPHM(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_HAOMA.getKey())); |
|
|
|
|
} else if ("used_car_purchase_invoice".equals(type)) { |
|
|
|
|
// -------------二手车销售统一发票特殊字段--------------
|
|
|
|
|
invoiceOcrData.setGMFMC(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_BUYER.getKey())); |
|
|
|
|
invoiceOcrData.setGMFSBH(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_BUYER_ID.getKey())); |
|
|
|
|
invoiceOcrData.setXHFMC(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_SELLER.getKey())); |
|
|
|
|
invoiceOcrData.setXHFSBH(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_SELLER_ID.getKey())); |
|
|
|
|
invoiceOcrData.setESCSC(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_MARKET.getKey())); |
|
|
|
|
invoiceOcrData.setCPZH(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_PLATE_NUM.getKey())); |
|
|
|
|
invoiceOcrData.setDJZH(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_CAR_MODEL.getKey())); |
|
|
|
|
invoiceOcrData.setCLSBH(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_VIN.getKey())); |
|
|
|
|
invoiceOcrData.setCPXH(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_CAR_MODEL.getKey())); |
|
|
|
|
invoiceOcrData.setESCNSRSBH(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_MARKET_TAX_ID.getKey())); |
|
|
|
|
invoiceOcrData.setESCNSRSBH(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_MARKET_TAX_ID.getKey())); |
|
|
|
|
invoiceOcrData.setJSHJ(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_TOTAL_PRICE_DIGITS.getKey())); |
|
|
|
|
invoiceOcrData.setKPRQ(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_ISSUE_DATE.getKey())); |
|
|
|
|
invoiceOcrData.setFPDM(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_DAIMA.getKey())); |
|
|
|
|
invoiceOcrData.setFPHM(itemData.get(OcrDataTypeEnum.VEHICLE_INVOICE_HAOMA.getKey())); |
|
|
|
|
} else if("vehicle_toll".equals(type)){ |
|
|
|
|
// -------------过路费特殊字段--------------
|
|
|
|
|
invoiceOcrData.setJSHJ(itemData.get(OcrDataTypeEnum.MONEY.getKey())); |
|
|
|
|
invoiceOcrData.setKPRQ(itemData.get(OcrDataTypeEnum.DATE.getKey())); |
|
|
|
|
invoiceOcrData.setSJ(itemData.get(OcrDataTypeEnum.TIME.getKey())); |
|
|
|
|
invoiceOcrData.setFPDM(itemData.get(OcrDataTypeEnum.TOLL_CODE.getKey())); |
|
|
|
|
invoiceOcrData.setFPHM(itemData.get(OcrDataTypeEnum.TOLL_NUMBER.getKey())); |
|
|
|
|
|
|
|
|
|
}else if ("quota_invoice".equals(type)) { |
|
|
|
|
invoiceOcrData.setJSHJ(itemData.get(OcrDataTypeEnum.MONEY_SMALL.getKey())); |
|
|
|
|
invoiceOcrData.setFPDM(itemData.get(OcrDataTypeEnum.QUOTA_INVOICE_CODE.getKey())); |
|
|
|
|
invoiceOcrData.setFPHM(itemData.get(OcrDataTypeEnum.QUOTA_INVOICE_NUMBER.getKey())); |
|
|
|
|
|
|
|
|
|
} else if ("taxi_ticket".equals(type)) { |
|
|
|
|
// -------------出租车发票特殊字段--------------
|
|
|
|
|
invoiceOcrData.setJSHJ(itemData.get(OcrDataTypeEnum.SUM.getKey())); |
|
|
|
|
invoiceOcrData.setFPDM(itemData.get(OcrDataTypeEnum.INVOICE_CODE.getKey())); |
|
|
|
|
invoiceOcrData.setFPHM(itemData.get(OcrDataTypeEnum.INVOICE_NO.getKey())); |
|
|
|
|
invoiceOcrData.setKPRQ(itemData.get(OcrDataTypeEnum.DATE.getKey())); |
|
|
|
|
invoiceOcrData.setSCSJ(itemData.get(OcrDataTypeEnum.BOARDING_TIME.getKey())); |
|
|
|
|
invoiceOcrData.setXCSJ(itemData.get(OcrDataTypeEnum.LANDING_TIME.getKey())); |
|
|
|
|
invoiceOcrData.setLC(itemData.get(OcrDataTypeEnum.MILEAGE.getKey())); |
|
|
|
|
invoiceOcrData.setSZD(itemData.get(OcrDataTypeEnum.LOCATION.getKey())); |
|
|
|
|
invoiceOcrData.setCPZH(itemData.get(OcrDataTypeEnum.TAXI_NO.getKey())); |
|
|
|
|
} else if("air_transport".equals(type)){ |
|
|
|
|
invoiceOcrData.setXM(itemData.get(OcrDataTypeEnum.PASSENGER_NAME.getKey())); |
|
|
|
|
invoiceOcrData.setSFZH(itemData.get(OcrDataTypeEnum.ID_NO.getKey())); |
|
|
|
|
invoiceOcrData.setPZHM(itemData.get(OcrDataTypeEnum.E_TICKET_NO.getKey())); |
|
|
|
|
invoiceOcrData.setTKRQ(itemData.get(OcrDataTypeEnum.ISSUED_DATE.getKey())); |
|
|
|
|
invoiceOcrData.setTKDW(itemData.get(OcrDataTypeEnum.ISSUED_BY.getKey())); |
|
|
|
|
invoiceOcrData.setPJ(itemData.get(OcrDataTypeEnum.FARE.getKey())); |
|
|
|
|
invoiceOcrData.setMHFZJJ(itemData.get(OcrDataTypeEnum.CIVIL_AVIATION_FUND.getKey())); |
|
|
|
|
invoiceOcrData.setRYFJF(itemData.get(OcrDataTypeEnum.FUEL_SURCHARGE.getKey())); |
|
|
|
|
invoiceOcrData.setQTSF(itemData.get(OcrDataTypeEnum.OTHER_TAXES.getKey())); |
|
|
|
|
invoiceOcrData.setZE(itemData.get(OcrDataTypeEnum.TOTAL.getKey())); |
|
|
|
|
invoiceOcrData.setBXF(itemData.get(OcrDataTypeEnum.INSURANCE.getKey())); |
|
|
|
|
} else if("train_ticket".equals(type)){ |
|
|
|
|
// -------------火车票特殊字段--------------
|
|
|
|
|
// invoiceOcrData.setPZHM(itemData.get(OcrDataTypeEnum.VAT_INVOICE_TYPE.getKey()));
|
|
|
|
|
invoiceOcrData.setKPRQ(itemData.get(OcrDataTypeEnum.DEPARTURE_DATE.getKey())); |
|
|
|
|
invoiceOcrData.setSJ(itemData.get(OcrDataTypeEnum.DEPARTURE_DATE.getKey())); |
|
|
|
|
// invoiceOcrData.setXM(itemData.get(OcrDataTypeEnum.VAT_INVOICE_TYPE.getKey()));
|
|
|
|
|
invoiceOcrData.setCFZD(itemData.get(OcrDataTypeEnum.DEPARTURE_STATION.getKey())); |
|
|
|
|
invoiceOcrData.setDDZD(itemData.get(OcrDataTypeEnum.ARRIVAL_STATION.getKey())); |
|
|
|
|
invoiceOcrData.setCC(itemData.get(OcrDataTypeEnum.TRAIN_NUMBER.getKey())); |
|
|
|
|
invoiceOcrData.setZWDJ(itemData.get(OcrDataTypeEnum.CLASS.getKey())); |
|
|
|
|
invoiceOcrData.setXLH(itemData.get(OcrDataTypeEnum.SEAT_NUMBER.getKey())); |
|
|
|
|
invoiceOcrData.setSFZH(itemData.get(OcrDataTypeEnum.PASSENGER_ID.getKey())); |
|
|
|
|
} else if ("general_machine_invoice".equals(type) || "highway_passenger_invoice".equals(type) || "shipping_invoice".equals(type) || "passenger_transport_invoice".equals(type)) { |
|
|
|
|
//为 general_machine_invoice(通用机打发票)、 highway_passenger_invoice(公路客运发票)、shipping_invoice(船运客票)、passenger_transport_invoice(旅客运输普票)
|
|
|
|
|
|
|
|
|
|
// -------------航空运输电子客票行程单特殊字段--------------
|
|
|
|
|
invoiceOcrData.setJSHJ(itemData.get(OcrDataTypeEnum.MONEY.getKey())); |
|
|
|
|
invoiceOcrData.setFPDM(itemData.get(OcrDataTypeEnum.INVOICE_CODE.getKey())); |
|
|
|
|
invoiceOcrData.setFPHM(itemData.get(OcrDataTypeEnum.INVOICE_NUMBER.getKey())); |
|
|
|
|
invoiceOcrData.setKPRQ(itemData.get(OcrDataTypeEnum.DATE.getKey())); |
|
|
|
|
invoiceOcrData.setSJ(itemData.get(OcrDataTypeEnum.TIME.getKey())); |
|
|
|
|
} else if ("parking_invoice".equals(type)) { |
|
|
|
|
invoiceOcrData.setJSHJ(itemData.get(OcrDataTypeEnum.MONEY.getKey())); |
|
|
|
|
invoiceOcrData.setFPHM(itemData.get(OcrDataTypeEnum.INVOICE_NUMBER.getKey())); |
|
|
|
|
} |
|
|
|
|
openServiceOcr.setData(invoiceOcrData); |
|
|
|
|
openServiceOcr.setRegion(ocrDataListEntity.getPosition()); |
|
|
|
|
openServices.add(openServiceOcr); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(openServices != null && !openServices.isEmpty()){ |
|
|
|
|
Map<String, Object> ocrResult = Maps.newHashMap(); |
|
|
|
|
List<OcrResultToyxVo> resultToyxVoList = Lists.newArrayList(); |
|
|
|
|
String batchId = String.valueOf(System.currentTimeMillis()); |
|
|
|
|
ocrResult.put("batchId",batchId); |
|
|
|
|
|
|
|
|
|
for (int j = 0; j < openServices.size(); j++) { |
|
|
|
|
OpenServiceOcr openServiceOcr = openServices.get(j); |
|
|
|
|
OpenServiceOcr.InvoiceOcrData invoiceOcrData = openServiceOcr.getData(); |
|
|
|
|
OcrResultToyxVo resultToyxVo = new OcrResultToyxVo(); |
|
|
|
|
resultToyxVo.setCompanyId(maintainVo.getCompanyCode()); |
|
|
|
|
resultToyxVo.setSource("01"); |
|
|
|
|
resultToyxVo.setInvoiceCode(invoiceOcrData.getFPDM()); |
|
|
|
|
resultToyxVo.setInvoiceNumber(invoiceOcrData.getFPHM()); |
|
|
|
|
resultToyxVo.setTotalAmount(invoiceOcrData.getJSHJ()); |
|
|
|
|
resultToyxVo.setBuyerName(invoiceOcrData.getGMFMC()); |
|
|
|
|
resultToyxVo.setSellerName(invoiceOcrData.getXHFMC()); |
|
|
|
|
resultToyxVo.setFileName(map.get("fileName")); |
|
|
|
|
resultToyxVo.setFileType(SnpjInvoiceTypeEnum.getVal(openServiceOcr.getFPLXDM())); |
|
|
|
|
resultToyxVo.setFileByte(map.get("pdfStream")); |
|
|
|
|
resultToyxVo.setEmail(map.get("emailName")); |
|
|
|
|
resultToyxVo.setEmployeeId(maintainVo.getUserId()); |
|
|
|
|
resultToyxVoList.add(resultToyxVo); |
|
|
|
|
} |
|
|
|
|
ocrResult.put("list",resultToyxVoList); |
|
|
|
|
try { |
|
|
|
|
String md5Encode = MD5.getMd5Encode(ocrResult.get("batchId") + "e4b0190b2fadc0adbe54471ffd79a729"); |
|
|
|
|
Map<String, String> hashMap = Maps.newHashMap(); |
|
|
|
|
hashMap.put("Authorization",md5Encode); |
|
|
|
|
log.info("调用影像票夹接口,调用地址:{},请求头:{},请求参数:{}","http://192.168.33.105:2333/ticket/receive",hashMap,JSONObject.toJSONString(ocrResult)); |
|
|
|
|
String body = HttpRequest.post("http://192.168.33.105:2333/ticket/receive").addHeaders(hashMap).body(JSONObject.toJSONString(ocrResult)).timeout(300000).execute().body(); |
|
|
|
|
log.info("调用影像票夹接口返回参数:{}",body); |
|
|
|
|
Map resultMap = JSONObject.parseObject(body, Map.class); |
|
|
|
|
Object status = resultMap.get("status"); |
|
|
|
|
log.info("status{}",status); |
|
|
|
|
} catch (NoSuchAlgorithmException e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}else { |
|
|
|
|
log.debug("山能OCR识别失败------"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}else { //无附件的不处理
|
|
|
|
|
log.debug("没有附件跳过"); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
//进行数据插入
|
|
|
|
|
if(StringUtils.isNotBlank(gatherLogVo.getFpdm()) && StringUtils.isNotBlank(gatherLogVo.getFphm())){ |
|
|
|
|
|
|
|
|
|
}else { |
|
|
|
|
log.info("未采集到有效数据"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
log.info("邮箱采集使用时间:{}",System.currentTimeMillis() - startTime); |
|
|
|
|
} catch (MessagingException e) { |
|
|
|
|
log.error("邮箱采集邮件解析异常:{}", e.toString()); |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
log.error("邮箱采集IO异常:{}", e); |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
}finally { |
|
|
|
|
if (uids.isEmpty() ||uids.indexOf(uid)>uids.indexOf(maintainVo.getEmailUid())){ |
|
|
|
|
System.out.println("保存uid:"+uid); |
|
|
|
|
} |
|
|
|
|
// 释放资源
|
|
|
|
|
// false为不更新邮件,true为更新,一般在删除邮件后使用
|
|
|
|
|
try { |
|
|
|
|
if (folder != null){ |
|
|
|
|
folder.close(false); |
|
|
|
|
} |
|
|
|
|
if (store != null){ |
|
|
|
|
store.close(); |
|
|
|
|
} |
|
|
|
|
} catch (MessagingException e) { |
|
|
|
|
log.debug("关流失败"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
//邮件接收协议
|
|
|
|
|
String mail_protocol = "mail.store.protocol"; |
|
|
|
|