|
|
@@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import top.haijunit.train.device.domain.CommandEnum;
|
|
|
import top.haijunit.train.device.entity.DeviceEntity;
|
|
|
+import top.haijunit.train.domain.constant.ControlConstant;
|
|
|
import top.haijunit.train.domain.constant.DirectionEnum;
|
|
|
import top.haijunit.train.domain.constant.DoorStatusEnum;
|
|
|
import top.haijunit.train.domain.entity.PlatformDoorEntity;
|
|
|
@@ -16,6 +17,7 @@ import top.haijunit.train.domain.repository.PlatformDoorRepository;
|
|
|
import top.haijunit.train.utils.TrainWebSocketUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -30,79 +32,141 @@ public class PlatformDoorService {
|
|
|
|
|
|
private final PlatformDoorRepository platformDoorRepository;
|
|
|
|
|
|
- public void updateIbpControl(DeviceEntity entity) {
|
|
|
+ /**
|
|
|
+ * 列车行驶进入站台判断是否有屏蔽门打开的情况,需要情急停车
|
|
|
+ */
|
|
|
+ public boolean existDoorOpen(Long stationId, DirectionEnum direction) {
|
|
|
+ return !platformDoorRepository.getDoorOpen(stationId, direction).isEmpty();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateDoorControl(DeviceEntity entity) {
|
|
|
switch (entity.getCommand()) {
|
|
|
case AFC_IBP:
|
|
|
case PSL_LOCK:
|
|
|
break;
|
|
|
case IBP_CONTROL:
|
|
|
+ if (updateDoorControl(ControlConstant.DoorControl.IBP, entity.getStatus() == 0, Convert.toLong(entity.getCode(), 0L))) {
|
|
|
+ log.info("更新站台门控制: {} -> {}", entity.getStatus(), ControlConstant.DoorControl.IBP);
|
|
|
+ }
|
|
|
+ break;
|
|
|
case PSL_CONTROL:
|
|
|
- // 更新权限
|
|
|
+ if (updateDoorControl(ControlConstant.DoorControl.PSL, entity.getStatus() == 0, Convert.toLong(entity.getCode(), 0L))) {
|
|
|
+ log.info("更新站台门控制: {} -> {}", entity.getStatus(), ControlConstant.DoorControl.PSL);
|
|
|
+ }
|
|
|
break;
|
|
|
case IBP_DOOR_OPEN:
|
|
|
+ updateDoorStatus(ControlConstant.DoorControl.IBP, DoorStatusEnum.OPEN, Convert.toLong(entity.getCode(), 0L));
|
|
|
+ break;
|
|
|
case PSL_DOOR_OPEN:
|
|
|
- sendDoorStatus(DoorStatusEnum.OPEN, Convert.toLong(entity.getCode(), 0L));
|
|
|
+ updateDoorStatus(ControlConstant.DoorControl.PSL, DoorStatusEnum.OPEN, Convert.toLong(entity.getCode(), 0L));
|
|
|
break;
|
|
|
case IBP_DOOR_CLOSE:
|
|
|
+ updateDoorStatus(ControlConstant.DoorControl.IBP, DoorStatusEnum.CLOSE, Convert.toLong(entity.getCode(), 0L));
|
|
|
+ break;
|
|
|
case PSL_DOOR_CLOSE:
|
|
|
- sendDoorStatus(DoorStatusEnum.CLOSE, Convert.toLong(entity.getCode(), 0L));
|
|
|
+ updateDoorStatus(ControlConstant.DoorControl.PSL, DoorStatusEnum.CLOSE, Convert.toLong(entity.getCode(), 0L));
|
|
|
break;
|
|
|
case PLATFORM_DOOR_LCW:
|
|
|
// LCW 更新屏蔽门
|
|
|
- List<PlatformDoorEntity> list = new ArrayList<>();
|
|
|
- list.add(platformDoorRepository.getReferenceById(Convert.toLong(entity.getCode(), 0L)));
|
|
|
+ Long doorId = Convert.toLong(entity.getCode(), 0L);
|
|
|
switch (entity.getStatus()) {
|
|
|
case 1:
|
|
|
- sendDoorStatus(DoorStatusEnum.OPEN, list);
|
|
|
+ updateDoorStatus(ControlConstant.DoorControl.LCW, DoorStatusEnum.OPEN, Collections.singletonList(platformDoorRepository.getReferenceById(doorId)));
|
|
|
break;
|
|
|
case 2:
|
|
|
- sendDoorStatus(DoorStatusEnum.CLOSE, list);
|
|
|
+ updateDoorStatus(ControlConstant.DoorControl.LCW, DoorStatusEnum.CLOSE, Collections.singletonList(platformDoorRepository.getReferenceById(doorId)));
|
|
|
break;
|
|
|
case 3:
|
|
|
- sendDoorStatus(DoorStatusEnum.DISABLE, list);
|
|
|
+ updateDoorStatus(ControlConstant.DoorControl.LCW, DoorStatusEnum.DISABLE, Collections.singletonList(platformDoorRepository.getReferenceById(doorId)));
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取可操作的控制源
|
|
|
+ * 控制顺序:LCW > PSL > IBP > AUTO
|
|
|
+ */
|
|
|
+ private List<String> getControlOriginList(String origin) {
|
|
|
+ List<String> originList = new ArrayList<>();
|
|
|
+ switch (origin) {
|
|
|
+ case "LCW":
|
|
|
+ originList.add(origin);
|
|
|
+ case "PSL":
|
|
|
+ originList.add(origin);
|
|
|
+ case "IBP":
|
|
|
+ originList.add(origin);
|
|
|
+ case "AUTO":
|
|
|
+ default:
|
|
|
+ originList.add(origin);
|
|
|
+ }
|
|
|
+ return originList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新对屏蔽门的控制
|
|
|
+ */
|
|
|
+ public boolean updateDoorControl(String origin, boolean effect, Long platformId) {
|
|
|
+ List<String> originList = getControlOriginList(origin);
|
|
|
+ List<PlatformDoorEntity> list = platformDoorRepository.getPlatformIdAndControlOriginIn(platformId, originList);
|
|
|
+ if (CollUtil.isEmpty(list)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ list.forEach(entity -> {
|
|
|
+ entity.setControlOrigin(effect ? origin : ControlConstant.DoorControl.AUTO);
|
|
|
+ platformDoorRepository.save(entity);
|
|
|
+ });
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 信号更新屏蔽门
|
|
|
- * @param state 状态
|
|
|
- * @param stationId 车站Id
|
|
|
- * @param direction 方向
|
|
|
*/
|
|
|
- public void sendDoorStatus(DoorStatusEnum state, Long stationId, DirectionEnum direction) {
|
|
|
- sendDoorStatus(state, platformDoorRepository.findByStationIdAndDirection(stationId, direction));
|
|
|
+ public void updateDoorStatus(DoorStatusEnum state, Long stationId, DirectionEnum direction) {
|
|
|
+ updateDoorStatus(ControlConstant.DoorControl.AUTO, state, platformDoorRepository.getStationIdAndDirection(stationId, direction, getControlOriginList(ControlConstant.DoorControl.AUTO)));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * IBP PSL 更新屏蔽门
|
|
|
- * @param state 状态
|
|
|
- * @param platformId 平台Id
|
|
|
+ * 更新屏蔽门状态
|
|
|
+ *
|
|
|
+ * @param origin 来源
|
|
|
+ * @param state 状态
|
|
|
+ * @param platformId 站台Id
|
|
|
*/
|
|
|
- public List<PlatformDoorEntity> sendDoorStatus(DoorStatusEnum state, Long platformId) {
|
|
|
- return sendDoorStatus(state, platformDoorRepository.findByPlatformId(platformId));
|
|
|
+ public void updateDoorStatus(String origin, DoorStatusEnum state, Long platformId) {
|
|
|
+ List<String> originList = getControlOriginList(origin);
|
|
|
+ List<PlatformDoorEntity> list = platformDoorRepository.getPlatformIdAndControlOriginIn(platformId, originList);
|
|
|
+ if (CollUtil.isEmpty(list)) {
|
|
|
+ log.error("没有找到屏蔽门,站台:{},控制源:{}", platformId, originList);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ updateDoorStatus(origin, state, list);
|
|
|
}
|
|
|
|
|
|
- private List<PlatformDoorEntity> sendDoorStatus(DoorStatusEnum state, List<PlatformDoorEntity> doorList) {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 信号更新屏蔽门
|
|
|
+ *
|
|
|
+ * @param state 状态
|
|
|
+ * @param doorList 站台门实体
|
|
|
+ */
|
|
|
+ private void updateDoorStatus(String origin, DoorStatusEnum state, List<PlatformDoorEntity> doorList) {
|
|
|
List<PlatformDoorEntity> list = new ArrayList<>();
|
|
|
for (PlatformDoorEntity entity : doorList) {
|
|
|
if (entity.getStatus() == DoorStatusEnum.DISABLE) {
|
|
|
continue;
|
|
|
}
|
|
|
entity.setStatus(state);
|
|
|
+ entity.setControlOrigin(origin);
|
|
|
list.add(entity);
|
|
|
JSONObject doorData = JSONUtil.createObj();
|
|
|
doorData.set(CommandEnum.PLATFORM_DOOR_LOCK.getNameStr(), Convert.toStr(entity.getId(), ""));
|
|
|
doorData.set(CommandEnum.PLATFORM_DOOR_LOCK.getStatusStr(), state.getCode());
|
|
|
TrainWebSocketUtils.sendMessage(CommandEnum.PLATFORM_DOOR_LOCK, doorData);
|
|
|
}
|
|
|
- if (CollUtil.isEmpty(list)) {
|
|
|
- return list;
|
|
|
- } else {
|
|
|
- return platformDoorRepository.saveAllAndFlush(list);
|
|
|
+ if (CollUtil.isNotEmpty(list)) {
|
|
|
+ platformDoorRepository.saveAllAndFlush(list);
|
|
|
}
|
|
|
}
|
|
|
}
|