|
|
@@ -63,7 +63,7 @@ public class TrainComputerService {
|
|
|
long timeDifference = Math.abs(nowMillis - train.getUpdateTimeMillis());
|
|
|
if (NumberUtil.isLessOrEqual(distance, BigDecimal.ZERO) && timeDifference <= TrainConstant.STOP_TIME_SECOND * 1000) {
|
|
|
// 停车状态 时间不足30S
|
|
|
- this.openOrCloseDoor(sectionList, train, timeDifference > (TrainConstant.STOP_TIME_SECOND - 2) * 1000 ? 1 : 0);
|
|
|
+ train.setOpenDoor(this.openOrCloseDoor(sectionList, train, timeDifference > (TrainConstant.STOP_TIME_SECOND - 2) * 1000 ? 0 : 1));
|
|
|
return train;
|
|
|
}
|
|
|
if (NumberUtil.isGreater(distance, BigDecimal.ZERO)) {
|
|
|
@@ -135,8 +135,12 @@ public class TrainComputerService {
|
|
|
}
|
|
|
|
|
|
// 开关屏蔽门
|
|
|
- @Async
|
|
|
- public void openOrCloseDoor(LinkedList<SectionItem> sectionList, TrainItem train, int state) {
|
|
|
+ public boolean openOrCloseDoor(LinkedList<SectionItem> sectionList, TrainItem train, int state) {
|
|
|
+ // 0 关门 1 开门
|
|
|
+ if ((train.isOpenDoor() && state == 1) || (!train.isOpenDoor() && state == 0)) {
|
|
|
+ // 避免重复发送
|
|
|
+ return train.isOpenDoor();
|
|
|
+ }
|
|
|
// 列车开关门
|
|
|
JSONObject trainData = JSONUtil.createObj();
|
|
|
trainData.set(CommandEnum.TRAIN_OPEN_DOOR.getNameStr(), train.getTrainNo());
|
|
|
@@ -144,15 +148,15 @@ public class TrainComputerService {
|
|
|
TrainWebSocketUtils.sendMessage(CommandEnum.TRAIN_OPEN_DOOR, trainData);
|
|
|
// 站台屏蔽门开关门
|
|
|
Optional<SectionItem> optional = sectionList.stream().filter(item -> item.getSectionId().equals(train.getTrainId())).findFirst();
|
|
|
- if (optional.isEmpty()) {
|
|
|
- return;
|
|
|
- }
|
|
|
- List<PlatformDoorEntity> doorList = platformDoorRepository.findByStationIdAndDirection(optional.get().getStationId(), train.getDirection());
|
|
|
- for (PlatformDoorEntity entity : doorList) {
|
|
|
- JSONObject doorData = JSONUtil.createObj();
|
|
|
- doorData.set(CommandEnum.PLATFORM_DOOR_LOCK.getNameStr(), entity.getId());
|
|
|
- doorData.set(CommandEnum.PLATFORM_DOOR_LOCK.getStatusStr(), state);
|
|
|
- TrainWebSocketUtils.sendMessage(CommandEnum.PLATFORM_DOOR_LOCK, doorData);
|
|
|
+ if (optional.isPresent()) {
|
|
|
+ List<PlatformDoorEntity> doorList = platformDoorRepository.findByStationIdAndDirection(optional.get().getStationId(), train.getDirection());
|
|
|
+ for (PlatformDoorEntity entity : doorList) {
|
|
|
+ JSONObject doorData = JSONUtil.createObj();
|
|
|
+ doorData.set(CommandEnum.PLATFORM_DOOR_LOCK.getNameStr(), entity.getId());
|
|
|
+ doorData.set(CommandEnum.PLATFORM_DOOR_LOCK.getStatusStr(), state);
|
|
|
+ TrainWebSocketUtils.sendMessage(CommandEnum.PLATFORM_DOOR_LOCK, doorData);
|
|
|
+ }
|
|
|
}
|
|
|
+ return state != 0;
|
|
|
}
|
|
|
}
|