|
@@ -1,8 +1,10 @@
|
|
|
package com.liangjiang.price_collection.service.impl;
|
|
package com.liangjiang.price_collection.service.impl;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.google.common.collect.Interner;
|
|
import com.google.common.collect.Interner;
|
|
|
import com.google.common.collect.Interners;
|
|
import com.google.common.collect.Interners;
|
|
|
import com.liangjiang.price_collection.dto.BackupsInfo;
|
|
import com.liangjiang.price_collection.dto.BackupsInfo;
|
|
|
|
|
+import com.liangjiang.price_collection.dto.PriceDto;
|
|
|
import com.liangjiang.price_collection.dto.PriceInfoDto;
|
|
import com.liangjiang.price_collection.dto.PriceInfoDto;
|
|
|
import com.liangjiang.price_collection.mapper.TableMapper;
|
|
import com.liangjiang.price_collection.mapper.TableMapper;
|
|
|
import com.liangjiang.price_collection.service.IBackupsInfoService;
|
|
import com.liangjiang.price_collection.service.IBackupsInfoService;
|
|
@@ -12,7 +14,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.jdbc.BadSqlGrammarException;
|
|
import org.springframework.jdbc.BadSqlGrammarException;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Service
|
|
@Service
|
|
@@ -36,6 +38,49 @@ public class TableServiceImpl implements ITableService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Set<String> getExchangeSelect (){
|
|
|
|
|
+ List<String> tableNames = this.getTableNames();
|
|
|
|
|
+ if (CollectionUtil.isEmpty(tableNames)){
|
|
|
|
|
+ return new HashSet<>();
|
|
|
|
|
+ }
|
|
|
|
|
+ Set<String> exchanges = new HashSet<>();
|
|
|
|
|
+
|
|
|
|
|
+ for (String tableName : tableNames){
|
|
|
|
|
+ String[] infos = tableName.split("_");
|
|
|
|
|
+ // 交易所和类型
|
|
|
|
|
+ exchanges.add(String.format("%s_%s", infos[1], infos[2]));
|
|
|
|
|
+ }
|
|
|
|
|
+ return exchanges;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Set<String> getCoinSelect(String[] exchanges){
|
|
|
|
|
+ if(exchanges == null || exchanges.length == 0){
|
|
|
|
|
+ return new HashSet<>();
|
|
|
|
|
+ }
|
|
|
|
|
+ List<String> tableNames = this.getTableNames();
|
|
|
|
|
+ if (CollectionUtil.isEmpty(tableNames)){
|
|
|
|
|
+ return new HashSet<>();
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, Set<String>> exchange_coin = new HashMap<>();
|
|
|
|
|
+ for (String exchange : exchanges){
|
|
|
|
|
+ exchange_coin.put(exchange, new HashSet<>());
|
|
|
|
|
+ }
|
|
|
|
|
+ for (String tableName : tableNames){
|
|
|
|
|
+ String[] infos = tableName.split("_");
|
|
|
|
|
+ // 交易所和类型
|
|
|
|
|
+ String key = String.format("%s_%s", infos[1], infos[2]);
|
|
|
|
|
+ if (exchange_coin.containsKey(key)){
|
|
|
|
|
+ // 存在加入币对
|
|
|
|
|
+ exchange_coin.get(key).add(infos[0]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ Set<Set<String>> values = new HashSet<>(exchange_coin.values());
|
|
|
|
|
+ // 返回交集
|
|
|
|
|
+ return getUnion(values);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public List<String> getTableNames(){
|
|
public List<String> getTableNames(){
|
|
|
return tableMapper.getTableName();
|
|
return tableMapper.getTableName();
|
|
@@ -77,4 +122,17 @@ public class TableServiceImpl implements ITableService {
|
|
|
backupsInfoService.save(backupsInfo);
|
|
backupsInfoService.save(backupsInfo);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<PriceDto> getPriceInfo(String tableName, Integer startTime, Integer endTime){
|
|
|
|
|
+ return this.tableMapper.getPriceInfo(tableName, startTime, endTime);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static Set<String> getUnion(Set<Set<String>> sets) {
|
|
|
|
|
+ Set<String> result = new HashSet<>();
|
|
|
|
|
+ for (Set<String> set : sets) {
|
|
|
|
|
+ result.addAll(set); // 将每个集合的元素添加到结果集合中
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|