|
|
|
@ -3,20 +3,28 @@ package com.dxhy.core.task; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.codec.Base64Decoder; |
|
|
|
|
import cn.hutool.core.util.IdUtil; |
|
|
|
|
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.MD5; |
|
|
|
|
import com.dxhy.core.job.entity.ScheduleJobEntity; |
|
|
|
|
import com.dxhy.core.job.service.ScheduleJobService; |
|
|
|
|
import com.dxhy.core.model.mailGather.EmailMaintainVo; |
|
|
|
|
import com.dxhy.core.model.mailGather.MailGatherLogVo; |
|
|
|
|
import com.dxhy.core.model.mailGather.OcrResultToyxVo; |
|
|
|
|
import com.dxhy.core.model.openservice.OpenServiceOcr; |
|
|
|
|
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.util.EmailParseUtils; |
|
|
|
|
import com.google.common.collect.Lists; |
|
|
|
|
import com.google.common.collect.Maps; |
|
|
|
|
import com.sun.mail.pop3.POP3Folder; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
@ -24,6 +32,7 @@ import javax.mail.*; |
|
|
|
|
import javax.mail.internet.MimeMessage; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
|
import java.security.NoSuchAlgorithmException; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
@ -42,6 +51,10 @@ public class SnEmailGatherTask { |
|
|
|
|
private MailGatherLogService mailGatherLogService; |
|
|
|
|
@Resource |
|
|
|
|
private IOpenServicePlatformService openServicePlatformService; |
|
|
|
|
@Value("${snyx.salt:}") |
|
|
|
|
private String snyxSalt; |
|
|
|
|
@Value("${snyx.pjurl:}") |
|
|
|
|
private String snyxPjurl; |
|
|
|
|
|
|
|
|
|
public void mailGatherTask(){ |
|
|
|
|
DynamicContextHolder.push(DbConstant.BASICS_READ); |
|
|
|
@ -49,6 +62,7 @@ public class SnEmailGatherTask { |
|
|
|
|
|
|
|
|
|
if (scheduleJobEntity != null && "0".equals(scheduleJobEntity.getJobStatus())) { |
|
|
|
|
try { |
|
|
|
|
log.info("邮箱采集接口开始--"); |
|
|
|
|
scheduleJobEntity.setJobStatus("1"); |
|
|
|
|
DynamicContextHolder.push(DbConstant.BASICS_WRITE); |
|
|
|
|
scheduleJobService.updateById(scheduleJobEntity); |
|
|
|
@ -136,29 +150,43 @@ public class SnEmailGatherTask { |
|
|
|
|
if(isContainerAttachment){ |
|
|
|
|
List<Map<String, String>> mapList = Lists.newArrayList(); |
|
|
|
|
EmailParseUtils.saveAttachment(msg, mapList); |
|
|
|
|
for (Map<String, String> map : mapList) { |
|
|
|
|
map.put("emailName",emailName); |
|
|
|
|
String pdfStream = map.get("pdfStream"); |
|
|
|
|
if(StringUtils.isNotBlank(pdfStream)){ |
|
|
|
|
List<OpenServiceOcr> openServiceOcrs = OpenServicePlatformServiceImpl.OcrToSnTest(pdfStream); |
|
|
|
|
if(openServiceOcrs != null && !openServiceOcrs.isEmpty()){ |
|
|
|
|
Map<String, Object> ocrResult = convertToOcrResult(openServiceOcrs, map, maintainVo); |
|
|
|
|
try { |
|
|
|
|
String md5Encode = MD5.getMd5Encode(ocrResult.get("batchId") + snyxSalt); |
|
|
|
|
Map<String, String> hashMap = Maps.newHashMap(); |
|
|
|
|
hashMap.put("Authorization",md5Encode); |
|
|
|
|
log.info("调用影像票夹接口,调用地址:{},请求头:{},请求参数:{}",snyxPjurl,snyxPjurl,JSONObject.toJSONString(ocrResult)); |
|
|
|
|
String body = HttpRequest.post(snyxPjurl).addHeaders(hashMap).body(JSONObject.toJSONString(ocrResult)).timeout(300000).execute().body(); |
|
|
|
|
log.info("d调用影像票夹接口返回参数:{}",body); |
|
|
|
|
Map resultMap = JSONObject.parseObject(body, Map.class); |
|
|
|
|
Object status = resultMap.get("status"); |
|
|
|
|
if(status != null && "200".equals(String.valueOf(status))){ |
|
|
|
|
|
|
|
|
|
}else { |
|
|
|
|
gatherLogVo.setFphm(""); |
|
|
|
|
gatherLogVo.setOcrType("0"); |
|
|
|
|
gatherLogVo.setErrorMsg("推送影像票夹失败"); |
|
|
|
|
mailGatherLogService.insert(gatherLogVo); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
System.out.println(body); |
|
|
|
|
} catch (NoSuchAlgorithmException e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// gatherLogVo.setFileType(map.get("contentType"));
|
|
|
|
|
// gatherLogVo.setFileName(map.get("fileName"));
|
|
|
|
|
// String pdfStream = map.get("pdfStream");
|
|
|
|
|
// if(StringUtils.isNotBlank(pdfStream)){
|
|
|
|
|
// List<OpenServiceOcr> openServiceOcrs = openServicePlatformService.ocrInvoice(pdfStream);
|
|
|
|
|
// if(openServiceOcrs != null && !openServiceOcrs.isEmpty()){
|
|
|
|
|
// openServiceOcrs.get(0).getData().getFPDM();
|
|
|
|
|
// gatherLogVo.setFpdm( openServiceOcrs.get(0).getData().getFPDM());
|
|
|
|
|
// gatherLogVo.setFphm( openServiceOcrs.get(0).getData().getFPHM());
|
|
|
|
|
// } else {
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
}else { //无附件的不处理
|
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Flags flags = msg.getFlags();
|
|
|
|
|
// if (!flags.contains(Flags.Flag.SEEN)) {
|
|
|
|
|
// //设置为已读
|
|
|
|
|
// msg.setFlag(Flags.Flag.SEEN, true);
|
|
|
|
|
// }
|
|
|
|
|
//进行数据插入
|
|
|
|
|
if(StringUtils.isNotBlank(gatherLogVo.getFpdm()) && StringUtils.isNotBlank(gatherLogVo.getFphm())){ |
|
|
|
|
gatherLogVo.setOcrType("0"); |
|
|
|
@ -179,6 +207,37 @@ public class SnEmailGatherTask { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static Map<String, Object> convertToOcrResult(List<OpenServiceOcr> openServiceOcrs, Map<String, String> map,EmailMaintainVo maintainVo){ |
|
|
|
|
List<OcrResultToyxVo> resultToyxVoList = Lists.newArrayList(); |
|
|
|
|
Map<String, Object> hashMap = Maps.newHashMap(); |
|
|
|
|
String batchId = String.valueOf(System.currentTimeMillis()); |
|
|
|
|
hashMap.put("batchId",batchId); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < openServiceOcrs.size(); i++) { |
|
|
|
|
OpenServiceOcr openServiceOcr = openServiceOcrs.get(i); |
|
|
|
|
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("102"); |
|
|
|
|
resultToyxVo.setFileByte(map.get("pdfStream")); |
|
|
|
|
resultToyxVo.setEmail(map.get("emailName")); |
|
|
|
|
resultToyxVo.setEmployeeId(maintainVo.getUserId()); |
|
|
|
|
|
|
|
|
|
resultToyxVoList.add(resultToyxVo); |
|
|
|
|
} |
|
|
|
|
hashMap.put("list",resultToyxVoList); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return hashMap; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Store mailAuth(String emailName, String password){ |
|
|
|
|
//判断是否为QQ还是163
|
|
|
|
|
//邮件接收协议
|
|
|
|
|