| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.zy.asrs.entity.BasStation; |
| | | import com.zy.asrs.entity.BasCrnp; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.BasStationService; |
| | | import com.zy.asrs.service.BasCrnpService; |
| | | import com.zy.asrs.service.WrkAnalysisService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.common.entity.FindCrnNoResult; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.enums.StationCommandType; |
| | | import com.zy.core.enums.WrkStsType; |
| | | import com.zy.core.move.StationMoveCoordinator; |
| | | import com.zy.core.move.StationMoveSession; |
| | | import com.zy.core.model.CommandResponse; |
| | | import com.zy.core.model.command.StationCommand; |
| | | import com.zy.core.model.protocol.StationProtocol; |
| | | import com.zy.core.thread.StationThread; |
| | | import com.zy.core.utils.CrnOperateProcessUtils; |
| | | import com.zy.core.utils.StationOperateProcessUtils; |
| | | import org.junit.jupiter.api.Test; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | |
| | | BasStationService basStationService = mock(BasStationService.class); |
| | | WrkAnalysisService wrkAnalysisService = mock(WrkAnalysisService.class); |
| | | StationOperateProcessUtils stationOperateProcessUtils = mock(StationOperateProcessUtils.class); |
| | | StationMoveCoordinator stationMoveCoordinator = mock(StationMoveCoordinator.class); |
| | | CommonService commonService = mock(CommonService.class); |
| | | BasCrnpService basCrnpService = mock(BasCrnpService.class); |
| | | CrnOperateProcessUtils crnOperateProcessUtils = mock(CrnOperateProcessUtils.class); |
| | | |
| | | WrkAnalysisStationArrivalScanner scanner = new WrkAnalysisStationArrivalScanner( |
| | | wrkMastService, |
| | | basStationService, |
| | | wrkAnalysisService, |
| | | stationOperateProcessUtils, |
| | | stationMoveCoordinator, |
| | | commonService, |
| | | basCrnpService, |
| | | crnOperateProcessUtils |
| | | stationOperateProcessUtils |
| | | ); |
| | | |
| | | WrkMast wrkMast = new WrkMast(); |
| | | wrkMast.setWrkNo(1001); |
| | | wrkMast.setIoType(1); |
| | | wrkMast.setWrkSts(WrkStsType.INBOUND_STATION_RUN.sts); |
| | | wrkMast.setStaNo(12); |
| | | |
| | | BasStation basStation = new BasStation(); |
| | | basStation.setStationId(12); |
| | | basStation.setDeviceNo(3); |
| | | WrkMast wrkMast = inboundWrkMast(1001, 12); |
| | | BasStation basStation = station(12, 3); |
| | | |
| | | when(wrkMastService.list(any(QueryWrapper.class))).thenReturn(List.of(wrkMast)); |
| | | when(basStationService.getOne(any())).thenReturn(basStation); |
| | |
| | | } |
| | | |
| | | @Test |
| | | void scanInboundStationArrival_dispatchesCrnMoveWhenOnlyFinalInletStationRemains() { |
| | | void scanInboundStationArrival_completesTaskWhenProtocolMatchesCurrentTask() { |
| | | WrkMastService wrkMastService = mock(WrkMastService.class); |
| | | BasStationService basStationService = mock(BasStationService.class); |
| | | WrkAnalysisService wrkAnalysisService = mock(WrkAnalysisService.class); |
| | | StationOperateProcessUtils stationOperateProcessUtils = mock(StationOperateProcessUtils.class); |
| | | StationMoveCoordinator stationMoveCoordinator = mock(StationMoveCoordinator.class); |
| | | CommonService commonService = mock(CommonService.class); |
| | | BasCrnpService basCrnpService = mock(BasCrnpService.class); |
| | | CrnOperateProcessUtils crnOperateProcessUtils = mock(CrnOperateProcessUtils.class); |
| | | |
| | | WrkAnalysisStationArrivalScanner scanner = new WrkAnalysisStationArrivalScanner( |
| | | wrkMastService, |
| | | basStationService, |
| | | wrkAnalysisService, |
| | | stationOperateProcessUtils, |
| | | stationMoveCoordinator, |
| | | commonService, |
| | | basCrnpService, |
| | | crnOperateProcessUtils |
| | | stationOperateProcessUtils |
| | | ); |
| | | |
| | | WrkMast wrkMast = new WrkMast(); |
| | | wrkMast.setWrkNo(1002); |
| | | wrkMast.setIoType(1); |
| | | wrkMast.setWrkSts(WrkStsType.INBOUND_STATION_RUN.sts); |
| | | wrkMast.setStaNo(12); |
| | | wrkMast.setLocNo("5-6-7"); |
| | | |
| | | BasStation basStation = new BasStation(); |
| | | basStation.setStationId(12); |
| | | basStation.setDeviceNo(3); |
| | | |
| | | StationMoveSession session = new StationMoveSession(); |
| | | session.setStatus(StationMoveSession.STATUS_RUNNING); |
| | | session.setCurrentStationId(11); |
| | | session.setFullPathStationIds(new ArrayList<>(List.of(10, 11, 12))); |
| | | |
| | | FindCrnNoResult findCrnNoResult = new FindCrnNoResult(); |
| | | findCrnNoResult.setCrnNo(1); |
| | | findCrnNoResult.setCrnType(SlaveType.Crn); |
| | | |
| | | BasCrnp basCrnp = new BasCrnp(); |
| | | basCrnp.setCrnNo(1); |
| | | basCrnp.setInStationList("[{\"stationId\":12,\"deviceRow\":2,\"deviceBay\":1,\"deviceLev\":1}]"); |
| | | WrkMast wrkMast = inboundWrkMast(1002, 15); |
| | | BasStation basStation = station(15, 5); |
| | | |
| | | when(wrkMastService.list(any(QueryWrapper.class))).thenReturn(List.of(wrkMast)); |
| | | when(basStationService.getOne(any())).thenReturn(basStation); |
| | | when(stationMoveCoordinator.loadSession(1002)).thenReturn(session); |
| | | when(commonService.findCrnNoByLocNo("5-6-7")).thenReturn(findCrnNoResult); |
| | | when(basCrnpService.getOne(any())).thenReturn(basCrnp); |
| | | when(crnOperateProcessUtils.dispatchCrnMove(1, "2-1-1")).thenReturn(true); |
| | | when(wrkAnalysisService.completeInboundStationRun(any(WrkMast.class), any(Date.class))).thenReturn(true); |
| | | |
| | | ArrivalAwareStationThread stationThread = new ArrivalAwareStationThread(false); |
| | | StationProtocol stationProtocol = new StationProtocol(); |
| | | stationProtocol.setStationId(12); |
| | | stationProtocol.setTaskNo(0); |
| | | stationProtocol.setLoading(false); |
| | | stationProtocol.setStationId(15); |
| | | stationProtocol.setTaskNo(1002); |
| | | stationProtocol.setLoading(true); |
| | | stationThread.putStatus(stationProtocol); |
| | | |
| | | SlaveConnection.put(SlaveType.Devp, 3, stationThread); |
| | | SlaveConnection.put(SlaveType.Devp, 5, stationThread); |
| | | try { |
| | | scanner.scanInboundStationArrival(); |
| | | } finally { |
| | | SlaveConnection.remove(SlaveType.Devp, 3); |
| | | SlaveConnection.remove(SlaveType.Devp, 5); |
| | | } |
| | | |
| | | verify(crnOperateProcessUtils).dispatchCrnMove(1, "2-1-1"); |
| | | verify(wrkAnalysisService, never()).completeInboundStationRun(any(WrkMast.class), any(Date.class)); |
| | | verify(wrkAnalysisService).completeInboundStationRun(any(WrkMast.class), any(Date.class)); |
| | | } |
| | | |
| | | @Test |
| | | void scanInboundStationArrival_skipsCrnMoveWhenTargetInletHasLoadTaskAndInEnable() { |
| | | void scanInboundStationArrival_skipsWhenArrivalWasNotObserved() { |
| | | WrkMastService wrkMastService = mock(WrkMastService.class); |
| | | BasStationService basStationService = mock(BasStationService.class); |
| | | WrkAnalysisService wrkAnalysisService = mock(WrkAnalysisService.class); |
| | | StationOperateProcessUtils stationOperateProcessUtils = mock(StationOperateProcessUtils.class); |
| | | StationMoveCoordinator stationMoveCoordinator = mock(StationMoveCoordinator.class); |
| | | CommonService commonService = mock(CommonService.class); |
| | | BasCrnpService basCrnpService = mock(BasCrnpService.class); |
| | | CrnOperateProcessUtils crnOperateProcessUtils = mock(CrnOperateProcessUtils.class); |
| | | |
| | | WrkAnalysisStationArrivalScanner scanner = new WrkAnalysisStationArrivalScanner( |
| | | wrkMastService, |
| | | basStationService, |
| | | wrkAnalysisService, |
| | | stationOperateProcessUtils, |
| | | stationMoveCoordinator, |
| | | commonService, |
| | | basCrnpService, |
| | | crnOperateProcessUtils |
| | | stationOperateProcessUtils |
| | | ); |
| | | |
| | | WrkMast wrkMast = new WrkMast(); |
| | | wrkMast.setWrkNo(1003); |
| | | wrkMast.setIoType(1); |
| | | wrkMast.setWrkSts(WrkStsType.INBOUND_STATION_RUN.sts); |
| | | wrkMast.setStaNo(12); |
| | | wrkMast.setLocNo("5-6-7"); |
| | | |
| | | BasStation basStation = new BasStation(); |
| | | basStation.setStationId(12); |
| | | basStation.setDeviceNo(3); |
| | | |
| | | StationMoveSession session = new StationMoveSession(); |
| | | session.setStatus(StationMoveSession.STATUS_RUNNING); |
| | | session.setCurrentStationId(11); |
| | | session.setFullPathStationIds(new ArrayList<>(List.of(10, 11, 12))); |
| | | WrkMast wrkMast = inboundWrkMast(1003, 18); |
| | | BasStation basStation = station(18, 8); |
| | | |
| | | when(wrkMastService.list(any(QueryWrapper.class))).thenReturn(List.of(wrkMast)); |
| | | when(basStationService.getOne(any())).thenReturn(basStation); |
| | | when(stationMoveCoordinator.loadSession(1003)).thenReturn(session); |
| | | |
| | | ArrivalAwareStationThread stationThread = new ArrivalAwareStationThread(false); |
| | | StationProtocol stationProtocol = new StationProtocol(); |
| | | stationProtocol.setStationId(12); |
| | | stationProtocol.setStationId(18); |
| | | stationProtocol.setTaskNo(9999); |
| | | stationProtocol.setLoading(true); |
| | | stationProtocol.setInEnable(true); |
| | | stationThread.putStatus(stationProtocol); |
| | | |
| | | SlaveConnection.put(SlaveType.Devp, 3, stationThread); |
| | | SlaveConnection.put(SlaveType.Devp, 8, stationThread); |
| | | try { |
| | | scanner.scanInboundStationArrival(); |
| | | } finally { |
| | | SlaveConnection.remove(SlaveType.Devp, 3); |
| | | SlaveConnection.remove(SlaveType.Devp, 8); |
| | | } |
| | | |
| | | verify(crnOperateProcessUtils, never()).dispatchCrnMove(any(), any()); |
| | | verify(commonService, never()).findCrnNoByLocNo(any()); |
| | | verify(wrkAnalysisService, never()).completeInboundStationRun(any(WrkMast.class), any(Date.class)); |
| | | } |
| | | |
| | | @Test |
| | | void scanInboundStationArrival_dispatchesCrnMoveWhenTargetInletOnlyHasLoad() { |
| | | void scanOutboundStationFlow_triggersStationOperateProcessSteps() { |
| | | WrkMastService wrkMastService = mock(WrkMastService.class); |
| | | BasStationService basStationService = mock(BasStationService.class); |
| | | WrkAnalysisService wrkAnalysisService = mock(WrkAnalysisService.class); |
| | | StationOperateProcessUtils stationOperateProcessUtils = mock(StationOperateProcessUtils.class); |
| | | StationMoveCoordinator stationMoveCoordinator = mock(StationMoveCoordinator.class); |
| | | CommonService commonService = mock(CommonService.class); |
| | | BasCrnpService basCrnpService = mock(BasCrnpService.class); |
| | | CrnOperateProcessUtils crnOperateProcessUtils = mock(CrnOperateProcessUtils.class); |
| | | |
| | | WrkAnalysisStationArrivalScanner scanner = new WrkAnalysisStationArrivalScanner( |
| | | wrkMastService, |
| | | basStationService, |
| | | wrkAnalysisService, |
| | | stationOperateProcessUtils, |
| | | stationMoveCoordinator, |
| | | commonService, |
| | | basCrnpService, |
| | | crnOperateProcessUtils |
| | | stationOperateProcessUtils |
| | | ); |
| | | |
| | | scanner.scanOutboundStationFlow(); |
| | | |
| | | verify(stationOperateProcessUtils).stationOutExecuteFinish(); |
| | | verify(stationOperateProcessUtils).checkTaskToComplete(); |
| | | } |
| | | |
| | | private WrkMast inboundWrkMast(int wrkNo, int stationId) { |
| | | WrkMast wrkMast = new WrkMast(); |
| | | wrkMast.setWrkNo(1004); |
| | | wrkMast.setWrkNo(wrkNo); |
| | | wrkMast.setIoType(1); |
| | | wrkMast.setWrkSts(WrkStsType.INBOUND_STATION_RUN.sts); |
| | | wrkMast.setStaNo(12); |
| | | wrkMast.setLocNo("5-6-7"); |
| | | wrkMast.setStaNo(stationId); |
| | | return wrkMast; |
| | | } |
| | | |
| | | private BasStation station(int stationId, int deviceNo) { |
| | | BasStation basStation = new BasStation(); |
| | | basStation.setStationId(12); |
| | | basStation.setDeviceNo(3); |
| | | |
| | | StationMoveSession session = new StationMoveSession(); |
| | | session.setStatus(StationMoveSession.STATUS_RUNNING); |
| | | session.setCurrentStationId(11); |
| | | session.setFullPathStationIds(new ArrayList<>(List.of(10, 11, 12))); |
| | | |
| | | FindCrnNoResult findCrnNoResult = new FindCrnNoResult(); |
| | | findCrnNoResult.setCrnNo(1); |
| | | findCrnNoResult.setCrnType(SlaveType.Crn); |
| | | |
| | | BasCrnp basCrnp = new BasCrnp(); |
| | | basCrnp.setCrnNo(1); |
| | | basCrnp.setInStationList("[{\"stationId\":12,\"deviceRow\":2,\"deviceBay\":1,\"deviceLev\":1}]"); |
| | | |
| | | when(wrkMastService.list(any(QueryWrapper.class))).thenReturn(List.of(wrkMast)); |
| | | when(basStationService.getOne(any())).thenReturn(basStation); |
| | | when(stationMoveCoordinator.loadSession(1004)).thenReturn(session); |
| | | when(commonService.findCrnNoByLocNo("5-6-7")).thenReturn(findCrnNoResult); |
| | | when(basCrnpService.getOne(any())).thenReturn(basCrnp); |
| | | when(crnOperateProcessUtils.dispatchCrnMove(1, "2-1-1")).thenReturn(true); |
| | | |
| | | ArrivalAwareStationThread stationThread = new ArrivalAwareStationThread(false); |
| | | StationProtocol stationProtocol = new StationProtocol(); |
| | | stationProtocol.setStationId(12); |
| | | stationProtocol.setTaskNo(0); |
| | | stationProtocol.setLoading(true); |
| | | stationProtocol.setInEnable(false); |
| | | stationThread.putStatus(stationProtocol); |
| | | |
| | | SlaveConnection.put(SlaveType.Devp, 3, stationThread); |
| | | try { |
| | | scanner.scanInboundStationArrival(); |
| | | } finally { |
| | | SlaveConnection.remove(SlaveType.Devp, 3); |
| | | } |
| | | |
| | | verify(crnOperateProcessUtils).dispatchCrnMove(1, "2-1-1"); |
| | | verify(wrkAnalysisService, never()).completeInboundStationRun(any(WrkMast.class), any(Date.class)); |
| | | basStation.setStationId(stationId); |
| | | basStation.setDeviceNo(deviceNo); |
| | | return basStation; |
| | | } |
| | | |
| | | private static class ArrivalAwareStationThread implements StationThread { |