diff --git a/dxhy-admin/src/main/java/com/dxhy/admin/sys/dao/SysUserOrgDao.java b/dxhy-admin/src/main/java/com/dxhy/admin/sys/dao/SysUserOrgDao.java index e9e30a39..c1031bd5 100644 --- a/dxhy-admin/src/main/java/com/dxhy/admin/sys/dao/SysUserOrgDao.java +++ b/dxhy-admin/src/main/java/com/dxhy/admin/sys/dao/SysUserOrgDao.java @@ -55,4 +55,6 @@ public interface SysUserOrgDao extends BaseMapper { * 用户id */ List getOrgsByUserId(Long userId); + + List getEmailOrgsByUserId(Long userId); } diff --git a/dxhy-admin/src/main/java/com/dxhy/admin/sys/model/User.java b/dxhy-admin/src/main/java/com/dxhy/admin/sys/model/User.java index c0c8ca7a..e902fd38 100644 --- a/dxhy-admin/src/main/java/com/dxhy/admin/sys/model/User.java +++ b/dxhy-admin/src/main/java/com/dxhy/admin/sys/model/User.java @@ -51,6 +51,8 @@ public class User implements Serializable { private List companyCodes; + private List emailCodes; + private String qsStatus; private String webscoketUrl; diff --git a/dxhy-admin/src/main/java/com/dxhy/admin/sys/service/SysUserOrgService.java b/dxhy-admin/src/main/java/com/dxhy/admin/sys/service/SysUserOrgService.java index eb552e13..7cd94660 100644 --- a/dxhy-admin/src/main/java/com/dxhy/admin/sys/service/SysUserOrgService.java +++ b/dxhy-admin/src/main/java/com/dxhy/admin/sys/service/SysUserOrgService.java @@ -69,4 +69,6 @@ public interface SysUserOrgService extends IService { */ List getOrgsByUserId(Long userId); + List getEmailOrgsByUserId(Long userId); + } diff --git a/dxhy-admin/src/main/java/com/dxhy/admin/sys/service/impl/SysUserOrgServiceImpl.java b/dxhy-admin/src/main/java/com/dxhy/admin/sys/service/impl/SysUserOrgServiceImpl.java index 1bbf8a3f..335bd6ef 100644 --- a/dxhy-admin/src/main/java/com/dxhy/admin/sys/service/impl/SysUserOrgServiceImpl.java +++ b/dxhy-admin/src/main/java/com/dxhy/admin/sys/service/impl/SysUserOrgServiceImpl.java @@ -89,6 +89,13 @@ public class SysUserOrgServiceImpl extends ServiceImpl getEmailOrgsByUserId(Long userId) { + DynamicContextHolder.push(DbConstant.BASICS_WRITE); + + return baseMapper.getEmailOrgsByUserId(userId); + } + @Transactional(rollbackFor = Exception.class) public void deleteUserOrg(Long userId) { baseMapper.delete(new QueryWrapper().eq("userid", userId)); diff --git a/dxhy-admin/src/main/java/com/dxhy/admin/sys/service/impl/SysUserServiceImpl.java b/dxhy-admin/src/main/java/com/dxhy/admin/sys/service/impl/SysUserServiceImpl.java index fd22b3a2..c9ae4164 100644 --- a/dxhy-admin/src/main/java/com/dxhy/admin/sys/service/impl/SysUserServiceImpl.java +++ b/dxhy-admin/src/main/java/com/dxhy/admin/sys/service/impl/SysUserServiceImpl.java @@ -1,6 +1,7 @@ package com.dxhy.admin.sys.service.impl; import java.util.*; +import java.util.stream.Collectors; import javax.annotation.Resource; @@ -325,6 +326,7 @@ public class SysUserServiceImpl extends ServiceImpl i } //获取组织编码 List companyEntitys = sysUserOrgService.getOrgsByUserId(userEntity.getUserId()); + List emailCodes = new ArrayList<>(); if (companyEntitys != null && companyEntitys.size() > 0) { for (SysCompanyEntity companyEntity : companyEntitys) { if (companyEntity != null) { @@ -338,6 +340,8 @@ public class SysUserServiceImpl extends ServiceImpl i // company.setCompanyName("()暂无组织编码发票"); // company.setCompanyCode("88"); // companyEntitys.add(company); + List collect = companyEntitys.stream().filter(e -> StringUtils.isNotBlank(e.getGfsh())).collect(Collectors.toList()); + emailCodes = JSON.parseArray(JSON.toJSONString(collect), SysCompanyEntity.class); } user = this.toUser(user, userEntity); @@ -345,10 +349,10 @@ public class SysUserServiceImpl extends ServiceImpl i user.setUserOrg(userOrgEntity); user.setUserBusiness(businessList); user.setCompanyCodes(companyEntitys); - user.setUserModels(this.getUserCompanyList(userEntity.getCompany())); // 刷新菜单缓存处理 this.setMetnuRedis(userEntity.getUserId()); + user.setEmailCodes(emailCodes); } catch (Exception e) { e.printStackTrace(); } diff --git a/dxhy-admin/src/main/resources/mapper/sys/SysUserOrgDao.xml b/dxhy-admin/src/main/resources/mapper/sys/SysUserOrgDao.xml index 0c8a9ec7..a45debdc 100644 --- a/dxhy-admin/src/main/resources/mapper/sys/SysUserOrgDao.xml +++ b/dxhy-admin/src/main/resources/mapper/sys/SysUserOrgDao.xml @@ -79,4 +79,11 @@ where org.userid = #{userId} + + diff --git a/dxhy-core/src/main/java/com/dxhy/core/controller/mailGather/EmailMaintainController.java b/dxhy-core/src/main/java/com/dxhy/core/controller/mailGather/EmailMaintainController.java index 5be951a3..9f7661e9 100644 --- a/dxhy-core/src/main/java/com/dxhy/core/controller/mailGather/EmailMaintainController.java +++ b/dxhy-core/src/main/java/com/dxhy/core/controller/mailGather/EmailMaintainController.java @@ -67,7 +67,7 @@ public class EmailMaintainController extends AbstractController { // } Object deptId = pramsMap.get("deptId"); if(deptId == null || "".equals(String.valueOf(deptId))){ - return ResponseEntity.ok(R.error("查询参数有误!")); + return ResponseEntity.ok(R.error("该组织未配置税号,请先联系管理员")); } if("99".equals(String.valueOf(deptId))){ pramsMap.put("deptId",""); @@ -141,6 +141,10 @@ public class EmailMaintainController extends AbstractController { data.put("data", ""); return ResponseEntity.ok(data); } + int count = emailMaintainService.selectByEmailAddressAndId(emailMaintain); + if(count>0){ + return ResponseEntity.ok(R.error("邮箱地址已存在!")); + } boolean b = emailMaintainService.update(emailMaintain); if(b){ diff --git a/dxhy-core/src/main/java/com/dxhy/core/dao/mailGather/EmailMaintainDao.java b/dxhy-core/src/main/java/com/dxhy/core/dao/mailGather/EmailMaintainDao.java index 4f58914a..5a55c27f 100644 --- a/dxhy-core/src/main/java/com/dxhy/core/dao/mailGather/EmailMaintainDao.java +++ b/dxhy-core/src/main/java/com/dxhy/core/dao/mailGather/EmailMaintainDao.java @@ -90,4 +90,5 @@ public interface EmailMaintainDao extends BaseMapper { String getUserName(@Param("userCode") String userCode); String getUserByUsername(@Param("username") String username); + int selectEmailWithId(@Param("email") EmailMaintainVo emailMaintainVo); } diff --git a/dxhy-core/src/main/java/com/dxhy/core/model/mailGather/EmailMaintainVo.java b/dxhy-core/src/main/java/com/dxhy/core/model/mailGather/EmailMaintainVo.java index 6d31465c..9555324d 100644 --- a/dxhy-core/src/main/java/com/dxhy/core/model/mailGather/EmailMaintainVo.java +++ b/dxhy-core/src/main/java/com/dxhy/core/model/mailGather/EmailMaintainVo.java @@ -1,6 +1,7 @@ package com.dxhy.core.model.mailGather; import com.dxhy.core.model.CommonDTO; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.EqualsAndHashCode; @@ -32,6 +33,8 @@ public class EmailMaintainVo extends CommonDTO { public String createUser; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") public Date createTime; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") public Date modifyTime; } diff --git a/dxhy-core/src/main/java/com/dxhy/core/service/mailGather/EmailMaintainService.java b/dxhy-core/src/main/java/com/dxhy/core/service/mailGather/EmailMaintainService.java index 9db4ec0f..2457d882 100644 --- a/dxhy-core/src/main/java/com/dxhy/core/service/mailGather/EmailMaintainService.java +++ b/dxhy-core/src/main/java/com/dxhy/core/service/mailGather/EmailMaintainService.java @@ -56,4 +56,6 @@ public interface EmailMaintainService { int selectByEmail(String email); EmailMaintainVo getEmailMaintainVo(EmailMaintainVo emailMaintain); + + int selectByEmailAddressAndId(EmailMaintainVo emailMaintainVo); } diff --git a/dxhy-core/src/main/java/com/dxhy/core/service/mailGather/impl/EmailMaintainServiceImpl.java b/dxhy-core/src/main/java/com/dxhy/core/service/mailGather/impl/EmailMaintainServiceImpl.java index 4c1a166e..96e69b24 100644 --- a/dxhy-core/src/main/java/com/dxhy/core/service/mailGather/impl/EmailMaintainServiceImpl.java +++ b/dxhy-core/src/main/java/com/dxhy/core/service/mailGather/impl/EmailMaintainServiceImpl.java @@ -144,6 +144,11 @@ public class EmailMaintainServiceImpl implements EmailMaintainService { return emailMaintainDao.getEmailMaintainVo(emailMaintain); } + @Override + public int selectByEmailAddressAndId(EmailMaintainVo emailMaintainVo) { + return emailMaintainDao.selectEmailWithId(emailMaintainVo); + } + //根据用户名进行查询 public void getdeptInfo(String deptId){ DynamicContextHolder.push(DbConstant.BASICS_READ); diff --git a/dxhy-core/src/main/java/com/dxhy/core/task/SnEmailGatherTask.java b/dxhy-core/src/main/java/com/dxhy/core/task/SnEmailGatherTask.java index c43c6764..79c12a8c 100644 --- a/dxhy-core/src/main/java/com/dxhy/core/task/SnEmailGatherTask.java +++ b/dxhy-core/src/main/java/com/dxhy/core/task/SnEmailGatherTask.java @@ -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 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 姓名 + * @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 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> mapList = Lists.newArrayList(); + EmailParseUtils.saveAttachment(msg, mapList); + log.debug("获取附件的数量:"+mapList.size()); + + String username = "一十七画生"; + maintainVo.setUserId(username); + + for (Map 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 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 ocrDataListEntities = ocrResponseVo.getResult().getObjectList(); + for (OcrDataListEntity ocrDataListEntity : ocrDataListEntities) { + List> productList = ocrDataListEntity.getProductList(); + + List itemList = ocrDataListEntity.getItemList(); + + String type = ocrDataListEntity.getType(); + if("other".equals(type)){ + break; + } + Map 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 invoiceOcrDetailList = Lists.newArrayList(); + for (List productListEntities: productList) { + Map 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 invoiceOcrDetailList = Lists.newArrayList(); + for (List productListEntities : productList) { + Map 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 ocrResult = Maps.newHashMap(); + List 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 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"; diff --git a/dxhy-core/src/main/resources/mapper/mailGather/EmailMaintainMapper.xml b/dxhy-core/src/main/resources/mapper/mailGather/EmailMaintainMapper.xml index f9ea5525..f7ba5c48 100644 --- a/dxhy-core/src/main/resources/mapper/mailGather/EmailMaintainMapper.xml +++ b/dxhy-core/src/main/resources/mapper/mailGather/EmailMaintainMapper.xml @@ -152,6 +152,9 @@ email_uid = #{emailUid}, + + modify_time = #{modifyTime}, + where id = #{id} @@ -173,5 +176,11 @@ select count(1) from email_maintain where email_address = #{email} + diff --git a/dxhy-core/src/main/resources/mapper/mailGather/MailGatherLogMapper.xml b/dxhy-core/src/main/resources/mapper/mailGather/MailGatherLogMapper.xml index eb3bf18f..b6657704 100644 --- a/dxhy-core/src/main/resources/mapper/mailGather/MailGatherLogMapper.xml +++ b/dxhy-core/src/main/resources/mapper/mailGather/MailGatherLogMapper.xml @@ -34,6 +34,9 @@ mail_gather_log m LEFT JOIN email_maintain e ON m.from_address = e.email_address + + and e.company_code = #{companyCode} + and e.dept_id = #{deptId}