|
@@ -3,223 +3,119 @@ package com.smppw.analysis.domain.service.impl;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.ListUtil;
|
|
import cn.hutool.core.collection.ListUtil;
|
|
import cn.hutool.core.map.MapUtil;
|
|
import cn.hutool.core.map.MapUtil;
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
|
import com.smppw.analysis.domain.dao.FundInformationDao;
|
|
import com.smppw.analysis.domain.dao.FundInformationDao;
|
|
-import com.smppw.analysis.domain.dao.IndexesProfileDao;
|
|
|
|
-import com.smppw.analysis.domain.dao.nav.RongzhiIndexNavDao;
|
|
|
|
-import com.smppw.analysis.domain.dataobject.CommonIndexDO;
|
|
|
|
-import com.smppw.analysis.domain.dataobject.MonetaryFundProfitDO;
|
|
|
|
import com.smppw.analysis.domain.dataobject.PrivatelyFundBaseInfoDo;
|
|
import com.smppw.analysis.domain.dataobject.PrivatelyFundBaseInfoDo;
|
|
import com.smppw.analysis.domain.dataobject.PubliclyFundBaseInfoDo;
|
|
import com.smppw.analysis.domain.dataobject.PubliclyFundBaseInfoDo;
|
|
-import com.smppw.analysis.domain.event.SaveCacheEvent;
|
|
|
|
-import com.smppw.analysis.domain.gateway.CacheFactory;
|
|
|
|
-import com.smppw.analysis.domain.gateway.CacheGateway;
|
|
|
|
-import com.smppw.analysis.domain.mapper.core.CommonIndexMapper;
|
|
|
|
import com.smppw.analysis.domain.service.BaseInfoService;
|
|
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.ValueLabelVO;
|
|
|
|
-import com.smppw.common.pojo.enums.Frequency;
|
|
|
|
-import com.smppw.common.pojo.enums.strategy.IStrategy;
|
|
|
|
-import com.smppw.constants.SecType;
|
|
|
|
import com.smppw.utils.StrategyHandleUtils;
|
|
import com.smppw.utils.StrategyHandleUtils;
|
|
-import org.springframework.beans.BeansException;
|
|
|
|
-import org.springframework.context.ApplicationContext;
|
|
|
|
-import org.springframework.context.ApplicationContextAware;
|
|
|
|
-import org.springframework.lang.NonNull;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
-public class BaseInfoServiceImpl implements BaseInfoService, ApplicationContextAware {
|
|
|
|
- public static final String HF = "HF";
|
|
|
|
- public static final String MF = "MF";
|
|
|
|
- public static final String CF = "CF";
|
|
|
|
- public static final String FA = "FA";
|
|
|
|
- public static final String CI = "CI";
|
|
|
|
- public static final String CO = "CO";
|
|
|
|
- public static final String PL = "PL";
|
|
|
|
- public static final String PO = "PO";
|
|
|
|
- public static final String IN = "IN";
|
|
|
|
- public static final String AP = "AP";
|
|
|
|
- private static final Map<String, Boolean> INDEX_EXIST = MapUtil.newConcurrentHashMap();
|
|
|
|
- private final CacheGateway<Object> cacheGateway;
|
|
|
|
- private final IndexesProfileDao indexesProfileDao;
|
|
|
|
- private final RongzhiIndexNavDao rongzhiIndexNavDao;
|
|
|
|
|
|
+public class BaseInfoServiceImpl implements BaseInfoService {
|
|
|
|
+// private final CacheGateway<Object> cacheGateway;
|
|
|
|
+// private final IndexesProfileDao indexesProfileDao;
|
|
private final FundInformationDao fundInformationDao;
|
|
private final FundInformationDao fundInformationDao;
|
|
- private final CommonIndexMapper commonIndexMapper;
|
|
|
|
- private ApplicationContext applicationContext;
|
|
|
|
|
|
+// private final CommonIndexMapper commonIndexMapper;
|
|
|
|
+// private ApplicationContext applicationContext;
|
|
|
|
|
|
- public BaseInfoServiceImpl(AnalysisProperty property, CacheFactory cacheFactory, IndexesProfileDao indexesProfileDao,
|
|
|
|
- RongzhiIndexNavDao rongzhiIndexNavDao, FundInformationDao fundInformationDao, CommonIndexMapper commonIndexMapper) {
|
|
|
|
- this.cacheGateway = cacheFactory.getCacheGateway(property.getCacheType());
|
|
|
|
- this.indexesProfileDao = indexesProfileDao;
|
|
|
|
- this.rongzhiIndexNavDao = rongzhiIndexNavDao;
|
|
|
|
|
|
+ public BaseInfoServiceImpl(FundInformationDao fundInformationDao) {
|
|
|
|
+// this.cacheGateway = cacheFactory.getCacheGateway(property.getCacheType());
|
|
|
|
+// this.indexesProfileDao = indexesProfileDao;
|
|
this.fundInformationDao = fundInformationDao;
|
|
this.fundInformationDao = fundInformationDao;
|
|
- this.commonIndexMapper = commonIndexMapper;
|
|
|
|
|
|
+// this.commonIndexMapper = commonIndexMapper;
|
|
}
|
|
}
|
|
|
|
+//
|
|
|
|
+// @Override
|
|
|
|
+// public void setApplicationContext(@NonNull ApplicationContext applicationContext) throws BeansException {
|
|
|
|
+// this.applicationContext = applicationContext;
|
|
|
|
+// }
|
|
|
|
|
|
- @Override
|
|
|
|
- public void setApplicationContext(@NonNull ApplicationContext applicationContext) throws BeansException {
|
|
|
|
- this.applicationContext = applicationContext;
|
|
|
|
- }
|
|
|
|
|
|
+// @Override
|
|
|
|
+// public List<ValueLabelVO> getCommonIndexList() {
|
|
|
|
+// List<CommonIndexDO> dataList = this.commonIndexMapper.selectList();
|
|
|
|
+// return dataList.stream().map(e -> new ValueLabelVO(e.getIndexId(), e.getIndexName())).collect(Collectors.toList());
|
|
|
|
+// }
|
|
|
|
|
|
- @Override
|
|
|
|
- public List<ValueLabelVO> getCommonIndexList() {
|
|
|
|
- List<CommonIndexDO> dataList = this.commonIndexMapper.selectList();
|
|
|
|
- return dataList.stream().map(e -> new ValueLabelVO(e.getIndexId(), e.getIndexName())).collect(Collectors.toList());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public String getSecType(String secId) {
|
|
|
|
- if (secId == null) {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- if (secId.startsWith(HF)) {
|
|
|
|
- return SecType.PRIVATELY_OFFERED_FUND;
|
|
|
|
- } else if (secId.startsWith(MF)) {
|
|
|
|
- return SecType.PUBLICLY_OFFERED_FUNDS;
|
|
|
|
- } else if (secId.startsWith(CF)) {
|
|
|
|
- return SecType.PRIVATE_FUND;
|
|
|
|
- } else if (secId.startsWith(FA)) {
|
|
|
|
- return SecType.FACTOR;
|
|
|
|
- } else if (secId.startsWith(CI)) {
|
|
|
|
- return SecType.UDF_INDEX;
|
|
|
|
- } else if (secId.startsWith(CO)) {
|
|
|
|
- return SecType.COMPANY;
|
|
|
|
- } else if (secId.startsWith(PL)) {
|
|
|
|
- return SecType.MANAGER;
|
|
|
|
- } else if (secId.startsWith(PO)) {
|
|
|
|
- return SecType.COMBINATION;
|
|
|
|
- } else if (StrUtil.isNumeric(secId)) {
|
|
|
|
- IStrategy strategy = StrategyHandleUtils.getStrategy(secId);
|
|
|
|
- if (strategy != null) {
|
|
|
|
- return SecType.STRATEGY;
|
|
|
|
- }
|
|
|
|
- } else if (secId.startsWith(IN)) {
|
|
|
|
- List<String> thirdIndexes = CaffeineLocalCache.getThirdIndexes();
|
|
|
|
- if (thirdIndexes != null && thirdIndexes.contains(secId)) {
|
|
|
|
- return SecType.THIRD_INDEX_FUND;
|
|
|
|
- }
|
|
|
|
- List<String> riskOfFreeIdList = CaffeineLocalCache.getRiskOfFreeId();
|
|
|
|
- if (riskOfFreeIdList != null && riskOfFreeIdList.contains(secId)) {
|
|
|
|
- return SecType.RISK_OF_FREE;
|
|
|
|
- }
|
|
|
|
- Boolean isExist = INDEX_EXIST.getOrDefault(secId, false);
|
|
|
|
- if (!isExist) {
|
|
|
|
- isExist = rongzhiIndexNavDao.isExist(secId);
|
|
|
|
- INDEX_EXIST.put(secId, isExist);
|
|
|
|
- return SecType.INDEX_FUND;
|
|
|
|
- } else {
|
|
|
|
- return SecType.RONGZHI_INDEX;
|
|
|
|
- }
|
|
|
|
- } else if (secId.startsWith(AP)) {
|
|
|
|
- return SecType.ADVISORY_POOL_CURVE;
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
|
|
+// @Override
|
|
|
|
+// public Frequency getNavFrequency(String secId) {
|
|
|
|
+// Frequency frequency;
|
|
|
|
+// String fundType = SecType.getSecType(secId, null);
|
|
|
|
+// 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, List<String>> getTypeSecMap(List<String> secIdList) {
|
|
|
|
- Map<String, List<String>> secIdTypeMap = new HashMap<>(10);
|
|
|
|
- for (String secId : secIdList) {
|
|
|
|
- String secIdType = getSecType(secId);
|
|
|
|
- if (secIdTypeMap.containsKey(secIdType)) {
|
|
|
|
- List<String> list = secIdTypeMap.get(secIdType);
|
|
|
|
- list.add(secId);
|
|
|
|
- } else {
|
|
|
|
- List<String> list = new ArrayList<>();
|
|
|
|
- list.add(secId);
|
|
|
|
- secIdTypeMap.put(secIdType, list);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return secIdTypeMap;
|
|
|
|
- }
|
|
|
|
|
|
+// @Override
|
|
|
|
+// public Map<String, String> querySecName(List<String> allSecIdList) {
|
|
|
|
+// if (CollUtil.isEmpty(allSecIdList)) {
|
|
|
|
+// return MapUtil.empty();
|
|
|
|
+// }
|
|
|
|
+// int size = allSecIdList.size();
|
|
|
|
+// String key = RedisConst.SEC_NAME;
|
|
|
|
+// Map<String, Object> hget = this.cacheGateway.hget(key);
|
|
|
|
+// if (MapUtil.isEmpty(hget)) {
|
|
|
|
+// hget = MapUtil.empty();
|
|
|
|
+// }
|
|
|
|
+// Map<Boolean, List<String>> redisSecMap = allSecIdList.stream().collect(Collectors.groupingBy(hget::containsKey));
|
|
|
|
+// List<String> redisSecIds = redisSecMap.getOrDefault(Boolean.TRUE, ListUtil.empty());
|
|
|
|
+// List<String> noRedisSecIds = redisSecMap.getOrDefault(Boolean.FALSE, ListUtil.empty());
|
|
|
|
+// Map<String, Object> secNameMap = MapUtil.newHashMap(size, false);
|
|
|
|
+// if (CollUtil.isNotEmpty(noRedisSecIds)) {
|
|
|
|
+// Map<String, List<String>> typeSecMap = SecType.getTypeSecMap(noRedisSecIds, null);
|
|
|
|
+// // 市场基金
|
|
|
|
+// List<String> marketFundIds = ListUtil.of(SecType.PRIVATELY_OFFERED_FUND, SecType.PUBLICLY_OFFERED_FUNDS);
|
|
|
|
+// this.loadNameMap(secNameMap, typeSecMap, marketFundIds, this.fundInformationDao::getMarketFundIdNameMap);
|
|
|
|
+// // 市场指数
|
|
|
|
+// List<String> marketIndexIds = ListUtil.of(SecType.INDEX_FUND, SecType.RONGZHI_INDEX, SecType.THIRD_INDEX_FUND);
|
|
|
|
+// this.loadNameMap(secNameMap, typeSecMap, marketIndexIds, this.indexesProfileDao::getFundIdNameMap);
|
|
|
|
+//// // 基金经理
|
|
|
|
+//// List<String> managerIds = ListUtil.of(SecType.MANAGER);
|
|
|
|
+//// this.loadNameMap(secNameMap, typeSecMap, managerIds, this.personnelInformationDao::getFundIdNameMap);
|
|
|
|
+//// // 基金管理人
|
|
|
|
+//// List<String> companyIds = ListUtil.of(SecType.COMPANY);
|
|
|
|
+//// this.loadNameMap(secNameMap, typeSecMap, companyIds, this.companyInformationDao::getFundIdNameMap);
|
|
|
|
+// // 策略
|
|
|
|
+// List<String> strategyIds = ListUtil.of(SecType.STRATEGY);
|
|
|
|
+// this.loadNameMap(secNameMap, typeSecMap, strategyIds, this::getStrategyIdNameMap);
|
|
|
|
+// // 推送事件,存缓存
|
|
|
|
+// SaveCacheEvent<Map<String, Object>> event = new SaveCacheEvent<>(key, secNameMap, t -> {
|
|
|
|
+// this.cacheGateway.hset(key, t);
|
|
|
|
+// return this.cacheGateway.expire(key, 1, TimeUnit.DAYS);
|
|
|
|
+// });
|
|
|
|
+// this.applicationContext.publishEvent(event);
|
|
|
|
+// }
|
|
|
|
+// // 解决乱序问题
|
|
|
|
+// Map<String, String> result = MapUtil.newHashMap(size, true);
|
|
|
|
+// for (String secId : allSecIdList) {
|
|
|
|
+// String name = redisSecIds.contains(secId) ? MapUtil.getStr(hget, secId) : MapUtil.getStr(secNameMap, secId);
|
|
|
|
+// result.put(secId, name);
|
|
|
|
+// }
|
|
|
|
+// return result;
|
|
|
|
+// }
|
|
|
|
|
|
- @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();
|
|
|
|
- }
|
|
|
|
- int size = allSecIdList.size();
|
|
|
|
- String key = RedisConst.SEC_NAME;
|
|
|
|
- Map<String, Object> hget = this.cacheGateway.hget(key);
|
|
|
|
- if (MapUtil.isEmpty(hget)) {
|
|
|
|
- hget = MapUtil.empty();
|
|
|
|
- }
|
|
|
|
- Map<Boolean, List<String>> redisSecMap = allSecIdList.stream().collect(Collectors.groupingBy(hget::containsKey));
|
|
|
|
- List<String> redisSecIds = redisSecMap.getOrDefault(Boolean.TRUE, ListUtil.empty());
|
|
|
|
- List<String> noRedisSecIds = redisSecMap.getOrDefault(Boolean.FALSE, ListUtil.empty());
|
|
|
|
- Map<String, Object> secNameMap = MapUtil.newHashMap(size, false);
|
|
|
|
- if (CollUtil.isNotEmpty(noRedisSecIds)) {
|
|
|
|
- Map<String, List<String>> typeSecMap = this.getTypeSecMap(noRedisSecIds);
|
|
|
|
- // 市场基金
|
|
|
|
- List<String> marketFundIds = ListUtil.of(SecType.PRIVATELY_OFFERED_FUND, SecType.PUBLICLY_OFFERED_FUNDS);
|
|
|
|
- this.loadNameMap(secNameMap, typeSecMap, marketFundIds, this.fundInformationDao::getMarketFundIdNameMap);
|
|
|
|
- // 市场指数
|
|
|
|
- List<String> marketIndexIds = ListUtil.of(SecType.INDEX_FUND, SecType.RONGZHI_INDEX, SecType.THIRD_INDEX_FUND);
|
|
|
|
- this.loadNameMap(secNameMap, typeSecMap, marketIndexIds, this.indexesProfileDao::getFundIdNameMap);
|
|
|
|
-// // 基金经理
|
|
|
|
-// List<String> managerIds = ListUtil.of(SecType.MANAGER);
|
|
|
|
-// this.loadNameMap(secNameMap, typeSecMap, managerIds, this.personnelInformationDao::getFundIdNameMap);
|
|
|
|
-// // 基金管理人
|
|
|
|
-// List<String> companyIds = ListUtil.of(SecType.COMPANY);
|
|
|
|
-// this.loadNameMap(secNameMap, typeSecMap, companyIds, this.companyInformationDao::getFundIdNameMap);
|
|
|
|
- // 策略
|
|
|
|
- List<String> strategyIds = ListUtil.of(SecType.STRATEGY);
|
|
|
|
- this.loadNameMap(secNameMap, typeSecMap, strategyIds, this::getStrategyIdNameMap);
|
|
|
|
- // 推送事件,存缓存
|
|
|
|
- SaveCacheEvent<Map<String, Object>> event = new SaveCacheEvent<>(key, secNameMap, t -> {
|
|
|
|
- this.cacheGateway.hset(key, t);
|
|
|
|
- return this.cacheGateway.expire(key, 1, TimeUnit.DAYS);
|
|
|
|
- });
|
|
|
|
- this.applicationContext.publishEvent(event);
|
|
|
|
- }
|
|
|
|
- // 解决乱序问题
|
|
|
|
- Map<String, String> result = MapUtil.newHashMap(size, true);
|
|
|
|
- for (String secId : allSecIdList) {
|
|
|
|
- String name = redisSecIds.contains(secId) ? MapUtil.getStr(hget, secId) : MapUtil.getStr(secNameMap, secId);
|
|
|
|
- result.put(secId, name);
|
|
|
|
- }
|
|
|
|
- return result;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public List<MonetaryFundProfitDO> queryMonetaryFund(String fundId) {
|
|
|
|
- return this.fundInformationDao.queryMonetaryFund(fundId);
|
|
|
|
- }
|
|
|
|
|
|
+// @Override
|
|
|
|
+// public List<MonetaryFundProfitDO> queryMonetaryFund(String fundId) {
|
|
|
|
+// return this.fundInformationDao.queryMonetaryFund(fundId);
|
|
|
|
+// }
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public PrivatelyFundBaseInfoDo listPrivatelyFundInfo(String fundId) {
|
|
public PrivatelyFundBaseInfoDo listPrivatelyFundInfo(String fundId) {
|