From db4da680f275e94a4d1778d39bc26a1606ea5a61 Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Sat, 1 Nov 2025 12:39:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/DashboardWebSocketService.java | 66 ++++++++++++------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/gaotao/modules/dashboard/service/DashboardWebSocketService.java b/src/main/java/com/gaotao/modules/dashboard/service/DashboardWebSocketService.java index e0b5917..d97391e 100644 --- a/src/main/java/com/gaotao/modules/dashboard/service/DashboardWebSocketService.java +++ b/src/main/java/com/gaotao/modules/dashboard/service/DashboardWebSocketService.java @@ -6,6 +6,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.stereotype.Service; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.Map; /** @@ -37,6 +39,20 @@ public class DashboardWebSocketService { @Autowired private SimpMessagingTemplate messagingTemplate; + /** + * 创建带服务器时间的响应 + * + * @param data 业务数据 + * @return 包含服务器时间的响应 + */ + private R createResponseWithServerTime(Map data) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss E"); + String serverTime = sdf.format(new Date()); + return R.ok() + .put("data", data) + .put("serverTime", serverTime); + } + /** * 推送人工拣选看板数据 * @@ -45,8 +61,8 @@ public class DashboardWebSocketService { public void pushManualPickingData(Map data) { log.debug("推送人工拣选看板数据"); try { - messagingTemplate.convertAndSend("/topic/dashboard/manual-picking", - R.ok().put("data", data)); + messagingTemplate.convertAndSend("/topic/dashboard/manual-picking", + createResponseWithServerTime(data)); } catch (Exception e) { log.error("推送人工拣选看板数据失败: {}", e.getMessage(), e); } @@ -58,12 +74,12 @@ public class DashboardWebSocketService { * @param data 看板数据 */ public void pushRobotPickingData(Map data) { - log.debug("推送机械臂拣选看板数据: 周转箱{}条, 原材{}条", + log.debug("推送机械臂拣选看板数据: 周转箱{}条, 原材{}条", data.get("containerList") != null ? ((java.util.List)data.get("containerList")).size() : 0, data.get("materialList") != null ? ((java.util.List)data.get("materialList")).size() : 0); try { - messagingTemplate.convertAndSend("/topic/dashboard/robot-picking", - R.ok().put("data", data)); + messagingTemplate.convertAndSend("/topic/dashboard/robot-picking", + createResponseWithServerTime(data)); } catch (Exception e) { log.error("推送机械臂拣选看板数据失败: {}", e.getMessage(), e); } @@ -77,8 +93,8 @@ public class DashboardWebSocketService { public void pushSlittingBoardData(Map data) { log.debug("推送分切区看板数据"); try { - messagingTemplate.convertAndSend("/topic/dashboard/slitting-board", - R.ok().put("data", data)); + messagingTemplate.convertAndSend("/topic/dashboard/slitting-board", + createResponseWithServerTime(data)); } catch (Exception e) { log.error("推送分切区看板数据失败: {}", e.getMessage(), e); } @@ -92,8 +108,8 @@ public class DashboardWebSocketService { public void pushInventoryBoardData(Map data) { log.debug("推送库存分析看板数据"); try { - messagingTemplate.convertAndSend("/topic/dashboard/inventory-board", - R.ok().put("data", data)); + messagingTemplate.convertAndSend("/topic/dashboard/inventory-board", + createResponseWithServerTime(data)); } catch (Exception e) { log.error("推送库存分析看板数据失败: {}", e.getMessage(), e); } @@ -107,8 +123,8 @@ public class DashboardWebSocketService { public void pushFinishedProductBoardData(Map data) { log.debug("推送成品入库出库区看板数据"); try { - messagingTemplate.convertAndSend("/topic/dashboard/finished-product-board", - R.ok().put("data", data)); + messagingTemplate.convertAndSend("/topic/dashboard/finished-product-board", + createResponseWithServerTime(data)); } catch (Exception e) { log.error("推送成品入库出库区看板数据失败: {}", e.getMessage(), e); } @@ -122,8 +138,8 @@ public class DashboardWebSocketService { public void pushMaterialReceivingBoardData(Map data) { log.debug("推送原材收货区看板数据"); try { - messagingTemplate.convertAndSend("/topic/dashboard/material-receiving-board", - R.ok().put("data", data)); + messagingTemplate.convertAndSend("/topic/dashboard/material-receiving-board", + createResponseWithServerTime(data)); } catch (Exception e) { log.error("推送原材收货区看板数据失败: {}", e.getMessage(), e); } @@ -137,8 +153,8 @@ public class DashboardWebSocketService { public void pushBufferBoardData(Map data) { log.debug("推送缓存区看板数据"); try { - messagingTemplate.convertAndSend("/topic/dashboard/buffer-board", - R.ok().put("data", data)); + messagingTemplate.convertAndSend("/topic/dashboard/buffer-board", + createResponseWithServerTime(data)); } catch (Exception e) { log.error("推送缓存区看板数据失败: {}", e.getMessage(), e); } @@ -152,8 +168,8 @@ public class DashboardWebSocketService { public void pushWorkshopFeedingBoardData(Map data) { log.debug("推送车间AGV放料区看板数据"); try { - messagingTemplate.convertAndSend("/topic/dashboard/workshop-feeding-board", - R.ok().put("data", data)); + messagingTemplate.convertAndSend("/topic/dashboard/workshop-feeding-board", + createResponseWithServerTime(data)); } catch (Exception e) { log.error("推送车间AGV放料区看板数据失败: {}", e.getMessage(), e); } @@ -167,8 +183,8 @@ public class DashboardWebSocketService { public void pushExceptionBoardData(Map data) { log.debug("推送异常处理区看板数据"); try { - messagingTemplate.convertAndSend("/topic/dashboard/exception-board", - R.ok().put("data", data)); + messagingTemplate.convertAndSend("/topic/dashboard/exception-board", + createResponseWithServerTime(data)); } catch (Exception e) { log.error("推送异常处理区看板数据失败: {}", e.getMessage(), e); } @@ -182,8 +198,8 @@ public class DashboardWebSocketService { public void broadcastToAllDashboards(Map data) { log.info("广播推送到所有看板"); try { - messagingTemplate.convertAndSend("/topic/dashboard/broadcast", - R.ok().put("data", data)); + messagingTemplate.convertAndSend("/topic/dashboard/broadcast", + createResponseWithServerTime(data)); } catch (Exception e) { log.error("广播推送到所有看板失败: {}", e.getMessage(), e); } @@ -197,8 +213,8 @@ public class DashboardWebSocketService { public void pushWarehouse3dBoardData(Map data) { log.debug("推送智能立体仓库看板数据"); try { - messagingTemplate.convertAndSend("/topic/dashboard/warehouse-3d", - R.ok().put("data", data)); + messagingTemplate.convertAndSend("/topic/dashboard/warehouse-3d", + createResponseWithServerTime(data)); } catch (Exception e) { log.error("推送智能立体仓库看板数据失败: {}", e.getMessage(), e); } @@ -213,7 +229,9 @@ public class DashboardWebSocketService { public void pushToTopic(String topic, Object data) { log.debug("推送数据到主题: {}", topic); try { - messagingTemplate.convertAndSend(topic, R.ok().put("data", data)); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss E"); + String serverTime = sdf.format(new Date()); + messagingTemplate.convertAndSend(topic, R.ok().put("data", data).put("serverTime", serverTime)); } catch (Exception e) { log.error("推送数据到主题{}失败: {}", topic, e.getMessage(), e); }