| | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.*; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | if (itemService.isSuspended(symbol)) { |
| | | return; |
| | | } |
| | | /*if (realtime.getSymbol().equals("axsusdt")) { |
| | | System.out.println("axsusdt1" + realtime); |
| | | /*if (realtime.getSymbol().equals("galausdt")) { |
| | | System.out.println("galausdt111" + realtime); |
| | | }*/ |
| | | DataCache.putLatestRealTime(symbol, realtime); |
| | | DataCache.putLatestOpen(symbol, realtime.getOpen()); |
| | |
| | | // 1. 确定时间戳单位(假设ts是毫秒级,若为秒级需用ofEpochSecond()) |
| | | Instant instant = Instant.ofEpochMilli(ts); |
| | | |
| | | // 2. 将时间戳转换为当地时区的日期(指定时区更准确,如Asia/Shanghai) |
| | | LocalDate tsDate = instant.atZone(ZoneId.of("Asia/Shanghai")).toLocalDate(); |
| | | // 2. 将时间戳转换为当地时区的日期(指定时区更准确,如Asia/Tokyo) |
| | | LocalDate tsDate = instant.atZone(ZoneId.of("Asia/Tokyo")).toLocalDate(); |
| | | |
| | | // 3. 获取“昨天的日期”(当前日期减1天) |
| | | LocalDate yesterday = LocalDate.now(ZoneId.of("Asia/Shanghai")).minusDays(1); |
| | | LocalDate yesterday = LocalDate.now(ZoneId.of("Asia/Tokyo")).minusDays(1); |
| | | |
| | | // 4. 判断是否为昨天 |
| | | boolean isYesterday = tsDate.equals(yesterday); |
| | |
| | | return realtime; |
| | | } |
| | | |
| | | @Override |
| | | public void cacheBefore24Hour(String symbol) { |
| | | // 计算“24小时前”的时间戳(毫秒级) |
| | | long twentyFourHoursAgo = Instant.now().minus(24, ChronoUnit.HOURS).toEpochMilli(); |
| | | RequestDataHelper.set("symbol", symbol); |
| | | LambdaQueryWrapper<Realtime> queryWrapper = new LambdaQueryWrapper<Realtime>() |
| | | .eq(Realtime::getSymbol, symbol) |
| | | .ge(Realtime::getTs, twentyFourHoursAgo) // 时间戳 >= 24小时前(前24小时内) |
| | | .orderByDesc(Realtime::getClose) // 24小时最高 |
| | | .last("LIMIT 1"); |
| | | Realtime realtimeHigh = realtimeService.getBaseMapper().selectOne(queryWrapper); |
| | | LambdaQueryWrapper<Realtime> queryWrapper2 = new LambdaQueryWrapper<Realtime>() |
| | | .eq(Realtime::getSymbol, symbol) |
| | | .ge(Realtime::getTs, twentyFourHoursAgo) // 时间戳 >= 24小时前(前24小时内) |
| | | .orderByAsc(Realtime::getClose) // 24小时最低 |
| | | .last("LIMIT 1"); |
| | | Realtime realtimeLow = realtimeService.getBaseMapper().selectOne(queryWrapper2); |
| | | RequestDataHelper.clear(); |
| | | System.out.println("realtimeHigh:" + realtimeHigh); |
| | | System.out.println("realtimeLow:" + realtimeLow); |
| | | if (realtimeHigh != null) { |
| | | DataCache.getRealtimeHigh().put(symbol, realtimeHigh.getClose().doubleValue()); |
| | | System.out.println("putRealtimeHigh:" + realtimeHigh.getClose().doubleValue()); |
| | | } |
| | | if (realtimeLow != null) { |
| | | DataCache.getRealtimeLow().put(symbol, realtimeLow.getClose().doubleValue()); |
| | | System.out.println("putRealtimeLow:" + realtimeLow.getClose().doubleValue()); |
| | | } |
| | | } |
| | | |
| | | public void deleteRealtime(int days) { |
| | | for (int i = 0; i <= Constants.TABLE_PARTITIONS - 1; i++) { |
| | | Map<String, Object> parameters = new HashMap(); |