peter
2025-08-25 3c0663624026a6a0caec98648c5904aa2f605572
src/main/java/project/web/api/RealtimeController.java
@@ -3,6 +3,11 @@
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
@@ -67,8 +72,17 @@
               realtime.setOrder(order);
               list_clone.add(realtime);
            }
            data = list_clone.stream().sorted(Comparator.comparing(Realtime::getClose).reversed()).collect(Collectors.toList());
//            data = list_clone.stream().sorted(Comparator.comparing(Realtime::getClose).reversed()).collect(Collectors.toList());
            // 自定义比较器,确保 BTC 排在第一,ETH 排在第二
         }
         data.sort((r1, r2) -> {
            if (r1.getSymbol().equals("btc")) return -1;  // BTC 应该排在第一
            if (r2.getSymbol().equals("btc")) return 1;
            if (r1.getSymbol().equals("eth")) return -1;  // ETH 应该排在第二
            if (r2.getSymbol().equals("eth")) return 1;
            return 0;  // 如果都不是 BTC 或 ETH,则保持原始顺序
         });
         resultObject.setData(this.revise(data));
         return JSONObject.toJSONString(resultObject);
      } catch (BusinessException e) {
@@ -90,13 +104,25 @@
         Map<String, Object> map = new HashMap<String, Object>();
         map.put("symbol", realtime.getSymbol());
         map.put("ts", realtime.getTs());
         String currentTime = realtime.getCurrent_time();
         // 设置时区为纽约的冬令时(Eastern Standard Time, EST)
         TimeZone timeZone = TimeZone.getTimeZone("America/New_York");
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         sdf.setTimeZone(timeZone);
         map.put("current_time",sdf.format(currentTime));
         map.put("name", realtime.getName());
         String currentTime = realtime.getCurrent_time(); // "yyyy-MM-dd HH:mm:ss"
         // 1. 解析原始时间(假设是 UTC 时间)
         DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         LocalDateTime localDateTime = LocalDateTime.parse(currentTime, inputFormatter);
         // 2. 转换为柏林时区的时间
         ZoneId berlinZone = ZoneId.of("Europe/Berlin");
         ZonedDateTime utcTime = localDateTime.atZone(ZoneOffset.UTC); // 假设原时间是 UTC
         ZonedDateTime berlinTime = utcTime.withZoneSameInstant(berlinZone);
         // 3. 格式化为字符串
         DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         String formattedTime = berlinTime.format(outputFormatter);
         map.put("current_time", formattedTime);
         Item item1 = this.itemService.cacheBySymbol(realtime.getSymbol(), false);
         map.put("name", item1.getName());
         map.put("change_ratio", realtime.getChange_ratio());
         Item item = this.itemService.cacheBySymbol(realtime.getSymbol(), true);
         if (item.getDecimals() == null || item.getDecimals() < 0) {