|
@@ -3,11 +3,14 @@ package com.smppw.analysis.domain.service.impl;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.collection.ListUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.smppw.analysis.domain.dao.FundInformationDao;
|
|
|
import com.smppw.analysis.domain.dao.IndexesProfileDao;
|
|
|
import com.smppw.analysis.domain.dao.RongzhiIndexNavDao;
|
|
|
+import com.smppw.analysis.domain.dataobject.FundSimilarDo;
|
|
|
import com.smppw.analysis.domain.dataobject.MonetaryFundProfitDO;
|
|
|
+import com.smppw.analysis.domain.dto.info.FundSimilarParams;
|
|
|
import com.smppw.analysis.domain.event.SaveCacheEvent;
|
|
|
import com.smppw.analysis.domain.gateway.CacheFactory;
|
|
|
import com.smppw.analysis.domain.gateway.CacheGateway;
|
|
@@ -15,9 +18,14 @@ import com.smppw.analysis.domain.service.BaseInfoService;
|
|
|
import com.smppw.analysis.infrastructure.config.AnalysisProperty;
|
|
|
import com.smppw.analysis.infrastructure.consts.RedisConst;
|
|
|
import com.smppw.common.cache.CaffeineLocalCache;
|
|
|
+import com.smppw.common.pojo.IStrategy;
|
|
|
+import com.smppw.common.pojo.enums.Frequency;
|
|
|
import com.smppw.common.pojo.enums.Indicator;
|
|
|
import com.smppw.common.pojo.enums.strategy.Strategy;
|
|
|
import com.smppw.constants.SecType;
|
|
|
+import com.smppw.utils.StrategyHandleUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeansException;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.context.ApplicationContextAware;
|
|
@@ -45,15 +53,15 @@ public class BaseInfoServiceImpl implements BaseInfoService, ApplicationContextA
|
|
|
public static final String IN = "IN";
|
|
|
public static final String AP = "AP";
|
|
|
private static final Map<String, Boolean> INDEX_EXIST = MapUtil.newConcurrentHashMap();
|
|
|
-
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
private final CacheGateway<Object> cacheGateway;
|
|
|
private final IndexesProfileDao indexesProfileDao;
|
|
|
private final RongzhiIndexNavDao rongzhiIndexNavDao;
|
|
|
private final FundInformationDao fundInformationDao;
|
|
|
private ApplicationContext applicationContext;
|
|
|
|
|
|
- public BaseInfoServiceImpl(AnalysisProperty property, CacheFactory factory, IndexesProfileDao indexesProfileDao,
|
|
|
- RongzhiIndexNavDao rongzhiIndexNavDao, FundInformationDao fundInformationDao) {
|
|
|
+ public BaseInfoServiceImpl(AnalysisProperty property, CacheFactory factory,
|
|
|
+ IndexesProfileDao indexesProfileDao, RongzhiIndexNavDao rongzhiIndexNavDao, FundInformationDao fundInformationDao) {
|
|
|
this.cacheGateway = factory.getCacheGateway(property.getCacheType());
|
|
|
this.indexesProfileDao = indexesProfileDao;
|
|
|
this.rongzhiIndexNavDao = rongzhiIndexNavDao;
|
|
@@ -147,6 +155,30 @@ public class BaseInfoServiceImpl implements BaseInfoService, ApplicationContextA
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public Frequency getNavFrequency(String secId) {
|
|
|
+ Frequency frequency;
|
|
|
+ String fundType = this.getSecType(secId);
|
|
|
+ if (SecType.MANAGER.equals(fundType) || SecType.COMPANY.equals(fundType)) {
|
|
|
+ frequency = Frequency.Monthly;
|
|
|
+ } else if (SecType.PRIVATELY_OFFERED_FUND.equals(fundType) ||
|
|
|
+ SecType.PUBLICLY_OFFERED_FUNDS.equals(fundType) ||
|
|
|
+ SecType.INDEX_FUND.equals(fundType) ||
|
|
|
+ SecType.RONGZHI_INDEX.equals(fundType)) {
|
|
|
+ String freq = this.fundInformationDao.getNavFrequencyByFundId(secId);
|
|
|
+ if ("天".equals(freq)) {
|
|
|
+ frequency = Frequency.Daily;
|
|
|
+ } else if ("周".equals(freq)) {
|
|
|
+ frequency = Frequency.Weekly;
|
|
|
+ } else {
|
|
|
+ frequency = Frequency.Monthly;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ frequency = Frequency.Daily;
|
|
|
+ }
|
|
|
+ return frequency;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public Map<String, String> querySecName(List<String> allSecIdList) {
|
|
|
if (CollUtil.isEmpty(allSecIdList)) {
|
|
|
return MapUtil.empty();
|
|
@@ -195,6 +227,30 @@ public class BaseInfoServiceImpl implements BaseInfoService, ApplicationContextA
|
|
|
return this.fundInformationDao.getFundRank(rankDate, fundId, indexIds, indicator);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<FundSimilarDo> getFundSimilarList(FundSimilarParams params) {
|
|
|
+ if (StrUtil.isBlank(params.getThreshold()) || !NumberUtil.isNumber(params.getThreshold())) {
|
|
|
+ logger.warn(String.format("相关性阈值 %s 设置错误,提供默认值:%s", params.getThreshold(), FundSimilarParams.DEFAULT_THRESHOLD));
|
|
|
+ params.setThreshold(FundSimilarParams.DEFAULT_THRESHOLD);
|
|
|
+ }
|
|
|
+ IStrategy strategy = StrategyHandleUtils.getStrategy(params.getStrategy());
|
|
|
+ String rankDate = this.getLatestRankRat();
|
|
|
+ List<FundSimilarDo> tempList = ListUtil.list(true);
|
|
|
+ if (params.getCalcType() == 2) {
|
|
|
+ Map<String, Object> req = MapUtil.<String, Object>builder().put("strategy", strategy.getStrategyId())
|
|
|
+ .put("tableName", "rz_hfdb_core.nav").put("trustId", params.getTrustId()).put("rankDate", rankDate).build();
|
|
|
+ tempList.addAll(this.fundInformationDao.getSameCompanyFundIds(req));
|
|
|
+ } else {
|
|
|
+ Map<String, Object> req = MapUtil.<String, Object>builder().put("strategy", strategy.getStrategyId()).put("rankNum", 50)
|
|
|
+ .put("tableName", "rz_hfdb_core.fund_indicator_ranking").put("fundId", params.getRefId()).put("rankDate", rankDate).build();
|
|
|
+ tempList.addAll(this.fundInformationDao.getSameStrategyFundIds(req));
|
|
|
+ }
|
|
|
+ List<FundSimilarDo> dataList = ListUtil.list(true);
|
|
|
+ // 过滤当前基金
|
|
|
+ dataList.addAll(tempList.stream().filter(e -> !params.getRefId().equals(e.getFundId())).collect(Collectors.toList()));
|
|
|
+ return dataList;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 把指定类型的标的的名称映射查询出来
|
|
|
*
|