Browse Source

解决告警分发接口时间报错问题

main
sjh 11 months ago
parent
commit
198a5dab90
  1. 16
      src/main/java/com/biutag/supervision/pojo/dto/jwdc/AlarmYjzjDto.java

16
src/main/java/com/biutag/supervision/pojo/dto/jwdc/AlarmYjzjDto.java

@ -8,9 +8,8 @@ import lombok.Setter;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.format.DateTimeFormatter;
@Setter @Setter
@Getter @Getter
@ -77,17 +76,12 @@ public class AlarmYjzjDto {
super(LocalDateTime.class); super(LocalDateTime.class);
} }
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@Override @Override
public LocalDateTime deserialize(com.fasterxml.jackson.core.JsonParser p, com.fasterxml.jackson.databind.DeserializationContext ctxt) throws IOException { public LocalDateTime deserialize(com.fasterxml.jackson.core.JsonParser p, com.fasterxml.jackson.databind.DeserializationContext ctxt) throws IOException {
String dateStr = p.getText(); String date = p.getText();
if (dateStr.startsWith("/Date(") && dateStr.endsWith(")/")) { return LocalDateTime.parse(date, FORMATTER);
String timestampStr = dateStr.substring(6, dateStr.length() - 2);
// 去掉时区部分
String[] parts = timestampStr.split("-");
long timestamp = Long.parseLong(parts[0]);
return LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault());
}
throw new IllegalArgumentException("Invalid date format: " + dateStr);
} }
} }
} }

Loading…
Cancel
Save