From 3e88e89097bf9ee78d8e35a313579bac4512475a Mon Sep 17 00:00:00 2001
From: zhangyh <zhangyahui@wealthgrow.cn>
Date: Thu, 18 Mar 2021 14:56:00 +0800
Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E9=87=91bug=E4=BF=AE=E5=A4=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../fund/service/impl/ProductServiceImpl.java | 92 +++++++++++++------
 1 file changed, 63 insertions(+), 29 deletions(-)

diff --git a/src/main/java/com/tanpu/fund/service/impl/ProductServiceImpl.java b/src/main/java/com/tanpu/fund/service/impl/ProductServiceImpl.java
index daa2767..fe14106 100644
--- a/src/main/java/com/tanpu/fund/service/impl/ProductServiceImpl.java
+++ b/src/main/java/com/tanpu/fund/service/impl/ProductServiceImpl.java
@@ -779,9 +779,13 @@ public class ProductServiceImpl implements ProductService, Constant {
                 if (i < fundNavs.size() - 1) {
                     FundNav pre = fundNavs.get(i + 1);
 
-                    if (pre.getNav().compareTo(BigDecimal.ZERO) == 1) {
-                        BigDecimal dailyIncrease = f.getNav().subtract(pre.getNav()).divide(pre.getNav(), 4, BigDecimal.ROUND_HALF_UP);
-                        vo.setDailyIncrease(BigDecimalUtil.multiply100(dailyIncrease));
+                    if (pre.getCumulativeNavWithdrawal() != null && f.getCumulativeNavWithdrawal() != null) {
+                        if (pre.getCumulativeNavWithdrawal().compareTo(BigDecimal.ZERO) == 1) {
+                            BigDecimal dailyIncrease = f.getCumulativeNavWithdrawal().subtract(pre.getCumulativeNavWithdrawal()).divide(pre.getCumulativeNavWithdrawal(), 4, BigDecimal.ROUND_HALF_UP);
+                            vo.setDailyIncrease(BigDecimalUtil.multiply100(dailyIncrease));
+                        }
+                    } else {
+                        vo.setDailyIncrease("--");
                     }
                 }
             }
@@ -878,20 +882,25 @@ public class ProductServiceImpl implements ProductService, Constant {
                 String fundId = managerMappingList.get(0).getFundId();
                 vo.setId(fundId);
 
-                FundInfo info = infoMap.get(fundId);
-                vo.setFundName(info.getFundShortName());
-                vo.setRatioId(ProductEnums.IndexEnum.getValue(info.getPrimaryBenchmarkId()));
-                FundCount fundCount = fundCountMap.get(fundId);
-                if (fundCount != null) {
-                    vo.setRetIncep(multiply100(fundCount.getRetIncep()));
-                    vo.setNet(new Net(fundCount.getEndDate() == null ? null : fundCount.getEndDate().getTime(),
-                            BigDecimalUtil.toString(fundCount.getCumulativeNav(), 4), BigDecimalUtil.toString(fundCount.getCumulativeNav(), 4)));
-                }
+                if (infoMap != null) {
+                    if (infoMap.containsKey(fundId)) {
+                        FundInfo info = infoMap.get(fundId);
+                        vo.setFundName(info.getFundShortName());
+                        vo.setRatioId(ProductEnums.IndexEnum.getValue(info.getPrimaryBenchmarkId()));
+                    }
 
-                if (infoMap.get(fundId) != null) {
-                    FundInfo fundInfo = infoMap.get(fundId);
-                    vo.setTime(timeLong(fundInfo.getRegisterDate()));
-                    vo.setInceptionDate(timeLong(fundInfo.getInceptionDate()));
+                    FundCount fundCount = fundCountMap.get(fundId);
+                    if (fundCount != null) {
+                        vo.setRetIncep(multiply100(fundCount.getRetIncep()));
+                        vo.setNet(new Net(fundCount.getEndDate() == null ? null : fundCount.getEndDate().getTime(),
+                                BigDecimalUtil.toString(fundCount.getCumulativeNav(), 4), BigDecimalUtil.toString(fundCount.getCumulativeNav(), 4)));
+                    }
+
+                    if (infoMap.get(fundId) != null) {
+                        FundInfo fundInfo = infoMap.get(fundId);
+                        vo.setTime(timeLong(fundInfo.getRegisterDate()));
+                        vo.setInceptionDate(timeLong(fundInfo.getInceptionDate()));
+                    }
                 }
                 // 设置代表基金id 其他基金信息
                 getDelegateById(i.getId(), map, infoMap, fundCountMap, vo);
@@ -1410,10 +1419,9 @@ public class ProductServiceImpl implements ProductService, Constant {
         detailResp.setRegisterNumber(fundInfo.getRegisterNumber());
 
         if (CollectionUtils.isNotEmpty(fundCountList)) {
-            detailResp.setNear1YearProfit(BigDecimalUtil.toString(fundCountList.get(0).getRet1y(), 2));
-            detailResp.setRet1y(BigDecimalUtil.toString(fundCountList.get(0).getRet1y(), 2));
-            detailResp.setRetYtd(BigDecimalUtil.toString(fundCountList.get(0).getRetYtd(), 2));
-
+            detailResp.setNear1YearProfit(BigDecimalUtil.multiply100(fundCountList.get(0).getRet1y()));
+            detailResp.setRet1y(BigDecimalUtil.multiply100(fundCountList.get(0).getRet1y()));
+            detailResp.setRetYtd(BigDecimalUtil.multiply100(fundCountList.get(0).getRetYtd()));
         }
 
         //子策略名称
@@ -1474,15 +1482,41 @@ public class ProductServiceImpl implements ProductService, Constant {
                         Collectors.toCollection(() ->
                                 new TreeSet<>(Comparator.comparing(IfaImportedFundNav::getPriceDate))), ArrayList::new));
 
-        return new Page<>(page, startPage.getTotal(), fundNavs.stream()
-                .sorted(Comparator.comparing(IfaImportedFundNav::getPriceDate).reversed())
-                .map(f -> {
-                    TrackNetVO vo = new TrackNetVO();
-                    vo.setPriceDate(DateUtil.format(f.getPriceDate(), DatePattern.NORM_DATE_PATTERN));
-                    vo.setNav(BigDecimalUtil.toString(f.getNav(), 4));
-                    vo.setCumulativeNav(BigDecimalUtil.toString(f.getCumulativeNav(), 4));
-                    return vo;
-                }).collect(Collectors.toList()));
+        //计算 日涨幅=(今日净值-前一日净值)/前一日净值
+        List<TrackNetVO> list = new ArrayList<>();
+        for (int i = 0; i < fundNavs.size(); i++) {
+            IfaImportedFundNav f = fundNavs.get(i);
+
+            TrackNetVO vo = new TrackNetVO();
+            vo.setDailyIncrease("0.00");
+            //日涨幅
+            {
+                if (i < fundNavs.size() - 1) {
+                    IfaImportedFundNav pre = fundNavs.get(i + 1);
+
+                    if (pre.getCumulativeNav() != null && f.getCumulativeNav() != null) {
+                        if (pre.getCumulativeNav().compareTo(BigDecimal.ZERO) == 1) {
+                            BigDecimal dailyIncrease = f.getCumulativeNav().subtract(pre.getCumulativeNav()).divide(pre.getCumulativeNav(), 4, BigDecimal.ROUND_HALF_UP);
+                            vo.setDailyIncrease(BigDecimalUtil.multiply100(dailyIncrease));
+                        }
+                    } else {
+                        vo.setDailyIncrease("--");
+                    }
+                }
+            }
+
+            vo.setPriceDate(DateUtil.format(f.getPriceDate(), DatePattern.NORM_DATE_PATTERN));
+            vo.setNav(BigDecimalUtil.toString(f.getNav(), 4));
+            vo.setCumulativeNav(BigDecimalUtil.toString(f.getCumulativeNav(), 4));
+            vo.setCumulativeNavWithdrawal(BigDecimalUtil.toString(f.getCumulativeNav(), 4));
+            list.add(vo);
+        }
+
+        if (list.size() > page.getPageSize()) {
+            //移除最后一条
+            list.remove(list.size() - 1);
+        }
+        return new Page<>(page, startPage.getTotal(), list);
     }
 
     @Override
-- 
2.18.1