邮箱采集问题修复

release
zhenghaiyang@ele-cloud.com 2 years ago
parent c287b27770
commit 324a7825b2
  1. 24
      dxhy-core/src/main/java/com/dxhy/core/controller/mailGather/EmailMaintainController.java
  2. 29
      dxhy-core/src/main/java/com/dxhy/core/controller/mailGather/MailGatherLogController.java
  3. 4
      dxhy-core/src/main/java/com/dxhy/core/dao/mailGather/EmailMaintainDao.java
  4. 15
      dxhy-core/src/main/java/com/dxhy/core/model/mailGather/MailGatherLogVo.java
  5. 2
      dxhy-core/src/main/java/com/dxhy/core/service/mailGather/EmailMaintainService.java
  6. 6
      dxhy-core/src/main/java/com/dxhy/core/service/mailGather/impl/EmailMaintainServiceImpl.java
  7. 7
      dxhy-core/src/main/java/com/dxhy/core/service/mailGather/impl/MailGatherLogServiceImpl.java
  8. 6
      dxhy-core/src/main/java/com/dxhy/core/task/SnEmailGatherTask.java
  9. 14
      dxhy-core/src/main/java/com/dxhy/core/task/SnEmailGatherTaskTest.java
  10. 2
      dxhy-core/src/main/resources/mapper/mailGather/EmailMaintainMapper.xml
  11. 48
      dxhy-core/src/main/resources/mapper/mailGather/MailGatherLogMapper.xml

