|
@@ -1,5 +1,6 @@
|
|
|
package com.smppw.analysis.application.service.style;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.collection.ListUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
@@ -7,12 +8,14 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.smppw.analysis.domain.dataobject.FundStyleStatsDO;
|
|
|
import com.smppw.analysis.domain.dto.style.*;
|
|
|
import com.smppw.analysis.domain.dto.style.py.PyReq;
|
|
|
import com.smppw.analysis.domain.dto.style.py.PyReqBody;
|
|
|
import com.smppw.analysis.domain.dto.style.py.PyReqParam;
|
|
|
import com.smppw.analysis.domain.dto.style.py.PyResBody;
|
|
|
import com.smppw.analysis.domain.service.BaseInfoService;
|
|
|
+import com.smppw.analysis.domain.service.FundStyleService;
|
|
|
import com.smppw.analysis.infrastructure.config.AnalysisProperty;
|
|
|
import com.smppw.analysis.infrastructure.consts.*;
|
|
|
import com.smppw.analysis.infrastructure.exception.APIException;
|
|
@@ -27,6 +30,7 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.nio.charset.Charset;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
@@ -144,10 +148,12 @@ public class StyleServiceImpl implements StyleService {
|
|
|
|
|
|
private final String pyBaseUrl;
|
|
|
private final BaseInfoService baseInfoService;
|
|
|
+ private final FundStyleService fundStyleService;
|
|
|
|
|
|
- public StyleServiceImpl(AnalysisProperty property, BaseInfoService baseInfoService) {
|
|
|
+ public StyleServiceImpl(AnalysisProperty property, BaseInfoService baseInfoService, FundStyleService fundStyleService) {
|
|
|
this.pyBaseUrl = property.getPyUrl();
|
|
|
this.baseInfoService = baseInfoService;
|
|
|
+ this.fundStyleService = fundStyleService;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1022,52 +1028,47 @@ public class StyleServiceImpl implements StyleService {
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public Map<String, Object> rzStyle(RzStyleParams params) {
|
|
|
try {
|
|
|
-// List<Map<String, String>> initDataList = new RZTrendDao(this.jdbcTemplate, params.getSecId(), params.getStartDate(), params.getEndDate(),
|
|
|
-// params.getRaiseType(), Strategy.All).query();
|
|
|
-// List<Map<String, Object>> dataset = ListUtil.list(true);
|
|
|
-// for (Map<String, String> data : initDataList) {
|
|
|
-// Map<String, Object> temp = MapUtil.newHashMap();
|
|
|
-// temp.put("date", data.get("end_date"));
|
|
|
-// temp.put("upside", data.get("upsidecapture_ratio"));
|
|
|
-// temp.put("downside", data.get("downsidecapture_ratio"));
|
|
|
-// temp.put("style", data.get("style_type"));
|
|
|
-// dataset.add(temp);
|
|
|
-// }
|
|
|
-// Map<String, String> mapper = MapUtil.<String, String>builder(MapUtil.newHashMap(true))
|
|
|
-// .put("date", "时间").put("upside", "进攻能力").put("downside", "防御能力").put("style", "风格").build();
|
|
|
-// Map<String, Object> chart1 = MapUtil.<String, Object>builder().put("dataset", dataset)
|
|
|
-// .put("chartProductNameMapping", mapper).put("tableProductNameMapping", mapper).build();
|
|
|
-//
|
|
|
-// List<String> secIdList = ListUtil.list(true);
|
|
|
-// List<String> fundBenchmarkList = ListUtil.toList(params.getSecId(), params.getBenchmarkId());
|
|
|
-// List<String> unionIds = CollUtil.addAllIfNotContains(fundBenchmarkList, secIdList);
|
|
|
-// Map<String, Object> rzTrend = this.globalService.getDataPoint(unionIds, params.getRaiseType(), params.getUserId());
|
|
|
-// List<String> categories = MapUtil.get(rzTrend, "categories", List.class);
|
|
|
-// List<List<Map<String, Object>>> datasetList = MapUtil.get(rzTrend, "dataset", List.class);
|
|
|
-// Map<String, Object> dataset2 = MapUtil.newHashMap();
|
|
|
-// for (int i = 0; i < categories.size(); i++) {
|
|
|
-// List<Map<String, Object>> tempList = datasetList.get(i);
|
|
|
-// List<Map<String, Object>> collect = tempList.stream().map(e -> {
|
|
|
-// List<Map<String, Object>> values = MapUtil.get(e, "values", List.class);
|
|
|
-// Map<String, Object> res = MapUtil.newHashMap();
|
|
|
-// res.put("id", e.get("id"));
|
|
|
-// res.put("type", e.get("type"));
|
|
|
-// res.put("value", values.get(0).get("value"));
|
|
|
-// return res;
|
|
|
-// }).collect(Collectors.toList());
|
|
|
-// dataset2.put(categories.get(i), collect);
|
|
|
-// }
|
|
|
-// Map<String, String> mapper2 = this.secId2NameService.query(categories);
|
|
|
-// Map<String, Object> chart2 = MapUtil.<String, Object>builder().put("dataset", dataset2)
|
|
|
-// .put("chartProductNameMapping", mapper2).put("tableProductNameMapping", mapper2).build();
|
|
|
-// return MapUtil.<String, Object>builder().put("chart1", chart1).put("chart2", chart2).build();
|
|
|
- return null;
|
|
|
+ List<FundStyleStatsDO> fundStyleStatsList = fundStyleService.listFundStyleOverview(params.getSecId());
|
|
|
+ List<Map<String, Object>> dataset = ListUtil.list(true);
|
|
|
+ for (FundStyleStatsDO fundStyleStatsDO : fundStyleStatsList) {
|
|
|
+ Map<String, Object> tempMap = MapUtil.newHashMap();
|
|
|
+ tempMap.put("date", fundStyleStatsDO.getEndDate());
|
|
|
+ tempMap.put("upside", fundStyleStatsDO.getUpsideCaptureRatio1y());
|
|
|
+ tempMap.put("downside",fundStyleStatsDO.getDownsideCaptureRatio1y());
|
|
|
+ tempMap.put("style", handleFundStyle(fundStyleStatsDO.getUpsideCaptureRatio1y(),fundStyleStatsDO.getDownsideCaptureRatio1y()));
|
|
|
+ dataset.add(tempMap);
|
|
|
+ }
|
|
|
+ Map<String, String> mapper = MapUtil.<String, String>builder(MapUtil.newHashMap(true))
|
|
|
+ .put("date", "时间").put("upside", "进攻能力").put("downside", "防御能力").put("style", "风格").build();
|
|
|
+ Map<String, Object> chart1 = MapUtil.<String, Object>builder().put("dataset", dataset)
|
|
|
+ .put("chartProductNameMapping", mapper).put("tableProductNameMapping", mapper).build();
|
|
|
+
|
|
|
+ List<String> secIdList = ListUtil.list(true);
|
|
|
+ List<String> fundBenchmarkList = ListUtil.toList(params.getSecId(), params.getBenchmarkId());
|
|
|
+ List<String> unionIds = CollUtil.addAllIfNotContains(fundBenchmarkList, secIdList);
|
|
|
+ return MapUtil.<String, Object>builder().put("chart1", chart1).build();
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
logger.error("风格总览计算错误" + e.getMessage());
|
|
|
return MapUtil.empty();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private String handleFundStyle(BigDecimal upside, BigDecimal downside) {
|
|
|
+ String style;
|
|
|
+ BigDecimal standardLevel = BigDecimal.valueOf(0.5);
|
|
|
+ if (standardLevel.compareTo(upside) <= 0 && standardLevel.compareTo(downside) >= 0) {
|
|
|
+ style = "攻守兼备型";
|
|
|
+ } else if (standardLevel.compareTo(upside) > 0 && standardLevel.compareTo(downside) > 0) {
|
|
|
+ style = "防御型";
|
|
|
+ } else if (standardLevel.compareTo(upside) < 0 && standardLevel.compareTo(downside) < 0) {
|
|
|
+ style = "进攻型";
|
|
|
+ } else {
|
|
|
+ style = "风格不明显";
|
|
|
+ }
|
|
|
+ return style;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 成长价值和行业配置接口重构,支持基金、机构、经理、组合等
|
|
|
*
|