| | |
| | | package com.zy.core.utils; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.entity.BasStation; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.BasDevpService; |
| | | import com.zy.asrs.service.BasStationService; |
| | | import com.zy.asrs.service.WrkAnalysisService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.enums.WrkIoType; |
| | | import com.zy.core.enums.WrkStsType; |
| | | import com.zy.core.model.StationObjModel; |
| | | import com.zy.core.model.protocol.StationProtocol; |
| | | import com.zy.core.task.MainProcessLane; |
| | | import com.zy.core.task.MainProcessTaskSubmitter; |
| | | import com.zy.core.thread.StationThread; |
| | | import com.zy.core.utils.station.StationDispatchLoadSupport; |
| | | import com.zy.core.utils.station.StationOutboundDispatchProcessor; |
| | |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | @Autowired |
| | | private BasStationService basStationService; |
| | | @Autowired |
| | | private WrkAnalysisService wrkAnalysisService; |
| | |
| | | private StationOutboundDispatchProcessor stationOutboundDispatchProcessor; |
| | | @Autowired |
| | | private StationRerouteProcessor stationRerouteProcessor; |
| | | @Autowired |
| | | private MainProcessTaskSubmitter mainProcessTaskSubmitter; |
| | | |
| | | //执行输送站点入库任务 |
| | | public synchronized void stationInExecute() { |
| | | stationRegularDispatchProcessor.stationInExecute(); |
| | | } |
| | | |
| | | // 执行单个站点的入库任务下发 |
| | | public void stationInExecute(BasDevp basDevp, StationObjModel stationObjModel) { |
| | | stationRegularDispatchProcessor.stationInExecute(basDevp, stationObjModel); |
| | | } |
| | | |
| | | //执行堆垛机输送站点出库任务 |
| | | public synchronized void crnStationOutExecute() { |
| | | stationOutboundDispatchProcessor.crnStationOutExecute(); |
| | | } |
| | | |
| | | // 执行单个出库任务对应的输送站点下发 |
| | | public void crnStationOutExecute(WrkMast wrkMast) { |
| | | stationOutboundDispatchProcessor.crnStationOutExecute(wrkMast); |
| | | } |
| | | |
| | | //执行双工位堆垛机输送站点出库任务 |
| | |
| | | //检测输送站点出库任务执行完成 |
| | | public synchronized void stationOutExecuteFinish() { |
| | | stationRegularDispatchProcessor.stationOutExecuteFinish(); |
| | | } |
| | | |
| | | // 检测单个出库任务是否到达目标站台 |
| | | public void stationOutExecuteFinish(WrkMast wrkMast) { |
| | | stationRegularDispatchProcessor.stationOutExecuteFinish(wrkMast); |
| | | } |
| | | |
| | | // 检测入库任务是否到达站台并转为站台运行完成 |
| | |
| | | } |
| | | } |
| | | |
| | | // 检测单个入库任务是否到达目标站台 |
| | | public void scanInboundStationArrival(WrkMast wrkMast) { |
| | | if (wrkMast == null || wrkMast.getWrkNo() == null || wrkMast.getStaNo() == null) { |
| | | return; |
| | | } |
| | | BasStation basStation = basStationService.getOne(new QueryWrapper<BasStation>() |
| | | .eq("station_id", wrkMast.getStaNo()) |
| | | .last("limit 1")); |
| | | if (basStation == null || basStation.getDeviceNo() == null) { |
| | | return; |
| | | } |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basStation.getDeviceNo()); |
| | | if (stationThread == null) { |
| | | return; |
| | | } |
| | | Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap(); |
| | | StationProtocol stationProtocol = statusMap == null ? null : statusMap.get(basStation.getStationId()); |
| | | boolean arrived = stationProtocol != null |
| | | && wrkMast.getWrkNo().equals(stationProtocol.getTaskNo()) |
| | | && stationProtocol.isLoading(); |
| | | if (!arrived && !stationThread.hasRecentArrival(basStation.getStationId(), wrkMast.getWrkNo())) { |
| | | return; |
| | | } |
| | | boolean updated = wrkAnalysisService.completeInboundStationRun(wrkMast, new Date()); |
| | | if (updated) { |
| | | News.info("入库站点到达扫描命中,工作号={},目标站={}", wrkMast.getWrkNo(), wrkMast.getStaNo()); |
| | | } |
| | | } |
| | | |
| | | // 检测任务转完成 |
| | | public synchronized void checkTaskToComplete() { |
| | | stationRegularDispatchProcessor.checkTaskToComplete(); |
| | | } |
| | | |
| | | // 检测单个出库任务是否可以转完成 |
| | | public void checkTaskToComplete(WrkMast wrkMast) { |
| | | stationRegularDispatchProcessor.checkTaskToComplete(wrkMast); |
| | | } |
| | | |
| | | //检测输送站点是否运行堵塞 |
| | |
| | | stationRerouteProcessor.checkStationRunBlock(); |
| | | } |
| | | |
| | | // 检测单个站点是否运行堵塞 |
| | | public void checkStationRunBlock(BasDevp basDevp, Integer stationId) { |
| | | stationRerouteProcessor.checkStationRunBlock(basDevp, stationId); |
| | | } |
| | | |
| | | //检测输送站点任务停留超时后重新计算路径 |
| | | public synchronized void checkStationIdleRecover() { |
| | | stationRerouteProcessor.checkStationIdleRecover(); |
| | | } |
| | | |
| | | // 检测单个站点任务停留超时后的恢复处理 |
| | | public void checkStationIdleRecover(BasDevp basDevp, Integer stationId) { |
| | | stationRerouteProcessor.checkStationIdleRecover(basDevp, stationId); |
| | | } |
| | | |
| | | //获取输送线任务数量 |
| | |
| | | stationRerouteProcessor.checkStationOutOrder(); |
| | | } |
| | | |
| | | // 检测单个站点的出库排序 |
| | | public void checkStationOutOrder(BasDevp basDevp, StationObjModel stationObjModel) { |
| | | stationRerouteProcessor.checkStationOutOrder(basDevp, stationObjModel); |
| | | } |
| | | |
| | | // 监控绕圈站点 |
| | | public synchronized void watchCircleStation() { |
| | | stationRerouteProcessor.watchCircleStation(); |
| | | } |
| | | |
| | | // 监控单个绕圈站点 |
| | | public void watchCircleStation(BasDevp basDevp, Integer stationId) { |
| | | stationRerouteProcessor.watchCircleStation(basDevp, stationId); |
| | | } |
| | | |
| | | public void submitStationInTasks(long minIntervalMs) { |
| | | submitStationInTasks(MainProcessLane.STATION_IN, minIntervalMs); |
| | | } |
| | | |
| | | public void submitStationInTasks(MainProcessLane lane, long minIntervalMs) { |
| | | List<BasDevp> basDevps = basDevpService.list(new QueryWrapper<>()); |
| | | for (BasDevp basDevp : basDevps) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap(); |
| | | if (stationMap == null || stationMap.isEmpty()) { |
| | | continue; |
| | | } |
| | | for (StationObjModel stationObjModel : basDevp.getBarcodeStationList$()) { |
| | | Integer stationId = stationObjModel == null ? null : stationObjModel.getStationId(); |
| | | if (stationId == null || !stationMap.containsKey(stationId)) { |
| | | continue; |
| | | } |
| | | StationProtocol stationProtocol = stationMap.get(stationId); |
| | | if (stationProtocol == null |
| | | || !stationProtocol.isAutoing() |
| | | || !stationProtocol.isLoading() |
| | | || stationProtocol.getTaskNo() <= 0) { |
| | | continue; |
| | | } |
| | | mainProcessTaskSubmitter.submitKeyedSerialTask( |
| | | lane, |
| | | stationId, |
| | | "stationInExecute", |
| | | minIntervalMs, |
| | | () -> stationInExecute(basDevp, stationObjModel) |
| | | ); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void submitCrnStationOutTasks(long minIntervalMs) { |
| | | submitCrnStationOutTasks(MainProcessLane.STATION_OUT, minIntervalMs); |
| | | } |
| | | |
| | | public void submitCrnStationOutTasks(MainProcessLane lane, long minIntervalMs) { |
| | | List<WrkMast> wrkMasts = wrkMastService.list(new QueryWrapper<WrkMast>() |
| | | .eq("wrk_sts", WrkStsType.OUTBOUND_RUN_COMPLETE.sts) |
| | | .isNotNull("crn_no")); |
| | | for (WrkMast wrkMast : wrkMasts) { |
| | | Integer laneKey = wrkMast == null ? null : wrkMast.getSourceStaNo(); |
| | | if (laneKey == null) { |
| | | laneKey = wrkMast == null ? null : wrkMast.getWrkNo(); |
| | | } |
| | | mainProcessTaskSubmitter.submitKeyedSerialTask( |
| | | lane, |
| | | laneKey, |
| | | "crnStationOutExecute", |
| | | minIntervalMs, |
| | | () -> crnStationOutExecute(wrkMast) |
| | | ); |
| | | } |
| | | } |
| | | |
| | | public void submitStationOutExecuteFinishTasks(long minIntervalMs) { |
| | | submitStationOutExecuteFinishTasks(MainProcessLane.STATION_OUT_FINISH, minIntervalMs); |
| | | } |
| | | |
| | | public void submitStationOutExecuteFinishTasks(MainProcessLane lane, long minIntervalMs) { |
| | | List<WrkMast> wrkMasts = wrkMastService.list(new QueryWrapper<WrkMast>() |
| | | .eq("wrk_sts", WrkStsType.STATION_RUN.sts) |
| | | .isNotNull("sta_no")); |
| | | for (WrkMast wrkMast : wrkMasts) { |
| | | mainProcessTaskSubmitter.submitKeyedSerialTask( |
| | | lane, |
| | | wrkMast.getStaNo(), |
| | | "stationOutExecuteFinish", |
| | | minIntervalMs, |
| | | () -> stationOutExecuteFinish(wrkMast) |
| | | ); |
| | | } |
| | | } |
| | | |
| | | public void submitInboundStationArrivalTasks(long minIntervalMs) { |
| | | submitInboundStationArrivalTasks(MainProcessLane.STATION_IN_ARRIVAL, minIntervalMs); |
| | | } |
| | | |
| | | public void submitInboundStationArrivalTasks(MainProcessLane lane, long minIntervalMs) { |
| | | List<WrkMast> wrkMasts = wrkMastService.list(new QueryWrapper<WrkMast>() |
| | | .eq("io_type", 1) |
| | | .eq("wrk_sts", WrkStsType.INBOUND_STATION_RUN.sts) |
| | | .isNotNull("sta_no")); |
| | | for (WrkMast wrkMast : wrkMasts) { |
| | | mainProcessTaskSubmitter.submitKeyedSerialTask( |
| | | lane, |
| | | wrkMast.getStaNo(), |
| | | "scanInboundStationArrival", |
| | | minIntervalMs, |
| | | () -> scanInboundStationArrival(wrkMast) |
| | | ); |
| | | } |
| | | } |
| | | |
| | | public void submitCheckTaskToCompleteTasks(long minIntervalMs) { |
| | | submitCheckTaskToCompleteTasks(MainProcessLane.STATION_COMPLETE, minIntervalMs); |
| | | } |
| | | |
| | | public void submitCheckTaskToCompleteTasks(MainProcessLane lane, long minIntervalMs) { |
| | | List<WrkMast> wrkMasts = wrkMastService.list(new QueryWrapper<WrkMast>() |
| | | .eq("wrk_sts", WrkStsType.STATION_RUN_COMPLETE.sts) |
| | | .isNotNull("sta_no")); |
| | | for (WrkMast wrkMast : wrkMasts) { |
| | | mainProcessTaskSubmitter.submitKeyedSerialTask( |
| | | lane, |
| | | wrkMast.getStaNo(), |
| | | "checkTaskToComplete", |
| | | minIntervalMs, |
| | | () -> checkTaskToComplete(wrkMast) |
| | | ); |
| | | } |
| | | } |
| | | |
| | | public void submitCheckStationOutOrderTasks(long minIntervalMs) { |
| | | submitCheckStationOutOrderTasks(MainProcessLane.STATION_OUT_ORDER, minIntervalMs); |
| | | } |
| | | |
| | | public void submitCheckStationOutOrderTasks(MainProcessLane lane, long minIntervalMs) { |
| | | List<BasDevp> basDevps = basDevpService.list(new QueryWrapper<>()); |
| | | for (BasDevp basDevp : basDevps) { |
| | | for (StationObjModel stationObjModel : basDevp.getOutOrderList$()) { |
| | | Integer stationId = stationObjModel == null ? null : stationObjModel.getStationId(); |
| | | if (stationId == null) { |
| | | continue; |
| | | } |
| | | mainProcessTaskSubmitter.submitKeyedSerialTask( |
| | | lane, |
| | | stationId, |
| | | "checkStationOutOrder", |
| | | minIntervalMs, |
| | | () -> checkStationOutOrder(basDevp, stationObjModel) |
| | | ); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void submitWatchCircleStationTasks(long minIntervalMs) { |
| | | submitWatchCircleStationTasks(MainProcessLane.STATION_WATCH_CIRCLE, minIntervalMs); |
| | | } |
| | | |
| | | public void submitWatchCircleStationTasks(MainProcessLane lane, long minIntervalMs) { |
| | | List<BasDevp> basDevps = basDevpService.list(new QueryWrapper<>()); |
| | | for (BasDevp basDevp : basDevps) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | for (StationProtocol stationProtocol : stationThread.getStatus()) { |
| | | Integer stationId = stationProtocol == null ? null : stationProtocol.getStationId(); |
| | | if (stationId == null) { |
| | | continue; |
| | | } |
| | | mainProcessTaskSubmitter.submitKeyedSerialTask( |
| | | lane, |
| | | stationId, |
| | | "watchCircleStation", |
| | | minIntervalMs, |
| | | () -> watchCircleStation(basDevp, stationId) |
| | | ); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void submitCheckStationRunBlockTasks(long minIntervalMs) { |
| | | submitCheckStationRunBlockTasks(MainProcessLane.STATION_RUN_BLOCK, minIntervalMs); |
| | | } |
| | | |
| | | public void submitCheckStationRunBlockTasks(MainProcessLane lane, long minIntervalMs) { |
| | | List<BasDevp> basDevps = basDevpService.list(new QueryWrapper<>()); |
| | | for (BasDevp basDevp : basDevps) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | for (StationProtocol stationProtocol : stationThread.getStatus()) { |
| | | Integer stationId = stationProtocol == null ? null : stationProtocol.getStationId(); |
| | | if (stationId == null) { |
| | | continue; |
| | | } |
| | | mainProcessTaskSubmitter.submitKeyedSerialTask( |
| | | lane, |
| | | stationId, |
| | | "checkStationRunBlock", |
| | | minIntervalMs, |
| | | () -> checkStationRunBlock(basDevp, stationId) |
| | | ); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void submitCheckStationIdleRecoverTasks(long minIntervalMs) { |
| | | submitCheckStationIdleRecoverTasks(MainProcessLane.STATION_IDLE_RECOVER, minIntervalMs); |
| | | } |
| | | |
| | | public void submitCheckStationIdleRecoverTasks(MainProcessLane lane, long minIntervalMs) { |
| | | List<BasDevp> basDevps = basDevpService.list(new QueryWrapper<>()); |
| | | for (BasDevp basDevp : basDevps) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | for (StationProtocol stationProtocol : stationThread.getStatus()) { |
| | | Integer stationId = stationProtocol == null ? null : stationProtocol.getStationId(); |
| | | if (stationId == null) { |
| | | continue; |
| | | } |
| | | mainProcessTaskSubmitter.submitKeyedSerialTask( |
| | | lane, |
| | | stationId, |
| | | "checkStationIdleRecover", |
| | | minIntervalMs, |
| | | () -> checkStationIdleRecover(basDevp, stationId) |
| | | ); |
| | | } |
| | | } |
| | | } |
| | | |
| | | RerouteCommandPlan buildRerouteCommandPlan(RerouteContext context, |
| | | RerouteDecision decision) { |
| | | return stationRerouteProcessor.buildRerouteCommandPlan(context, decision); |