package com.zy.core.utils; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.zy.asrs.entity.BasStation; import com.zy.asrs.entity.WrkMast; import com.zy.asrs.service.BasStationService; import com.zy.asrs.service.WrkAnalysisService; import com.zy.asrs.service.WrkMastService; import com.zy.core.News; import com.zy.core.cache.SlaveConnection; import com.zy.core.enums.SlaveType; import com.zy.core.enums.WrkIoType; import com.zy.core.enums.WrkStsType; import com.zy.core.model.protocol.StationProtocol; import com.zy.core.thread.StationThread; import com.zy.core.utils.station.StationDispatchLoadSupport; import com.zy.core.utils.station.StationOutboundDispatchProcessor; import com.zy.core.utils.station.StationRegularDispatchProcessor; import com.zy.core.utils.station.StationRerouteProcessor; import com.zy.core.utils.station.model.RerouteCommandPlan; import com.zy.core.utils.station.model.RerouteContext; import com.zy.core.utils.station.model.RerouteDecision; import com.zy.core.utils.station.model.RerouteExecutionResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Date; import java.util.List; import java.util.Map; @Component public class StationOperateProcessUtils { @Autowired private WrkMastService wrkMastService; @Autowired private BasStationService basStationService; @Autowired private WrkAnalysisService wrkAnalysisService; @Autowired private StationRegularDispatchProcessor stationRegularDispatchProcessor; @Autowired private StationDispatchLoadSupport stationDispatchLoadSupport; @Autowired private StationOutboundDispatchProcessor stationOutboundDispatchProcessor; @Autowired private StationRerouteProcessor stationRerouteProcessor; //执行输送站点入库任务 public synchronized void stationInExecute() { stationRegularDispatchProcessor.stationInExecute(); } //执行堆垛机输送站点出库任务 public synchronized void crnStationOutExecute() { stationOutboundDispatchProcessor.crnStationOutExecute(); } //执行双工位堆垛机输送站点出库任务 public synchronized void dualCrnStationOutExecute() { stationOutboundDispatchProcessor.dualCrnStationOutExecute(); } //检测输送站点出库任务执行完成 public synchronized void stationOutExecuteFinish() { stationRegularDispatchProcessor.stationOutExecuteFinish(); } // 检测入库任务是否到达站台并转为站台运行完成 public synchronized void scanInboundStationArrival() { List wrkMasts = wrkMastService.list(new QueryWrapper() .eq("io_type", 1) .eq("wrk_sts", WrkStsType.INBOUND_STATION_RUN.sts) .isNotNull("sta_no")); for (WrkMast wrkMast : wrkMasts) { if (wrkMast == null || wrkMast.getWrkNo() == null || wrkMast.getStaNo() == null) { continue; } BasStation basStation = basStationService.getOne(new QueryWrapper() .eq("station_id", wrkMast.getStaNo()) .last("limit 1")); if (basStation == null || basStation.getDeviceNo() == null) { continue; } StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basStation.getDeviceNo()); if (stationThread == null) { continue; } Map 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())) { continue; } boolean updated = wrkAnalysisService.completeInboundStationRun(wrkMast, new Date()); if (updated) { News.info("入库站点到达扫描命中,工作号={},目标站={}", wrkMast.getWrkNo(), wrkMast.getStaNo()); } } } // 检测任务转完成 public synchronized void checkTaskToComplete() { stationRegularDispatchProcessor.checkTaskToComplete(); } //检测输送站点是否运行堵塞 public synchronized void checkStationRunBlock() { stationRerouteProcessor.checkStationRunBlock(); } //检测输送站点任务停留超时后重新计算路径 public synchronized void checkStationIdleRecover() { stationRerouteProcessor.checkStationIdleRecover(); } //获取输送线任务数量 public int getCurrentStationTaskCount() { return stationDispatchLoadSupport.countCurrentStationTask(); } public synchronized int getCurrentOutboundTaskCountByTargetStation(Integer stationId) { if (stationId == null) { return 0; } return (int) wrkMastService.count(new QueryWrapper() .eq("io_type", WrkIoType.OUT.id) .eq("sta_no", stationId) .in("wrk_sts", WrkStsType.OUTBOUND_RUN.sts, WrkStsType.OUTBOUND_RUN_COMPLETE.sts, WrkStsType.STATION_RUN.sts)); } // 检测出库排序 public synchronized void checkStationOutOrder() { stationRerouteProcessor.checkStationOutOrder(); } // 监控绕圈站点 public synchronized void watchCircleStation() { stationRerouteProcessor.watchCircleStation(); } RerouteCommandPlan buildRerouteCommandPlan(RerouteContext context, RerouteDecision decision) { return stationRerouteProcessor.buildRerouteCommandPlan(context, decision); } RerouteExecutionResult executeReroutePlan(RerouteContext context, RerouteCommandPlan plan) { return stationRerouteProcessor.executeReroutePlan(context, plan); } RerouteDecision resolveSharedRerouteDecision(RerouteContext context) { return stationRerouteProcessor.resolveSharedRerouteDecision(context); } boolean shouldUseRunBlockDirectReassign(WrkMast wrkMast, Integer stationId, List runBlockReassignLocStationList) { return stationRerouteProcessor.shouldUseRunBlockDirectReassign(wrkMast, stationId, runBlockReassignLocStationList); } private boolean shouldSkipIdleRecoverForRecentDispatch(Integer taskNo, Integer stationId) { return stationRerouteProcessor.shouldSkipIdleRecoverForRecentDispatch(taskNo, stationId); } }