|
|
@@ -1,11 +1,18 @@
|
|
|
package top.haijunit.train.listener;
|
|
|
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.context.ApplicationListener;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import top.haijunit.train.device.domain.CommandEnum;
|
|
|
+import top.haijunit.train.device.entity.DeviceEntity;
|
|
|
import top.haijunit.train.device.service.DeviceService;
|
|
|
+import top.haijunit.train.utils.TrainWebSocketUtils;
|
|
|
import top.haijunit.websocket.event.MessageEvent;
|
|
|
|
|
|
/**
|
|
|
@@ -26,11 +33,49 @@ public class MessageEventListener implements ApplicationListener<MessageEvent> {
|
|
|
if (StrUtil.isBlank(event.getMessage())) {
|
|
|
return;
|
|
|
}
|
|
|
- try {
|
|
|
- deviceService.updateDevice(event.getMessage());
|
|
|
- } catch (RuntimeException exception) {
|
|
|
- log.error("消息处理异常: {}", event.getMessage());
|
|
|
+ deviceMessageHandle(event.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Async
|
|
|
+ public void deviceMessageHandle(String message) {
|
|
|
+ try {
|
|
|
+ DeviceEntity entity = deviceService.updateDevice(message);
|
|
|
+ if (entity == null) {
|
|
|
+ return;
|
|
|
}
|
|
|
+ log.info("设备信息更新成功: {}", entity.getCode());
|
|
|
+ switch (entity.getCommand()) {
|
|
|
+ case AFC_GATE_MACHINE_STATUS:
|
|
|
+ TrainWebSocketUtils.sendMessage(CommandEnum.AFC_GATE_MACHINE, getMessage(CommandEnum.AFC_GATE_MACHINE, entity));
|
|
|
+ break;
|
|
|
+ case AFC_TICKETING_AUTO_STATUS:
|
|
|
+ TrainWebSocketUtils.sendMessage(CommandEnum.AFC_TICKETING_AUTO, getMessage(CommandEnum.AFC_TICKETING_AUTO, entity));
|
|
|
+ break;
|
|
|
+ case ELEVATOR_VERTICAL_COMMAND:
|
|
|
+ TrainWebSocketUtils.sendMessage(CommandEnum.ELEVATOR_VERTICAL, getMessage(CommandEnum.ELEVATOR_VERTICAL, entity));
|
|
|
+ case ELEVATOR_HAND_COMMAND:
|
|
|
+ TrainWebSocketUtils.sendMessage(CommandEnum.ELEVATOR_HAND, getMessage(CommandEnum.ELEVATOR_HAND, entity));
|
|
|
+ default:
|
|
|
+ // TrainWebSocketUtils.sendMessage(CommandEnum.PLATFORM_DOOR_LOCK, getMessage(CommandEnum.PLATFORM_DOOR_LOCK, entity));
|
|
|
+ // TrainWebSocketUtils.sendMessage(CommandEnum.PLATFORM_DOOR_CONTROL, getMessage(CommandEnum.PLATFORM_DOOR_CONTROL, entity));
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (RuntimeException exception) {
|
|
|
+ log.error("消息处理异常: {}", message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private JSONObject getMessage(CommandEnum command, DeviceEntity device) {
|
|
|
+ JSONObject data;
|
|
|
+ if (StrUtil.isAllNotBlank(device.getJsonStr())) {
|
|
|
+ data = JSONUtil.parseObj(device.getJsonStr());
|
|
|
+ } else {
|
|
|
+ data = JSONUtil.createObj();
|
|
|
}
|
|
|
+ data.set(command.getNameStr(), device.getCode());
|
|
|
+ data.set(command.getStatusStr(), device.getStatus());
|
|
|
+ data.set("stationId", Convert.toLong(device.getStationId(), 104002L));
|
|
|
+ return data;
|
|
|
}
|
|
|
}
|