| | |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.model.command.StationCommand; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | import java.util.Objects; |
| | | import java.util.function.Supplier; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class StationMoveCoordinator { |
| | | |
| | |
| | | if (session == null || !session.isActive()) { |
| | | return; |
| | | } |
| | | log.info("markCancelPending, taskNo={}, routeVersion={}, cancelReason={}", taskNo, session.getRouteVersion(), cancelReason); |
| | | session.setStatus(StationMoveSession.STATUS_CANCEL_PENDING); |
| | | session.setCancelReason(cancelReason); |
| | | saveSession(session); |
| | |
| | | |
| | | command.setRouteVersion(session.getRouteVersion()); |
| | | saveSession(session); |
| | | log.info("recordDispatch done, taskNo={}, routeVersion={}, reuse={}, prevRouteVersion={}, dispatchStationId={}, triggerName={}", |
| | | taskNo, session.getRouteVersion(), reuseCurrent, |
| | | current == null ? null : current.getRouteVersion(), |
| | | dispatchStationId, triggerName); |
| | | |
| | | if (circleRoute) { |
| | | saveLegacyCircleCommand(taskNo, command); |
| | |
| | | clearLegacyCircleCommand(taskNo); |
| | | return null; |
| | | } |
| | | log.info("cancelSession, taskNo={}, routeVersion={}, cancelReason=reroute_cancelled", taskNo, session.getRouteVersion()); |
| | | session.setStatus(StationMoveSession.STATUS_CANCELLED); |
| | | session.setCancelReason("reroute_cancelled"); |
| | | saveSession(session); |
| | |
| | | } |
| | | StationMoveSession session = sessionRegistry.load(taskNo); |
| | | if (session == null || !Objects.equals(session.getRouteVersion(), routeVersion)) { |
| | | log.warn("updateTerminal skipped: session mismatch, taskNo={}, cmdRouteVersion={}, sessionRouteVersion={}, targetStatus={}, cancelReason={}", |
| | | taskNo, routeVersion, session == null ? null : session.getRouteVersion(), status, cancelReason); |
| | | return; |
| | | } |
| | | log.info("updateTerminal, taskNo={}, routeVersion={}, status={}, cancelReason={}", taskNo, routeVersion, status, cancelReason); |
| | | session.setCurrentStationId(currentStationId); |
| | | session.setStatus(status); |
| | | session.setCancelReason(cancelReason); |
| | |
| | | import com.alibaba.fastjson.serializer.SerializerFeature; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class StationMoveSessionRegistry { |
| | | |
| | |
| | | |
| | | public synchronized boolean canDispatchRoute(Integer taskNo, Integer routeVersion) { |
| | | StationMoveSession session = load(taskNo); |
| | | if (session == null || routeVersion == null || !Objects.equals(routeVersion, session.getRouteVersion())) { |
| | | if (session == null) { |
| | | log.warn("canDispatchRoute rejected: session=null, taskNo={}, routeVersion={}", taskNo, routeVersion); |
| | | return false; |
| | | } |
| | | return StationMoveSession.STATUS_WAITING.equals(session.getStatus()) |
| | | if (routeVersion == null) { |
| | | log.warn("canDispatchRoute rejected: routeVersion=null, taskNo={}, session.routeVersion={}, session.status={}", |
| | | taskNo, session.getRouteVersion(), session.getStatus()); |
| | | return false; |
| | | } |
| | | if (!Objects.equals(routeVersion, session.getRouteVersion())) { |
| | | log.warn("canDispatchRoute rejected: routeVersion mismatch, taskNo={}, cmdRouteVersion={}, sessionRouteVersion={}, session.status={}, session.cancelReason={}", |
| | | taskNo, routeVersion, session.getRouteVersion(), session.getStatus(), session.getCancelReason()); |
| | | return false; |
| | | } |
| | | boolean dispatchable = StationMoveSession.STATUS_WAITING.equals(session.getStatus()) |
| | | || StationMoveSession.STATUS_RUNNING.equals(session.getStatus()); |
| | | if (!dispatchable) { |
| | | log.warn("canDispatchRoute rejected: status not dispatchable, taskNo={}, routeVersion={}, session.status={}, session.cancelReason={}", |
| | | taskNo, routeVersion, session.getStatus(), session.getCancelReason()); |
| | | } |
| | | return dispatchable; |
| | | } |
| | | |
| | | public synchronized boolean shouldSkipOutOrderDecision(Integer taskNo, Integer currentStationId) { |
| | |
| | | import com.zy.asrs.domain.vo.StationTaskTraceSegmentVo; |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.enums.SlaveType; |
| | |
| | | import java.util.Map; |
| | | import java.util.function.Function; |
| | | |
| | | @Slf4j |
| | | public class StationSegmentExecutor { |
| | | |
| | | private static final String CFG_STATION_COMMAND_SEGMENT_ADVANCE_RATIO = "stationCommandSegmentAdvanceRatio"; |
| | |
| | | return true; |
| | | } |
| | | StationMoveCoordinator moveCoordinator = loadMoveCoordinator(); |
| | | return moveCoordinator == null || moveCoordinator.canDispatchRoute(taskNo, routeVersion); |
| | | if (moveCoordinator == null) { |
| | | return true; |
| | | } |
| | | boolean dispatchable = moveCoordinator.canDispatchRoute(taskNo, routeVersion); |
| | | if (!dispatchable) { |
| | | log.warn("isRouteDispatchable rejected, taskNo={}, routeVersion={}, threadImpl={}", |
| | | taskNo, routeVersion, deviceConfig == null ? null : deviceConfig.getThreadImpl()); |
| | | } |
| | | return dispatchable; |
| | | } |
| | | |
| | | private StationMoveCoordinator loadMoveCoordinator() { |