Forráskód Böngészése

fix: 解析邮件详情查询优化,过滤空数据

chenjianhua 4 hónapja
szülő
commit
d95b97d10b

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

@@ -261,11 +261,28 @@ public class EmailParseService {
             Integer fileId = emailFundNavCollectionVOList.get(0).getFileId();
             Long count = emailFundNavCollectionMapper.countByFileId(fileId);
             if(count == 0L){
-                emailFundNavCollectionMapper.batchInsert(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());
+                try{
+                    emailFundNavCollectionMapper.batchInsert(emailFundNavCollectionVOList);
+                }catch (Exception ex){
+                    //如果批量插入报错,可能是因为解析的数据超过限制长度,这种情况基本是垃圾数据,直接跳过
+                    emailFundNavCollectionVOList.forEach(e -> saveEmailFundNavCollection(e));
+                }
+
             }
         }
     }
 
+    private void saveEmailFundNavCollection(EmailFundNavCollectionDO fundNavCollectionDO) {
+        try{
+            emailFundNavCollectionMapper.batchInsert(CollUtil.toList(fundNavCollectionDO));
+        }catch (Exception e){
+            //如果是异常,说明是垃圾数据
+        }
+    }
+
     private EmailFundNavCollectionDO toEmailFundNavCollectionVO(EmailFundNavDTO fundNavDTO, Integer fileId,Date parseDate) {
         EmailFundNavCollectionDO vo = new EmailFundNavCollectionDO();
         vo.setFileId(fileId);