|
@@ -29,6 +29,7 @@ import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -153,31 +154,23 @@ public class BaseInfoServiceImpl implements BaseInfoService, ApplicationContextA
|
|
|
int size = allSecIdList.size();
|
|
|
String key = RedisConst.INFO_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.get(Boolean.TRUE);
|
|
|
- List<String> noRedisSecIds = redisSecMap.get(Boolean.FALSE);
|
|
|
+ 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.list(true);
|
|
|
- CollUtil.addAllIfNotContains(marketFundIds, typeSecMap.getOrDefault(SecType.PRIVATELY_OFFERED_FUND, ListUtil.empty()));
|
|
|
- CollUtil.addAllIfNotContains(marketFundIds, typeSecMap.getOrDefault(SecType.PUBLICLY_OFFERED_FUNDS, ListUtil.empty()));
|
|
|
- if (CollUtil.isNotEmpty(marketFundIds)) {
|
|
|
- Map<String, String> marketFundIdNameMap = fundInformationDao.getMarketFundIdNameMap(marketFundIds);
|
|
|
- secNameMap.putAll(marketFundIdNameMap);
|
|
|
- }
|
|
|
+ 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.list(true);
|
|
|
- CollUtil.addAllIfNotContains(marketIndexIds, typeSecMap.getOrDefault(SecType.INDEX_FUND, ListUtil.empty()));
|
|
|
- CollUtil.addAllIfNotContains(marketIndexIds, typeSecMap.getOrDefault(SecType.RONGZHI_INDEX, ListUtil.empty()));
|
|
|
- CollUtil.addAllIfNotContains(marketIndexIds, typeSecMap.getOrDefault(SecType.THIRD_INDEX_FUND, ListUtil.empty()));
|
|
|
- if (CollUtil.isNotEmpty(marketIndexIds)) {
|
|
|
- Map<String, String> marketFundIdNameMap = indexesProfileDao.getFundIdNameMap(marketIndexIds);
|
|
|
- secNameMap.putAll(marketFundIdNameMap);
|
|
|
- }
|
|
|
+ List<String> marketIndexIds = ListUtil.of(SecType.INDEX_FUND, SecType.RONGZHI_INDEX, SecType.THIRD_INDEX_FUND);
|
|
|
+ this.loadNameMap(secNameMap, typeSecMap, marketIndexIds, this.indexesProfileDao::getFundIdNameMap);
|
|
|
// 推送事件,存缓存
|
|
|
- SaveCacheEvent<Map<String, Object>> event = new SaveCacheEvent<>(this, secNameMap, t -> {
|
|
|
+ SaveCacheEvent<Map<String, Object>> event = new SaveCacheEvent<>(key, secNameMap, t -> {
|
|
|
this.cacheGateway.hset(key, t);
|
|
|
return this.cacheGateway.expire(key, 1, TimeUnit.DAYS);
|
|
|
});
|
|
@@ -201,4 +194,23 @@ public class BaseInfoServiceImpl implements BaseInfoService, ApplicationContextA
|
|
|
public List<Map<String, Object>> getFundRank(String rankDate, String fundId, List<String> indexIds, Indicator indicator) {
|
|
|
return this.fundInformationDao.getFundRank(rankDate, fundId, indexIds, indicator);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 把指定类型的标的的名称映射查询出来
|
|
|
+ *
|
|
|
+ * @param secNameMap 保存的map
|
|
|
+ * @param typeSecMap 指定类型对应的标的
|
|
|
+ * @param types 指定类型列表
|
|
|
+ * @param function 查询操作封装
|
|
|
+ */
|
|
|
+ private void loadNameMap(Map<String, Object> secNameMap, Map<String, List<String>> typeSecMap,
|
|
|
+ List<String> types, Function<List<String>, Map<String, String>> function) {
|
|
|
+ List<String> refIds = ListUtil.list(true);
|
|
|
+ for (String type : types) {
|
|
|
+ CollUtil.addAllIfNotContains(refIds, typeSecMap.getOrDefault(type, ListUtil.empty()));
|
|
|
+ }
|
|
|
+ if (CollUtil.isNotEmpty(refIds)) {
|
|
|
+ secNameMap.putAll(function.apply(refIds));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|