From cae4e3e8a1859b977eb5353b69052112641848a2 Mon Sep 17 00:00:00 2001 From: xiepufeng <1072271977@qq.com> Date: Tue, 6 Feb 2024 17:40:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=86=E9=A2=91ai=E6=84=9F=E7=9F=A5=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E5=AD=98=E5=82=A8=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/enums/WarningSubclassEnum.java | 12 +++++++- .../device/handler/DeviceMessageHandler.java | 29 ++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/enums/WarningSubclassEnum.java b/zc-business/src/main/java/com/zc/business/enums/WarningSubclassEnum.java index 990fdf28..6727263a 100644 --- a/zc-business/src/main/java/com/zc/business/enums/WarningSubclassEnum.java +++ b/zc-business/src/main/java/com/zc/business/enums/WarningSubclassEnum.java @@ -70,6 +70,16 @@ public enum WarningSubclassEnum { } public static String getDecorateInfo(String code) { - return ENUM_BY_CODE.get(code).getDecorateInfo(); + if (code == null) { + return ""; + } + + WarningSubclassEnum warningSubclassEnum = ENUM_BY_CODE.get(code); + + if (warningSubclassEnum == null) { + return ""; + } + + return warningSubclassEnum.getDecorateInfo(); } } diff --git a/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java b/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java index f0b5db58..e96500e0 100644 --- a/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java +++ b/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java @@ -19,6 +19,10 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.List; import java.util.stream.Collectors; @@ -119,8 +123,11 @@ public class DeviceMessageHandler { String stakeMarkDescription = data.getString("stakeMarkDescription"); + String title = stakeMarkDescription + WarningSubclassEnum.getDecorateInfo(warningSubclass); + // 标题 - dcWarning.setWarningTitle(stakeMarkDescription + WarningSubclassEnum.getDecorateInfo(warningSubclass)); + dcWarning.setWarningTitle(title); + dcWarning.setRemark(convertTimestampToString(captureTime) + " " + title); // 影响车道 dcWarning.setLane(String.valueOf(data.getInteger("relatedLaneNo"))); @@ -146,4 +153,24 @@ public class DeviceMessageHandler { } + /** + * 将毫秒级时间戳转换为"yyyy-MM-dd HH:mm:ss"格式的字符串 + * + * @param timestampInMillis 毫秒级时间戳 + * @return 格式化后的日期时间字符串 + */ + public static String convertTimestampToString(long timestampInMillis) { + // 转换为Instant对象 + Instant instant = Instant.ofEpochMilli(timestampInMillis); + + // 转换为LocalDateTime(默认时区) + LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault()); + + // 创建DateTimeFormatter实例并指定输出格式 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + + // 格式化LocalDateTime对象为字符串 + return localDateTime.format(formatter); + } + }