1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package com.tanpu.fund.service.impl;
import com.github.pagehelper.page.PageMethod;
import com.tanpu.common.enums.Constant;
import com.tanpu.common.model.Page;
import com.tanpu.common.model.Pageable;
import com.tanpu.common.model.product.resp.Net;
import com.tanpu.common.model.product.resp.ProductLabel;
import com.tanpu.common.resp.CommonResp;
import com.tanpu.common.utils.BigDecimalUtil;
import com.tanpu.fund.api.model.FundInfoVO;
import com.tanpu.fund.api.model.resp.FundGroupVO;
import com.tanpu.fund.api.model.resp.FundSetListVO;
import com.tanpu.fund.entity.generator.*;
import com.tanpu.fund.enums.ProStrategyEnums;
import com.tanpu.fund.enums.ProTypeEnums;
import com.tanpu.fund.feign.user.FeignClientForFatools;
import com.tanpu.fund.mapper.generator.*;
import com.tanpu.fund.service.FundCombineInfoService;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static com.tanpu.common.utils.BigDecimalUtil.multiply100;
@Service
public class FundCombineInfoServiceImpl implements FundCombineInfoService {
@Resource
private FundInfoMapper fundInfoMapper;
@Resource
private FundNavMapper fundNavMapper;
@Resource
private FundPerformanceMapper fundPerformanceMapper;
@Resource
private FundCountMapper fundCountMapper;
@Resource
private FeignClientForFatools feignClientForFatools;
@Resource
private FundCombineInfoMapper fundCombineInfoMapper;
@Override
public Page<FundSetListVO> queryFundCombines(Integer strategyType, Pageable pageable) {
// 分页查询
com.github.pagehelper.Page<FundSetListVO> page = PageMethod.startPage(pageable.getPageNumber(), pageable.getPageSize());
FundCountExample example = new FundCountExample();
example.createCriteria().andStrategyEqualTo(strategyType).andDataSourcesEqualTo(Constant.ONE_NUM)
.andStatusEqualTo(1).andDeleteTagEqualTo(Constant.ZERO_NUM);
example.setOrderByClause("sort desc,create_time desc");
List<FundCount> fundCounts = this.fundCountMapper.selectByExample(example);
List<String> fundIds = fundCounts.stream().map(FundCount::getFundId).collect(Collectors.toList());
//查询基金信息
Map<String, FundInfo> fundMap;
{
if (CollectionUtils.isEmpty(fundIds)) {
fundMap = new HashMap<>(0);
} else {
FundInfoExample fundInfoExample = new FundInfoExample();
fundInfoExample.createCriteria().andIdIn(fundIds).andDeleteTagEqualTo(Constant.ZERO_NUM);
List<FundInfo> fundInfoList = this.fundInfoMapper.selectByExample(fundInfoExample);
fundMap = fundInfoList.stream().collect(Collectors.toMap(FundInfo::getId, c -> c));
}
}
//基金收益
Map<String, FundCount> performanceMap = fundCounts.stream().collect(Collectors.toMap(FundCount::getFundId, c -> c));
//组装返回结果
List<FundSetListVO> resList = fundCounts.stream()
.filter(f -> fundMap.get(f.getFundId()) != null && performanceMap.get(f.getFundId()) != null)
.map(item -> {
FundCount fundCount = performanceMap.get(item.getFundId());
FundInfo fundInfo = fundMap.get(item.getFundId());
return FundSetListVO.builder()
.id(item.getFundId())
.name(fundInfo.getFundShortName())
.strategy(fundCount == null ? null : fundCount.getStrategy())
.strategyName(ProStrategyEnums.getName(fundCount == null ? null : fundCount.getStrategy()))
.desc(fundInfo.getDescInfo())
.ratioId(fundInfo.getPrimaryBenchmarkId())
.foundProfit(multiply100(fundCount.getRetIncep()))
.build();
}).collect(Collectors.toList());
return new Page<>(pageable, page.getTotal(), resList);
}
@Override
public FundGroupVO detail(String id) {
//查询组合基金详情
FundInfo fundInfo = this.fundInfoMapper.selectByPrimaryKey(id);
FundGroupVO resItem = FundGroupVO.builder()
.productName(fundInfo.getFundShortName())
.groupTarget(fundInfo.getCombineTarget())
.customerGroup(fundInfo.getFitGroup())
.groupComment(fundInfo.getCombineComment())
.transferComment(fundInfo.getTransferComment())
.build();
resItem.setRiskLevel(fundInfo.getRiskLevel());
//查询组合基金标签
{
CommonResp<List<ProductLabel>> resp = this.feignClientForFatools.querytagbyrelid(id);
if (resp.isSuccess()) {
resItem.setProductLabels(resp.getAttributes());
}
}
//查询最新净值
{
FundNavExample example = new FundNavExample();
example.createCriteria().andFundIdEqualTo(id).andDeleteTagEqualTo(Constant.ZERO_NUM);
example.setOrderByClause(FundNav.Column.priceDate.desc());
List<FundNav> fundNavs = this.fundNavMapper.selectByExampleWithRowbounds(example, new RowBounds(0, 1));
if (!CollectionUtils.isEmpty(fundNavs)) {
FundNav fundNav = fundNavs.get(0);
resItem.setNet(Net.builder()
.netDate(fundNav.getPriceDate().getTime())
.netValue(BigDecimalUtil.toString(fundNav.getNav(),4))
.build());
}
}
//查询最近收益
{
FundCountExample example = new FundCountExample();
example.createCriteria().andFundIdEqualTo(id).andStatusEqualTo(Constant.ONE_NUM).andDeleteTagEqualTo(Constant.ZERO_NUM);
List<FundCount> fundCounts = this.fundCountMapper.selectByExample(example);
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(fundCounts)) {
FundCount fundCount = fundCounts.get(0);
resItem.setNear1Month(multiply100(fundCount.getRet1m()));
resItem.setNear1YearRatio(multiply100(fundCount.getRet1y()));
resItem.setRetIncep(multiply100(fundCount.getRetIncep()));
}
}
//查询基金占比
{
FundCombineInfoExample example = new FundCombineInfoExample();
example.createCriteria().andPFundIdEqualTo(id).andFlagEqualTo(Constant.ZERO_NUM).andDeleteTagEqualTo(Constant.ZERO_NUM);
List<FundCombineInfo> fundCombineInfos = fundCombineInfoMapper.selectByExample(example);
if (!CollectionUtils.isEmpty(fundCombineInfos)) {
List<String> fundIdList = fundCombineInfos.stream().map(FundCombineInfo::getFundId).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(fundIdList)) {
FundInfoExample infoExample = new FundInfoExample();
infoExample.createCriteria().andIdIn(fundIdList).andDeleteTagEqualTo(Constant.ZERO_NUM);
List<FundInfo> fundInfos = fundInfoMapper.selectByExample(infoExample);
if (!CollectionUtils.isEmpty(fundInfos)) {
Map<String, FundInfo> map = fundInfos.stream().collect(Collectors.toMap(FundInfo::getId, c -> c));
List<FundInfoVO> fundInfoVOList = fundCombineInfos.stream().filter(item -> map.get(item.getFundId()) != null).map(item -> {
FundInfo info = map.get(item.getFundId());
FundInfoVO p = FundInfoVO.builder()
.fundName(info.getFundShortName())
.ratio(multiply100(item.getProportionRatio()))
.bonusTypeName(ProTypeEnums.getName(info.getFundType()))
.bonusType(info.getFundType())
.build();
return p;
}).collect(Collectors.toList());
resItem.setFundInfoVOList(fundInfoVOList);
}
}
}
}
return resItem;
}
}