Kaynağa Gözat

fix: 邮件解析详情整改,优化文件ID相同导致数据不一致的情况

chenjianhua 4 ay önce
ebeveyn
işleme
8ca165bba9

+ 15 - 15
service-daq/src/main/java/com/simuwang/daq/service/EmailParseService.java

@@ -203,7 +203,8 @@ public class EmailParseService {
             //记录采集表
             if(CollUtil.isNotEmpty(fundNavDTOList)){
                 List<EmailFundNavCollectionDO> emailFundNavCollectionVOList = new ArrayList<>();
-                fundNavDTOList.stream().forEach( e -> emailFundNavCollectionVOList.add(toEmailFundNavCollectionVO(e,fileId,parseDate,emailAddress,senderEmail,emailDate)));
+                Integer finalEmailId = emailId;
+                fundNavDTOList.stream().forEach(e -> emailFundNavCollectionVOList.add(toEmailFundNavCollectionVO(e, finalEmailId,fileId,parseDate,emailAddress,senderEmail,emailDate)));
                 batchSaveEmailFundNavCollection(emailFundNavCollectionVOList);
             }
             if (CollUtil.isNotEmpty(fundNavDTOList)) {
@@ -258,22 +259,20 @@ public class EmailParseService {
     }
 
     private void batchSaveEmailFundNavCollection(List<EmailFundNavCollectionDO> emailFundNavCollectionVOList) {
+        //过滤空数据
+        emailFundNavCollectionVOList = emailFundNavCollectionVOList.stream().filter(e -> (StringUtil.isNotEmpty(e.getNav())||
+                StringUtil.isNotEmpty(e.getCumulativeNavWithdrawal()) ||  StringUtil.isNotEmpty(e.getPriceDate()) ||  StringUtil.isNotEmpty(e.getFundName()) || StringUtil.isNotEmpty(e.getRegisterNumber()))).collect(Collectors.toList());
         if(CollUtil.isNotEmpty(emailFundNavCollectionVOList)){
             Integer fileId = emailFundNavCollectionVOList.get(0).getFileId();
-            Long count = emailFundNavCollectionMapper.countByFileId(fileId);
-            if(count == 0L){
-                //过滤空数据
-                emailFundNavCollectionVOList = emailFundNavCollectionVOList.stream().filter(e -> (StringUtil.isNotEmpty(e.getNav())||
-                        StringUtil.isNotEmpty(e.getCumulativeNavWithdrawal()) ||  StringUtil.isNotEmpty(e.getPriceDate()) ||  StringUtil.isNotEmpty(e.getFundName()) || StringUtil.isNotEmpty(e.getRegisterNumber()))).collect(Collectors.toList());
-                try{
-                    if(emailFundNavCollectionVOList.size() > 0){
-                        emailFundNavCollectionMapper.batchInsert(emailFundNavCollectionVOList);
-                    }
-                }catch (Exception ex){
-                    //如果批量插入报错,可能是因为解析的数据超过限制长度,这种情况基本是垃圾数据,直接跳过
-                    emailFundNavCollectionVOList.forEach(e -> saveEmailFundNavCollection(e));
+            Integer emailId = emailFundNavCollectionVOList.get(0).getEmailId();
+            emailFundNavCollectionMapper.delete(fileId,emailId);
+            try{
+                if(emailFundNavCollectionVOList.size() > 0){
+                    emailFundNavCollectionMapper.batchInsert(emailFundNavCollectionVOList);
                 }
-
+            }catch (Exception ex){
+                //如果批量插入报错,可能是因为解析的数据超过限制长度,这种情况基本是垃圾数据,直接跳过
+                emailFundNavCollectionVOList.forEach(e -> saveEmailFundNavCollection(e));
             }
         }
     }
@@ -286,9 +285,10 @@ public class EmailParseService {
         }
     }
 
-    private EmailFundNavCollectionDO toEmailFundNavCollectionVO(EmailFundNavDTO fundNavDTO, Integer fileId,Date parseDate,String email,String senderEmail,String emailDate) {
+    private EmailFundNavCollectionDO toEmailFundNavCollectionVO(EmailFundNavDTO fundNavDTO, Integer emailId,Integer fileId,Date parseDate,String email,String senderEmail,String emailDate) {
         EmailFundNavCollectionDO vo = new EmailFundNavCollectionDO();
         vo.setFileId(fileId);
+        vo.setEmailId(emailId);
         vo.setFundName(fundNavDTO.getFundName());
         vo.setAssetNet(fundNavDTO.getAssetNet());
         vo.setAssetShare(fundNavDTO.getAssetShare());