|
|
@ -27,10 +27,11 @@ import java.util.concurrent.locks.ReentrantLock; |
|
|
|
|
|
|
|
|
@Slf4j |
|
|
@Slf4j |
|
|
public class FrontendMessagePushService implements MqttCallback { |
|
|
public class FrontendMessagePushService implements MqttCallback { |
|
|
|
|
|
public static final FrontendMessagePushService INSTANCE = new FrontendMessagePushService(); |
|
|
|
|
|
|
|
|
private volatile LccConfigProperties.FrontendMqtt mqttConfig; |
|
|
private volatile LccConfigProperties.FrontendMqtt mqttConfig; |
|
|
private volatile String clientId; |
|
|
private volatile String clientId; |
|
|
private volatile MqttClient mqttClient; |
|
|
private volatile MqttClient mqttClient; |
|
|
private final LogisticsRuntime runtime; |
|
|
|
|
|
private final MemoryPersistence persistence = new MemoryPersistence(); |
|
|
private final MemoryPersistence persistence = new MemoryPersistence(); |
|
|
|
|
|
|
|
|
private final Lock connectionLock = new ReentrantLock(); |
|
|
private final Lock connectionLock = new ReentrantLock(); |
|
|
@ -46,8 +47,7 @@ public class FrontendMessagePushService implements MqttCallback { |
|
|
@Getter |
|
|
@Getter |
|
|
private volatile boolean connected = false; |
|
|
private volatile boolean connected = false; |
|
|
|
|
|
|
|
|
public FrontendMessagePushService(LogisticsRuntime runtime) { |
|
|
private FrontendMessagePushService() { |
|
|
this.runtime = runtime; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -64,7 +64,7 @@ public class FrontendMessagePushService implements MqttCallback { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
log.info("Starting FRONTEND_MQTT service for project: {}, env: {}", this.runtime.projectUuid, this.runtime.envId); |
|
|
log.info("Starting FRONTEND_MQTT service for clientId: {}", this.clientId); |
|
|
|
|
|
|
|
|
// 创建MQTT客户端
|
|
|
// 创建MQTT客户端
|
|
|
mqttClient = new MqttClient(mqttConfig.getBrokerUrl(), clientId, persistence); |
|
|
mqttClient = new MqttClient(mqttConfig.getBrokerUrl(), clientId, persistence); |
|
|
@ -139,10 +139,11 @@ public class FrontendMessagePushService implements MqttCallback { |
|
|
* 推送服务器状态 |
|
|
* 推送服务器状态 |
|
|
* /lcc/{proj_id}/{env_id}/server |
|
|
* /lcc/{proj_id}/{env_id}/server |
|
|
* |
|
|
* |
|
|
|
|
|
* @param runtime 运行时环境 |
|
|
* @param statusData 状态数据 |
|
|
* @param statusData 状态数据 |
|
|
*/ |
|
|
*/ |
|
|
public void pushServerState(ServerStatusVo statusData) { |
|
|
public void pushServerState(LogisticsRuntime runtime, ServerStatusVo statusData) { |
|
|
String topic = buildTopic("server"); |
|
|
String topic = buildTopic(runtime, "server"); |
|
|
publishJson(topic, statusData); |
|
|
publishJson(topic, statusData); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -150,10 +151,11 @@ public class FrontendMessagePushService implements MqttCallback { |
|
|
* 推送客户端状态 |
|
|
* 推送客户端状态 |
|
|
* /lcc/{proj_id}/{env_id}/client |
|
|
* /lcc/{proj_id}/{env_id}/client |
|
|
* |
|
|
* |
|
|
|
|
|
* @param runtime 运行时环境 |
|
|
* @param clientData 客户端数据 |
|
|
* @param clientData 客户端数据 |
|
|
*/ |
|
|
*/ |
|
|
public void pushClientState(Map<String, Object> clientData) { |
|
|
public void pushClientState(LogisticsRuntime runtime, Map<String, Object> clientData) { |
|
|
String topic = buildTopic("client"); |
|
|
String topic = buildTopic(runtime, "client"); |
|
|
publishJson(topic, clientData); |
|
|
publishJson(topic, clientData); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -161,10 +163,11 @@ public class FrontendMessagePushService implements MqttCallback { |
|
|
* 推送任务更新 |
|
|
* 推送任务更新 |
|
|
* /lcc/{proj_id}/{env_id}/task |
|
|
* /lcc/{proj_id}/{env_id}/task |
|
|
* |
|
|
* |
|
|
|
|
|
* @param runtime 运行时环境 |
|
|
* @param taskData 任务数据 |
|
|
* @param taskData 任务数据 |
|
|
*/ |
|
|
*/ |
|
|
public void pushTaskUpdate(Object taskData) { |
|
|
public void pushTaskUpdate(LogisticsRuntime runtime, Object taskData) { |
|
|
String topic = buildTopic("task"); |
|
|
String topic = buildTopic(runtime, "task"); |
|
|
publishJson(topic, taskData); |
|
|
publishJson(topic, taskData); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -172,13 +175,14 @@ public class FrontendMessagePushService implements MqttCallback { |
|
|
* 推送库存更新 |
|
|
* 推送库存更新 |
|
|
* /lcc/{proj_id}/{env_id}/inv |
|
|
* /lcc/{proj_id}/{env_id}/inv |
|
|
* |
|
|
* |
|
|
|
|
|
* @param runtime 运行时环境 |
|
|
* @param lpn 容器号 |
|
|
* @param lpn 容器号 |
|
|
* @param before 更新前库存 |
|
|
* @param before 更新前库存 |
|
|
* @param after 更新后库存 |
|
|
* @param after 更新后库存 |
|
|
* @param qty 更新数量 |
|
|
* @param qty 更新数量 |
|
|
*/ |
|
|
*/ |
|
|
public void pushInvUpdate(String lpn, BasLocationVo before, BasLocationVo after, int qty) { |
|
|
public void pushInvUpdate(LogisticsRuntime runtime, String lpn, BasLocationVo before, BasLocationVo after, int qty) { |
|
|
String topic = buildTopic("inv"); |
|
|
String topic = buildTopic(runtime, "inv"); |
|
|
|
|
|
|
|
|
publishJson(topic, new InvUpdateVo( |
|
|
publishJson(topic, new InvUpdateVo( |
|
|
lpn, |
|
|
lpn, |
|
|
@ -192,23 +196,25 @@ public class FrontendMessagePushService implements MqttCallback { |
|
|
* 推送设备状态 |
|
|
* 推送设备状态 |
|
|
* /lcc/{proj_id}/{env_id}/device/{id}/status |
|
|
* /lcc/{proj_id}/{env_id}/device/{id}/status |
|
|
* |
|
|
* |
|
|
|
|
|
* @param runtime 运行时环境 |
|
|
* @param deviceId 设备ID |
|
|
* @param deviceId 设备ID |
|
|
* @param statusData 状态数据 |
|
|
* @param statusData 状态数据 |
|
|
*/ |
|
|
*/ |
|
|
public void pushDeviceStatus(String deviceId, AgvStatusVo statusData) { |
|
|
public void pushDeviceStatus(LogisticsRuntime runtime, String deviceId, AgvStatusVo statusData) { |
|
|
String topic = buildTopic("device/" + deviceId + "/status"); |
|
|
String topic = buildTopic(runtime, "device/" + deviceId + "/status"); |
|
|
publishJson(topic, statusData); |
|
|
publishJson(topic, statusData); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 推送设备存活状态 |
|
|
* 推送设备存活状态 |
|
|
* |
|
|
* |
|
|
|
|
|
* @param runtime 运行时环境 |
|
|
* @param deviceId 设备ID |
|
|
* @param deviceId 设备ID |
|
|
* @param type 设备类型 |
|
|
* @param type 设备类型 |
|
|
* @param online 是否在线 |
|
|
* @param online 是否在线 |
|
|
*/ |
|
|
*/ |
|
|
public void pushDeviceAlive(String deviceId, String type, boolean online) { |
|
|
public void pushDeviceAlive(LogisticsRuntime runtime, String deviceId, String type, boolean online) { |
|
|
String topic = buildTopic("device/" + deviceId + "/alive"); |
|
|
String topic = buildTopic(runtime, "device/" + deviceId + "/alive"); |
|
|
|
|
|
|
|
|
Map<String, Object> data = new HashMap<>(); |
|
|
Map<String, Object> data = new HashMap<>(); |
|
|
data.put("id", deviceId); |
|
|
data.put("id", deviceId); |
|
|
@ -222,11 +228,12 @@ public class FrontendMessagePushService implements MqttCallback { |
|
|
* 推送日志 |
|
|
* 推送日志 |
|
|
* /lcc/{proj_id}/{env_id}/log/{type} |
|
|
* /lcc/{proj_id}/{env_id}/log/{type} |
|
|
* |
|
|
* |
|
|
|
|
|
* @param runtime 运行时环境 |
|
|
* @param logType 日志类型 |
|
|
* @param logType 日志类型 |
|
|
* @param logData 日志数据 |
|
|
* @param logData 日志数据 |
|
|
*/ |
|
|
*/ |
|
|
public void pushLogs(String logType, Object logData) { |
|
|
public void pushLogs(LogisticsRuntime runtime, String logType, Object logData) { |
|
|
String topic = buildTopic("log/" + logType); |
|
|
String topic = buildTopic(runtime, "log/" + logType); |
|
|
publishJson(topic, logData); |
|
|
publishJson(topic, logData); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -234,10 +241,11 @@ public class FrontendMessagePushService implements MqttCallback { |
|
|
* 推送告警 |
|
|
* 推送告警 |
|
|
* /lcc/{proj_id}/{env_id}/alarm |
|
|
* /lcc/{proj_id}/{env_id}/alarm |
|
|
* |
|
|
* |
|
|
|
|
|
* @param runtime 运行时环境 |
|
|
* @param alarmData 告警数据 |
|
|
* @param alarmData 告警数据 |
|
|
*/ |
|
|
*/ |
|
|
public void pushAlarm(Object alarmData) { |
|
|
public void pushAlarm(LogisticsRuntime runtime, Object alarmData) { |
|
|
String topic = buildTopic("alarm"); |
|
|
String topic = buildTopic(runtime, "alarm"); |
|
|
publishJson(topic, alarmData); |
|
|
publishJson(topic, alarmData); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -245,11 +253,12 @@ public class FrontendMessagePushService implements MqttCallback { |
|
|
* 推送脚本更新 |
|
|
* 推送脚本更新 |
|
|
* /lcc/{proj_id}/script |
|
|
* /lcc/{proj_id}/script |
|
|
* |
|
|
* |
|
|
|
|
|
* @param runtime 运行时环境 |
|
|
* @param scriptData 脚本数据 |
|
|
* @param scriptData 脚本数据 |
|
|
*/ |
|
|
*/ |
|
|
public void pushScriptUpdate(Object scriptData) { |
|
|
public void pushScriptUpdate(LogisticsRuntime runtime, Object scriptData) { |
|
|
// 脚本系统没有环境ID
|
|
|
// 脚本系统没有环境ID
|
|
|
String topic = "/lcc/" + this.runtime.projectUuid + "/script"; |
|
|
String topic = "/lcc/" + runtime.projectUuid + "/script"; |
|
|
publishJson(topic, scriptData); |
|
|
publishJson(topic, scriptData); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -258,8 +267,8 @@ public class FrontendMessagePushService implements MqttCallback { |
|
|
/** |
|
|
/** |
|
|
* 构建主题路径 |
|
|
* 构建主题路径 |
|
|
*/ |
|
|
*/ |
|
|
private String buildTopic(String suffix) { |
|
|
private String buildTopic(LogisticsRuntime runtime, String suffix) { |
|
|
return "/lcc/" + this.runtime.projectUuid + "/" + this.runtime.envId + "/" + suffix; |
|
|
return "/lcc/" + runtime.projectUuid + "/" + runtime.envId + "/" + suffix; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|