|
|
|
@ -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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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); |
|
|
|
} |
|
|
|
|