|
@@ -1,5 +1,6 @@
|
|
|
package com.simuwang.daq.service;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.exceptions.ExceptionUtil;
|
|
@@ -57,12 +58,15 @@ public class EmailParseService {
|
|
|
private final EmailFundNavMapper emailFundNavMapper;
|
|
|
private final EmailFundAssetMapper emailFundAssetMapper;
|
|
|
private final FundAliasMapper fundAliasMapper;
|
|
|
+ private final AssetMapper assetMapper;
|
|
|
+ private final NavMapper navMapper;
|
|
|
|
|
|
public EmailParseService(EmailTypeRuleMapper emailTypeRuleMapper, EmailRuleConfig emailRuleConfig,
|
|
|
EmailFieldMappingMapper emailFieldMapper, EmailParserFactory emailParserFactory,
|
|
|
EmailParseInfoMapper emailParseInfoMapper, FundInfoMapper fundInfoMapper,
|
|
|
EmailFileInfoMapper emailFileInfoMapper, EmailFundNavMapper emailFundNavMapper,
|
|
|
- EmailFundAssetMapper emailFundAssetMapper, FundAliasMapper fundAliasMapper) {
|
|
|
+ EmailFundAssetMapper emailFundAssetMapper, FundAliasMapper fundAliasMapper,
|
|
|
+ AssetMapper assetMapper, NavMapper navMapper) {
|
|
|
this.emailTypeRuleMapper = emailTypeRuleMapper;
|
|
|
this.emailRuleConfig = emailRuleConfig;
|
|
|
this.emailFieldMapper = emailFieldMapper;
|
|
@@ -73,6 +77,8 @@ public class EmailParseService {
|
|
|
this.emailFundNavMapper = emailFundNavMapper;
|
|
|
this.emailFundAssetMapper = emailFundAssetMapper;
|
|
|
this.fundAliasMapper = fundAliasMapper;
|
|
|
+ this.assetMapper = assetMapper;
|
|
|
+ this.navMapper = navMapper;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -144,7 +150,7 @@ public class EmailParseService {
|
|
|
}
|
|
|
for (EmailFundNavDTO fundNavDTO : fundNavDTOList) {
|
|
|
// 设置净值数据的解析状态
|
|
|
- setNavParseStatus(fundNavDTO, emailTitle, emailDate);
|
|
|
+ setNavParseStatus(fundNavDTO, emailTitle);
|
|
|
}
|
|
|
// 保存净值表和规模表
|
|
|
saveNavAndAssetNet(fileId, fundNavDTOList, parseDate);
|
|
@@ -162,15 +168,61 @@ public class EmailParseService {
|
|
|
}
|
|
|
// 净值数据
|
|
|
List<EmailFundNavDO> emailFundNavDOList = fundNavDTOList.stream()
|
|
|
- .map(e -> buildEmailFundNavDo(fileId, e, parseDate)).flatMap(List::stream).collect(Collectors.toList());
|
|
|
+ .map(e -> buildEmailFundNavDo(fileId, e, parseDate)).filter(CollUtil::isNotEmpty).flatMap(List::stream).collect(Collectors.toList());
|
|
|
if (CollUtil.isNotEmpty(emailFundNavDOList)) {
|
|
|
emailFundNavMapper.batchInsert(emailFundNavDOList);
|
|
|
+ List<NavDO> navDOList = emailFundNavDOList.stream().filter(e -> StrUtil.isNotBlank(e.getFundId()))
|
|
|
+ .map(e -> BeanUtil.copyProperties(e, NavDO.class)).collect(Collectors.toList());
|
|
|
+ saveNavDo(navDOList);
|
|
|
}
|
|
|
// 保存规模数据
|
|
|
List<EmailFundAssetDO> emailFundAssetDOList = fundNavDTOList.stream()
|
|
|
- .map(e -> buildEmailFundAssetDo(fileId, e, parseDate)).flatMap(List::stream).collect(Collectors.toList());
|
|
|
+ .map(e -> buildEmailFundAssetDo(fileId, e, parseDate)).filter(CollUtil::isNotEmpty).flatMap(List::stream).collect(Collectors.toList());
|
|
|
if (CollUtil.isNotEmpty(emailFundAssetDOList)) {
|
|
|
emailFundAssetMapper.batchInsert(emailFundAssetDOList);
|
|
|
+ List<AssetDO> assetDOList = emailFundAssetDOList.stream().filter(e -> StrUtil.isNotBlank(e.getFundId()))
|
|
|
+ .map(e -> BeanUtil.copyProperties(e, AssetDO.class)).collect(Collectors.toList());
|
|
|
+ saveAssetDo(assetDOList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveNavDo(List<NavDO> navDOList) {
|
|
|
+ if (CollUtil.isEmpty(navDOList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, List<NavDO>> fundIdNavMap = navDOList.stream().collect(Collectors.groupingBy(NavDO::getFundId));
|
|
|
+ for (Map.Entry<String, List<NavDO>> entry : fundIdNavMap.entrySet()) {
|
|
|
+ List<NavDO> navDOS = entry.getValue();
|
|
|
+ List<String> priceDateList = navDOS.stream().map(NavDO::getPriceDate).map(e -> DateUtil.format(e, DateConst.YYYY_MM_DD)).collect(Collectors.toList());
|
|
|
+ List<String> dateList = navMapper.queryFundNavByDate(entry.getKey(), priceDateList);
|
|
|
+ List<NavDO> updateNavDoList = navDOS.stream().filter(e -> dateList.contains(DateUtil.format(e.getPriceDate(), DateConst.YYYY_MM_DD))).collect(Collectors.toList());
|
|
|
+ List<NavDO> insertNavDoList = navDOS.stream().filter(e -> !dateList.contains(DateUtil.format(e.getPriceDate(), DateConst.YYYY_MM_DD))).collect(Collectors.toList());
|
|
|
+ if(CollUtil.isNotEmpty(insertNavDoList)){
|
|
|
+ navMapper.batchInsert(insertNavDoList);
|
|
|
+ }
|
|
|
+ if(CollUtil.isNotEmpty(updateNavDoList)){
|
|
|
+ navMapper.batchUpdate(updateNavDoList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveAssetDo(List<AssetDO> assetDOList) {
|
|
|
+ if (CollUtil.isEmpty(assetDOList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, List<AssetDO>> fundIdNavMap = assetDOList.stream().collect(Collectors.groupingBy(AssetDO::getFundId));
|
|
|
+ for (Map.Entry<String, List<AssetDO>> entry : fundIdNavMap.entrySet()) {
|
|
|
+ List<AssetDO> assetDOS = entry.getValue();
|
|
|
+ List<String> priceDateList = assetDOS.stream().map(AssetDO::getPriceDate).map(e -> DateUtil.format(e, DateConst.YYYY_MM_DD)).collect(Collectors.toList());
|
|
|
+ List<String> dateList = assetMapper.queryFundNavByDate(entry.getKey(), priceDateList);
|
|
|
+ List<AssetDO> updateAssetDoList = assetDOS.stream().filter(e -> dateList.contains(DateUtil.format(e.getPriceDate(), DateConst.YYYY_MM_DD))).collect(Collectors.toList());
|
|
|
+ List<AssetDO> insertAssetDoList = assetDOS.stream().filter(e -> !dateList.contains(DateUtil.format(e.getPriceDate(), DateConst.YYYY_MM_DD))).collect(Collectors.toList());
|
|
|
+ if(CollUtil.isNotEmpty(insertAssetDoList)){
|
|
|
+ assetMapper.batchInsert(insertAssetDoList);
|
|
|
+ }
|
|
|
+ if(CollUtil.isNotEmpty(updateAssetDoList)){
|
|
|
+ assetMapper.batchUpdate(updateAssetDoList);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -222,6 +274,9 @@ public class EmailParseService {
|
|
|
Date priceDate = DateUtil.parse(fundNavDTO.getPriceDate(), DateConst.YYYY_MM_DD);
|
|
|
BigDecimal nav = StrUtil.isNotBlank(fundNavDTO.getNav()) ? new BigDecimal(fundNavDTO.getNav()) : null;
|
|
|
BigDecimal cumulativeNavWithdrawal = StrUtil.isNotBlank(fundNavDTO.getCumulativeNavWithdrawal()) ? new BigDecimal(fundNavDTO.getCumulativeNavWithdrawal()) : null;
|
|
|
+ if (nav == null && cumulativeNavWithdrawal == null) {
|
|
|
+ return CollUtil.newArrayList();
|
|
|
+ }
|
|
|
Integer isStored = fundNavDTO.getParseStatus() != null && !fundNavDTO.getParseStatus().equals(NavParseStatusConst.NAV_DEFICIENCY)
|
|
|
&& !fundNavDTO.getParseStatus().equals(NavParseStatusConst.NOT_MATCH) ? 1 : 0;
|
|
|
if (CollUtil.isNotEmpty(fundNavDTO.getFundIdList())) {
|
|
@@ -282,11 +337,10 @@ public class EmailParseService {
|
|
|
return emailFileInfoDO;
|
|
|
}
|
|
|
|
|
|
- private void setNavParseStatus(EmailFundNavDTO fundNavDTO, String emailTitle, String emailDate) {
|
|
|
- Integer navParseStatus = getDataParseStatus(fundNavDTO);
|
|
|
- fundNavDTO.setParseStatus(navParseStatus);
|
|
|
- if (navParseStatus.equals(NavParseStatusConst.NAV_DEFICIENCY)) {
|
|
|
- log.info("判断数据的解析状态 -> 邮件主题:{},邮件日期:{},数据解析状态:{}", emailTitle, emailDate, fundNavDTO.getParseStatus());
|
|
|
+ private void setNavParseStatus(EmailFundNavDTO fundNavDTO, String emailTitle) {
|
|
|
+ // 1.单位净值或累计净值缺失
|
|
|
+ if (StrUtil.isBlank(fundNavDTO.getNav()) || StrUtil.isBlank(fundNavDTO.getCumulativeNavWithdrawal())) {
|
|
|
+ fundNavDTO.setParseStatus(NavParseStatusConst.NAV_DEFICIENCY);
|
|
|
return;
|
|
|
}
|
|
|
// 2.匹配基金
|
|
@@ -295,6 +349,21 @@ public class EmailParseService {
|
|
|
fundNavDTO.setParseStatus(NavParseStatusConst.NOT_MATCH);
|
|
|
}
|
|
|
fundNavDTO.setFundIdList(fundIdList);
|
|
|
+ // 考虑单独规模文件时 -> 无单位净值和累计净值
|
|
|
+ // 3.单位净值或累计净值不大于0
|
|
|
+ if (!emailTitle.contains("规模")) {
|
|
|
+ if (StrUtil.isBlank(fundNavDTO.getNav()) || StrUtil.isBlank(fundNavDTO.getCumulativeNavWithdrawal())
|
|
|
+ || (fundNavDTO.getNav().compareTo("0") <= 0 || fundNavDTO.getCumulativeNavWithdrawal().compareTo("0") <= 0)) {
|
|
|
+ fundNavDTO.setParseStatus(NavParseStatusConst.NAV_NEGATIVE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 4.资产净值不大于0
|
|
|
+ if (StrUtil.isNotBlank(fundNavDTO.getAssetNet()) && fundNavDTO.getAssetNet().compareTo("0") <= 0) {
|
|
|
+ fundNavDTO.setParseStatus(NavParseStatusConst.ASSET_NET_NEGATIVE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ fundNavDTO.setParseStatus(NavParseStatusConst.SUCCESS);
|
|
|
}
|
|
|
|
|
|
private List<String> matchFund(String fundName, String registerNumber) {
|
|
@@ -356,22 +425,6 @@ public class EmailParseService {
|
|
|
return emailParseInfoDO;
|
|
|
}
|
|
|
|
|
|
- private Integer getDataParseStatus(EmailFundNavDTO fundNavDTO) {
|
|
|
- // 1.单位净值或累计净值缺失
|
|
|
- if (StrUtil.isBlank(fundNavDTO.getNav()) || StrUtil.isBlank(fundNavDTO.getCumulativeNavWithdrawal())) {
|
|
|
- return NavParseStatusConst.NAV_DEFICIENCY;
|
|
|
- }
|
|
|
- // 3.单位净值或累计净值不大于0
|
|
|
- if (fundNavDTO.getNav().compareTo("0") <= 0 || fundNavDTO.getCumulativeNavWithdrawal().compareTo("0") <= 0) {
|
|
|
- return NavParseStatusConst.NAV_NEGATIVE;
|
|
|
- }
|
|
|
- // 4.资产净值不大于0
|
|
|
- if (StrUtil.isNotBlank(fundNavDTO.getAssetNet()) && fundNavDTO.getAssetNet().compareTo("0") <= 0) {
|
|
|
- return NavParseStatusConst.ASSET_NET_NEGATIVE;
|
|
|
- }
|
|
|
- return NavParseStatusConst.SUCCESS;
|
|
|
- }
|
|
|
-
|
|
|
public Map<String, List<String>> getEmailFieldMapping() {
|
|
|
List<EmailFieldMappingDO> emailFieldMappingDOList = emailFieldMapper.getEmailFieldMapping();
|
|
|
return emailFieldMappingDOList.stream()
|