You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
225 lines
7.0 KiB
225 lines
7.0 KiB
package com.gaotao.modules.dashboard.service;
|
|
|
|
import com.gaotao.common.utils.R;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
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;
|
|
|
|
/**
|
|
* 看板WebSocket推送服务
|
|
*
|
|
* <p><b>功能说明:</b></p>
|
|
* <ul>
|
|
* <li>向订阅的前端看板推送实时数据</li>
|
|
* <li>支持按看板类型定向推送</li>
|
|
* <li>支持广播推送到所有看板</li>
|
|
* </ul>
|
|
*
|
|
* <p><b>订阅主题列表:</b></p>
|
|
* <ul>
|
|
* <li>/topic/dashboard/manual-picking - 人工拣选看板</li>
|
|
* <li>/topic/dashboard/robot-picking - 机械臂拣选看板</li>
|
|
* <li>/topic/dashboard/slitting-board - 分切区看板</li>
|
|
* <li>/topic/dashboard/inventory-board - 库存分析看板</li>
|
|
* <li>/topic/dashboard/warehouse-3d - 智能立体仓库看板</li>
|
|
* </ul>
|
|
*
|
|
* @author System
|
|
* @since 2025-01-23
|
|
*/
|
|
@Slf4j
|
|
@Service
|
|
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);
|
|
}
|
|
|
|
/**
|
|
* 推送人工拣选看板数据
|
|
*
|
|
* @param data 看板数据
|
|
*/
|
|
public void pushManualPickingData(Map<String, Object> data) {
|
|
try {
|
|
messagingTemplate.convertAndSend("/topic/dashboard/manual-picking",
|
|
createResponseWithServerTime(data));
|
|
} catch (Exception e) {
|
|
log.error("推送人工拣选看板数据失败: {}", e.getMessage(), e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 推送机械臂拣选看板数据
|
|
*
|
|
* @param data 看板数据
|
|
*/
|
|
public void pushRobotPickingData(Map<String, Object> data) {
|
|
try {
|
|
messagingTemplate.convertAndSend("/topic/dashboard/robot-picking",
|
|
createResponseWithServerTime(data));
|
|
} catch (Exception e) {
|
|
log.error("推送机械臂拣选看板数据失败: {}", e.getMessage(), e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 推送分切区看板数据
|
|
*
|
|
* @param data 看板数据
|
|
*/
|
|
public void pushSlittingBoardData(Map<String, Object> data) {
|
|
try {
|
|
messagingTemplate.convertAndSend("/topic/dashboard/slitting-board",
|
|
createResponseWithServerTime(data));
|
|
} catch (Exception e) {
|
|
log.error("推送分切区看板数据失败: {}", e.getMessage(), e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 推送库存分析看板数据
|
|
*
|
|
* @param data 看板数据
|
|
*/
|
|
public void pushInventoryBoardData(Map<String, Object> data) {
|
|
try {
|
|
messagingTemplate.convertAndSend("/topic/dashboard/inventory-board",
|
|
createResponseWithServerTime(data));
|
|
} catch (Exception e) {
|
|
log.error("推送库存分析看板数据失败: {}", e.getMessage(), e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 推送成品入库出库区看板数据
|
|
*
|
|
* @param data 看板数据
|
|
*/
|
|
public void pushFinishedProductBoardData(Map<String, Object> data) {
|
|
try {
|
|
messagingTemplate.convertAndSend("/topic/dashboard/finished-product-board",
|
|
createResponseWithServerTime(data));
|
|
} catch (Exception e) {
|
|
log.error("推送成品入库出库区看板数据失败: {}", e.getMessage(), e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 推送原材收货区看板数据
|
|
*
|
|
* @param data 看板数据
|
|
*/
|
|
public void pushMaterialReceivingBoardData(Map<String, Object> data) {
|
|
try {
|
|
messagingTemplate.convertAndSend("/topic/dashboard/material-receiving-board",
|
|
createResponseWithServerTime(data));
|
|
} catch (Exception e) {
|
|
log.error("推送原材收货区看板数据失败: {}", e.getMessage(), e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 推送缓存区看板数据
|
|
*
|
|
* @param data 看板数据
|
|
*/
|
|
public void pushBufferBoardData(Map<String, Object> data) {
|
|
try {
|
|
messagingTemplate.convertAndSend("/topic/dashboard/buffer-board",
|
|
createResponseWithServerTime(data));
|
|
} catch (Exception e) {
|
|
log.error("推送缓存区看板数据失败: {}", e.getMessage(), e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 推送车间AGV放料区看板数据
|
|
*
|
|
* @param data 看板数据
|
|
*/
|
|
public void pushWorkshopFeedingBoardData(Map<String, Object> data) {
|
|
try {
|
|
messagingTemplate.convertAndSend("/topic/dashboard/workshop-feeding-board",
|
|
createResponseWithServerTime(data));
|
|
} catch (Exception e) {
|
|
log.error("推送车间AGV放料区看板数据失败: {}", e.getMessage(), e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 推送异常处理区看板数据
|
|
*
|
|
* @param data 看板数据
|
|
*/
|
|
public void pushExceptionBoardData(Map<String, Object> data) {
|
|
try {
|
|
messagingTemplate.convertAndSend("/topic/dashboard/exception-board",
|
|
createResponseWithServerTime(data));
|
|
} catch (Exception e) {
|
|
log.error("推送异常处理区看板数据失败: {}", e.getMessage(), e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 广播推送到所有看板
|
|
*
|
|
* @param data 看板数据
|
|
*/
|
|
public void broadcastToAllDashboards(Map<String, Object> data) {
|
|
try {
|
|
messagingTemplate.convertAndSend("/topic/dashboard/broadcast",
|
|
createResponseWithServerTime(data));
|
|
} catch (Exception e) {
|
|
log.error("广播推送到所有看板失败: {}", e.getMessage(), e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 推送智能立体仓库看板数据
|
|
*
|
|
* @param data 看板数据
|
|
*/
|
|
public void pushWarehouse3dBoardData(Map<String, Object> data) {
|
|
try {
|
|
messagingTemplate.convertAndSend("/topic/dashboard/warehouse-3d",
|
|
createResponseWithServerTime(data));
|
|
} catch (Exception e) {
|
|
log.error("推送智能立体仓库看板数据失败: {}", e.getMessage(), e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 推送到指定主题
|
|
*
|
|
* @param topic 主题名称
|
|
* @param data 数据
|
|
*/
|
|
public void pushToTopic(String topic, Object data) {
|
|
try {
|
|
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);
|
|
}
|
|
}
|
|
}
|