@ -4,7 +4,9 @@ import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSONObject;
import com.dxhy.common.constant.DbConstant;
import com.dxhy.common.controller.AbstractController;
import com.dxhy.common.datasource.config.DynamicContextHolder;
import com.dxhy.common.util.UUIDUtils;
import com.dxhy.common.utils.Base64Encoding;
import com.dxhy.common.utils.R;
@ -91,6 +93,13 @@ public class EmailMaintainController extends AbstractController {
}
String loginname = getUserInfo().getLoginname();
emailMaintain.setCreateUser(loginname);
DynamicContextHolder.push(DbConstant.BASICS_READ);
EmailMaintainVo vo = new EmailMaintainVo();
vo.setEmailAddress(emailMaintain.getEmailAddress());
EmailMaintainVo maintainVo = emailMaintainService.getEmailMaintainVo(vo);
if(maintainVo != null){
return ResponseEntity.ok(R.error("邮箱地址已存在!"));
}
boolean insert = this.emailMaintainService.insert(emailMaintain);
if(insert){
return ResponseEntity.ok(R.ok());
@ -106,6 +115,19 @@ public class EmailMaintainController extends AbstractController {
*/
@PostMapping("/edit")
public ResponseEntity<R> edit(@RequestBody EmailMaintainVo emailMaintain) {
if(StringUtils.isBlank(emailMaintain.getEmailPassword()) || StringUtils.isBlank(emailMaintain.getEmailAddress()) ){
return ResponseEntity.ok(R.error("邮箱地址/密码不能为空!"));
}else {
String encode = Base64Encoding.encode(emailMaintain.getEmailPassword());
emailMaintain.setEmailPassword(encode);
}
DynamicContextHolder.push(DbConstant.BASICS_READ);
EmailMaintainVo vo = new EmailMaintainVo();
vo.setEmailAddress(emailMaintain.getEmailAddress());
EmailMaintainVo maintainVo = emailMaintainService.getEmailMaintainVo(vo);
if(maintainVo != null && maintainVo.getId().equals(emailMaintain.getId())){
return ResponseEntity.ok(R.error("邮箱地址已存在!"));
}
boolean b = emailMaintainService.update(emailMaintain);
if(b){
return ResponseEntity.ok(R.ok());
@ -142,6 +164,7 @@ public class EmailMaintainController extends AbstractController {
errorMsgList.add("第" + resultIndex + "行,用户编码不能为空");
continue;
}
DynamicContextHolder.push(DbConstant.BASICS_READ);
String userName = emailMaintainService.getUserName(userId);
if(StringUtils.isBlank(userName)){
errorMsgList.add("第" + resultIndex + "行,用户编码在系统中查询不到,请核实!");
@ -206,6 +229,7 @@ public class EmailMaintainController extends AbstractController {
if(StringUtils.isEmpty(userCode)){
return ResponseEntity.ok(R.error("数据不能为空!"));
}
DynamicContextHolder.push(DbConstant.BASICS_READ);
String userName = emailMaintainService.getUserName(userCode);
if(StringUtils.isNotEmpty(userName)){
JSONObject json = new JSONObject();

@ -1,8 +1,12 @@
package com.dxhy.core.controller.mailGather;
import com.dxhy.common.constant.DbConstant;
import com.dxhy.common.controller.AbstractController;
import com.dxhy.common.datasource.config.DynamicContextHolder;
import com.dxhy.common.utils.R;
import com.dxhy.core.service.mailGather.MailGatherLogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -10,6 +14,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
/**
@ -18,6 +25,7 @@ import java.util.Map;
* @author makejava
* @since 2023-03-23 08:42:35
*/
@Slf4j
@RestController
@RequestMapping("/mailGatherLog")
public class MailGatherLogController extends AbstractController {
@ -26,6 +34,7 @@ public class MailGatherLogController extends AbstractController {
*/
@Resource
private MailGatherLogService mailGatherLogService;
final SimpleDateFormat sf2 = new SimpleDateFormat("yyyy-MM-dd");
/**
* 分页查询
@ -46,6 +55,26 @@ public class MailGatherLogController extends AbstractController {
if (pramsMap.get("parseEnd") == null || "".equals(pramsMap.get("parseEnd"))) {
return ResponseEntity.ok(R.error("结束日期不能为空!"));
}
Object parseStart = pramsMap.get("parseStart");
Object parseEnd = pramsMap.get("parseEnd");
if (parseEnd == null || parseEnd == null) {
} else {
try {
Date starttime = sf2.parse(String.valueOf(parseStart));
Date endtime = sf2.parse(String.valueOf(parseEnd));
if (starttime.after(endtime)) {
return ResponseEntity.ok(R.error("开始时间不能大于结束时间"));
}
pramsMap.put("startTime", starttime);
pramsMap.put("endTime", endtime);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
String loginname = getUserInfo().getLoginname();
pramsMap.put("createUser",loginname);
DynamicContextHolder.push(DbConstant.BASICS_READ);
return ResponseEntity.ok(R.ok().put("data",this.mailGatherLogService.queryByPage(pramsMap)));
}

@ -35,7 +35,7 @@ public interface EmailMaintainDao extends BaseMapper<EmailMaintainVo> {
* @param emailMaintainVo 查询条件
* @return 总行数
*/
long count(EmailMaintainVo emailMaintainVo);
EmailMaintainVo getEmailMaintainVo(EmailMaintainVo emailMaintainVo);
/**
* 新增数据
@ -81,4 +81,6 @@ public interface EmailMaintainDao extends BaseMapper<EmailMaintainVo> {
String getUserName(@Param("userCode") String userCode);
}

@ -16,7 +16,7 @@ public class MailGatherLogVo extends CommonDTO {
private String subject;
private String fromAddress;
private String receiveAddress;
private String sentDate;
private Date sentDate;
private String fileType;
private String fpdm;
private String fphm;
@ -26,4 +26,17 @@ public class MailGatherLogVo extends CommonDTO {
private String fileName;
private Date createTime;
public String deptId;
private String companyCode;
public String deptName;
public String username;
public String userId;
public String createUser;
}

@ -51,4 +51,6 @@ public interface EmailMaintainService {
String getUserName(String userCode);
int insertBatch(List<EmailMaintainVo> entities);
EmailMaintainVo getEmailMaintainVo(EmailMaintainVo emailMaintain);
}

@ -117,9 +117,13 @@ public class EmailMaintainServiceImpl implements EmailMaintainService {
return emailMaintainDao.insertBatch(entities);
}
@Override
public EmailMaintainVo getEmailMaintainVo(EmailMaintainVo emailMaintain) {
return emailMaintainDao.getEmailMaintainVo(emailMaintain);
}
//根据用户名进行查询
public void getdeptInfo(String deptId){
DynamicContextHolder.push(DbConstant.BASICS_READ);
}
}

@ -5,16 +5,19 @@ import cn.hutool.core.codec.Base64;
import com.alibaba.fastjson.JSONObject;
import com.dxhy.common.constant.DbConstant;
import com.dxhy.common.datasource.config.DynamicContextHolder;
import com.dxhy.common.util.UUIDUtils;
import com.dxhy.core.dao.mailGather.MailGatherLogDao;
import com.dxhy.core.model.mailGather.MailGatherLogVo;
import com.dxhy.core.service.mailGather.MailGatherLogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -70,6 +73,10 @@ public class MailGatherLogServiceImpl implements MailGatherLogService {
*/
@Override
public MailGatherLogVo insert(MailGatherLogVo mailGatherLog) {
if(StringUtils.isEmpty(mailGatherLog.getId())){
mailGatherLog.setId(UUIDUtils.generateShortUuid());
}
mailGatherLog.setCreateTime(new Date());
this.mailGatherLogDao.insert(mailGatherLog);
return mailGatherLog;
}

@ -8,6 +8,7 @@ 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.common.util.UUIDUtils;
import com.dxhy.core.job.entity.ScheduleJobEntity;
import com.dxhy.core.job.service.ScheduleJobService;
import com.dxhy.core.model.mailGather.EmailMaintainVo;
@ -89,18 +90,17 @@ public class SnEmailGatherTask {
}
public void parseEmail(EmailMaintainVo maintainVo){
log.info("邮箱采集内部方法开始执行--");
long startTime = System.currentTimeMillis();
String password = Base64Decoder.decodeStr(maintainVo.getEmailPassword());
String emailName = maintainVo.getEmailAddress();
try {
Store store = mailAuth(emailName, password);
if(store == null){
MailGatherLogVo gatherLogVo = new MailGatherLogVo();
gatherLogVo.setId(IdUtil.nanoId());
gatherLogVo.setId(UUIDUtils.generateShortUuid());
gatherLogVo.setErrorMsg("邮箱认证失败");
gatherLogVo.setOcrType("1");
gatherLogVo.setCreateTime(new Date());
gatherLogVo.setFromAddress(emailName);
mailGatherLogService.insert(gatherLogVo);
return;

@ -37,8 +37,10 @@ class SnEmailGatherTaskTest {
String port = "110";
//邮件接收服务器地址
String mail_host = "mail.pop3.host";
String emailName = "15201210373@163.com";
String password = "JKZATQTPHDDQTQSH";
String emailName = "1149953701@qq.com";
String password = "pmdzleyabmlzgdhc";
// String emailName = "15201210373@163.com";
// String password = "JKZATQTPHDDQTQSH";
String mailSuffix = emailName.split("@")[1];
//邮箱类型
String mailType = mailSuffix.split("\\.")[0];
@ -61,7 +63,7 @@ class SnEmailGatherTaskTest {
//连接邮箱服务器
//获取当前时间
Date currentTime = new Date();
// 获得收件箱 pop3协议只有一个有效的文件夹就是INBOX
// 品 ping获得收件箱 pop3协议只有一个有效的文件夹就是INBOX
Folder folder = store.getFolder("INBOX");
//获取邮件列表
folder.open(Folder.READ_WRITE);
@ -113,8 +115,8 @@ class SnEmailGatherTaskTest {
Map resultMap = JSONObject.parseObject(body, Map.class);
Object status = resultMap.get("status");
System.out.println(JSONObject.toJSONString("================="+resultMap));
if(status != null && "200".equals(String.valueOf(status))){
}
System.out.println(body);
} catch (NoSuchAlgorithmException e) {
@ -165,7 +167,7 @@ class SnEmailGatherTaskTest {
OpenServiceOcr openServiceOcr = openServiceOcrs.get(i);
OpenServiceOcr.InvoiceOcrData invoiceOcrData = openServiceOcr.getData();
OcrResultToyxVo resultToyxVo = new OcrResultToyxVo();
resultToyxVo.setCompanyId("");
resultToyxVo.setCompanyId("c040");
resultToyxVo.setSource("01");
resultToyxVo.setInvoiceCode(invoiceOcrData.getFPDM());
resultToyxVo.setInvoiceNumber(invoiceOcrData.getFPHM());
@ -176,7 +178,7 @@ class SnEmailGatherTaskTest {
resultToyxVo.setFileType("102");
resultToyxVo.setFileByte(map.get("pdfStream"));
resultToyxVo.setEmail(map.get("emailName"));
resultToyxVo.setEmployeeId("");
resultToyxVo.setEmployeeId("01142085");
resultToyxVoList.add(resultToyxVo);
}

@ -48,7 +48,7 @@
</select>
<!--统计总行数-->
<select id="count" resultType="java.lang.Long">
<select id="getEmailMaintainVo" resultMap="EmailMaintainMap">
select count(1)
from email_maintain
<where>

@ -7,7 +7,7 @@
<result property="subject" column="subject" jdbcType="VARCHAR"/>
<result property="fromAddress" column="from_address" jdbcType="VARCHAR"/>
<result property="receiveAddress" column="receive_address" jdbcType="VARCHAR"/>
<result property="sentDate" column="sent_date" jdbcType="VARCHAR"/>
<result property="sentDate" column="sent_date" jdbcType="TIMESTAMP"/>
<result property="fileType" column="file_type" jdbcType="VARCHAR"/>
<result property="fpdm" column="fpdm" jdbcType="VARCHAR"/>
<result property="fphm" column="fphm" jdbcType="VARCHAR"/>
@ -28,42 +28,32 @@
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="MailGatherLogMap" parameterType="java.util.Map">
select
id, subject, from_address, receive_address, sent_date, file_type, fpdm, fphm, msg_uid, ocr_type, error_msg, file_name, create_time
from mail_gather_log
SELECT
m.sent_date, e.dept_name, e.username, m.from_address, m.file_name, m.file_type, m.ocr_type, m.error_msg
FROM
mail_gather_log m
LEFT JOIN email_maintain e ON m.from_address = e.email_address
<where>
<if test="fromAddress != null and fromAddress != ''">
and from_address = #{fromAddress}
</if>
<if test="receiveAddress != null and receiveAddress != ''">
and receive_address = #{receiveAddress}
<if test="deptId != null and deptId != ''">
and e.dept_id = #{deptId}
</if>
<if test="sentDate != null and sentDate != ''">
and sent_date = #{sentDate}
<if test="username != null and username != ''">
and e.username = #{username}
</if>
<if test="fileType != null and fileType != ''">
and file_type = #{fileType}
<if test="userId != null and userId != ''">
and e.user_id = #{userId}
</if>
<if test="fpdm != null and fpdm != ''">
and fpdm = #{fpdm}
</if>
<if test="fphm != null and fphm != ''">
and fphm = #{fphm}
</if>
<if test="msgUid != null and msgUid != ''">
and msg_uid = #{msgUid}
<if test="createUser != null and createUser != ''">
and e.create_user = #{createUser}
</if>
<if test="ocrType != null and ocrType != ''">
and ocr_type = #{ocrType}
and m.ocr_type = #{ocrType}
</if>
<if test="errorMsg != null and errorMsg != ''">
and error_msg = #{errorMsg}
</if>
<if test="fileName != null and fileName != ''">
and file_name = #{fileName}
<if test="startTime !=null and startTime != ''">
and m.sent_date >= #{startTime}
</if>
<if test="createTime != null">
and create_time = #{createTime}
<if test="endTime !=null and endTime != ''">
and #{endTime} >= m.sent_date
</if>
</where>
</select>

Loading…
Cancel
Save