Commit b89bfb71 authored by 王亚雷's avatar 王亚雷

Merge remote-tracking branch 'origin/master'

parents cc94695e 363db6e6
...@@ -66,4 +66,6 @@ public interface FundInfoCustomMapper { ...@@ -66,4 +66,6 @@ public interface FundInfoCustomMapper {
* @return * @return
*/ */
List<FundLatestNav> getFundLatestNet(@Param("start") Date start); List<FundLatestNav> getFundLatestNet(@Param("start") Date start);
List<FundLatestNav> getFundLatestNetInRH(@Param("start") Date start);
} }
...@@ -48,14 +48,33 @@ public class FundLatestNavService { ...@@ -48,14 +48,33 @@ public class FundLatestNavService {
List<FundLatestNav> list = fundLatestNavMapper.selectByExample(example); List<FundLatestNav> list = fundLatestNavMapper.selectByExample(example);
Date startTime = list.get(0).getCreateTime(); Date startTime = list.get(0).getCreateTime();
List<FundLatestNav> latestList = fundInfoCustomMapper.getFundLatestNet(startTime); List<FundLatestNav> latestList = fundInfoCustomMapper.getFundLatestNet(startTime);
log.info("私募新净值统计, count: {}, start: {}", latestList.size(), DateUtils.format(startTime)); List<FundLatestNav> latestListRH = fundInfoCustomMapper.getFundLatestNetInRH(startTime);
if (CollectionUtils.isEmpty(latestList)) { Date newStartTime = latestList.stream().map(FundLatestNav::getCreateTime).max(Date::compareTo).orElseGet(()->null);
Date newStartTimeRH = latestListRH.stream().map(FundLatestNav::getCreateTime).max(Date::compareTo).orElseGet(()->null);
List<FundLatestNav> navList = new ArrayList<>(latestListRH.size() + latestList.size() + 1);
navList.addAll(latestList);
navList.addAll(latestListRH);
navList.sort((p1, p2) -> {
int dif = p1.getFundId().compareTo(p2.getFundId());
if (dif != 0) {
return dif;
}
if (p1.getPriceDate() == null) {
return -1;
}
if (p1.getPriceDate() == null) {
return 1;
}
return p1.getPriceDate().compareTo(p1.getPriceDate());
});
log.info("私募新净值统计, count: {}, start: {}", navList.size(), DateUtils.format(startTime));
if (CollectionUtils.isEmpty(navList)) {
log.info("私募没有新净值数据,结束"); log.info("私募没有新净值数据,结束");
return; return;
} }
int p = 0; int p = 0;
while (p < latestList.size()) { while (p < navList.size()) {
List<FundLatestNav> batchList = latestList.subList(p, Math.min(latestList.size(), p + 200)); List<FundLatestNav> batchList = navList.subList(p, Math.min(navList.size(), p + 200));
if (CollectionUtils.isEmpty(batchList)) { if (CollectionUtils.isEmpty(batchList)) {
break; break;
} }
...@@ -64,12 +83,21 @@ public class FundLatestNavService { ...@@ -64,12 +83,21 @@ public class FundLatestNavService {
latestNavExample.createCriteria().andFundIdIn(idList); latestNavExample.createCriteria().andFundIdIn(idList);
Map<String, List<FundLatestNav>> existMap = fundLatestNavMapper.selectByExample(latestNavExample) Map<String, List<FundLatestNav>> existMap = fundLatestNavMapper.selectByExample(latestNavExample)
.stream().collect(Collectors.groupingBy(FundLatestNav::getFundId)); .stream().collect(Collectors.groupingBy(FundLatestNav::getFundId));
FundLatestNavExample updateExample = new FundLatestNavExample();
for (FundLatestNav latestNav : batchList) { for (FundLatestNav latestNav : batchList) {
// 这几个字段不用更新
latestNav.setUpdateTime(null); latestNav.setUpdateTime(null);
if (existMap.containsKey(latestNav.getFundId())) { latestNav.setId(null);
latestNav.setCreateTime(null);
List<FundLatestNav> existNavs = existMap.get(latestNav.getFundId());
if (CollectionUtils.isNotEmpty(existNavs)) {
// update // update
latestNav.setId(existMap.get(latestNav.getFundId()).get(0).getId()); FundLatestNav eNav = existNavs.get(0);
fundLatestNavMapper.updateByPrimaryKeySelective(latestNav); if (eNav.getPriceDate().compareTo(latestNav.getPriceDate()) <= 0) {
updateExample.clear();
updateExample.createCriteria().andFundIdEqualTo(latestNav.getFundId());
fundLatestNavMapper.updateByExampleSelective(latestNav, updateExample);
}
} else { } else {
// insert // insert
fundLatestNavMapper.insertSelective(latestNav); fundLatestNavMapper.insertSelective(latestNav);
...@@ -78,9 +106,13 @@ public class FundLatestNavService { ...@@ -78,9 +106,13 @@ public class FundLatestNavService {
p += 200; p += 200;
} }
Date newStartTime = latestList.stream().map(FundLatestNav::getCreateTime).max(Date::compareTo).get(); if (newStartTime == null || newStartTimeRH == null) {
log.info("私募新净值起始时间本次不需要更新,newStartTime: {}, start: {}", newStartTime, newStartTimeRH);
return;
}
FundLatestNav target = new FundLatestNav(); FundLatestNav target = new FundLatestNav();
target.setCreateTime(newStartTime); // 存储较小的那个,保证两个表里的都能被扫描到.
target.setCreateTime(newStartTime.before(newStartTimeRH) ? newStartTime : newStartTimeRH);
int c = fundLatestNavMapper.updateByExampleSelective(target, example); int c = fundLatestNavMapper.updateByExampleSelective(target, example);
log.info("私募新净值更新起始时间,affected: {}, start: {}", c, DateUtils.format(newStartTime)); log.info("私募新净值更新起始时间,affected: {}, start: {}", c, DateUtils.format(newStartTime));
} }
......
...@@ -37,9 +37,7 @@ ...@@ -37,9 +37,7 @@
res.price_date as priceDate, res.price_date as priceDate,
res.nav as nav, res.nav as nav,
res.cumulative_nav as cumulativeNav, res.cumulative_nav as cumulativeNav,
res.cumulative_nav_withdrawal as cumulativeNavWithdrawal, res.cumulative_nav_withdrawal as cumulativeNavWithdrawal
res.ishigh_or_low as ishighOrLow,
res.tohigh_nav_ratio as tohighNavRatio
from from
(SELECT fund_id, max(price_date) as price_date FROM fund_nav WHERE fund_id in (SELECT fund_id, max(price_date) as price_date FROM fund_nav WHERE fund_id in
<foreach close=")" collection="list" item="fundId" open="(" separator=","> <foreach close=")" collection="list" item="fundId" open="(" separator=",">
...@@ -71,8 +69,6 @@ ...@@ -71,8 +69,6 @@
res.nav as nav, res.nav as nav,
res.cumulative_nav as cumulativeNav, res.cumulative_nav as cumulativeNav,
res.cumulative_nav_withdrawal as cumulativeNavWithdrawal, res.cumulative_nav_withdrawal as cumulativeNavWithdrawal,
res.ishigh_or_low as ishighOrLow,
res.tohigh_nav_ratio as tohighNavRatio,
res.update_time as createTime res.update_time as createTime
from from
(SELECT fund_id, max(price_date) as price_date FROM fund_nav WHERE (SELECT fund_id, max(price_date) as price_date FROM fund_nav WHERE
...@@ -82,4 +78,20 @@ ...@@ -82,4 +78,20 @@
left join fund_nav res on t.fund_id = res.fund_id and t.price_date = res.price_date left join fund_nav res on t.fund_id = res.fund_id and t.price_date = res.price_date
</select> </select>
<select id="getFundLatestNetInRH" resultType="com.tanpu.fund.entity.generator.FundLatestNav">
select
res.fund_id as fundId,
res.price_date as priceDate,
res.nav as nav,
res.cumulative_nav as cumulativeNav,
res.cumulative_nav_withdrawal as cumulativeNavWithdrawal,
res.update_time as createTime
from
(SELECT fund_id, max(price_date) as price_date FROM fund_nav_sub_pp_rh_view WHERE
update_time <![CDATA[ >]]> #{start, jdbcType=TIMESTAMP} and delete_tag = 0
and nav is not null and cumulative_nav is not null
GROUP by fund_id) t
left join fund_nav_sub_pp_rh_view res on t.fund_id = res.fund_id and t.price_date = res.price_date
</select>
</mapper> </mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment