|
|
@@ -45,14 +45,23 @@ public class QueryService {
|
|
|
results.add(dto);
|
|
|
}
|
|
|
}
|
|
|
+ // 时间切片
|
|
|
+ Set<Integer> times = generateArithmeticSequence(startTime, endTime);
|
|
|
if(CollectionUtil.isEmpty(results)){
|
|
|
log.warn("没有查询到数据");
|
|
|
- return PriceListDto.builder().time(new HashSet<>()).values(new LinkedList<>()).build();
|
|
|
+ if (!isAdd) {
|
|
|
+ return PriceListDto.builder().time(new HashSet<>()).values(new LinkedList<>()).build();
|
|
|
+ }
|
|
|
+ PriceListDto empty_result = PriceListDto.builder().time(times).values(new LinkedList<>()).build();
|
|
|
+ List<String> emptyArr = new LinkedList<>();
|
|
|
+ for (String exchange : exchanges) {
|
|
|
+ empty_result.getValues().add(ExchangeCoinPriceArrDto.builder().exchange(exchange).symbol(coin).ask(emptyArr).bid(emptyArr).build());
|
|
|
+ }
|
|
|
+ return empty_result;
|
|
|
}
|
|
|
List<Future<ExchangeCoinPriceArrDto>> resultFutures = new LinkedList<>();
|
|
|
List<ExchangeCoinPriceArrDto> data = new LinkedList<>();
|
|
|
- //
|
|
|
- Set<Integer> times = generateArithmeticSequence(startTime, endTime);
|
|
|
+
|
|
|
|
|
|
// 获取已有时间的合集
|
|
|
// Set<Integer> times = new TreeSet<>();
|
|
|
@@ -71,7 +80,23 @@ public class QueryService {
|
|
|
data.add(dto);
|
|
|
}
|
|
|
priceListDto.setTime(times);
|
|
|
- priceListDto.setValues(data.stream().sorted(Comparator.comparing(ExchangeCoinPriceArrDto::getExchange)).collect(Collectors.toList()));
|
|
|
+ // 最终结果排序处理
|
|
|
+ priceListDto.setValues(data.stream()
|
|
|
+ .sorted(Comparator.comparing(ExchangeCoinPriceArrDto::getExchange))
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ // 交易所数量对不上则补
|
|
|
+ if (priceListDto.getValues().size() != exchanges.length) {
|
|
|
+ Set<String> processedExchanges = priceListDto.getValues().stream()
|
|
|
+ .map(ExchangeCoinPriceArrDto::getExchange)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ List<String> emptyArr = new LinkedList<>();
|
|
|
+ for (String exchange : exchanges) {
|
|
|
+ if (!processedExchanges.contains(exchange)) {
|
|
|
+ priceListDto.getValues().add(ExchangeCoinPriceArrDto.builder().exchange(exchange).ask(emptyArr).bid(emptyArr).symbol(coin).build());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return priceListDto;
|
|
|
}
|
|
|
|
|
|
@@ -80,10 +105,10 @@ public class QueryService {
|
|
|
executorService.shutdown();
|
|
|
}
|
|
|
|
|
|
- public static Integer[] getDaysAgoTime(long startTime, long dayNum){
|
|
|
+ public static Integer[] getDaysAgoTime(long startTime, long hoursNum){
|
|
|
int startTimeInt = Math.toIntExact(startTime / 1000);
|
|
|
- // 计算3天的毫秒数 (3天 * 24小时 * 60分钟 * 60秒 * 1000毫秒)
|
|
|
- long threeDaysInMillis = dayNum * 24 * 60 * 60 * 1000;
|
|
|
+ // 计算hoursNum小时的毫秒数 (hoursNum * 60分钟 * 60秒 * 1000毫秒)
|
|
|
+ long threeDaysInMillis = hoursNum * 60 * 60 * 1000;
|
|
|
// 计算3天前的毫秒级时间戳
|
|
|
long threeDaysAgoMillis = startTime - threeDaysInMillis;
|
|
|
// 将毫秒级时间戳转换为秒级时间戳
|