فهرست منبع

feat:已经解析成功的邮件不用重新下载

wangzaijun 2 هفته پیش
والد
کامیت
1ca782e5bd

+ 12 - 7
mo-daq/src/main/java/com/smppw/modaq/domain/mapper/EmailParseInfoMapper.java

@@ -15,11 +15,11 @@ public interface EmailParseInfoMapper {
 
 //    List<EmailParseInfoDO> searchEmailList(EmailParseQuery emailParseQuery);
 
-    EmailParseInfoDO searchEmailById(@Param("id") Integer id);
-
-    Integer searchEmailCount(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("parseStatus") Integer parseStatus);
-
-    EmailParseInfoDO queryById(@Param("id") Integer id);
+//    EmailParseInfoDO searchEmailById(@Param("id") Integer id);
+//
+//    Integer searchEmailCount(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("parseStatus") Integer parseStatus);
+//
+//    EmailParseInfoDO queryById(@Param("id") Integer id);
 
 //    long countEmailList(EmailParseQuery emailParseQuery);
 
@@ -33,7 +33,12 @@ public interface EmailParseInfoMapper {
 //
 //    Long countpdfNoData(@Param("item") DataboardQuery databoardQuery, @Param("errorInfo")String errorInfo);
 
-    Long countEmailTotal(@Param("emailType") Integer emailType);
+//    Long countEmailTotal(@Param("emailType") Integer emailType);
+//
+//    EmailParseInfoDO searchEmail(EmailParseInfoDO entity);
 
-    EmailParseInfoDO searchEmail(EmailParseInfoDO entity);
+    Integer countEmailByInfoAndStatus(@Param("emailTitle") String emailTitle,
+                                      @Param("senderAddress") String senderAddress,
+                                      @Param("emailAddress") String emailAddress,
+                                      @Param("emailDate") String emailDate);
 }

+ 12 - 5
mo-daq/src/main/java/com/smppw/modaq/domain/service/EmailParseService.java

@@ -78,7 +78,6 @@ public class EmailParseService {
             // 按需添加其他类型...
     );
 
-    //    private final EmailFieldMappingMapper emailFieldMapper;
     private final EmailParseInfoMapper emailParseInfoMapper;
     private final EmailFileInfoMapper emailFileInfoMapper;
     /* 报告解析和入库的方法 */
@@ -859,6 +858,7 @@ public class EmailParseService {
             log.warn("{} 获取不到邮件 -> 邮箱信息:{},开始时间:{},结束时间:{}", folderName, mailboxInfoDTO, startDate, endDate);
             return MapUtil.newHashMap();
         }
+        String emailAddress = mailboxInfoDTO.getAccount();
         Map<String, List<EmailContentInfoDTO>> emailMessageMap = MapUtil.newHashMap();
         for (Message message : messages) {
             long start = System.currentTimeMillis();
@@ -874,14 +874,13 @@ public class EmailParseService {
                 if (log.isInfoEnabled()) {
                     log.info("{} 邮件{} 数据获取中,邮件时间:{}", folderName, emailTitle, emailDateStr);
                 }
-
                 boolean isNotParseConditionSatisfied = emailDate == null
                         || (endDate != null && emailDate.compareTo(endDate) > 0)
                         || (startDate != null && emailDate.compareTo(startDate) < 0);
                 if (isNotParseConditionSatisfied) {
                     String st = DateUtil.formatDateTime(startDate);
                     String ed = DateUtil.formatDateTime(endDate);
-                    log.warn("{} 邮件[{}]日期{}不在区间内【{} ~ {}】", folderName, emailTitle, emailDateStr, st, ed);
+                    log.warn("{} 邮件{} 发送时间{}不在区间内【{} ~ {}】", folderName, emailTitle, emailDateStr, st, ed);
                     continue;
                 }
                 String senderEmail = getSenderEmail(message);
@@ -890,15 +889,23 @@ public class EmailParseService {
                     log.warn("{} 邮件不满足解析条件 -> 邮件主题:{},邮件日期:{}", folderName, emailTitle, emailDateStr);
                     continue;
                 }
+                // 成功解析的邮件不用重复下载
+                Integer okNum = this.emailParseInfoMapper.countEmailByInfoAndStatus(emailTitle, senderEmail, emailAddress, emailDateStr);
+                if (okNum > 0) {
+                    if (log.isInfoEnabled()) {
+                        log.info("{} 邮件{} 已经存在解析完成的记录,不要重复下载了。", folderName, emailTitle);
+                    }
+                    continue;
+                }
                 if (log.isInfoEnabled()) {
                     log.info("{} 邮件{} 基本信息获取完成,开始下载附件!邮件日期:{}", folderName, emailTitle, emailDateStr);
                 }
                 Object content = message.getContent();
 
                 if (content instanceof Multipart multipart) {
-                    this.reMultipart(mailboxInfoDTO.getAccount(), emailTitle, emailDate, multipart, dtos);
+                    this.reMultipart(emailAddress, emailTitle, emailDate, multipart, dtos);
                 } else if (content instanceof Part part) {
-                    this.rePart(mailboxInfoDTO.getAccount(), emailTitle, emailDate, part, dtos);
+                    this.rePart(emailAddress, emailTitle, emailDate, part, dtos);
                 } else {
                     log.warn("{} 不支持的邮件数据 {}", folderName, emailTitle);
                 }

+ 57 - 47
mo-daq/src/main/resources/mapper/EmailParseInfoMapper.xml

@@ -109,33 +109,33 @@
 <!--        </choose>-->
 <!--     limit #{offset},#{pageSize}-->
 <!--    </select>-->
-    <select id="searchEmailById" resultMap="BaseResultMap">
-        <include refid="selectEmailParse"/>
-        where epi.isvalid =1 and epi.id =#{id}
-    </select>
+<!--    <select id="searchEmailById" resultMap="BaseResultMap">-->
+<!--        <include refid="selectEmailParse"/>-->
+<!--        where epi.isvalid =1 and epi.id =#{id}-->
+<!--    </select>-->
 
-    <select id="searchEmailCount" resultType="java.lang.Integer">
-        select count(1) from mo_email_parse_info where isvalid=1
-        <if test="parseStatus != null and parseStatus != -1">
-            and parse_status=#{parseStatus}
-        </if>
-        <if test="parseStatus != null and parseStatus == -1">
-            and parse_status != 1
-        </if>
-        <if test="startDate != null  and startDate != ''">
-            and parse_date >= #{startDate}
-        </if>
-        <if test="endDate != null and endDate != ''">
-            and parse_date <![CDATA[ <= ]]> #{endDate}
-        </if>
-    </select>
+<!--    <select id="searchEmailCount" resultType="java.lang.Integer">-->
+<!--        select count(1) from mo_email_parse_info where isvalid=1-->
+<!--        <if test="parseStatus != null and parseStatus != -1">-->
+<!--            and parse_status=#{parseStatus}-->
+<!--        </if>-->
+<!--        <if test="parseStatus != null and parseStatus == -1">-->
+<!--            and parse_status != 1-->
+<!--        </if>-->
+<!--        <if test="startDate != null  and startDate != ''">-->
+<!--            and parse_date >= #{startDate}-->
+<!--        </if>-->
+<!--        <if test="endDate != null and endDate != ''">-->
+<!--            and parse_date <![CDATA[ <= ]]> #{endDate}-->
+<!--        </if>-->
+<!--    </select>-->
 
-    <select id="queryById" resultMap="BaseResultMap">
-        select id, email,email_key, email_date, parse_date, email_title, email_type, sender_email,parse_status,attr_size
-        from mo_email_parse_info
-        where isvalid = 1
-          and id = #{id}
-    </select>
+<!--    <select id="queryById" resultMap="BaseResultMap">-->
+<!--        select id, email,email_key, email_date, parse_date, email_title, email_type, sender_email,parse_status,attr_size-->
+<!--        from mo_email_parse_info-->
+<!--        where isvalid = 1-->
+<!--          and id = #{id}-->
+<!--    </select>-->
 <!--    <select id="countEmailList" resultType="java.lang.Long"-->
 <!--            parameterType="com.simuwang.base.pojo.dto.query.EmailParseQuery">-->
 <!--        select count(*) from PPW_EMAIL.email_parse_info epi-->
@@ -231,28 +231,38 @@
 <!--            and fail_reason like concat('%',#{errorInfo},'%')-->
 <!--        </if>-->
 <!--    </select>-->
-    <select id="countEmailTotal" resultType="java.lang.Long">
-        select count(1) from mo_email_parse_info where isvalid=1
-        <if test="emailType !=null">
-            and email_type = #{emailType}
-        </if>
-    </select>
+<!--    <select id="countEmailTotal" resultType="java.lang.Long">-->
+<!--        select count(1) from mo_email_parse_info where isvalid=1-->
+<!--        <if test="emailType !=null">-->
+<!--            and email_type = #{emailType}-->
+<!--        </if>-->
+<!--    </select>-->
+
+<!--    <select id="searchEmail" parameterType="com.smppw.modaq.domain.entity.EmailParseInfoDO" resultMap="BaseResultMap">-->
+<!--        select *-->
+<!--        from mo_email_parse_info where isvalid = 1-->
+<!--        <if test="senderEmail !=null and senderEmail != ''">-->
+<!--            and sender_email = #{senderEmail}-->
+<!--        </if>-->
+<!--        <if test="email != null  and email != ''">-->
+<!--            and email = #{email}-->
+<!--        </if>-->
+<!--        <if test="emailDate != null">-->
+<!--            and email_date = #{emailDate}-->
+<!--        </if>-->
+<!--        <if test="emailTitle != null  and emailTitle != ''">-->
+<!--            and email_title = #{emailTitle}-->
+<!--        </if>-->
+<!--        limit 1-->
+<!--    </select>-->
 
-    <select id="searchEmail" parameterType="com.smppw.modaq.domain.entity.EmailParseInfoDO" resultMap="BaseResultMap">
-        select *
-        from mo_email_parse_info where isvalid = 1
-        <if test="senderEmail !=null and senderEmail != ''">
-            and sender_email = #{senderEmail}
-        </if>
-        <if test="email != null  and email != ''">
-            and email = #{email}
-        </if>
-        <if test="emailDate != null">
-            and email_date = #{emailDate}
-        </if>
-        <if test="emailTitle != null  and emailTitle != ''">
-            and email_title = #{emailTitle}
-        </if>
-        limit 1
+    <select id="countEmailByInfoAndStatus" resultType="java.lang.Integer">
+        select count(1)
+        from mo_email_parse_info t
+        where t.sender_email = #{senderAddress}
+          and t.email = #{emailAddress}
+          and t.email_date = #{emailDate}
+          and t.email_title = #{emailTitle}
+          and t.parse_status = 1
     </select>
 </mapper>

+ 1 - 1
mo-daq/src/test/java/com/smppw/modaq/MoDaqApplicationTests.java

@@ -42,7 +42,7 @@ public class MoDaqApplicationTests {
     @Test
     public void reportTest() {
         MailboxInfoDTO emailInfoDTO = this.buildMailbox("*@simuwang.com", "*");
-        Date startDate = DateUtil.parse("2025-06-10 11:20:00", DateConst.YYYY_MM_DD_HH_MM_SS);
+        Date startDate = DateUtil.parse("2025-06-04 11:20:00", DateConst.YYYY_MM_DD_HH_MM_SS);
         Date endDate = DateUtil.parse("2025-06-10 18:56:00", DateConst.YYYY_MM_DD_HH_MM_SS);
         try {
             List<String> folderNames = ListUtil.list(false);